Search in sources :

Example 66 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class SetShipPilotMessage method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    PacketBuffer packetBuffer = new PacketBuffer(buf);
    entityUniqueID = packetBuffer.readUuid();
}
Also used : PacketBuffer(net.minecraft.network.PacketBuffer)

Example 67 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method writeSpawnData.

public void writeSpawnData(ByteBuf buffer) {
    PacketBuffer modifiedBuffer = new PacketBuffer(buffer);
    modifiedBuffer.writeInt(ownedChunks.centerX);
    modifiedBuffer.writeInt(ownedChunks.centerZ);
    modifiedBuffer.writeInt(ownedChunks.radius);
    modifiedBuffer.writeDouble(wrapper.posX);
    modifiedBuffer.writeDouble(wrapper.posY);
    modifiedBuffer.writeDouble(wrapper.posZ);
    modifiedBuffer.writeDouble(wrapper.pitch);
    modifiedBuffer.writeDouble(wrapper.yaw);
    modifiedBuffer.writeDouble(wrapper.roll);
    centerCoord.writeToByteBuf(modifiedBuffer);
    for (boolean[] array : ownedChunks.chunkOccupiedInLocal) {
        for (boolean b : array) {
            modifiedBuffer.writeBoolean(b);
        }
    }
    NBTTagCompound entityFixedPositionNBT = new NBTTagCompound();
    NBTUtils.writeEntityPositionHashMapToNBT("entityFixedPosMap", entityLocalPositions, entityFixedPositionNBT);
    modifiedBuffer.writeNBTTagCompoundToBuffer(entityFixedPositionNBT);
    modifiedBuffer.writeBoolean(isNameCustom);
    modifiedBuffer.writeEnumValue(shipType);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 68 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method readSpawnData.

public void readSpawnData(ByteBuf additionalData) {
    PacketBuffer modifiedBuffer = new PacketBuffer(additionalData);
    ownedChunks = new ChunkSet(modifiedBuffer.readInt(), modifiedBuffer.readInt(), modifiedBuffer.readInt());
    wrapper.posX = modifiedBuffer.readDouble();
    wrapper.posY = modifiedBuffer.readDouble();
    wrapper.posZ = modifiedBuffer.readDouble();
    wrapper.pitch = modifiedBuffer.readDouble();
    wrapper.yaw = modifiedBuffer.readDouble();
    wrapper.roll = modifiedBuffer.readDouble();
    wrapper.prevPitch = wrapper.pitch;
    wrapper.prevYaw = wrapper.yaw;
    wrapper.prevRoll = wrapper.roll;
    wrapper.lastTickPosX = wrapper.posX;
    wrapper.lastTickPosY = wrapper.posY;
    wrapper.lastTickPosZ = wrapper.posZ;
    centerCoord = new Vector(modifiedBuffer);
    for (boolean[] array : ownedChunks.chunkOccupiedInLocal) {
        for (int i = 0; i < array.length; i++) {
            array[i] = modifiedBuffer.readBoolean();
        }
    }
    loadClaimedChunks();
    renderer.updateOffsetPos(refrenceBlockPos);
    coordTransform.stack.pushMessage(new PhysWrapperPositionMessage(this));
    try {
        NBTTagCompound entityFixedPositionNBT = modifiedBuffer.readNBTTagCompoundFromBuffer();
        entityLocalPositions = NBTUtils.readEntityPositionMap("entityFixedPosMap", entityFixedPositionNBT);
    // if(worldObj.isRemote){
    // System.out.println(entityLocalPositions.containsKey(Minecraft.getMinecraft().thePlayer.getPersistentID().hashCode()));
    // System.out.println(Minecraft.getMinecraft().thePlayer.getPersistentID().hashCode());
    // }
    } catch (IOException e) {
        System.err.println("Couldn't load the entityFixedPosNBT; this is really bad.");
        e.printStackTrace();
    }
    isNameCustom = modifiedBuffer.readBoolean();
    shipType = modifiedBuffer.readEnumValue(ShipType.class);
}
Also used : PhysWrapperPositionMessage(ValkyrienWarfareBase.Network.PhysWrapperPositionMessage) ChunkSet(ValkyrienWarfareBase.ChunkManagement.ChunkSet) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) Vector(ValkyrienWarfareBase.API.Vector) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 69 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project SpongeCommon by SpongePowered.

the class BookFaker method fakeBookView.

public static void fakeBookView(BookView bookView, Player player) {
    EntityPlayerMP mcPlayer = (EntityPlayerMP) player;
    NetHandlerPlayServer receiver = mcPlayer.connection;
    // First we need to send a fake a Book ItemStack with the BookView's
    // contents to the player's hand
    ItemStack item = ItemStack.of(ItemTypes.WRITTEN_BOOK, 1);
    item.offer(Keys.DISPLAY_NAME, bookView.getTitle());
    item.offer(Keys.BOOK_AUTHOR, bookView.getAuthor());
    item.offer(Keys.BOOK_PAGES, bookView.getPages());
    InventoryPlayer inventory = mcPlayer.inventory;
    int bookSlot = inventory.mainInventory.size() + inventory.currentItem;
    receiver.sendPacket(new SPacketSetSlot(WINDOW_PLAYER_INVENTORY, bookSlot, ItemStackUtil.toNative(item)));
    // Next we tell the client to open the Book GUI
    PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
    packetbuffer.writeEnumValue(EnumHand.MAIN_HAND);
    receiver.sendPacket(new SPacketCustomPayload("MC|BOpen", packetbuffer));
    // Now we can remove the fake Book since it's contents will have already
    // been transferred to the GUI
    receiver.sendPacket(new SPacketSetSlot(WINDOW_PLAYER_INVENTORY, bookSlot, inventory.getCurrentItem()));
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) SPacketCustomPayload(net.minecraft.network.play.server.SPacketCustomPayload) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 70 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Charset by CharsetMC.

the class PacketChannelHandler method decode.

@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
    INetHandler iNetHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
    Packet newMsg = registry.instantiatePacket(msg.payload().readUnsignedByte());
    if (newMsg != null) {
        newMsg.readData(iNetHandler, new PacketBuffer(msg.payload()));
        if (newMsg.isAsynchronous()) {
            newMsg.apply(iNetHandler);
        } else {
            IThreadListener listener = Packet.getThreadListener(iNetHandler);
            if (listener.isCallingFromMinecraftThread()) {
                newMsg.apply(iNetHandler);
            } else {
                listener.addScheduledTask(() -> newMsg.apply(iNetHandler));
            }
        }
    }
}
Also used : FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) INetHandler(net.minecraft.network.INetHandler) IThreadListener(net.minecraft.util.IThreadListener) 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