Java Code Examples for net.minecraft.network.PacketBuffer#readItemStack()

The following examples show how to use net.minecraft.network.PacketBuffer#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: MessageBackpackUpdate.java    From WearableBackpacks with MIT License 6 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {
	PacketBuffer buffer = new PacketBuffer(buf);
	try {
		_entityId = buffer.readInt();
		_type = UpdateType.fromByte(buffer.readByte());
		switch (_type) {
			case STACK: _stack = buffer.readItemStack(); break;
			case OPEN: _open = buffer.readBoolean(); break;
			default: throw new RuntimeException("Invalid UpdateType");
		}
	} catch (Exception ex) {
		_entityId = -1;
		_type = UpdateType.INVALID;
		_stack = ItemStack.EMPTY;
		_open = false;
	}
}
 
Example 2
Source File: PhantomSlotWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void handleClientAction(int id, PacketBuffer buffer) {
    if (id == 1) {
        ItemStack stackHeld;
        try {
            stackHeld = buffer.readItemStack();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        int mouseButton = buffer.readVarInt();
        boolean shiftKeyDown = buffer.readBoolean();
        ClickType clickType = shiftKeyDown ? ClickType.QUICK_MOVE : ClickType.PICKUP;
        SlotUtil.slotClickPhantom(slotReference, mouseButton, clickType, stackHeld);
    }
}
 
Example 3
Source File: PlayerInventoryUIFactory.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
protected PlayerInventoryHolder readHolderFromSyncData(PacketBuffer syncData) {
    EntityPlayer entityPlayer = Minecraft.getMinecraft().player;
    EnumHand enumHand = EnumHand.values()[syncData.readByte()];
    ItemStack itemStack;
    try {
        itemStack = syncData.readItemStack();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
    return new PlayerInventoryHolder(entityPlayer, enumHand, itemStack);
}
 
Example 4
Source File: CreateRecipe.java    From EnderStorage with MIT License 5 votes vote down vote up
@Nullable
@Override
public CreateRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
    String s = buffer.readString(32767);
    NonNullList<Ingredient> ingredients = NonNullList.withSize(3 * 3, Ingredient.EMPTY);

    for (int k = 0; k < ingredients.size(); ++k) {
        ingredients.set(k, Ingredient.read(buffer));
    }

    ItemStack result = buffer.readItemStack();
    return new CreateRecipe(recipeId, s, result, ingredients);
}
 
Example 5
Source File: ReColourRecipe.java    From EnderStorage with MIT License 5 votes vote down vote up
@Nullable
@Override
public ReColourRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
    String s = buffer.readString(32767);
    Ingredient ing = Ingredient.read(buffer);
    ItemStack result = buffer.readItemStack();
    return new ReColourRecipe(recipeId, s, result, ing);
}
 
Example 6
Source File: ChoppingRecipe.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ChoppingRecipe read(ResourceLocation recipeId, PacketBuffer buffer)
{

    String group = buffer.readString(32767);
    Ingredient ingredient = Ingredient.read(buffer);
    ItemStack itemstack = buffer.readItemStack();
    double outputMultiplier = buffer.readDouble();
    double hitCountMultiplier = buffer.readDouble();
    int maxOutput = buffer.readVarInt();
    int sawingTime = buffer.readVarInt();
    return new ChoppingRecipe(recipeId, group, ingredient, itemstack, outputMultiplier, hitCountMultiplier, maxOutput, sawingTime);
}
 
Example 7
Source File: DryingRecipe.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public DryingRecipe read(ResourceLocation recipeId, PacketBuffer buffer)
{
    String group = buffer.readString(32767);
    Ingredient ingredient = Ingredient.read(buffer);
    ItemStack itemstack = buffer.readItemStack();
    int dryingTime = buffer.readVarInt();
    return new DryingRecipe(recipeId, group, ingredient, itemstack, dryingTime);
}
 
Example 8
Source File: PacketGhostSlot.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static PacketGhostSlot decode(PacketBuffer buffer) {
    return new PacketGhostSlot(buffer.readInt(), buffer.readItemStack());
}
 
Example 9
Source File: ScrapingMessage.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ScrapingMessage(PacketBuffer buf)
{
    stack = buf.readItemStack();
    ret = buf.readItemStack();
}
 
Example 10
Source File: SyncableItemStack.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void readFromStream(PacketBuffer stream) throws IOException {
	this.stack = stream.readItemStack();
}