Search in sources :

Example 1 with TransferItemsRequestMessage

use of com.minecolonies.coremod.network.messages.server.colony.building.TransferItemsRequestMessage in project minecolonies by ldtteam.

the class WindowBuilderResModule method transferItems.

/**
 * On Button click transfert Items.
 *
 * @param button the clicked button.
 */
private void transferItems(@NotNull final Button button) {
    final Pane pane = button.getParent();
    button.disable();
    final Text idLabel = pane.findPaneOfTypeByID(RESOURCE_ID, Text.class);
    final int index = Integer.parseInt(idLabel.getTextAsString());
    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 = res.getItemStack().copy();
        itemStack.setCount(1);
        final Text quantityLabel = pane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Text.class);
        final int quantity = Integer.parseInt(quantityLabel.getTextAsString());
        final int needed = res.getAmount() - res.getAvailable();
        res.setAvailable(Math.min(res.getAmount(), res.getAvailable() + res.getPlayerAmount()));
        res.setPlayerAmount(Math.max(0, res.getPlayerAmount() - needed));
        resources.sort(new BuildingBuilderResource.ResourceComparator());
        Network.getNetwork().sendToServer(new TransferItemsRequestMessage(this.buildingView, itemStack, quantity, true));
    }
}
Also used : Text(com.ldtteam.blockout.controls.Text) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack) Pane(com.ldtteam.blockout.Pane) NotNull(org.jetbrains.annotations.NotNull) TransferItemsRequestMessage(com.minecolonies.coremod.network.messages.server.colony.building.TransferItemsRequestMessage)

Example 2 with TransferItemsRequestMessage

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

the class WindowBuilderResModule method transferItems.

/**
 * On Button click transfert Items.
 *
 * @param button the clicked button.
 */
private void transferItems(@NotNull final Button button) {
    final Pane pane = button.getParent();
    button.disable();
    final Text idLabel = pane.findPaneOfTypeByID(RESOURCE_ID, Text.class);
    final int index = Integer.parseInt(idLabel.getTextAsString());
    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 = res.getItemStack().copy();
        itemStack.setCount(1);
        final Text quantityLabel = pane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Text.class);
        final int quantity = Integer.parseInt(quantityLabel.getTextAsString());
        final int needed = res.getAmount() - res.getAvailable();
        res.setAvailable(Math.min(res.getAmount(), res.getAvailable() + res.getPlayerAmount()));
        res.setPlayerAmount(Math.max(0, res.getPlayerAmount() - needed));
        resources.sort(new BuildingBuilderResource.ResourceComparator());
        Network.getNetwork().sendToServer(new TransferItemsRequestMessage(this.buildingView, itemStack, quantity, true));
    }
}
Also used : Text(com.ldtteam.blockout.controls.Text) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack) Pane(com.ldtteam.blockout.Pane) NotNull(org.jetbrains.annotations.NotNull) TransferItemsRequestMessage(com.minecolonies.coremod.network.messages.server.colony.building.TransferItemsRequestMessage)

Aggregations

Pane (com.ldtteam.blockout.Pane)2 Text (com.ldtteam.blockout.controls.Text)2 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)2 TransferItemsRequestMessage (com.minecolonies.coremod.network.messages.server.colony.building.TransferItemsRequestMessage)2 ItemStack (net.minecraft.item.ItemStack)2 NotNull (org.jetbrains.annotations.NotNull)2