Search in sources :

Example 1 with AddRemoveRecipeMessage

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

the class WindowListRecipes method onButtonClicked.

/**
 * Called when any button has been clicked.
 *
 * @param button the clicked button.
 */
@Override
public void onButtonClicked(@NotNull final Button button) {
    final int row = recipeList.getListElementIndexByPane(button) - 1;
    if (button.getID().equals(BUTTON_REMOVE)) {
        final IRecipeStorage data = recipes.get(row + 1);
        building.removeRecipe(row + 1);
        MineColonies.getNetwork().sendToServer(new AddRemoveRecipeMessage(data, building, true));
    } else if (button.getID().equals(BUTTON_UP)) {
        building.switchIndex(row, row + 1);
        MineColonies.getNetwork().sendToServer(new ChangeRecipePriorityMessage(building, row, true));
    } else if (button.getID().equals(BUTTON_DOWN)) {
        building.switchIndex(row, row - 1);
        MineColonies.getNetwork().sendToServer(new ChangeRecipePriorityMessage(building, row, false));
    } else if (button.getID().equals(BUTTON_CANCEL)) {
        building.openGui(false);
    }
}
Also used : ChangeRecipePriorityMessage(com.minecolonies.coremod.network.messages.ChangeRecipePriorityMessage) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) AddRemoveRecipeMessage(com.minecolonies.coremod.network.messages.AddRemoveRecipeMessage)

Example 2 with AddRemoveRecipeMessage

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

the class WindowGuiCrafting method mouseClicked.

@Override
protected void mouseClicked(final int mouseX, final int mouseY, final int mouseButton) throws IOException {
    super.mouseClicked(mouseX, mouseY, mouseButton);
    if (doneButton.isMouseOver()) {
        final List<ItemStack> input = new ArrayList<>();
        final List<ItemStack> secondaryOutput = new ArrayList<>();
        for (int i = 1; i <= CRAFTING_GRID_SIZE; i++) {
            final ItemStack stack = inventorySlots.getInventory().get(i);
            if (ItemStackUtils.isEmpty(stack)) {
                continue;
            }
            final ItemStack copy = stack.copy();
            ItemStackUtils.setSize(copy, 1);
            input.add(copy);
            if (copy.getItem().hasContainerItem(copy)) {
                secondaryOutput.add(copy.getItem().getContainerItem(copy));
            }
        }
        final ItemStack primaryOutput = inventorySlots.getSlot(0).getStack().copy();
        if (!ItemStackUtils.isEmpty(primaryOutput)) {
            MineColonies.getNetwork().sendToServer(new AddRemoveRecipeMessage(input, 2, primaryOutput, secondaryOutput, building, false));
            LanguageHandler.sendPlayerMessage(Minecraft.getMinecraft().player, "com.minecolonies.coremod.gui.recipe.done");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) AddRemoveRecipeMessage(com.minecolonies.coremod.network.messages.AddRemoveRecipeMessage) ItemStack(net.minecraft.item.ItemStack)

Aggregations

AddRemoveRecipeMessage (com.minecolonies.coremod.network.messages.AddRemoveRecipeMessage)2 IRecipeStorage (com.minecolonies.api.crafting.IRecipeStorage)1 ChangeRecipePriorityMessage (com.minecolonies.coremod.network.messages.ChangeRecipePriorityMessage)1 ArrayList (java.util.ArrayList)1 ItemStack (net.minecraft.item.ItemStack)1