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

The following examples show how to use net.minecraftforge.fml.common.network.ByteBufUtils#readItemStack() . 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: PacketUpdateGui.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
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));
            default:
                throw new IllegalArgumentException("Invalid sync type! " + type);
        }
    }
 
Example 2
Source File: RewardForDiscardingItemImplementation.java    From malmo with MIT License 5 votes vote down vote up
@Override
public void onMessage(MalmoMessageType messageType, Map<String, String> data) 
{
    String bufstring = data.get("message");
    ByteBuf buf = Unpooled.copiedBuffer(DatatypeConverter.parseBase64Binary(bufstring));
    ItemStack itemStack = ByteBufUtils.readItemStack(buf);
    if (itemStack != null && itemStack.getItem() != null)
    {
        accumulateReward(this.params.getDimension(), itemStack);
    }
    else
    {
        System.out.println("Error - couldn't understand the itemstack we received.");
    }
}
 
Example 3
Source File: RewardForCollectingItemImplementation.java    From malmo with MIT License 5 votes vote down vote up
@Override
public void onMessage(MalmoMessageType messageType, Map<String, String> data) 
{
    String bufstring = data.get("message");
    ByteBuf buf = Unpooled.copiedBuffer(DatatypeConverter.parseBase64Binary(bufstring));
    ItemStack itemStack = ByteBufUtils.readItemStack(buf);
    if (itemStack != null && itemStack.getItem() != null)
    {
        accumulateReward(this.params.getDimension(), itemStack);
    }
    else
    {
        System.out.println("Error - couldn't understand the itemstack we received.");
    }
}
 
Example 4
Source File: DiscreteMovementCommandsImplementation.java    From malmo with MIT License 5 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf)
{
    this.pos = new BlockPos( buf.readInt(), buf.readInt(), buf.readInt() );
    this.itemStack = ByteBufUtils.readItemStack(buf);
    this.face = EnumFacing.values()[buf.readInt()];
    this.standOnPlacedBlock = buf.readBoolean();
    this.hitVec = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
}
 
Example 5
Source File: InventoryCommandsImplementation.java    From malmo with MIT License 5 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf)
{
    boolean gainedItems = buf.readBoolean();
    if (gainedItems)
        this.itemsGained = ByteBufUtils.readItemStack(buf);
    boolean lostItems = buf.readBoolean();
    if (lostItems)
        this.itemsLost = ByteBufUtils.readItemStack(buf);
}
 
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 fromBytes(ByteBuf buf) {
	this.pos = BlockPos.fromLong(buf.readLong());
	this.stack = ByteBufUtils.readItemStack(buf);
}
 
Example 7
Source File: TriggerActiveAbilityPacket.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf)
{
	stack = ByteBufUtils.readItemStack(buf);
}