Skip to content

Commit

Permalink
Switch from chunk to block notification.
Browse files Browse the repository at this point in the history
Individual blocks need to be destroyed because complete chunks may not
be used.
  • Loading branch information
tastybento committed Dec 24, 2023
1 parent b7c7883 commit 513851d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/main/java/world/bentobox/bentobox/hooks/SlimefunHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package world.bentobox.bentobox.hooks;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -46,5 +47,9 @@ public void clearBlockInfo(Block b, boolean destroy) {
BlockStorage.clearBlockInfo(b, destroy);
}

public void clearBlockInfo(Location location, boolean destroy) {
BlockStorage.clearBlockInfo(location, destroy);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ public CompletableFuture<Void> regenerateChunk(Chunk chunk) {

private CompletableFuture<Void> regenerateChunk(@Nullable IslandDeletion di, World world, int chunkX, int chunkZ) {

// Notify Slimefun
plugin.getHooks().getHook("Slimefun")
.ifPresent(sf -> ((SlimefunHook) sf).clearAllBlockInfoAtChunk(world, chunkX, chunkZ, true));

CompletableFuture<Chunk> seedWorldFuture = getSeedWorldChunk(world, chunkX, chunkZ);

// Set up a future to get the chunk requests using Paper's Lib. If Paper is used, this should be done async
Expand Down Expand Up @@ -198,6 +194,10 @@ private void copyChunkDataToChunk(Chunk toChunk, Chunk fromChunk, BoundingBox li
if (x % 4 == 0 && y % 4 == 0 && z % 4 == 0) {
toChunk.getBlock(x, y, z).setBiome(fromChunk.getBlock(x, y, z).getBiome());
}
// Delete any slimefun blocks
Location loc = new Location(toChunk.getWorld(), baseX + x, y, baseZ + z);
plugin.getHooks().getHook("Slimefun")
.ifPresent(sf -> ((SlimefunHook) sf).clearBlockInfo(loc, true));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.concurrent.CompletableFuture;

import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -91,10 +92,6 @@ private boolean isEnded(int chunkX) {

@SuppressWarnings("deprecation")
private CompletableFuture<Void> regenerateChunk(GameModeAddon gm, IslandDeletion di, World world, int chunkX, int chunkZ) {
// Notify Slimefun
plugin.getHooks().getHook("Slimefun")
.ifPresent(sf -> ((SlimefunHook) sf).clearAllBlockInfoAtChunk(world, chunkX, chunkZ, true));

CompletableFuture<Chunk> chunkFuture = PaperLib.getChunkAtAsync(world, chunkX, chunkZ);
CompletableFuture<Void> invFuture = chunkFuture.thenAccept(chunk ->
Arrays.stream(chunk.getTileEntities()).filter(InventoryHolder.class::isInstance)
Expand Down Expand Up @@ -145,6 +142,10 @@ private void copyChunkDataToChunk(Chunk chunk, ChunkGenerator.ChunkData chunkDat
if (x % 4 == 0 && y % 4 == 0 && z % 4 == 0) {
chunk.getBlock(x, y, z).setBiome(biomeGrid.getBiome(x, y, z));
}
// Delete any slimefun blocks
Location loc = new Location(chunk.getWorld(), baseX + x, y, baseZ + z);
plugin.getHooks().getHook("Slimefun")
.ifPresent(sf -> ((SlimefunHook) sf).clearBlockInfo(loc, true));
}
}
}
Expand Down

0 comments on commit 513851d

Please sign in to comment.