Java Code Examples for net.minecraftforge.fml.common.network.ByteBufUtils#writeItemStack()

The following examples show how to use net.minecraftforge.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: RewardForItemBase.java    From malmo with MIT License 5 votes vote down vote up
protected static void sendItemStackToClient(EntityPlayerMP player, MalmoMessageType message, ItemStack is)
{
    ByteBuf buf = Unpooled.buffer();
    ByteBufUtils.writeItemStack(buf, is);
    byte[] bytes = new byte[buf.readableBytes()];
    buf.getBytes(0, bytes);
    String data = DatatypeConverter.printBase64Binary(bytes);
    MalmoMod.MalmoMessage msg = new MalmoMod.MalmoMessage(message, data);
    MalmoMod.network.sendTo(msg, player);
}
 
Example 2
Source File: DiscreteMovementCommandsImplementation.java    From malmo with MIT License 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf)
{
    buf.writeInt(this.pos.getX());
    buf.writeInt(this.pos.getY());
    buf.writeInt(this.pos.getZ());
    ByteBufUtils.writeItemStack(buf, this.itemStack);
    buf.writeInt(this.face.ordinal());
    buf.writeBoolean(this.standOnPlacedBlock);
    buf.writeDouble(this.hitVec.xCoord);
    buf.writeDouble(this.hitVec.yCoord);
    buf.writeDouble(this.hitVec.zCoord);
}
 
Example 3
Source File: InventoryCommandsImplementation.java    From malmo with MIT License 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf)
{
    buf.writeBoolean(this.itemsGained != null);
    if (this.itemsGained != null)
        ByteBufUtils.writeItemStack(buf, this.itemsGained);
    buf.writeBoolean(this.itemsLost != null);
    if (this.itemsLost != null)
        ByteBufUtils.writeItemStack(buf, this.itemsLost);
}
 
Example 4
Source File: PacketUpdateGui.java    From Signals 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 5
Source File: PlainInventory.java    From HoloInventory with MIT License 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf)
{
    super.toBytes(buf);
    ByteBufUtils.writeUTF8String(buf, Strings.nullToEmpty(name));
    buf.writeInt(stacks.size());
    for (ItemStack stack : stacks) ByteBufUtils.writeItemStack(buf, stack);
}
 
Example 6
Source File: PacketUpdateAltar.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
	buf.writeLong(this.pos.toLong());
	ByteBufUtils.writeItemStack(buf, this.stack);
}
 
Example 7
Source File: TriggerActiveAbilityPacket.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf)
{
	ByteBufUtils.writeItemStack(buf, stack);
}