Search in sources :

Example 81 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project GregTech by GregTechCE.

the class ModularUIContainer method writeClientAction.

@Override
public void writeClientAction(Widget widget, int updateId, Consumer<PacketBuffer> payloadWriter) {
    int widgetId = modularUI.guiWidgets.inverse().get(widget);
    PacketBuffer packetBuffer = new PacketBuffer(Unpooled.buffer());
    packetBuffer.writeVarInt(updateId);
    payloadWriter.accept(packetBuffer);
    if (modularUI.entityPlayer instanceof EntityPlayerSP) {
        PacketUIClientAction widgetUpdate = new PacketUIClientAction(windowId, widgetId, packetBuffer);
        NetworkHandler.channel.sendToServer(NetworkHandler.packet2proxy(widgetUpdate));
    }
}
Also used : PacketUIClientAction(gregtech.api.net.PacketUIClientAction) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 82 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project GregTech by GregTechCE.

the class ModularUIContainer method writeUpdateInfo.

@Override
public void writeUpdateInfo(Widget widget, int updateId, Consumer<PacketBuffer> payloadWriter) {
    int widgetId = modularUI.guiWidgets.inverse().get(widget);
    PacketBuffer packetBuffer = new PacketBuffer(Unpooled.buffer());
    packetBuffer.writeVarInt(updateId);
    payloadWriter.accept(packetBuffer);
    if (modularUI.entityPlayer instanceof EntityPlayerMP) {
        PacketUIWidgetUpdate widgetUpdate = new PacketUIWidgetUpdate(windowId, widgetId, packetBuffer);
        if (!accumulateWidgetUpdateData) {
            NetworkHandler.channel.sendTo(NetworkHandler.packet2proxy(widgetUpdate), (EntityPlayerMP) modularUI.entityPlayer);
        } else {
            accumulatedUpdates.add(widgetUpdate);
        }
    }
}
Also used : PacketUIWidgetUpdate(gregtech.api.net.PacketUIWidgetUpdate) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 83 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project GregTech by GregTechCE.

the class SyncedTileEntityBase method getUpdateTag.

@Override
public NBTTagCompound getUpdateTag() {
    NBTTagCompound updateTag = super.getUpdateTag();
    ByteBuf backedBuffer = Unpooled.buffer();
    writeInitialSyncData(new PacketBuffer(backedBuffer));
    byte[] updateData = Arrays.copyOfRange(backedBuffer.array(), 0, backedBuffer.writerIndex());
    updateTag.setByteArray("d", updateData);
    return updateTag;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ByteBuf(io.netty.buffer.ByteBuf) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 84 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project GregTech by GregTechCE.

the class SyncedTileEntityBase method handleUpdateTag.

@Override
public void handleUpdateTag(@Nonnull NBTTagCompound tag) {
    // deserializes Forge data and capabilities
    super.readFromNBT(tag);
    byte[] updateData = tag.getByteArray("d");
    ByteBuf backedBuffer = Unpooled.copiedBuffer(updateData);
    receiveInitialSyncData(new PacketBuffer(backedBuffer));
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 85 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project GregTech by GregTechCE.

the class NetworkHandler method proxy2packet.

@SuppressWarnings("unchecked")
public static Packet proxy2packet(FMLProxyPacket packet) {
    PacketBuffer payload = (PacketBuffer) packet.payload();
    Class<Packet> packetClass = (Class<Packet>) packetMap.get(payload.readVarInt());
    PacketCodec<Packet> codec = (PacketCodec<Packet>) codecMap.get(packetClass);
    return codec.decoder.decode(payload);
}
Also used : FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) PacketBuffer(net.minecraft.network.PacketBuffer)

Aggregations

PacketBuffer (net.minecraft.network.PacketBuffer)105 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)20 IOException (java.io.IOException)14 FMLProxyPacket (net.minecraftforge.fml.common.network.internal.FMLProxyPacket)14 ByteBuf (io.netty.buffer.ByteBuf)11 SPacketCustomPayload (net.minecraft.network.play.server.SPacketCustomPayload)7 BlockPos (net.minecraft.util.math.BlockPos)7 HashMap (java.util.HashMap)4 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)4 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)3 Test (org.junit.Test)3 PacketBufferBC (buildcraft.lib.net.PacketBufferBC)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 PacketCustomTileData (gregtech.api.net.PacketCustomTileData)2 PacketUIWidgetUpdate (gregtech.api.net.PacketUIWidgetUpdate)2 AbstractData (hellfirepvp.fracture.common.data.AbstractData)2