Implement basic structure gen

This commit is contained in:
dfsek 2020-09-28 02:16:49 -07:00
parent 3e2fada357
commit 080a6d98f9
4 changed files with 19 additions and 4 deletions

View File

@ -19,6 +19,7 @@ public class TerraProfiler extends WorldProfiler {
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "OreTime")
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "CaveTime")
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "StructureTime")
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "StructurePasteTime")
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "CaveBlockUpdate");
profilerMap.put(w, this);
}

View File

@ -118,7 +118,12 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
@Override
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
return Arrays.asList(new CavePopulator(), popMan);
try {
return Arrays.asList(new CavePopulator(), new StructurePopulator(), popMan);
} catch(IOException e) {
e.printStackTrace();
throw new IllegalArgumentException();
}
}
@Override

View File

@ -22,7 +22,7 @@ import java.util.Set;
public class StructurePopulator extends BlockPopulator {
StructureSpawn spawnTest = new StructureSpawn(250, 250);
GaeaStructure struc = GaeaStructure.load(new File(Terra.getInstance().getDataFolder() + File.separator + "export" + File.separator + "structures", "demo2.tstructure"));
double horizontal = struc.getStructureInfo().getMaxHorizontal()/16D + 1D;
double horizontal = struc.getStructureInfo().getMaxHorizontal();
public StructurePopulator() throws IOException {
}
@ -30,7 +30,16 @@ public class StructurePopulator extends BlockPopulator {
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("StructureTime")) {
int cx = (chunk.getX() << 4);
int cz = (chunk.getZ() << 4);
Location spawn = spawnTest.getNearestSpawn(cx+ 8, cz + 8, world.getSeed()).toLocation(world);
spawn.setY(72);
if(Math.abs((cx+8)-spawn.getBlockX()) <= horizontal && Math.abs((cz+8)-spawn.getBlockZ()) <= horizontal) {
try(ProfileFuture ignore = TerraProfiler.fromWorld(world).measure("StructurePasteTime")) {
struc.paste(spawn, chunk);
}
Bukkit.getLogger().info("Pasted at " + spawn);
}
}
}
}

View File

@ -96,7 +96,7 @@ public class GaeaStructure implements Serializable {
private void pasteBlock(StructureContainedBlock block, Location origin) {
BlockData data = block.getBlockData();
Block worldBlock = origin.clone().add(block.getX()-structureInfo.getCenterX(), block.getY(), block.getZ()-structureInfo.getCenterZ()).getBlock();
if(!data.getMaterial().equals(Material.STRUCTURE_VOID)) worldBlock.setBlockData(data);
if(!data.getMaterial().equals(Material.STRUCTURE_VOID)) worldBlock.setBlockData(data, false);
if(block.getState() != null) {
block.getState().getState(worldBlock.getState()).update();
}