Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NMS support and add setBlock raw setter #2590

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading