cpw.mods.fml.common.network.ByteBufUtils Java Examples
The following examples show how to use
cpw.mods.fml.common.network.ByteBufUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItemCreator.java From ehacks-pro with GNU General Public License v3.0 | 6 votes |
public void giveItem(ItemStack stack) { ByteBuf buf = Unpooled.buffer(0); buf.writeByte(10); ItemStack mail = new ItemStack(Items.stick); NBTTagList tagList = new NBTTagList(); for (int i = 0; i < 6; i++) { NBTTagCompound item = new NBTTagCompound(); item.setByte("Slot", (byte) i); stack.writeToNBT(item); tagList.appendTag(item); } NBTTagCompound inv = new NBTTagCompound(); inv.setTag("Items", tagList); inv.setString("UniqueID", UUID.randomUUID().toString()); mail.stackTagCompound = new NBTTagCompound(); mail.stackTagCompound.setTag("Package", inv); ByteBufUtils.writeItemStack(buf, mail); C17PacketCustomPayload packet = new C17PacketCustomPayload("cfm", buf); Wrapper.INSTANCE.player().sendQueue.addToSendQueue(packet); }
Example #2
Source File: AmadronOfferCustom.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
public void writeToBuf(ByteBuf buf){ ByteBufUtils.writeUTF8String(buf, offeringPlayerName); ByteBufUtils.writeUTF8String(buf, offeringPlayerId); if(providingPosition != null) { buf.writeBoolean(true); buf.writeInt(providingPosition.chunkPosX); buf.writeInt(providingPosition.chunkPosY); buf.writeInt(providingPosition.chunkPosZ); buf.writeInt(providingDimensionId); } else { buf.writeBoolean(false); } if(returningPosition != null) { buf.writeBoolean(true); buf.writeInt(returningPosition.chunkPosX); buf.writeInt(returningPosition.chunkPosY); buf.writeInt(returningPosition.chunkPosZ); buf.writeInt(returningDimensionId); } else { buf.writeBoolean(false); } buf.writeInt(inStock); buf.writeInt(maxTrades); buf.writeInt(pendingPayments); }
Example #3
Source File: PacketUpdateGui.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
public static Object readField(ByteBuf buf, int type){ switch(type){ case 0: return buf.readInt(); case 1: return buf.readFloat(); case 2: return buf.readDouble(); case 3: return buf.readBoolean(); case 4: return ByteBufUtils.readUTF8String(buf); case 5: return buf.readByte(); case 6: return ByteBufUtils.readItemStack(buf); case 7: if(!buf.readBoolean()) return null; return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf)); } throw new IllegalArgumentException("Invalid sync type! " + type); }
Example #4
Source File: ReactantContainer.java From BigReactors with MIT License | 6 votes |
public void deserialize(ByteBuf buffer) { capacity = buffer.readInt(); for(int i = 0; i < tankNames.length; i++) { tanks[i] = null; boolean hasReactant = buffer.readBoolean(); if(hasReactant) { String reactantName = ByteBufUtils.readUTF8String(buffer); int amount = buffer.readInt(); if(!Reactants.isKnown(reactantName)) { BRLog.warning("Read an unknown reactant <%s> from a network message; tank %s will remain empty", reactantName, tankNames[i]); } else { tanks[i] = new ReactantStack(reactantName, amount); levelAtLastUpdate[i] = amount; } } } }
Example #5
Source File: PacketBlockSync.java From Framez with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buf) { super.toBytes(buf); List<IMovingBlock> l = structure.getBlocks(); buf.writeInt(l.size()); for (IMovingBlock b : l) { buf.writeInt(b.getX()); buf.writeInt(b.getY()); buf.writeInt(b.getZ()); NBTTagCompound t = FrameMovementRegistry.instance().writeInfo(b); ByteBufUtils.writeTag(buf, t); } }
Example #6
Source File: PacketSpawnParticle.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buffer){ super.toBytes(buffer); ByteBufUtils.writeUTF8String(buffer, particleName); buffer.writeDouble(dx); buffer.writeDouble(dy); buffer.writeDouble(dz); }
Example #7
Source File: PacketSingleBlockSync.java From Framez with GNU General Public License v3.0 | 5 votes |
@Override public void fromBytes(ByteBuf buf) { super.fromBytes(buf); v = new Vec3i(buf.readInt(), buf.readInt(), buf.readInt()); t = ByteBufUtils.readTag(buf); }
Example #8
Source File: PacketPlaySound.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void fromBytes(ByteBuf buffer){ super.fromBytes(buffer); sound = ByteBufUtils.readUTF8String(buffer); volume = buffer.readFloat(); pitch = buffer.readFloat(); bool = buffer.readBoolean(); }
Example #9
Source File: MegaExploit.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
public void setMagic(int x, int y, int z, ItemStack item) { ByteBuf buf = Unpooled.buffer(0); buf.writeByte(8); buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); ByteBufUtils.writeItemStack(buf, item); C17PacketCustomPayload packet = new C17PacketCustomPayload("TConstruct", buf); Wrapper.INSTANCE.player().sendQueue.addToSendQueue(packet); }
Example #10
Source File: TableTop.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
public void setSlot(int x, int y, int z) throws Exception { ByteBuf buf = Unpooled.buffer(0); ItemStack stack = Statics.STATIC_ITEMSTACK.copy(); stack.setStackDisplayName("Mega Super Spell"); ByteBufUtils.writeItemStack(buf, stack); buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); buf.writeInt(1); C17PacketCustomPayload packet = new C17PacketCustomPayload("BiblioMCBEdit", buf); Wrapper.INSTANCE.player().sendQueue.addToSendQueue(packet); }
Example #11
Source File: ResearchGod.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
private void doResearch(String researchId) { ByteBuf buf = Unpooled.buffer(0); buf.writeByte(14); ByteBufUtils.writeUTF8String(buf, researchId); buf.writeInt(Wrapper.INSTANCE.player().dimension); ByteBufUtils.writeUTF8String(buf, Wrapper.INSTANCE.player().getCommandSenderName()); buf.writeByte(0); C17PacketCustomPayload packet = new C17PacketCustomPayload("thaumcraft", buf); Wrapper.INSTANCE.player().sendQueue.addToSendQueue(packet); }
Example #12
Source File: MagicGod.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
private void doGive(String a1, String a2) { ByteBuf buf = Unpooled.buffer(0); buf.writeByte(13); buf.writeInt(Wrapper.INSTANCE.player().dimension); buf.writeInt(Wrapper.INSTANCE.player().getEntityId()); buf.writeInt(0); buf.writeInt(0); buf.writeInt(0); ByteBufUtils.writeUTF8String(buf, a1); ByteBufUtils.writeUTF8String(buf, a2); buf.writeBoolean(true); buf.writeBoolean(true); C17PacketCustomPayload packet = new C17PacketCustomPayload("thaumcraft", buf); Wrapper.INSTANCE.player().sendQueue.addToSendQueue(packet); }
Example #13
Source File: PacketTileEntityNBT.java From LookingGlass with GNU General Public License v3.0 | 5 votes |
public static FMLProxyPacket createPacket(int xPos, int yPos, int zPos, NBTTagCompound nbt, int dim) { // This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe. ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass()); data.writeInt(dim); data.writeInt(xPos); data.writeInt(yPos); data.writeInt(zPos); ByteBufUtils.writeTag(data, nbt); return buildPacket(data); }
Example #14
Source File: PacketTileEntityNBT.java From LookingGlass with GNU General Public License v3.0 | 5 votes |
@Override public void handle(ByteBuf data, EntityPlayer player) { int dimension = data.readInt(); int xPos = data.readInt(); int yPos = data.readInt(); int zPos = data.readInt(); NBTTagCompound nbt = ByteBufUtils.readTag(data); WorldClient proxyworld = ProxyWorldManager.getProxyworld(dimension); if (proxyworld == null) return; if (proxyworld.provider.dimensionId != dimension) return; if (proxyworld.blockExists(xPos, yPos, zPos)) { TileEntity tileentity = proxyworld.getTileEntity(xPos, yPos, zPos); if (tileentity != null) { tileentity.readFromNBT(nbt); } else { //Create tile entity from data tileentity = TileEntity.createAndLoadEntity(nbt); if (tileentity != null) { proxyworld.addTileEntity(tileentity); } } proxyworld.markTileEntityChunkModified(xPos, yPos, zPos, tileentity); proxyworld.setTileEntity(xPos, yPos, zPos, tileentity); proxyworld.markBlockForUpdate(xPos, yPos, zPos); } }
Example #15
Source File: Debug.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
public static void sendProxyPacket(String channel, Object... data) { ByteBuf buf = Unpooled.buffer(); for (Object o : data) { if (o instanceof Integer) { buf.writeInt(((int) o)); continue; } if (o instanceof Byte) { buf.writeByte(((byte) o)); continue; } if (o instanceof Short) { buf.writeShort(((short) o)); continue; } if (o instanceof String) { ByteBufUtils.writeUTF8String(buf, ((String) o)); continue; } if (o instanceof ItemStack) { ByteBufUtils.writeItemStack(buf, ((ItemStack) o)); continue; } if (!(o instanceof NBTTagCompound)) { continue; } ByteBufUtils.writeTag(buf, ((NBTTagCompound) o)); } NetworkDispatcher.get(Wrapper.INSTANCE.mc().getNetHandler().getNetworkManager()).sendProxy(new FMLProxyPacket(buf, channel)); }
Example #16
Source File: CTTClientSyncMessage.java From NewHorizonsCoreMod with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes( ByteBuf pBuffer ) { pBuffer.writeInt( _mFrame ); pBuffer.writeInt( _mNumFrames ); ByteBufUtils.writeUTF8String( pBuffer, _mPayload ); }
Example #17
Source File: PacketAphorismTileUpdate.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void fromBytes(ByteBuf buffer){ super.fromBytes(buffer); int lines = buffer.readInt(); text = new String[lines]; for(int i = 0; i < lines; i++) { text[i] = ByteBufUtils.readUTF8String(buffer); } }
Example #18
Source File: PacketBlockSync.java From Framez with GNU General Public License v3.0 | 5 votes |
@Override public void fromBytes(ByteBuf buf) { super.fromBytes(buf); int count = buf.readInt(); for (int i = 0; i < count; i++) { Vec3i v = new Vec3i(buf.readInt(), buf.readInt(), buf.readInt()); NBTTagCompound t = ByteBufUtils.readTag(buf); data.put(v, t); } }
Example #19
Source File: PacketPlaySound.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buffer){ super.toBytes(buffer); ByteBufUtils.writeUTF8String(buffer, sound); buffer.writeFloat(volume); buffer.writeFloat(pitch); buffer.writeBoolean(bool); }
Example #20
Source File: PacketSetLogisticsFluidFilterStack.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buf){ super.toBytes(buf); buf.writeBoolean(settingStack != null); if(settingStack != null) { ByteBufUtils.writeUTF8String(buf, settingStack.getFluid().getName()); buf.writeInt(settingStack.amount); ByteBufUtils.writeTag(buf, settingStack.tag); } buf.writeInt(settingIndex); }
Example #21
Source File: PacketDescription.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void fromBytes(ByteBuf buf){ super.fromBytes(buf); type = IDescSynced.Type.values()[buf.readByte()]; int dataAmount = buf.readInt(); types = new byte[dataAmount]; values = new Object[dataAmount]; for(int i = 0; i < dataAmount; i++) { types[i] = buf.readByte(); values[i] = PacketUpdateGui.readField(buf, types[i]); } extraData = ByteBufUtils.readTag(buf); }
Example #22
Source File: PacketSyncAmadronOffers.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public static void writeFluidOrItemStack(Object object, ByteBuf buf){ if(object instanceof ItemStack) { buf.writeByte(0); ByteBufUtils.writeItemStack(buf, (ItemStack)object); } else { buf.writeByte(1); FluidStack stack = (FluidStack)object; ByteBufUtils.writeUTF8String(buf, stack.getFluid().getName()); buf.writeInt(stack.amount); ByteBufUtils.writeTag(buf, stack.tag); } }
Example #23
Source File: PacketSyncAmadronOffers.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public static Object getFluidOrItemStack(ByteBuf buf){ if(buf.readByte() == 0) { return ByteBufUtils.readItemStack(buf); } else { return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf)); } }
Example #24
Source File: PacketDescription.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buf){ super.toBytes(buf); buf.writeByte(type.ordinal()); buf.writeInt(values.length); for(int i = 0; i < types.length; i++) { buf.writeByte(types[i]); PacketUpdateGui.writeField(buf, values[i], types[i]); } ByteBufUtils.writeTag(buf, extraData); }
Example #25
Source File: PacketSetGlobalVariable.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buf){ ByteBufUtils.writeUTF8String(buf, varName); buf.writeInt(value.chunkPosX); buf.writeInt(value.chunkPosY); buf.writeInt(value.chunkPosZ); }
Example #26
Source File: AmadronOfferCustom.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public static AmadronOfferCustom loadFromBuf(ByteBuf buf){ AmadronOfferCustom offer = new AmadronOfferCustom(PacketSyncAmadronOffers.getFluidOrItemStack(buf), PacketSyncAmadronOffers.getFluidOrItemStack(buf), ByteBufUtils.readUTF8String(buf), ByteBufUtils.readUTF8String(buf)); if(buf.readBoolean()) { offer.setProvidingPosition(new ChunkPosition(buf.readInt(), buf.readInt(), buf.readInt()), buf.readInt()); } if(buf.readBoolean()) { offer.setReturningPosition(new ChunkPosition(buf.readInt(), buf.readInt(), buf.readInt()), buf.readInt()); } offer.inStock = buf.readInt(); offer.maxTrades = buf.readInt(); offer.pendingPayments = buf.readInt(); return offer; }
Example #27
Source File: MessageAutoChisel.java From Chisel-2 with GNU General Public License v2.0 | 5 votes |
@Override public void fromBytes(ByteBuf buf) { super.fromBytes(buf); this.playSound = buf.readBoolean(); this.breakChisel = buf.readBoolean(); this.chiseled = buf.readInt(); this.base = ByteBufUtils.readItemStack(buf); }
Example #28
Source File: PacketUpdateGui.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public static void writeField(ByteBuf buf, Object value, int type){ switch(type){ case 0: buf.writeInt((Integer)value); break; case 1: buf.writeFloat((Float)value); break; case 2: buf.writeDouble((Double)value); break; case 3: buf.writeBoolean((Boolean)value); break; case 4: ByteBufUtils.writeUTF8String(buf, (String)value); break; case 5: buf.writeByte((Byte)value); break; case 6: ByteBufUtils.writeItemStack(buf, (ItemStack)value); break; case 7: buf.writeBoolean(value != null); if(value != null) { FluidStack stack = (FluidStack)value; ByteBufUtils.writeUTF8String(buf, stack.getFluid().getName()); buf.writeInt(stack.amount); ByteBufUtils.writeTag(buf, stack.tag); } break; } }
Example #29
Source File: PacketAddChatMessage.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buffer){ ByteBufUtils.writeUTF8String(buffer, message); if(replacements != null) { buffer.writeInt(replacements.length); for(String replacement : replacements) { ByteBufUtils.writeUTF8String(buffer, replacement); } } else { buffer.writeInt(0); } }
Example #30
Source File: PacketAphorismTileUpdate.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buffer){ super.toBytes(buffer); buffer.writeInt(text.length); for(String line : text) { ByteBufUtils.writeUTF8String(buffer, line); } }