use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project Ublisk by Derkades.
the class PlayerInteract method staffTool.
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW)
public void staffTool(PlayerInteractEvent event) {
ItemStack itemInHand = event.getPlayer().getInventory().getItemInMainHand();
if (itemInHand.getType() != Material.COAL_ORE || event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Player player = event.getPlayer();
String itemName = itemInHand.getItemMeta().getDisplayName();
final Block block = event.getClickedBlock();
event.setCancelled(true);
if (itemName == null) {
sendStaffToolInfoMessage(player);
return;
}
if (itemName.contains("farmland")) {
block.setType(Material.SOIL);
block.setData((byte) 7);
Location loc = block.getLocation();
Block wheat = new Location(Var.WORLD, loc.getX(), loc.getY() + 1, loc.getZ()).getBlock();
wheat.setType(Material.CROPS);
wheat.setData((byte) 7);
} else if (itemName.contains("invis")) {
block.setData((byte) 0);
block.setType(Material.PISTON_MOVING_PIECE);
event.getPlayer().sendMessage("Placed invisible block. To remove invisible block, type /u rinv while standing inside an invisible block.");
} else if (itemName.contains("coal")) {
block.setType(Material.GLASS);
new URunnable() {
public void run() {
block.setType(Material.COAL_ORE);
}
}.runLater(1 * 20);
} else if (itemName.contains("lighting")) {
Chunk chunk = ((CraftChunk) block.getChunk()).getHandle();
chunk.initLighting();
} else {
sendStaffToolInfoMessage(player);
}
}
use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project Denizen-For-Bukkit by DenizenScript.
the class BlockHelperImpl method doRandomTick.
@Override
public void doRandomTick(Location location) {
BlockPosition pos = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
Chunk nmsChunk = ((CraftChunk) location.getChunk()).getHandle();
IBlockData nmsBlock = nmsChunk.getType(pos);
WorldServer nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
if (nmsBlock.isTicking()) {
nmsBlock.b(nmsWorld, pos, nmsWorld.random);
}
Fluid fluid = nmsBlock.getFluid();
if (fluid.f()) {
fluid.b(nmsWorld, pos, nmsWorld.random);
}
}
use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project Denizen-For-Bukkit by DenizenScript.
the class BlockHelperImpl method doRandomTick.
@Override
public void doRandomTick(Location location) {
BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
LevelChunk nmsChunk = ((CraftChunk) location.getChunk()).getHandle();
net.minecraft.world.level.block.state.BlockState nmsBlock = nmsChunk.getBlockState(pos);
ServerLevel nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
if (nmsBlock.isRandomlyTicking()) {
nmsBlock.randomTick(nmsWorld, pos, nmsWorld.random);
}
try {
// FluidState fluid = nmsBlock.getFluidState();
// if (fluid.isRandomlyTicking()) {
// fluid.animateTick(nmsWorld, pos, nmsWorld.random);
// }
Object fluid = BLOCKSTATEBASE_GETFLUIDSTATE.invoke(nmsBlock);
if ((boolean) FLUIDSTATE_ISRANDOMLYTICKING.invoke(fluid)) {
FLUIDSTATE_ANIMATETICK.invoke(fluid, nmsWorld, pos, nmsWorld.random);
}
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project Denizen-For-Bukkit by DenizenScript.
the class ChunkHelperImpl method getHeightMap.
@Override
public int[] getHeightMap(Chunk chunk) {
Heightmap map = ((CraftChunk) chunk).getHandle().heightmaps.get(Heightmap.Types.MOTION_BLOCKING);
int[] outputMap = new int[256];
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
outputMap[x * 16 + y] = map.getFirstAvailable(x, y);
}
}
return outputMap;
}
use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project Denizen-For-Bukkit by DenizenScript.
the class ChunkHelperImpl method refreshChunkSections.
@Override
public void refreshChunkSections(Chunk chunk) {
ClientboundLevelChunkPacket packet = new ClientboundLevelChunkPacket(((CraftChunk) chunk).getHandle());
ChunkPos pos = new ChunkPos(chunk.getX(), chunk.getZ());
ChunkHolder playerChunk = ((CraftWorld) chunk.getWorld()).getHandle().getChunkProvider().chunkMap.l.get(pos.toLong());
if (playerChunk == null) {
return;
}
playerChunk.playerProvider.getPlayers(pos, false).forEach(player -> {
player.connection.send(packet);
});
}
Aggregations