StructurePiece
constructor and addAdditionalSaveData
Signature
This commit is contained in:
parent
036d594012
commit
32f9bf288e
7 changed files with 34 additions and 26 deletions
|
@ -2,11 +2,12 @@ package ru.betterend.world.structures.piece;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.world.level.levelgen.feature.StructurePieceType;
|
import net.minecraft.world.level.levelgen.feature.StructurePieceType;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||||
import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
||||||
|
|
||||||
public abstract class BasePiece extends StructurePiece {
|
public abstract class BasePiece extends StructurePiece {
|
||||||
protected BasePiece(StructurePieceType type, int i) {
|
protected BasePiece(StructurePieceType type, int i, BoundingBox boundingBox) {
|
||||||
super(type, i);
|
super(type, i, boundingBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BasePiece(StructurePieceType type, CompoundTag tag) {
|
protected BasePiece(StructurePieceType type, CompoundTag tag) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.StructureFeatureManager;
|
import net.minecraft.world.level.StructureFeatureManager;
|
||||||
import net.minecraft.world.level.WorldGenLevel;
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
|
@ -25,7 +26,7 @@ public class CavePiece extends BasePiece {
|
||||||
private float radius;
|
private float radius;
|
||||||
|
|
||||||
public CavePiece(BlockPos center, float radius, int id) {
|
public CavePiece(BlockPos center, float radius, int id) {
|
||||||
super(EndStructures.CAVE_PIECE, id);
|
super(EndStructures.CAVE_PIECE, id, null);
|
||||||
this.center = center;
|
this.center = center;
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
this.noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
|
this.noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
|
||||||
|
@ -39,12 +40,12 @@ public class CavePiece extends BasePiece {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||||
int x1 = MHelper.max(this.boundingBox.x0, blockBox.x0);
|
int x1 = MHelper.max(this.boundingBox.minX(), blockBox.minX());
|
||||||
int z1 = MHelper.max(this.boundingBox.z0, blockBox.z0);
|
int z1 = MHelper.max(this.boundingBox.minZ(), blockBox.minZ());
|
||||||
int x2 = MHelper.min(this.boundingBox.x1, blockBox.x1);
|
int x2 = MHelper.min(this.boundingBox.maxX(), blockBox.maxX());
|
||||||
int z2 = MHelper.min(this.boundingBox.z1, blockBox.z1);
|
int z2 = MHelper.min(this.boundingBox.maxZ(), blockBox.maxZ());
|
||||||
int y1 = this.boundingBox.y0;
|
int y1 = this.boundingBox.minY();
|
||||||
int y2 = this.boundingBox.y1;
|
int y2 = this.boundingBox.maxY();
|
||||||
|
|
||||||
double hr = radius * 0.75;
|
double hr = radius * 0.75;
|
||||||
double nr = radius * 0.25;
|
double nr = radius * 0.25;
|
||||||
|
@ -83,7 +84,7 @@ public class CavePiece extends BasePiece {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addAdditionalSaveData(CompoundTag tag) {
|
protected void addAdditionalSaveData(ServerLevel serverLevel, CompoundTag tag) {
|
||||||
tag.put("center", NbtUtils.writeBlockPos(center));
|
tag.put("center", NbtUtils.writeBlockPos(center));
|
||||||
tag.putFloat("radius", radius);
|
tag.putFloat("radius", radius);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,11 @@ import com.google.common.collect.Maps;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.SectionPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.StructureFeatureManager;
|
import net.minecraft.world.level.StructureFeatureManager;
|
||||||
|
@ -46,7 +48,7 @@ public class LakePiece extends BasePiece {
|
||||||
private ResourceLocation biomeID;
|
private ResourceLocation biomeID;
|
||||||
|
|
||||||
public LakePiece(BlockPos center, float radius, float depth, Random random, Biome biome) {
|
public LakePiece(BlockPos center, float radius, float depth, Random random, Biome biome) {
|
||||||
super(EndStructures.LAKE_PIECE, random.nextInt());
|
super(EndStructures.LAKE_PIECE, random.nextInt(), null);
|
||||||
this.center = center;
|
this.center = center;
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
this.depth = depth;
|
this.depth = depth;
|
||||||
|
@ -63,7 +65,7 @@ public class LakePiece extends BasePiece {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addAdditionalSaveData(CompoundTag tag) {
|
protected void addAdditionalSaveData(ServerLevel serverLevel, CompoundTag tag) {
|
||||||
tag.put("center", NbtUtils.writeBlockPos(center));
|
tag.put("center", NbtUtils.writeBlockPos(center));
|
||||||
tag.putFloat("radius", radius);
|
tag.putFloat("radius", radius);
|
||||||
tag.putFloat("depth", depth);
|
tag.putFloat("depth", depth);
|
||||||
|
@ -84,10 +86,10 @@ public class LakePiece extends BasePiece {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||||
int minY = this.boundingBox.y0;
|
int minY = this.boundingBox.minY();
|
||||||
int maxY = this.boundingBox.y1;
|
int maxY = this.boundingBox.maxY();
|
||||||
int sx = chunkPos.x << 4;
|
int sx = SectionPos.sectionToBlockCoord(chunkPos.x);
|
||||||
int sz = chunkPos.z << 4;
|
int sz = SectionPos.sectionToBlockCoord(chunkPos.z);
|
||||||
MutableBlockPos mut = new MutableBlockPos();
|
MutableBlockPos mut = new MutableBlockPos();
|
||||||
ChunkAccess chunk = world.getChunk(chunkPos.x, chunkPos.z);
|
ChunkAccess chunk = world.getChunk(chunkPos.x, chunkPos.z);
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
|
@ -144,8 +146,8 @@ public class LakePiece extends BasePiece {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fixWater(WorldGenLevel world, ChunkAccess chunk, MutableBlockPos mut, Random random, int sx, int sz) {
|
private void fixWater(WorldGenLevel world, ChunkAccess chunk, MutableBlockPos mut, Random random, int sx, int sz) {
|
||||||
int minY = this.boundingBox.y0;
|
int minY = this.boundingBox.minY();
|
||||||
int maxY = this.boundingBox.y1;
|
int maxY = this.boundingBox.maxY();
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
mut.setX(x);
|
mut.setX(x);
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.level.WorldGenLevel;
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
@ -34,7 +35,7 @@ public abstract class MountainPiece extends BasePiece {
|
||||||
protected int seed2;
|
protected int seed2;
|
||||||
|
|
||||||
public MountainPiece(StructurePieceType type, BlockPos center, float radius, float height, Random random, Biome biome) {
|
public MountainPiece(StructurePieceType type, BlockPos center, float radius, float height, Random random, Biome biome) {
|
||||||
super(type, random.nextInt());
|
super(type, random.nextInt(), null);
|
||||||
this.center = center;
|
this.center = center;
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
@ -53,7 +54,7 @@ public abstract class MountainPiece extends BasePiece {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addAdditionalSaveData(CompoundTag tag) {
|
protected void addAdditionalSaveData(ServerLevel serverLevel, CompoundTag tag) {
|
||||||
tag.put("center", NbtUtils.writeBlockPos(center));
|
tag.put("center", NbtUtils.writeBlockPos(center));
|
||||||
tag.putFloat("radius", radius);
|
tag.putFloat("radius", radius);
|
||||||
tag.putFloat("height", height);
|
tag.putFloat("height", height);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.StructureFeatureManager;
|
import net.minecraft.world.level.StructureFeatureManager;
|
||||||
import net.minecraft.world.level.WorldGenLevel;
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
|
@ -30,7 +31,7 @@ public class NBTPiece extends BasePiece {
|
||||||
private boolean cover;
|
private boolean cover;
|
||||||
|
|
||||||
public NBTPiece(ResourceLocation structureID, StructureTemplate structure, BlockPos pos, int erosion, boolean cover, Random random) {
|
public NBTPiece(ResourceLocation structureID, StructureTemplate structure, BlockPos pos, int erosion, boolean cover, Random random) {
|
||||||
super(EndStructures.NBT_PIECE, random.nextInt());
|
super(EndStructures.NBT_PIECE, random.nextInt(), null);
|
||||||
this.structureID = structureID;
|
this.structureID = structureID;
|
||||||
this.structure = structure;
|
this.structure = structure;
|
||||||
this.rotation = Rotation.getRandom(random);
|
this.rotation = Rotation.getRandom(random);
|
||||||
|
@ -47,7 +48,7 @@ public class NBTPiece extends BasePiece {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addAdditionalSaveData(CompoundTag tag) {
|
protected void addAdditionalSaveData(ServerLevel serverLevel, CompoundTag tag) {
|
||||||
tag.putString("structureID", structureID.toString());
|
tag.putString("structureID", structureID.toString());
|
||||||
tag.putInt("rotation", rotation.ordinal());
|
tag.putInt("rotation", rotation.ordinal());
|
||||||
tag.putInt("mirror", mirror.ordinal());
|
tag.putInt("mirror", mirror.ordinal());
|
||||||
|
|
|
@ -7,6 +7,7 @@ import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.ListTag;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.StructureFeatureManager;
|
import net.minecraft.world.level.StructureFeatureManager;
|
||||||
import net.minecraft.world.level.WorldGenLevel;
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
|
@ -33,8 +34,8 @@ public class PaintedMountainPiece extends MountainPiece {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addAdditionalSaveData(CompoundTag tag) {
|
protected void addAdditionalSaveData(ServerLevel serverLevel, CompoundTag tag) {
|
||||||
super.addAdditionalSaveData(tag);
|
super.addAdditionalSaveData(serverLevel, tag);
|
||||||
ListTag slise = new ListTag();
|
ListTag slise = new ListTag();
|
||||||
for (BlockState state: slises) {
|
for (BlockState state: slises) {
|
||||||
slise.add(NbtUtils.writeBlockState(state));
|
slise.add(NbtUtils.writeBlockState(state));
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.function.Consumer;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.StructureFeatureManager;
|
import net.minecraft.world.level.StructureFeatureManager;
|
||||||
import net.minecraft.world.level.WorldGenLevel;
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
|
@ -18,7 +19,7 @@ public class VoxelPiece extends BasePiece {
|
||||||
private StructureWorld world;
|
private StructureWorld world;
|
||||||
|
|
||||||
public VoxelPiece(Consumer<StructureWorld> function, int id) {
|
public VoxelPiece(Consumer<StructureWorld> function, int id) {
|
||||||
super(EndStructures.VOXEL_PIECE, id);
|
super(EndStructures.VOXEL_PIECE, id, null);
|
||||||
world = new StructureWorld();
|
world = new StructureWorld();
|
||||||
function.accept(world);
|
function.accept(world);
|
||||||
this.boundingBox = world.getBounds();
|
this.boundingBox = world.getBounds();
|
||||||
|
@ -30,7 +31,7 @@ public class VoxelPiece extends BasePiece {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addAdditionalSaveData(CompoundTag tag) {
|
protected void addAdditionalSaveData(ServerLevel serverLevel, CompoundTag compoundTag) {
|
||||||
tag.put("world", world.toBNT());
|
tag.put("world", world.toBNT());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue