use of org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData in project THP-Engine by TheHollowPlanetMC.
the class PacketManager method createBlockChangePacket.
@Nullable
public static Object createBlockChangePacket(ParallelWorld parallelWorld, int blockX, int blockY, int blockZ) {
PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange();
BlockData blockData = parallelWorld.getBlockData(blockX, blockY, blockZ);
if (blockData == null)
return null;
try {
BlockChangePacketHandler.a.set(packet, new BlockPosition(blockX, blockY, blockZ));
packet.block = ((CraftBlockData) blockData).getState();
return packet;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData in project THP-Engine by TheHollowPlanetMC.
the class PacketManager method createMultiBlockChangePacket.
public static Set<Object> createMultiBlockChangePacket(ParallelWorld parallelWorld, Set<BlockPosition3i> blocks) {
Map<ChunkPosition, Set<BlockPosition3i>> chunkMap = new HashMap<>();
for (BlockPosition3i bp : blocks) {
chunkMap.computeIfAbsent(new ChunkPosition(bp.getX(), bp.getZ()), cp -> new HashSet<>()).add(bp);
}
Set<Object> packets = new HashSet<>();
for (Map.Entry<ChunkPosition, Set<BlockPosition3i>> entry : chunkMap.entrySet()) {
ChunkPosition chunkPosition = entry.getKey();
Set<BlockPosition3i> bps = entry.getValue();
ParallelChunk parallelChunk = parallelWorld.getChunk(chunkPosition.x, chunkPosition.z);
if (parallelChunk == null)
continue;
PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
List<PacketPlayOutMultiBlockChange.MultiBlockChangeInfo> infoList = new ArrayList<>();
for (BlockPosition3i bp : bps) {
BlockData blockData = parallelChunk.getBlockData(bp.getX(), bp.getY(), bp.getZ());
if (blockData == null)
continue;
short loc = (short) ((bp.getX() & 0xF) << 12 | (bp.getZ() & 0xF) << 8 | bp.getY());
infoList.add(packet.new MultiBlockChangeInfo(loc, ((CraftBlockData) blockData).getState()));
}
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] array = infoList.toArray(new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[infoList.size()]);
try {
MultiBlockChangePacketHandler.a.set(packet, new ChunkCoordIntPair(chunkPosition.x, chunkPosition.z));
MultiBlockChangePacketHandler.b.set(packet, array);
packets.add(packet);
} catch (Exception e) {
e.printStackTrace();
}
}
return packets;
}
use of org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData in project Mohist by MohistMC.
the class CraftMinecart method setDisplayBlockData.
@Override
public void setDisplayBlockData(BlockData blockData) {
if (blockData != null) {
BlockState block = ((CraftBlockData) blockData).getState();
this.getHandle().setDisplayBlockState(block);
} else {
// Set block to air (default) and set the flag to not have a display block.
this.getHandle().setDisplayBlockState(Blocks.AIR.defaultBlockState());
this.getHandle().setCustomDisplay(false);
}
}
use of org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData in project VanillaSource 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_14_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);
}
}
Aggregations