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();
}
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);
}
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);
}
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()));
}
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));
}
}
}
}
Aggregations