Portals as structure feature
This commit is contained in:
parent
97eacdff1c
commit
40f8342732
7 changed files with 190 additions and 84 deletions
|
@ -0,0 +1,45 @@
|
|||
package ru.betterend.world.structures.features;
|
||||
|
||||
import net.minecraft.structure.Structure;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.util.MHelper;
|
||||
import ru.betterend.util.StructureHelper;
|
||||
import ru.betterend.world.structures.piece.NBTPiece;
|
||||
|
||||
public class StructureEternalPortal extends StructureFeatureBase {
|
||||
private static final Identifier STRUCTURE_ID = BetterEnd.makeID("portal/eternal_portal");
|
||||
private static final Structure STRUCTURE = StructureHelper.readStructure(STRUCTURE_ID);
|
||||
|
||||
@Override
|
||||
public StructureFeature.StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
|
||||
return SDFStructureStart::new;
|
||||
}
|
||||
|
||||
public static class SDFStructureStart extends StructureStart<DefaultFeatureConfig> {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box, int references, long seed) {
|
||||
super(feature, chunkX, chunkZ, box, references, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
|
||||
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
|
||||
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
|
||||
if (y > 50) {
|
||||
this.children.add(new NBTPiece(STRUCTURE_ID, STRUCTURE, new BlockPos(x, y - 3, z), random));
|
||||
}
|
||||
this.setBoundingBoxFromChildren();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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