-
Notifications
You must be signed in to change notification settings - Fork 0
Description
This feature is very interesting and beneficial for maintaining the consistency of the plugin, or at least making it optional so that it can be enabled.
It would be very easy to achieve this goal if performance were not a requirement, which is why I opened this issue to keep the discussion open to the public.
1. ChunkLoadEvent
I was able to implement it using the LoadChunkEvent event, but I came across the following problems:
-
Huge loss of performance
Caused a huge loss of performance due to iterating over the vast amount of blocks for each chunk. -
Chunk edge updates were forcing new chunk loads
It was necessary to be careful with modifications to the edges of chunks to avoid forcing additional chunk loads, so dirt blocks on the edges were not affected. I even considered modifying the edges only if the adjacent chunk was loaded, but the result was still unsatisfactory.
@EventHandler
public void x(ChunkLoadEvent event){
Chunk chunk = event.getChunk();
World world = chunk.getWorld();
int worldMinHeight = world.getMinHeight();
int worldMaxHeight = world.getMaxHeight();
Block block;
Block topBlock;
for(int coordY = worldMinHeight; coordY < worldMaxHeight - 1; coordY++){
for(int coordX = 1; coordX < 15; coordX++){
for(int coordZ = 1; coordZ < 15; coordZ++){
block = chunk.getBlock(coordX, coordY, coordZ);
if(block.getType() != Material.DIRT){
continue;
}
topBlock = chunk.getBlock(coordX, coordY + 1, coordZ);
if(topBlock.getType() != Material.WATER){
continue;
}
block.setType(Material.MUD);
}
}
}
Bukkit.broadcastMessage("loaded chunk - X: " + chunk.getX() + ", Y: " + chunk.getZ());
}2. ChunkGenerator
With the abstract ChunkGenerator class we can create a custom chunk generator, an idea that seems to be more performant, since it will only be called when generating new chunks. But there are still problems:
-
Conflit between plugins?
I can call the default generator first before making my changes, but this may conflict with other plugins that also generate chunks.I actually discovered that it is not possible to change the chunk generator of an existing world, or at least I was not successful, so will it not be possible to add this game mechanic? -
Old chunks remain the same
Chunk lakes that have already been generated will remain the same, only new chunks will be affected.