use of net.minecraft.network.FriendlyByteBuf in project Denizen-For-Bukkit by DenizenScript.
the class FakeBlockHelper method handleMapChunkPacket.
public static ClientboundLevelChunkWithLightPacket handleMapChunkPacket(World world, ClientboundLevelChunkWithLightPacket originalPacket, int chunkX, int chunkZ, List<FakeBlock> blocks) {
try {
ClientboundLevelChunkWithLightPacket duplicateCorePacket = new ClientboundLevelChunkWithLightPacket(DenizenNetworkManagerImpl.copyPacket(originalPacket));
copyPacketPaperPatch(duplicateCorePacket, originalPacket);
FriendlyByteBuf copier = new FriendlyByteBuf(Unpooled.buffer());
originalPacket.getChunkData().write(copier);
ClientboundLevelChunkPacketData packet = new ClientboundLevelChunkPacketData(copier, chunkX, chunkZ);
FriendlyByteBuf serial = originalPacket.getChunkData().getReadBuffer();
FriendlyByteBuf outputSerial = new FriendlyByteBuf(Unpooled.buffer(serial.readableBytes()));
List blockEntities = new ArrayList((List) CHUNKDATA_BLOCK_ENTITIES.get(originalPacket.getChunkData()));
CHUNKDATA_BLOCK_ENTITIES.set(packet, blockEntities);
ListIterator iterator = blockEntities.listIterator();
while (iterator.hasNext()) {
Object blockEnt = iterator.next();
int xz = CHUNKDATA_BLOCKENTITYINFO_PACKEDXZ.getInt(blockEnt);
int y = CHUNKDATA_BLOCKENTITYINFO_Y.getInt(blockEnt);
int x = (chunkX << 4) + ((xz >> 4) & 15);
int z = (chunkZ << 4) + (xz & 15);
for (FakeBlock block : blocks) {
LocationTag loc = block.location;
if (loc.getBlockX() == x && loc.getBlockY() == y && loc.getBlockZ() == z && block.material != null) {
iterator.remove();
break;
}
}
}
int worldMinY = world.getMinHeight();
int worldMaxY = world.getMaxHeight();
int minChunkY = worldMinY >> 4;
int maxChunkY = worldMaxY >> 4;
Registry<Biome> biomeRegistry = ((CraftWorld) world).getHandle().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
for (int y = minChunkY; y < maxChunkY; y++) {
int blockCount = serial.readShort();
// reflected constructors as workaround for spigot remapper bug - Mojang "IdMap" became Spigot "IRegistry" but should be "Registry"
PalettedContainer<BlockState> states = (PalettedContainer<BlockState>) PALETTEDCONTAINER_CTOR.newInstance(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES);
states.read(serial);
PalettedContainer<Biome> biomes = (PalettedContainer<Biome>) PALETTEDCONTAINER_CTOR.newInstance(biomeRegistry, biomeRegistry.getOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES);
biomes.read(serial);
if (anyBlocksInSection(blocks, y)) {
int minY = y << 4;
int maxY = (y << 4) + 16;
for (FakeBlock block : blocks) {
int blockY = block.location.getBlockY();
if (blockY >= minY && blockY < maxY && block.material != null) {
int blockX = block.location.getBlockX();
int blockZ = block.location.getBlockZ();
blockX -= (blockX >> 4) * 16;
blockY -= (blockY >> 4) * 16;
blockZ -= (blockZ >> 4) * 16;
BlockState oldState = states.get(blockX, blockY, blockZ);
BlockState newState = getNMSState(block);
if (oldState.isAir() && !newState.isAir()) {
blockCount++;
} else if (newState.isAir() && !oldState.isAir()) {
blockCount--;
}
states.set(blockX, blockY, blockZ, newState);
}
}
}
outputSerial.writeShort(blockCount);
states.write(outputSerial);
biomes.write(outputSerial);
}
byte[] outputBytes = outputSerial.array();
CHUNKDATA_BUFFER_SETTER.invoke(packet, outputBytes);
CHUNKPACKET_CHUNKDATA_SETTER.invoke(duplicateCorePacket, packet);
return duplicateCorePacket;
} catch (Throwable ex) {
Debug.echoError(ex);
}
return null;
}
use of net.minecraft.network.FriendlyByteBuf in project Denizen-For-Bukkit by DenizenScript.
the class DenizenPacketListenerImpl method handleCustomPayload.
@Override
public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {
if (NMSHandler.debugPackets) {
Debug.log("Custom packet payload: " + packet.identifier.toString() + " sent from " + player.getScoreboardName());
}
if (packet.identifier.getNamespace().equals("minecraft") && packet.identifier.getPath().equals("brand")) {
FriendlyByteBuf newData = new FriendlyByteBuf(packet.data.copy());
// read off the varInt of length to get rid of it
int i = newData.readVarInt();
brand = StandardCharsets.UTF_8.decode(newData.nioBuffer()).toString();
}
super.handleCustomPayload(packet);
}
use of net.minecraft.network.FriendlyByteBuf in project Denizen-For-Bukkit by DenizenScript.
the class DenizenPacketListenerImpl method handleCustomPayload.
@Override
public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {
if (NMSHandler.debugPackets) {
Debug.log("Custom packet payload: " + packet.identifier.toString() + " sent from " + player.getScoreboardName());
}
if (packet.identifier.getNamespace().equals("minecraft") && packet.identifier.getPath().equals("brand")) {
FriendlyByteBuf newData = new FriendlyByteBuf(packet.data.copy());
// read off the varInt of length to get rid of it
int i = newData.readVarInt();
brand = StandardCharsets.UTF_8.decode(newData.nioBuffer()).toString();
}
super.handleCustomPayload(packet);
}
use of net.minecraft.network.FriendlyByteBuf in project MinecraftForge by MinecraftForge.
the class SimpleChannel method toBuffer.
private <MSG> Pair<FriendlyByteBuf, Integer> toBuffer(MSG msg) {
final FriendlyByteBuf bufIn = new FriendlyByteBuf(Unpooled.buffer());
int index = encodeMessage(msg, bufIn);
return Pair.of(bufIn, index);
}
use of net.minecraft.network.FriendlyByteBuf in project MinecraftForge by MinecraftForge.
the class MCRegisterPacketHandler method sendRegistry.
public void sendRegistry(Connection manager, final NetworkDirection dir) {
FriendlyByteBuf pb = new FriendlyByteBuf(Unpooled.buffer());
pb.writeBytes(getFrom(manager).toByteArray());
final ICustomPacket<Packet<?>> iPacketICustomPacket = dir.buildPacket(Pair.of(pb, 0), NetworkConstants.MC_REGISTER_RESOURCE);
manager.send(iPacketICustomPacket.getThis());
}
Aggregations