minecraft-source/src/net/minecraft/world/level/levelgen/structure/PoolElementStructurePiece.java

116 lines
5.0 KiB
Java

package net.minecraft.world.level.levelgen.structure;
import net.minecraft.world.level.ChunkPos;
import java.util.Random;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.LevelAccessor;
import java.util.Iterator;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.level.levelgen.feature.structures.StructurePoolElementType;
import net.minecraft.util.Deserializer;
import net.minecraft.core.Registry;
import com.mojang.datafixers.types.DynamicOps;
import com.mojang.datafixers.Dynamic;
import net.minecraft.nbt.NbtOps;
import net.minecraft.world.level.levelgen.feature.structures.EmptyPoolElement;
import net.minecraft.nbt.CompoundTag;
import com.google.common.collect.Lists;
import net.minecraft.world.level.levelgen.feature.StructurePieceType;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.levelgen.feature.structures.JigsawJunction;
import java.util.List;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.levelgen.feature.structures.StructurePoolElement;
public abstract class PoolElementStructurePiece extends StructurePiece {
protected final StructurePoolElement element;
protected BlockPos position;
private final int groundLevelDelta;
protected final Rotation rotation;
private final List<JigsawJunction> junctions;
private final StructureManager structureManager;
public PoolElementStructurePiece(final StructurePieceType cfj, final StructureManager cml, final StructurePoolElement cih, final BlockPos fk, final int integer, final Rotation btr, final BoundingBox cky) {
super(cfj, 0);
this.junctions = Lists.newArrayList();
this.structureManager = cml;
this.element = cih;
this.position = fk;
this.groundLevelDelta = integer;
this.rotation = btr;
this.boundingBox = cky;
}
public PoolElementStructurePiece(final StructureManager cml, final CompoundTag jt, final StructurePieceType cfj) {
super(cfj, jt);
this.junctions = Lists.newArrayList();
this.structureManager = cml;
this.position = new BlockPos(jt.getInt("PosX"), jt.getInt("PosY"), jt.getInt("PosZ"));
this.groundLevelDelta = jt.getInt("ground_level_delta");
this.element = Deserializer.<Object, EmptyPoolElement, StructurePoolElementType>deserialize((com.mojang.datafixers.Dynamic<Object>)new Dynamic((DynamicOps)NbtOps.INSTANCE, jt.getCompound("pool_element")), Registry.STRUCTURE_POOL_ELEMENT, "element_type", EmptyPoolElement.INSTANCE);
this.rotation = Rotation.valueOf(jt.getString("rotation"));
this.boundingBox = this.element.getBoundingBox(cml, this.position, this.rotation);
final ListTag jz5 = jt.getList("junctions", 10);
this.junctions.clear();
jz5.forEach(kj -> this.junctions.add(JigsawJunction.deserialize((com.mojang.datafixers.Dynamic<Object>)new Dynamic((DynamicOps)NbtOps.INSTANCE, kj))));
}
@Override
protected void addAdditionalSaveData(final CompoundTag jt) {
jt.putInt("PosX", this.position.getX());
jt.putInt("PosY", this.position.getY());
jt.putInt("PosZ", this.position.getZ());
jt.putInt("ground_level_delta", this.groundLevelDelta);
jt.put("pool_element", (Tag)this.element.serialize((com.mojang.datafixers.types.DynamicOps<Object>)NbtOps.INSTANCE).getValue());
jt.putString("rotation", this.rotation.name());
final ListTag jz3 = new ListTag();
for (final JigsawJunction cid5 : this.junctions) {
jz3.add((Tag)cid5.serialize((com.mojang.datafixers.types.DynamicOps<Object>)NbtOps.INSTANCE).getValue());
}
jt.put("junctions", jz3);
}
@Override
public boolean postProcess(final LevelAccessor bju, final ChunkGenerator<?> bzx, final Random random, final BoundingBox cky, final ChunkPos bje) {
return this.element.place(this.structureManager, bju, bzx, this.position, this.rotation, cky, random);
}
@Override
public void move(final int integer1, final int integer2, final int integer3) {
super.move(integer1, integer2, integer3);
this.position = this.position.offset(integer1, integer2, integer3);
}
@Override
public Rotation getRotation() {
return this.rotation;
}
@Override
public String toString() {
return String.format("<%s | %s | %s | %s>", this.getClass().getSimpleName(), this.position, this.rotation, this.element);
}
public StructurePoolElement getElement() {
return this.element;
}
public BlockPos getPosition() {
return this.position;
}
public int getGroundLevelDelta() {
return this.groundLevelDelta;
}
public void addJunction(final JigsawJunction cid) {
this.junctions.add(cid);
}
public List<JigsawJunction> getJunctions() {
return this.junctions;
}
}