use of org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method setFallingBlockType.
@Override
public void setFallingBlockType(FallingBlock entity, BlockData block) {
BlockState state = ((CraftBlockData) block).getState();
FallingBlockEntity nmsEntity = ((CraftFallingBlock) entity).getHandle();
try {
FALLINGBLOCK_TYPE_SETTER.invoke(nmsEntity, state);
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
use of org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData in project THP-Engine by TheHollowPlanetMC.
the class MultiBlockChangePacketHandler method rewrite.
@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
ParallelUniverse universe = EnginePlayer.getUniverse();
if (universe == null)
return packet;
String worldName = EnginePlayer.getBukkitPlayer().getWorld().getName();
ParallelWorld parallelWorld = universe.getWorld(worldName);
try {
ChunkCoordIntPair aValue = (ChunkCoordIntPair) a.get(packet);
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] bValue = (PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[]) b.get(packet);
int chunkX = aValue.x;
int chunkZ = aValue.z;
ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
if (parallelChunk == null)
return packet;
PacketPlayOutMultiBlockChange newPacket = new PacketPlayOutMultiBlockChange();
a.set(newPacket, aValue);
int length = bValue.length;
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] newInfo = new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[length];
for (int index = 0; index < length; index++) {
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo info = bValue[index];
BlockPosition bp = info.a();
BlockData blockData = parallelChunk.getBlockData(bp.getX(), bp.getY(), bp.getZ());
if (blockData == null) {
newInfo[index] = info;
} else {
newInfo[index] = newPacket.new MultiBlockChangeInfo(info.b(), ((CraftBlockData) blockData).getState());
}
}
b.set(newPacket, newInfo);
return newPacket;
} catch (Exception e) {
e.printStackTrace();
}
return packet;
}
use of org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData in project THP-Engine by TheHollowPlanetMC.
the class BlockChangePacketHandler method rewrite.
@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
ParallelUniverse universe = EnginePlayer.getUniverse();
if (universe == null)
return packet;
String worldName = EnginePlayer.getBukkitPlayer().getWorld().getName();
ParallelWorld parallelWorld = universe.getWorld(worldName);
try {
PacketPlayOutBlockChange blockChange = (PacketPlayOutBlockChange) packet;
BlockPosition bp = (BlockPosition) a.get(blockChange);
BlockData blockData = parallelWorld.getBlockData(bp.getX(), bp.getY(), bp.getZ());
if (blockData == null)
return packet;
PacketPlayOutBlockChange newPacket = new PacketPlayOutBlockChange();
a.set(newPacket, bp);
newPacket.block = ((CraftBlockData) blockData).getState();
return newPacket;
} catch (Exception e) {
e.printStackTrace();
}
return packet;
}
use of org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData in project THP-Engine by TheHollowPlanetMC.
the class PacketManager method sendClearChunkMultiBlockChangePacketAtPrimaryThread.
public static void sendClearChunkMultiBlockChangePacketAtPrimaryThread(Player player, ParallelChunk parallelChunk, NMSHandler nmsHandler) {
if (!Bukkit.isPrimaryThread())
throw new IllegalStateException("DO NOT CALL FROM ASYNC THREAD!");
org.bukkit.World world = Bukkit.getWorld(parallelChunk.getWorld().getName());
if (world == null)
return;
if (player.getWorld() != world)
return;
org.bukkit.Chunk chunk = world.getChunkAt(parallelChunk.getChunkX(), parallelChunk.getChunkZ());
net.minecraft.server.v1_16_R3.Chunk nmsChunk = ((CraftChunk) chunk).getHandle();
for (int sectionIndex = 0; sectionIndex < 16; sectionIndex++) {
SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(sectionIndex);
if (sectionTypeArray == null)
continue;
ChunkSection chunkSection = nmsChunk.getSections()[sectionIndex];
if (chunkSection == null)
continue;
List<Short> coordList = new ArrayList<>();
List<IBlockData> dataList = new ArrayList<>();
boolean notEmpty = sectionTypeArray.threadsafeIteration((x, y, z, iBlockData) -> {
coordList.add((short) (x << 8 | z << 4 | y));
IBlockData chunkData = chunkSection.getType(x, y, z);
if (chunkData == null)
chunkData = ((CraftBlockData) org.bukkit.Material.AIR.createBlockData()).getState();
dataList.add(chunkData);
});
if (!notEmpty)
continue;
short[] coordArray = new short[coordList.size()];
IBlockData[] dataArray = new IBlockData[dataList.size()];
for (int i = 0; i < coordList.size(); i++) {
coordArray[i] = coordList.get(i);
dataArray[i] = dataList.get(i);
}
try {
PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
MultiBlockChangePacketHandler.a.set(packet, SectionPosition.a(parallelChunk.getChunkX(), sectionIndex, parallelChunk.getChunkZ()));
MultiBlockChangePacketHandler.b.set(packet, coordArray);
MultiBlockChangePacketHandler.c.set(packet, dataArray);
MultiBlockChangePacketHandler.d.setBoolean(packet, true);
nmsHandler.sendPacket(player, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData in project MechanicsMain by WeaponMechanics.
the class Block_1_15_R1 method getMultiBlockMaskPacket.
@Override
@NotNull
public List<Object> getMultiBlockMaskPacket(@NotNull List<Block> blocks, @Nullable Material mask, byte data) {
if (blocks == null || blocks.isEmpty()) {
throw new IllegalArgumentException("No blocks are being changed!");
}
Map<org.bukkit.Chunk, List<Block>> sortedBlocks = new HashMap<>();
for (Block block : blocks) {
List<Block> list = sortedBlocks.computeIfAbsent(block.getChunk(), chunk -> new ArrayList<>());
list.add(block);
}
List<Object> packets = new ArrayList<>(sortedBlocks.size());
IBlockData theMask = mask == null ? null : ((CraftBlockData) mask.createBlockData()).getState();
for (List<Block> entry : sortedBlocks.values()) {
packets.add(getMultiBlockMaskPacket(entry, theMask));
}
return packets;
}
Aggregations