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));
}
}
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));
}
}
Aggregations