Generate Random Seed For Structure Generator If Not Specified
All checks were successful
EnergonRelics/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-08-19 15:53:46 -04:00
parent 1c23d15d2e
commit f6e94963d2

View File

@ -20,6 +20,7 @@ public class StructureGeneratorBlockEntity extends BlockEntity {
StructurePart<?> create(World world, Random random, List<StructurePart.Transformation> transformations); StructurePart<?> create(World world, Random random, List<StructurePart.Transformation> transformations);
} }
private boolean hasSeed = false;
private long seed = 0; private long seed = 0;
private boolean generated = false; private boolean generated = false;
@ -31,12 +32,14 @@ public class StructureGeneratorBlockEntity extends BlockEntity {
} }
public void setSeed(long seed) { public void setSeed(long seed) {
hasSeed = true;
this.seed = seed; this.seed = seed;
} }
@Override @Override
public CompoundTag toTag(CompoundTag tag) { public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag); super.toTag(tag);
tag.putBoolean("HasSeed", hasSeed);
tag.putLong("Seed", seed); tag.putLong("Seed", seed);
tag.putBoolean("Generated", generated); tag.putBoolean("Generated", generated);
return tag; return tag;
@ -45,12 +48,17 @@ public class StructureGeneratorBlockEntity extends BlockEntity {
@Override @Override
public void fromTag(BlockState state, CompoundTag tag) { public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag); super.fromTag(state, tag);
hasSeed = tag.getBoolean("HasSeed");
seed = tag.getLong("Seed"); seed = tag.getLong("Seed");
generated = tag.getBoolean("Generated"); generated = tag.getBoolean("Generated");
} }
public void generate() { public void generate() {
if (hasWorld() && !Objects.requireNonNull(getWorld()).isClient() && !generated) { if (hasWorld() && !Objects.requireNonNull(getWorld()).isClient() && !generated) {
if (!hasSeed) {
seed = getWorld().random.nextLong();
}
Direction facing = getCachedState().get(StructureGeneratorBlock.HORIZONTAL_FACING); Direction facing = getCachedState().get(StructureGeneratorBlock.HORIZONTAL_FACING);
generated = true; generated = true;
new StructurePlacer(factory.create(getWorld(), new Random(seed), Collections.singletonList(StructurePart.directionToTransformation(facing)))).place(getWorld(), getPos()); new StructurePlacer(factory.create(getWorld(), new Random(seed), Collections.singletonList(StructurePart.directionToTransformation(facing)))).place(getWorld(), getPos());