Java Code Examples for cpw.mods.fml.common.network.ByteBufUtils#writeItemStack()

The following examples show how to use cpw.mods.fml.common.network.ByteBufUtils#writeItemStack() . 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 vote down vote up
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: Debug.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
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 3
Source File: MegaExploit.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
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 4
Source File: TableTop.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
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 5
Source File: MessageAutoChisel.java    From Chisel-2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
	super.toBytes(buf);
	buf.writeBoolean(playSound);
	buf.writeBoolean(breakChisel);
	buf.writeInt(chiseled);
	ByteBufUtils.writeItemStack(buf, base);
}
 
Example 6
Source File: PacketSyncAmadronOffers.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: PacketCommandGetGlobalVariableOutput.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf){
    ByteBufUtils.writeUTF8String(buf, varName);
    buf.writeInt(pos.chunkPosX);
    buf.writeInt(pos.chunkPosY);
    buf.writeInt(pos.chunkPosZ);
    ByteBufUtils.writeItemStack(buf, stack);
}
 
Example 8
Source File: PacketUpdateGui.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: EntityLingeringEffect.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@Override
public void writeSpawnData(ByteBuf buffer) {
	ByteBufUtils.writeItemStack(buffer, stack);
}
 
Example 10
Source File: EntityLingeringPotion.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@Override
public void writeSpawnData(ByteBuf buffer) {
	ByteBufUtils.writeItemStack(buffer, stack);
}
 
Example 11
Source File: TileEntityCamoMine.java    From AdvancedMod with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void writeToPacket(ByteBuf buf){
    for(ItemStack stack : camoStacks)
        ByteBufUtils.writeItemStack(buf, stack);
}
 
Example 12
Source File: MessageSlotUpdate.java    From Chisel-2 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
	super.toBytes(buf);
	buf.writeInt(slot);
	ByteBufUtils.writeItemStack(buf, stack);
}
 
Example 13
Source File: PacketSetLogisticsFilterStack.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf){
    super.toBytes(buf);
    ByteBufUtils.writeItemStack(buf, settingStack);
    buf.writeInt(settingIndex);
}
 
Example 14
Source File: PacketUseItem.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buffer){
    ByteBufUtils.writeItemStack(buffer, new ItemStack(item, amount, 0));
}