Search in sources :

Example 1 with ContainerCraftingFurnace

use of com.minecolonies.api.inventory.container.ContainerCraftingFurnace 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 2 with ContainerCraftingFurnace

use of com.minecolonies.api.inventory.container.ContainerCraftingFurnace in project minecolonies by Minecolonies.

the class TransferRecipeCraftingTeachingMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final PlayerEntity player = ctxIn.getSender();
    if (player.containerMenu instanceof ContainerCrafting) {
        final ContainerCrafting container = (ContainerCrafting) player.containerMenu;
        if (complete) {
            container.handleSlotClick(container.getSlot(1), itemStacks.getOrDefault(0, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(2), itemStacks.getOrDefault(1, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(3), itemStacks.getOrDefault(2, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(4), itemStacks.getOrDefault(3, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(5), itemStacks.getOrDefault(4, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(6), itemStacks.getOrDefault(5, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(7), itemStacks.getOrDefault(6, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(8), itemStacks.getOrDefault(7, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(9), itemStacks.getOrDefault(8, ItemStackUtils.EMPTY));
        } else {
            container.handleSlotClick(container.getSlot(1), itemStacks.getOrDefault(0, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(2), itemStacks.getOrDefault(1, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(3), itemStacks.getOrDefault(3, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(4), itemStacks.getOrDefault(4, ItemStackUtils.EMPTY));
        }
        container.broadcastChanges();
    } else if (player.containerMenu instanceof ContainerCraftingFurnace) {
        final ContainerCraftingFurnace container = (ContainerCraftingFurnace) player.containerMenu;
        container.setFurnaceInput(itemStacks.getOrDefault(0, ItemStack.EMPTY));
    }
}
Also used : ContainerCraftingFurnace(com.minecolonies.api.inventory.container.ContainerCraftingFurnace) ContainerCrafting(com.minecolonies.api.inventory.container.ContainerCrafting) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 3 with ContainerCraftingFurnace

use of com.minecolonies.api.inventory.container.ContainerCraftingFurnace in project minecolonies by ldtteam.

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 ContainerCraftingFurnace

use of com.minecolonies.api.inventory.container.ContainerCraftingFurnace in project minecolonies by Minecolonies.

the class OpenCraftingGUIMessage method onExecute.

@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
    final ServerPlayerEntity player = ctxIn.getSender();
    if (player == null) {
        return;
    }
    final AbstractCraftingBuildingModule module = building.getModuleMatching(AbstractCraftingBuildingModule.class, m -> m.getId().equals(id));
    if (module.canLearnFurnaceRecipes()) {
        NetworkHooks.openGui(player, new INamedContainerProvider() {

            @NotNull
            @Override
            public ITextComponent getDisplayName() {
                return new StringTextComponent("Furnace Crafting GUI");
            }

            @NotNull
            @Override
            public Container createMenu(final int id, @NotNull final PlayerInventory inv, @NotNull final PlayerEntity player) {
                return new ContainerCraftingFurnace(id, inv, building.getID(), module.getId());
            }
        }, buffer -> new PacketBuffer(buffer.writeBlockPos(building.getID()).writeUtf(module.getId())));
    } else {
        NetworkHooks.openGui(player, new INamedContainerProvider() {

            @NotNull
            @Override
            public ITextComponent getDisplayName() {
                return new StringTextComponent("Crafting GUI");
            }

            @NotNull
            @Override
            public Container createMenu(final int id, @NotNull final PlayerInventory inv, @NotNull final PlayerEntity player) {
                return new ContainerCrafting(id, inv, module.canLearnLargeRecipes(), building.getID(), module.getId());
            }
        }, buffer -> new PacketBuffer(buffer.writeBoolean(module.canLearnLargeRecipes())).writeBlockPos(building.getID()).writeUtf(module.getId()));
    }
}
Also used : AbstractCraftingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule) ContainerCrafting(com.minecolonies.api.inventory.container.ContainerCrafting) ITextComponent(net.minecraft.util.text.ITextComponent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) PlayerInventory(net.minecraft.entity.player.PlayerInventory) NotNull(org.jetbrains.annotations.NotNull) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Container(net.minecraft.inventory.container.Container) ContainerCraftingFurnace(com.minecolonies.api.inventory.container.ContainerCraftingFurnace) StringTextComponent(net.minecraft.util.text.StringTextComponent) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 5 with ContainerCraftingFurnace

use of com.minecolonies.api.inventory.container.ContainerCraftingFurnace in project minecolonies by ldtteam.

the class OpenCraftingGUIMessage method onExecute.

@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
    final ServerPlayerEntity player = ctxIn.getSender();
    if (player == null) {
        return;
    }
    final AbstractCraftingBuildingModule module = building.getModuleMatching(AbstractCraftingBuildingModule.class, m -> m.getId().equals(id));
    if (module.canLearnFurnaceRecipes()) {
        NetworkHooks.openGui(player, new INamedContainerProvider() {

            @NotNull
            @Override
            public ITextComponent getDisplayName() {
                return new StringTextComponent("Furnace Crafting GUI");
            }

            @NotNull
            @Override
            public Container createMenu(final int id, @NotNull final PlayerInventory inv, @NotNull final PlayerEntity player) {
                return new ContainerCraftingFurnace(id, inv, building.getID(), module.getId());
            }
        }, buffer -> new PacketBuffer(buffer.writeBlockPos(building.getID()).writeUtf(module.getId())));
    } else {
        NetworkHooks.openGui(player, new INamedContainerProvider() {

            @NotNull
            @Override
            public ITextComponent getDisplayName() {
                return new StringTextComponent("Crafting GUI");
            }

            @NotNull
            @Override
            public Container createMenu(final int id, @NotNull final PlayerInventory inv, @NotNull final PlayerEntity player) {
                return new ContainerCrafting(id, inv, module.canLearnLargeRecipes(), building.getID(), module.getId());
            }
        }, buffer -> new PacketBuffer(buffer.writeBoolean(module.canLearnLargeRecipes())).writeBlockPos(building.getID()).writeUtf(module.getId()));
    }
}
Also used : AbstractCraftingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule) ContainerCrafting(com.minecolonies.api.inventory.container.ContainerCrafting) ITextComponent(net.minecraft.util.text.ITextComponent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) PlayerInventory(net.minecraft.entity.player.PlayerInventory) NotNull(org.jetbrains.annotations.NotNull) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Container(net.minecraft.inventory.container.Container) ContainerCraftingFurnace(com.minecolonies.api.inventory.container.ContainerCraftingFurnace) StringTextComponent(net.minecraft.util.text.StringTextComponent) PacketBuffer(net.minecraft.network.PacketBuffer)

Aggregations

ContainerCraftingFurnace (com.minecolonies.api.inventory.container.ContainerCraftingFurnace)6 PlayerEntity (net.minecraft.entity.player.PlayerEntity)6 ContainerCrafting (com.minecolonies.api.inventory.container.ContainerCrafting)4 NotNull (org.jetbrains.annotations.NotNull)4 Network (com.minecolonies.coremod.Network)2 AbstractCraftingBuildingModule (com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule)2 TransferRecipeCraftingTeachingMessage (com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Nullable (javax.annotation.Nullable)2 IRecipeLayout (mezz.jei.api.gui.IRecipeLayout)2 IGuiIngredient (mezz.jei.api.gui.ingredient.IGuiIngredient)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 PlayerInventory (net.minecraft.entity.player.PlayerInventory)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 Container (net.minecraft.inventory.container.Container)2 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)2 ItemStack (net.minecraft.item.ItemStack)2