Skip to content

Commit

Permalink
Add NMS support for 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Oct 26, 2024
1 parent c5b1a90 commit 3288d22
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/main/java/world/bentobox/bentobox/api/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ public void sendMessage(String reference, String... variables) {
* @param message The message to send, containing inline commands in square brackets.
*/
public void sendRawMessage(String message) {
BentoBox.getInstance().logDebug(message);
// Create a base TextComponent for the message
TextComponent baseComponent = new TextComponent();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package world.bentobox.bentobox.nms.v1_21_3_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_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_21_R2.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<Void> 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());
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package world.bentobox.bentobox.nms.v1_21_3_R0_1_SNAPSHOT;

import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_21_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_21_R2.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);
}

}
2 changes: 2 additions & 0 deletions src/main/java/world/bentobox/bentobox/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ public static WorldRegenerator getRegenerator() {
throw new IllegalStateException("Class " + clazz.getName() + " does not implement WorldRegenerator");
}
} catch (Exception e) {
e.printStackTrace();
plugin.logWarning("No Regenerator found for " + bukkitVersion + ", falling back to Bukkit API.");
handler = new world.bentobox.bentobox.nms.fallback.WorldRegeneratorImpl();
}
Expand Down Expand Up @@ -772,6 +773,7 @@ public static PasteHandler getPasteHandler() {
throw new IllegalStateException("Class " + clazz.getName() + " does not implement PasteHandler");
}
} catch (Exception e) {
e.printStackTrace();
plugin.logWarning("No PasteHandler found for " + bukkitVersion + ", falling back to Bukkit API.");
handler = new world.bentobox.bentobox.nms.fallback.PasteHandlerImpl();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ public enum ServerVersion {
/**
* @since 2.5.0
*/
V1_21_1(Compatibility.COMPATIBLE);
V1_21_1(Compatibility.COMPATIBLE),

/**
* @since 2.7.0
*/
V1_21_2(Compatibility.INCOMPATIBLE), V1_21_3(Compatibility.COMPATIBLE);

private final Compatibility compatibility;

Expand Down

0 comments on commit 3288d22

Please sign in to comment.