Skip to content

Commit

Permalink
Merge pull request #2590 from BentoBoxWorld/remove_nms_support_for_older
Browse files Browse the repository at this point in the history
Remove NMS support and add setBlock raw setter
  • Loading branch information
tastybento authored Jan 2, 2025
2 parents 8e93aca + 75586e1 commit 710de36
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 125 deletions.
9 changes: 9 additions & 0 deletions src/main/java/world/bentobox/bentobox/nms/PasteHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,6 +39,14 @@ default CompletableFuture<Void> pasteBlocks(Island island, World world, Map<Loca

CompletableFuture<Void> 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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,4 +45,12 @@ public CompletableFuture<Void> pasteEntities(Island island, World world, Map<Loc
public CompletableFuture<Void> 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;
}

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ public class PasteHandlerImpl implements PasteHandler {
@Override
public CompletableFuture<Void> 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);
Expand All @@ -42,11 +52,6 @@ public CompletableFuture<Void> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,27 @@ public class PasteHandlerImpl implements PasteHandler {
@Override
public CompletableFuture<Void> 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());
// 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());
}
});
return block;
}
}

This file was deleted.

This file was deleted.

0 comments on commit 710de36

Please sign in to comment.