-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5b1a90
commit 3288d22
Showing
5 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/world/bentobox/bentobox/nms/v1_21_3_R0_1_SNAPSHOT/PasteHandlerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
}); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/world/bentobox/bentobox/nms/v1_21_3_R0_1_SNAPSHOT/WorldRegeneratorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters