Search in sources :

Example 1 with TransferRecipeCraftingTeachingMessage

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

the class PrivateCraftingTeachingTransferHandler method transferRecipe.

@Nullable
@Override
public IRecipeTransferError transferRecipe(@NotNull final ContainerCrafting craftingGUIBuilding, @NotNull final Object recipe, @NotNull final IRecipeLayout recipeLayout, @NotNull final PlayerEntity player, final boolean maxTransfer, final boolean doTransfer) {
    final IGuiItemStackGroup itemStackGroup = recipeLayout.getItemStacks();
    // compact the crafting grid into a 2x2 area
    final Map<Integer, ItemStack> guiIngredients = new HashMap<>();
    guiIngredients.put(0, ItemStackUtils.EMPTY);
    guiIngredients.put(1, ItemStackUtils.EMPTY);
    guiIngredients.put(3, ItemStackUtils.EMPTY);
    guiIngredients.put(4, ItemStackUtils.EMPTY);
    // indexes that do not fit into the player crafting grid
    final Set<Integer> badIndexes;
    if (craftingGUIBuilding.isComplete()) {
        guiIngredients.put(2, ItemStackUtils.EMPTY);
        guiIngredients.put(5, ItemStackUtils.EMPTY);
        guiIngredients.put(6, ItemStackUtils.EMPTY);
        guiIngredients.put(7, ItemStackUtils.EMPTY);
        guiIngredients.put(8, ItemStackUtils.EMPTY);
        badIndexes = ImmutableSet.of();
    } else {
        badIndexes = ImmutableSet.of(2, 5, 6, 7, 8);
    }
    int inputIndex = 0;
    for (final IGuiIngredient<ItemStack> ingredient : itemStackGroup.getGuiIngredients().values()) {
        if (ingredient.isInput()) {
            if (!ingredient.getAllIngredients().isEmpty()) {
                if (badIndexes.contains(inputIndex)) {
                    final ITextComponent tooltipMessage = new TranslationTextComponent("jei.tooltip.error.recipe.transfer.too.large.player.inventory");
                    return handlerHelper.createUserErrorForSlots(tooltipMessage, badIndexes);
                }
                guiIngredients.put(inputIndex, ingredient.getDisplayedIngredient());
            }
            inputIndex++;
        }
    }
    if (doTransfer) {
        final CraftingInventory craftMatrix = craftingGUIBuilding.getInv();
        if (craftingGUIBuilding.isComplete()) {
            craftMatrix.setItem(0, guiIngredients.get(0));
            craftMatrix.setItem(1, guiIngredients.get(1));
            craftMatrix.setItem(2, guiIngredients.get(2));
            craftMatrix.setItem(3, guiIngredients.get(3));
            craftMatrix.setItem(4, guiIngredients.get(4));
            craftMatrix.setItem(5, guiIngredients.get(5));
            craftMatrix.setItem(6, guiIngredients.get(6));
            craftMatrix.setItem(7, guiIngredients.get(7));
            craftMatrix.setItem(8, guiIngredients.get(8));
        } else {
            craftMatrix.setItem(0, guiIngredients.get(0));
            craftMatrix.setItem(1, guiIngredients.get(1));
            craftMatrix.setItem(2, guiIngredients.get(3));
            craftMatrix.setItem(3, guiIngredients.get(4));
        }
        final TransferRecipeCraftingTeachingMessage message = new TransferRecipeCraftingTeachingMessage(guiIngredients, craftingGUIBuilding.isComplete());
        Network.getNetwork().sendToServer(message);
    }
    return null;
}
Also used : CraftingInventory(net.minecraft.inventory.CraftingInventory) TransferRecipeCraftingTeachingMessage(com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage) HashMap(java.util.HashMap) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 2 with TransferRecipeCraftingTeachingMessage

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

the class FurnaceCraftingGuiHandler method updateServer.

@Override
protected void updateServer(@NotNull final WindowFurnaceCrafting gui) {
    final Map<Integer, ItemStack> matrix = new HashMap<>();
    matrix.put(0, gui.getMenu().getSlot(0).getItem());
    final TransferRecipeCraftingTeachingMessage message = new TransferRecipeCraftingTeachingMessage(matrix, false);
    Network.getNetwork().sendToServer(message);
}
Also used : TransferRecipeCraftingTeachingMessage(com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage) ItemStack(net.minecraft.item.ItemStack)

Example 3 with TransferRecipeCraftingTeachingMessage

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

the class PrivateSmeltingTeachingTransferHandler method transferRecipe.

@Nullable
@Override
public IRecipeTransferError transferRecipe(@NotNull final ContainerCraftingFurnace craftingGUIBuilding, @NotNull final Object recipe, @NotNull final IRecipeLayout recipeLayout, @NotNull final PlayerEntity player, final boolean maxTransfer, final boolean doTransfer) {
    // we only care about the first input ingredient for furnace recipes
    final ItemStack input = recipeLayout.getItemStacks().getGuiIngredients().values().stream().filter(ingredient -> ingredient.isInput() && !ingredient.getAllIngredients().isEmpty()).map(IGuiIngredient::getDisplayedIngredient).findFirst().orElse(ItemStack.EMPTY);
    if (!input.isEmpty() && doTransfer) {
        craftingGUIBuilding.setFurnaceInput(input);
        final Map<Integer, ItemStack> guiIngredients = new HashMap<>();
        guiIngredients.put(0, input);
        final TransferRecipeCraftingTeachingMessage message = new TransferRecipeCraftingTeachingMessage(guiIngredients, false);
        Network.getNetwork().sendToServer(message);
    }
    return null;
}
Also used : IRecipeTransferError(mezz.jei.api.recipe.transfer.IRecipeTransferError) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TransferRecipeCraftingTeachingMessage(com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage) HashMap(java.util.HashMap) IGuiIngredient(mezz.jei.api.gui.ingredient.IGuiIngredient) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) ContainerCraftingFurnace(com.minecolonies.api.inventory.container.ContainerCraftingFurnace) Network(com.minecolonies.coremod.Network) IRecipeTransferHandlerHelper(mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper) IRecipeTransferHandler(mezz.jei.api.recipe.transfer.IRecipeTransferHandler) NotNull(org.jetbrains.annotations.NotNull) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) Nullable(javax.annotation.Nullable) TransferRecipeCraftingTeachingMessage(com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage) IGuiIngredient(mezz.jei.api.gui.ingredient.IGuiIngredient) HashMap(java.util.HashMap) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 4 with TransferRecipeCraftingTeachingMessage

use of com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage in project minecolonies by ldtteam.

the class FurnaceCraftingGuiHandler method updateServer.

@Override
protected void updateServer(@NotNull final WindowFurnaceCrafting gui) {
    final Map<Integer, ItemStack> matrix = new HashMap<>();
    matrix.put(0, gui.getMenu().getSlot(0).getItem());
    final TransferRecipeCraftingTeachingMessage message = new TransferRecipeCraftingTeachingMessage(matrix, false);
    Network.getNetwork().sendToServer(message);
}
Also used : TransferRecipeCraftingTeachingMessage(com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage) ItemStack(net.minecraft.item.ItemStack)

Example 5 with TransferRecipeCraftingTeachingMessage

use of com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage in project minecolonies by ldtteam.

the class PrivateCraftingTeachingTransferHandler method transferRecipe.

@Nullable
@Override
public IRecipeTransferError transferRecipe(@NotNull final ContainerCrafting craftingGUIBuilding, @NotNull final Object recipe, @NotNull final IRecipeLayout recipeLayout, @NotNull final PlayerEntity player, final boolean maxTransfer, final boolean doTransfer) {
    final IGuiItemStackGroup itemStackGroup = recipeLayout.getItemStacks();
    // compact the crafting grid into a 2x2 area
    final Map<Integer, ItemStack> guiIngredients = new HashMap<>();
    guiIngredients.put(0, ItemStackUtils.EMPTY);
    guiIngredients.put(1, ItemStackUtils.EMPTY);
    guiIngredients.put(3, ItemStackUtils.EMPTY);
    guiIngredients.put(4, ItemStackUtils.EMPTY);
    // indexes that do not fit into the player crafting grid
    final Set<Integer> badIndexes;
    if (craftingGUIBuilding.isComplete()) {
        guiIngredients.put(2, ItemStackUtils.EMPTY);
        guiIngredients.put(5, ItemStackUtils.EMPTY);
        guiIngredients.put(6, ItemStackUtils.EMPTY);
        guiIngredients.put(7, ItemStackUtils.EMPTY);
        guiIngredients.put(8, ItemStackUtils.EMPTY);
        badIndexes = ImmutableSet.of();
    } else {
        badIndexes = ImmutableSet.of(2, 5, 6, 7, 8);
    }
    int inputIndex = 0;
    for (final IGuiIngredient<ItemStack> ingredient : itemStackGroup.getGuiIngredients().values()) {
        if (ingredient.isInput()) {
            if (!ingredient.getAllIngredients().isEmpty()) {
                if (badIndexes.contains(inputIndex)) {
                    final ITextComponent tooltipMessage = new TranslationTextComponent("jei.tooltip.error.recipe.transfer.too.large.player.inventory");
                    return handlerHelper.createUserErrorForSlots(tooltipMessage, badIndexes);
                }
                guiIngredients.put(inputIndex, ingredient.getDisplayedIngredient());
            }
            inputIndex++;
        }
    }
    if (doTransfer) {
        final CraftingInventory craftMatrix = craftingGUIBuilding.getInv();
        if (craftingGUIBuilding.isComplete()) {
            craftMatrix.setItem(0, guiIngredients.get(0));
            craftMatrix.setItem(1, guiIngredients.get(1));
            craftMatrix.setItem(2, guiIngredients.get(2));
            craftMatrix.setItem(3, guiIngredients.get(3));
            craftMatrix.setItem(4, guiIngredients.get(4));
            craftMatrix.setItem(5, guiIngredients.get(5));
            craftMatrix.setItem(6, guiIngredients.get(6));
            craftMatrix.setItem(7, guiIngredients.get(7));
            craftMatrix.setItem(8, guiIngredients.get(8));
        } else {
            craftMatrix.setItem(0, guiIngredients.get(0));
            craftMatrix.setItem(1, guiIngredients.get(1));
            craftMatrix.setItem(2, guiIngredients.get(3));
            craftMatrix.setItem(3, guiIngredients.get(4));
        }
        final TransferRecipeCraftingTeachingMessage message = new TransferRecipeCraftingTeachingMessage(guiIngredients, craftingGUIBuilding.isComplete());
        Network.getNetwork().sendToServer(message);
    }
    return null;
}
Also used : CraftingInventory(net.minecraft.inventory.CraftingInventory) TransferRecipeCraftingTeachingMessage(com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage) HashMap(java.util.HashMap) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Aggregations

TransferRecipeCraftingTeachingMessage (com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage)8 ItemStack (net.minecraft.item.ItemStack)8 HashMap (java.util.HashMap)4 Nullable (javax.annotation.Nullable)4 CraftingInventory (net.minecraft.inventory.CraftingInventory)4 ContainerCraftingFurnace (com.minecolonies.api.inventory.container.ContainerCraftingFurnace)2 Network (com.minecolonies.coremod.Network)2 Map (java.util.Map)2 IRecipeLayout (mezz.jei.api.gui.IRecipeLayout)2 IGuiIngredient (mezz.jei.api.gui.ingredient.IGuiIngredient)2 IGuiItemStackGroup (mezz.jei.api.gui.ingredient.IGuiItemStackGroup)2 IRecipeTransferError (mezz.jei.api.recipe.transfer.IRecipeTransferError)2 IRecipeTransferHandler (mezz.jei.api.recipe.transfer.IRecipeTransferHandler)2 IRecipeTransferHandlerHelper (mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ITextComponent (net.minecraft.util.text.ITextComponent)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 NotNull (org.jetbrains.annotations.NotNull)2