Generate Random Seed For Structure Generator If Not Specified
All checks were successful
EnergonRelics/pipeline/head This commit looks good
All checks were successful
EnergonRelics/pipeline/head This commit looks good
This commit is contained in:
parent
1c23d15d2e
commit
f6e94963d2
@ -20,6 +20,7 @@ public class StructureGeneratorBlockEntity extends BlockEntity {
|
||||
StructurePart<?> create(World world, Random random, List<StructurePart.Transformation> transformations);
|
||||
}
|
||||
|
||||
private boolean hasSeed = false;
|
||||
private long seed = 0;
|
||||
private boolean generated = false;
|
||||
|
||||
@ -31,12 +32,14 @@ public class StructureGeneratorBlockEntity extends BlockEntity {
|
||||
}
|
||||
|
||||
public void setSeed(long seed) {
|
||||
hasSeed = true;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
super.toTag(tag);
|
||||
tag.putBoolean("HasSeed", hasSeed);
|
||||
tag.putLong("Seed", seed);
|
||||
tag.putBoolean("Generated", generated);
|
||||
return tag;
|
||||
@ -45,12 +48,17 @@ public class StructureGeneratorBlockEntity extends BlockEntity {
|
||||
@Override
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
super.fromTag(state, tag);
|
||||
hasSeed = tag.getBoolean("HasSeed");
|
||||
seed = tag.getLong("Seed");
|
||||
generated = tag.getBoolean("Generated");
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
if (hasWorld() && !Objects.requireNonNull(getWorld()).isClient() && !generated) {
|
||||
if (!hasSeed) {
|
||||
seed = getWorld().random.nextLong();
|
||||
}
|
||||
|
||||
Direction facing = getCachedState().get(StructureGeneratorBlock.HORIZONTAL_FACING);
|
||||
generated = true;
|
||||
new StructurePlacer(factory.create(getWorld(), new Random(seed), Collections.singletonList(StructurePart.directionToTransformation(facing)))).place(getWorld(), getPos());
|
||||
|
Reference in New Issue
Block a user