Portals as structure feature
This commit is contained in:
parent
97eacdff1c
commit
40f8342732
7 changed files with 190 additions and 84 deletions
|
@ -125,16 +125,7 @@ public class LakePiece extends BasePiece {
|
|||
BlockState state = chunk.getBlockState(pos);
|
||||
if (state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN)) {
|
||||
if (pos.getY() > 56) {
|
||||
pos.setY(pos.getY() + 1);
|
||||
state = chunk.getBlockState(pos);
|
||||
pos.setY(pos.getY() - 1);
|
||||
if (state.getMaterial().isReplaceable()) {
|
||||
state = world.getBiome(pos.add(sx, 0, sz)).getGenerationSettings().getSurfaceConfig().getTopMaterial();
|
||||
}
|
||||
else {
|
||||
state = EndBlocks.ENDSTONE_DUST.getDefaultState();
|
||||
}
|
||||
chunk.setBlockState(pos, state, false);
|
||||
chunk.setBlockState(pos, AIR, false);
|
||||
}
|
||||
else if (pos.getY() == 56) {
|
||||
if (random.nextBoolean()) {
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package ru.betterend.world.structures.piece;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.structure.Structure;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructurePlacementData;
|
||||
import net.minecraft.util.BlockMirror;
|
||||
import net.minecraft.util.BlockRotation;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import ru.betterend.registry.EndStructures;
|
||||
import ru.betterend.util.StructureHelper;
|
||||
|
||||
public class NBTPiece extends BasePiece {
|
||||
private Identifier structureID;
|
||||
private BlockRotation rotation;
|
||||
private BlockMirror mirror;
|
||||
private Structure structure;
|
||||
private BlockPos pos;
|
||||
|
||||
public NBTPiece(Identifier structureID, Structure structure, BlockPos pos, Random random) {
|
||||
super(EndStructures.NBT_PIECE, random.nextInt());
|
||||
this.structureID = structureID;
|
||||
this.structure = structure;
|
||||
this.rotation = BlockRotation.random(random);
|
||||
this.mirror = BlockMirror.values()[random.nextInt(3)];
|
||||
this.pos = StructureHelper.offsetPos(pos, structure, rotation, mirror);
|
||||
makeBoundingBox();
|
||||
}
|
||||
|
||||
public NBTPiece(StructureManager manager, CompoundTag tag) {
|
||||
super(EndStructures.NBT_PIECE, tag);
|
||||
makeBoundingBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toNbt(CompoundTag tag) {
|
||||
tag.putString("id", structureID.toString());
|
||||
tag.putInt("rotation", rotation.ordinal());
|
||||
tag.putInt("mirror", mirror.ordinal());
|
||||
tag.put("pos", NbtHelper.fromBlockPos(pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fromNbt(CompoundTag tag) {
|
||||
structureID = new Identifier(tag.getString("id"));
|
||||
rotation = BlockRotation.values()[tag.getInt("rotation")];
|
||||
mirror = BlockMirror.values()[tag.getInt("mirror")];
|
||||
pos = NbtHelper.toBlockPos(tag.getCompound("pos"));
|
||||
structure = StructureHelper.readStructure(structureID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
StructurePlacementData placementData = new StructurePlacementData().setRotation(rotation).setMirror(mirror).setBoundingBox(blockBox);
|
||||
structure.place(world, pos, placementData, random);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void makeBoundingBox() {
|
||||
this.boundingBox = StructureHelper.getStructureBounds(pos, structure, rotation, mirror);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue