From 75586e1648a3be1ad08cee662c91f912b86c5f70 Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 2 Jan 2025 10:06:01 -0800 Subject: [PATCH] Remove NMS support and add setBlock raw setter --- .../bentobox/bentobox/nms/PasteHandler.java | 9 ++++ .../nms/fallback/PasteHandlerImpl.java | 10 ++++ .../PasteHandlerImpl.java | 8 --- .../WorldRegeneratorImpl.java | 8 --- .../PasteHandlerImpl.java | 8 --- .../WorldRegeneratorImpl.java | 8 --- .../PasteHandlerImpl.java | 19 ++++--- .../PasteHandlerImpl.java | 21 +++++--- .../v1_21_R0_1_SNAPSHOT/PasteHandlerImpl.java | 52 ------------------- .../WorldRegeneratorImpl.java | 26 ---------- 10 files changed, 44 insertions(+), 125 deletions(-) delete mode 100644 src/main/java/world/bentobox/bentobox/nms/v1_21_1_R0_1_SNAPSHOT/PasteHandlerImpl.java delete mode 100644 src/main/java/world/bentobox/bentobox/nms/v1_21_1_R0_1_SNAPSHOT/WorldRegeneratorImpl.java delete mode 100644 src/main/java/world/bentobox/bentobox/nms/v1_21_2_R0_1_SNAPSHOT/PasteHandlerImpl.java delete mode 100644 src/main/java/world/bentobox/bentobox/nms/v1_21_2_R0_1_SNAPSHOT/WorldRegeneratorImpl.java delete mode 100644 src/main/java/world/bentobox/bentobox/nms/v1_21_R0_1_SNAPSHOT/PasteHandlerImpl.java delete mode 100644 src/main/java/world/bentobox/bentobox/nms/v1_21_R0_1_SNAPSHOT/WorldRegeneratorImpl.java diff --git a/src/main/java/world/bentobox/bentobox/nms/PasteHandler.java b/src/main/java/world/bentobox/bentobox/nms/PasteHandler.java index e4e72d494..c991d69a3 100644 --- a/src/main/java/world/bentobox/bentobox/nms/PasteHandler.java +++ b/src/main/java/world/bentobox/bentobox/nms/PasteHandler.java @@ -9,6 +9,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBlock; @@ -38,6 +39,14 @@ default CompletableFuture pasteBlocks(Island island, World world, Map setBlock(Island island, Location location, BlueprintBlock bpBlock); + /** + * Set the block at location to the block data + * @param location + * @param blockData + * @return + */ + Block setBlock(Location location, BlockData blockData); + /** * Create a future to paste the entities * diff --git a/src/main/java/world/bentobox/bentobox/nms/fallback/PasteHandlerImpl.java b/src/main/java/world/bentobox/bentobox/nms/fallback/PasteHandlerImpl.java index 81aef5a4f..dbdcf73ea 100644 --- a/src/main/java/world/bentobox/bentobox/nms/fallback/PasteHandlerImpl.java +++ b/src/main/java/world/bentobox/bentobox/nms/fallback/PasteHandlerImpl.java @@ -7,6 +7,8 @@ import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBlock; import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity; @@ -43,4 +45,12 @@ public CompletableFuture pasteEntities(Island island, World world, Map setBlock(Island island, Location location, BlueprintBlock bpBlock) { return DefaultPasteUtil.setBlock(island, location, bpBlock); } + + @Override + public Block setBlock(Location location, BlockData blockData) { + Block block = location.getBlock(); + block.setBlockData(blockData); + return block; + } + } diff --git a/src/main/java/world/bentobox/bentobox/nms/v1_21_1_R0_1_SNAPSHOT/PasteHandlerImpl.java b/src/main/java/world/bentobox/bentobox/nms/v1_21_1_R0_1_SNAPSHOT/PasteHandlerImpl.java deleted file mode 100644 index 91850adac..000000000 --- a/src/main/java/world/bentobox/bentobox/nms/v1_21_1_R0_1_SNAPSHOT/PasteHandlerImpl.java +++ /dev/null @@ -1,8 +0,0 @@ -package world.bentobox.bentobox.nms.v1_21_1_R0_1_SNAPSHOT; - -/** - * Same as 1.21 - */ -public class PasteHandlerImpl extends world.bentobox.bentobox.nms.v1_21_R0_1_SNAPSHOT.PasteHandlerImpl { - // Do nothing special -} diff --git a/src/main/java/world/bentobox/bentobox/nms/v1_21_1_R0_1_SNAPSHOT/WorldRegeneratorImpl.java b/src/main/java/world/bentobox/bentobox/nms/v1_21_1_R0_1_SNAPSHOT/WorldRegeneratorImpl.java deleted file mode 100644 index 11d3f41ed..000000000 --- a/src/main/java/world/bentobox/bentobox/nms/v1_21_1_R0_1_SNAPSHOT/WorldRegeneratorImpl.java +++ /dev/null @@ -1,8 +0,0 @@ -package world.bentobox.bentobox.nms.v1_21_1_R0_1_SNAPSHOT; - -/** - * Same as 1.21 - */ -public class WorldRegeneratorImpl extends world.bentobox.bentobox.nms.v1_21_R0_1_SNAPSHOT.WorldRegeneratorImpl { - // Do nothing special - } diff --git a/src/main/java/world/bentobox/bentobox/nms/v1_21_2_R0_1_SNAPSHOT/PasteHandlerImpl.java b/src/main/java/world/bentobox/bentobox/nms/v1_21_2_R0_1_SNAPSHOT/PasteHandlerImpl.java deleted file mode 100644 index 1a2cb4315..000000000 --- a/src/main/java/world/bentobox/bentobox/nms/v1_21_2_R0_1_SNAPSHOT/PasteHandlerImpl.java +++ /dev/null @@ -1,8 +0,0 @@ -package world.bentobox.bentobox.nms.v1_21_2_R0_1_SNAPSHOT; - -/** - * Same as 1.21 - */ -public class PasteHandlerImpl extends world.bentobox.bentobox.nms.v1_21_R0_1_SNAPSHOT.PasteHandlerImpl { - // Do nothing special -} diff --git a/src/main/java/world/bentobox/bentobox/nms/v1_21_2_R0_1_SNAPSHOT/WorldRegeneratorImpl.java b/src/main/java/world/bentobox/bentobox/nms/v1_21_2_R0_1_SNAPSHOT/WorldRegeneratorImpl.java deleted file mode 100644 index a8e048d5a..000000000 --- a/src/main/java/world/bentobox/bentobox/nms/v1_21_2_R0_1_SNAPSHOT/WorldRegeneratorImpl.java +++ /dev/null @@ -1,8 +0,0 @@ -package world.bentobox.bentobox.nms.v1_21_2_R0_1_SNAPSHOT; - -/** - * Same as 1.21 - */ -public class WorldRegeneratorImpl extends world.bentobox.bentobox.nms.v1_21_R0_1_SNAPSHOT.WorldRegeneratorImpl { - // Do nothing special - } diff --git a/src/main/java/world/bentobox/bentobox/nms/v1_21_3_R0_1_SNAPSHOT/PasteHandlerImpl.java b/src/main/java/world/bentobox/bentobox/nms/v1_21_3_R0_1_SNAPSHOT/PasteHandlerImpl.java index dbdd672f9..7feba0d19 100644 --- a/src/main/java/world/bentobox/bentobox/nms/v1_21_3_R0_1_SNAPSHOT/PasteHandlerImpl.java +++ b/src/main/java/world/bentobox/bentobox/nms/v1_21_3_R0_1_SNAPSHOT/PasteHandlerImpl.java @@ -31,9 +31,19 @@ public class PasteHandlerImpl implements PasteHandler { @Override public CompletableFuture setBlock(Island island, Location location, BlueprintBlock bpBlock) { return Util.getChunkAtAsync(location).thenRun(() -> { + Block block = setBlock(location, DefaultPasteUtil.createBlockData(bpBlock)); + DefaultPasteUtil.setBlockState(island, block, bpBlock); + // Set biome + if (bpBlock.getBiome() != null) { + block.setBiome(bpBlock.getBiome()); + } + }); + } + + @Override + public Block setBlock(Location location, BlockData bd) { Block block = location.getBlock(); // Set the block data - default is AIR - BlockData bd = DefaultPasteUtil.createBlockData(bpBlock); CraftBlockData craft = (CraftBlockData) bd; net.minecraft.world.level.World nmsWorld = ((CraftWorld) location.getWorld()).getHandle(); Chunk nmsChunk = nmsWorld.d(location.getBlockX() >> 4, location.getBlockZ() >> 4); @@ -42,11 +52,6 @@ public CompletableFuture setBlock(Island island, Location location, Bluepr nmsChunk.a(bp, AIR, false); nmsChunk.a(bp, craft.getState(), false); block.setBlockData(bd, false); - DefaultPasteUtil.setBlockState(island, block, bpBlock); - // Set biome - if (bpBlock.getBiome() != null) { - block.setBiome(bpBlock.getBiome()); - } - }); + return block; } } diff --git a/src/main/java/world/bentobox/bentobox/nms/v1_21_4_R0_1_SNAPSHOT/PasteHandlerImpl.java b/src/main/java/world/bentobox/bentobox/nms/v1_21_4_R0_1_SNAPSHOT/PasteHandlerImpl.java index e0096f298..390ae2669 100644 --- a/src/main/java/world/bentobox/bentobox/nms/v1_21_4_R0_1_SNAPSHOT/PasteHandlerImpl.java +++ b/src/main/java/world/bentobox/bentobox/nms/v1_21_4_R0_1_SNAPSHOT/PasteHandlerImpl.java @@ -31,10 +31,20 @@ public class PasteHandlerImpl implements PasteHandler { @Override public CompletableFuture setBlock(Island island, Location location, BlueprintBlock bpBlock) { return Util.getChunkAtAsync(location).thenRun(() -> { + Block block = setBlock(location, DefaultPasteUtil.createBlockData(bpBlock)); + DefaultPasteUtil.setBlockState(island, block, bpBlock); + // Set biome + if (bpBlock.getBiome() != null) { + block.setBiome(bpBlock.getBiome()); + } + }); + } + + @Override + public Block setBlock(Location location, BlockData bd) { Block block = location.getBlock(); // Set the block data - default is AIR - BlockData bd = DefaultPasteUtil.createBlockData(bpBlock); - CraftBlockData craft = (CraftBlockData) bd; + CraftBlockData craft = (CraftBlockData) bd; net.minecraft.world.level.World nmsWorld = ((CraftWorld) location.getWorld()).getHandle(); Chunk nmsChunk = nmsWorld.d(location.getBlockX() >> 4, location.getBlockZ() >> 4); BlockPosition bp = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()); @@ -42,11 +52,6 @@ public CompletableFuture setBlock(Island island, Location location, Bluepr nmsChunk.a(bp, AIR, false); nmsChunk.a(bp, craft.getState(), false); block.setBlockData(bd, false); - DefaultPasteUtil.setBlockState(island, block, bpBlock); - // Set biome - if (bpBlock.getBiome() != null) { - block.setBiome(bpBlock.getBiome()); - } - }); + return block; } } diff --git a/src/main/java/world/bentobox/bentobox/nms/v1_21_R0_1_SNAPSHOT/PasteHandlerImpl.java b/src/main/java/world/bentobox/bentobox/nms/v1_21_R0_1_SNAPSHOT/PasteHandlerImpl.java deleted file mode 100644 index ece376eb2..000000000 --- a/src/main/java/world/bentobox/bentobox/nms/v1_21_R0_1_SNAPSHOT/PasteHandlerImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -package world.bentobox.bentobox.nms.v1_21_R0_1_SNAPSHOT; - -import java.util.concurrent.CompletableFuture; - -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_21_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_21_R1.block.data.CraftBlockData; - -import net.minecraft.core.BlockPosition; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.Chunk; -import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBlock; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.nms.PasteHandler; -import world.bentobox.bentobox.util.DefaultPasteUtil; -import world.bentobox.bentobox.util.Util; - -public class PasteHandlerImpl implements PasteHandler { - - protected static final IBlockData AIR = ((CraftBlockData) AIR_BLOCKDATA).getState(); - - /** - * Set the block to the location - * - * @param island - island - * @param location - location - * @param bpBlock - blueprint block - */ - @Override - public CompletableFuture setBlock(Island island, Location location, BlueprintBlock bpBlock) { - return Util.getChunkAtAsync(location).thenRun(() -> { - Block block = location.getBlock(); - // Set the block data - default is AIR - BlockData bd = DefaultPasteUtil.createBlockData(bpBlock); - CraftBlockData craft = (CraftBlockData) bd; - net.minecraft.world.level.World nmsWorld = ((CraftWorld) location.getWorld()).getHandle(); - Chunk nmsChunk = nmsWorld.d(location.getBlockX() >> 4, location.getBlockZ() >> 4); - BlockPosition bp = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - // Setting the block to air before setting to another state prevents some console errors - nmsChunk.a(bp, AIR, false); - nmsChunk.a(bp, craft.getState(), false); - block.setBlockData(bd, false); - DefaultPasteUtil.setBlockState(island, block, bpBlock); - // Set biome - if (bpBlock.getBiome() != null) { - block.setBiome(bpBlock.getBiome()); - } - }); - } -} diff --git a/src/main/java/world/bentobox/bentobox/nms/v1_21_R0_1_SNAPSHOT/WorldRegeneratorImpl.java b/src/main/java/world/bentobox/bentobox/nms/v1_21_R0_1_SNAPSHOT/WorldRegeneratorImpl.java deleted file mode 100644 index 6e1e3855f..000000000 --- a/src/main/java/world/bentobox/bentobox/nms/v1_21_R0_1_SNAPSHOT/WorldRegeneratorImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package world.bentobox.bentobox.nms.v1_21_R0_1_SNAPSHOT; - -import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_21_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_21_R1.block.data.CraftBlockData; - -import net.minecraft.core.BlockPosition; -import net.minecraft.world.level.World; -import net.minecraft.world.level.chunk.Chunk; -import world.bentobox.bentobox.nms.CopyWorldRegenerator; - -public class WorldRegeneratorImpl extends CopyWorldRegenerator { - - @Override - public void setBlockInNativeChunk(org.bukkit.Chunk chunk, int x, int y, int z, BlockData blockData, - boolean applyPhysics) { - CraftBlockData craft = (CraftBlockData) blockData; - World nmsWorld = ((CraftWorld) chunk.getWorld()).getHandle(); - Chunk nmsChunk = nmsWorld.d(chunk.getX(), chunk.getZ()); - BlockPosition bp = new BlockPosition((chunk.getX() << 4) + x, y, (chunk.getZ() << 4) + z); - // Setting the block to air before setting to another state prevents some console errors - nmsChunk.a(bp, PasteHandlerImpl.AIR, applyPhysics); - nmsChunk.a(bp, craft.getState(), applyPhysics); - } - -} \ No newline at end of file