Search in sources :

Example 1 with TransferItemsRequestMessage

use of com.minecolonies.coremod.network.messages.TransferItemsRequestMessage in project minecolonies by Minecolonies.

the class WindowHutBuilder method transferItems.

/**
 * On Button click transfert Items.
 *
 * @param button the clicked button.
 */
private void transferItems(@NotNull final Button button) {
    final Pane pane = button.getParent();
    final Label idLabel = pane.findPaneOfTypeByID(RESOURCE_ID, Label.class);
    final int index = Integer.parseInt(idLabel.getLabelText());
    final BuildingBuilderResource res = resources.get(index);
    if (res == null) {
        Log.getLogger().warn("WindowHutBuilder.transferItems: Error - Could not find the resource.");
    } else {
        // The itemStack size should not be greater than itemStack.getMaxStackSize, We send 1 instead
        // and use quantity for the size
        @NotNull final ItemStack itemStack = new ItemStack(res.getItem(), 1, res.getDamageValue());
        itemStack.setTagCompound(res.getItemStack().getTagCompound());
        final Label quantityLabel = pane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Label.class);
        final int quantity = Integer.parseInt(quantityLabel.getLabelText());
        MineColonies.getNetwork().sendToServer(new TransferItemsRequestMessage(this.building, itemStack, quantity, true));
    }
}
Also used : Label(com.minecolonies.blockout.controls.Label) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack) Pane(com.minecolonies.blockout.Pane) NotNull(org.jetbrains.annotations.NotNull) TransferItemsRequestMessage(com.minecolonies.coremod.network.messages.TransferItemsRequestMessage)

Aggregations

Pane (com.minecolonies.blockout.Pane)1 Label (com.minecolonies.blockout.controls.Label)1 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)1 TransferItemsRequestMessage (com.minecolonies.coremod.network.messages.TransferItemsRequestMessage)1 ItemStack (net.minecraft.item.ItemStack)1 NotNull (org.jetbrains.annotations.NotNull)1