diff --git a/src/main/java/com/minecolonies/api/util/constant/WindowConstants.java b/src/main/java/com/minecolonies/api/util/constant/WindowConstants.java index 5c1bafafe4f..a0d71599cd9 100755 --- a/src/main/java/com/minecolonies/api/util/constant/WindowConstants.java +++ b/src/main/java/com/minecolonies/api/util/constant/WindowConstants.java @@ -1,7 +1,9 @@ package com.minecolonies.api.util.constant; import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.common.util.Size2i; +import static com.minecolonies.api.util.constant.Constants.MOD_ID; import static com.minecolonies.api.util.constant.TranslationConstants.*; /** @@ -1278,6 +1280,16 @@ public final class WindowConstants */ public static final String TITLE_LABEL = "title"; + /** + * Crafting switch buttons texture. + */ + public static final ResourceLocation CRAFTING_SWITCH_TEXTURE = new ResourceLocation(MOD_ID, "textures/gui/craftingswitch.png"); + + /** + * Switch button size. + */ + public static final Size2i CRAFTING_SWITCH_SIZE = new Size2i(20, 18); + /** * Private constructor to hide implicit public one. */ diff --git a/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java b/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java index 1fd7a0a1755..b31c381b2f3 100755 --- a/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java +++ b/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java @@ -1,15 +1,19 @@ package com.minecolonies.core.client.gui.containers; import com.minecolonies.api.colony.IColonyManager; +import com.minecolonies.api.colony.requestsystem.request.IRequest; +import com.minecolonies.api.colony.requestsystem.requestable.IConcreteDeliverable; import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.crafting.ModCraftingTypes; import com.minecolonies.api.inventory.container.ContainerCrafting; import com.minecolonies.api.util.ItemStackUtils; import com.minecolonies.core.Network; +import com.minecolonies.core.client.gui.modules.WindowSelectRequest; import com.minecolonies.core.colony.buildings.moduleviews.CraftingModuleView; import com.minecolonies.core.colony.buildings.views.AbstractBuildingView; import com.minecolonies.core.network.messages.server.SwitchRecipeCraftingTeachingMessage; import com.minecolonies.core.network.messages.server.colony.building.worker.AddRemoveRecipeMessage; +import com.minecolonies.core.util.DomumOrnamentumUtils; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.ImageButton; @@ -19,12 +23,17 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.function.Consumer; import static com.minecolonies.api.util.constant.Constants.MOD_ID; import static com.minecolonies.api.util.constant.TranslationConstants.WARNING_MAXIMUM_NUMBER_RECIPES; +import static com.minecolonies.api.util.constant.WindowConstants.*; import static com.minecolonies.api.util.constant.translation.BaseGameTranslationConstants.BASE_GUI_DONE; /** @@ -36,8 +45,6 @@ public class WindowCrafting extends AbstractContainerScreen private static final ResourceLocation CRAFTING_TABLE_GUI_TEXTURES3X3 = new ResourceLocation(MOD_ID, "textures/gui/crafting3x3.png"); - private static final ResourceLocation SWITCH_TEXTURE = new ResourceLocation(MOD_ID, "textures/gui/craftingswitch.png"); - /** * X offset of the button. */ @@ -58,16 +65,6 @@ public class WindowCrafting extends AbstractContainerScreen */ private static final int BUTTON_HEIGHT = 20; - /** - * Switch button width. - */ - private static final int SWITCH_WIDTH = 20; - - /** - * Switch button height. - */ - private static final int SWITCH_HEIGHT = 18; - /** * Switch button horizontal location. */ @@ -76,7 +73,13 @@ public class WindowCrafting extends AbstractContainerScreen /** * Switch button vertical location. */ - private static final int SWITCH_Y_OFFSET = 43 - (SWITCH_HEIGHT / 2); + private static final int SWITCH_Y_OFFSET = 43 - (CRAFTING_SWITCH_SIZE.height / 2); + + /** + * Request list button location. + */ + private static final int REQUEST_X_OFFSET = 100 - (CRAFTING_SWITCH_SIZE.width / 2); + private static final int REQUEST_Y_OFFSET = 70 - CRAFTING_SWITCH_SIZE.height; /** * Color of the gui description. @@ -123,6 +126,9 @@ public class WindowCrafting extends AbstractContainerScreen */ private ImageButton switchButton; + @Nullable public static Consumer JEI_REQUEST_HOOK; + private final Map, ItemStack> requestables = new HashMap<>(); + /** * Create a crafting gui window. * @@ -167,13 +173,21 @@ protected void init() doneButton.active = false; } - this.switchButton = new ImageButton(leftPos + SWITCH_X_OFFSET, topPos + SWITCH_Y_OFFSET, SWITCH_WIDTH, SWITCH_HEIGHT, - 0, 0, SWITCH_HEIGHT + 1, SWITCH_TEXTURE, btn -> + this.switchButton = new ImageButton(leftPos + SWITCH_X_OFFSET, topPos + SWITCH_Y_OFFSET, CRAFTING_SWITCH_SIZE.width, CRAFTING_SWITCH_SIZE.height, + 0, 0, CRAFTING_SWITCH_SIZE.height + 1, CRAFTING_SWITCH_TEXTURE, btn -> { Network.getNetwork().sendToServer(new SwitchRecipeCraftingTeachingMessage()); }); this.switchButton.visible = false; this.addRenderableWidget(this.switchButton); + + final ImageButton requestsButton = new ImageButton(leftPos + REQUEST_X_OFFSET, topPos + REQUEST_Y_OFFSET, CRAFTING_SWITCH_SIZE.width, CRAFTING_SWITCH_SIZE.height, + CRAFTING_SWITCH_SIZE.width + 1, 0, CRAFTING_SWITCH_SIZE.height + 1, CRAFTING_SWITCH_TEXTURE, btn -> + { + requestables.clear(); + new WindowSelectRequest(this.building, this::matchingRequest, this::reopenWithRequest).open(); + }); + this.addRenderableWidget(requestsButton); } @Override @@ -184,6 +198,33 @@ protected void containerTick() this.switchButton.visible = this.menu.canSwitchRecipes(); } + private boolean matchingRequest(@NotNull final IRequest request) + { + if (!DomumOrnamentumUtils.getRequestedStack(request).isEmpty()) return false; + + if (request.getRequest() instanceof IConcreteDeliverable deliverable) + { + for (final ItemStack stack : deliverable.getRequestedItems()) + { + // todo filter? + requestables.put(request, stack); + return true; + } + } + return false; + } + + private void reopenWithRequest(@Nullable final IRequest request) + { + minecraft.setScreen(this); + + final ItemStack stack = requestables.getOrDefault(request, ItemStack.EMPTY); + if (!stack.isEmpty() && JEI_REQUEST_HOOK != null) + { + JEI_REQUEST_HOOK.accept(stack); + } + } + private void onDoneClicked(final Button button) { if (module.canLearn(ModCraftingTypes.SMALL_CRAFTING.get())) diff --git a/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java b/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java index 0aed618d76c..49f4cb5a0a4 100755 --- a/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java +++ b/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java @@ -1,17 +1,22 @@ package com.minecolonies.core.client.gui.containers; import com.minecolonies.api.colony.IColonyManager; +import com.minecolonies.api.colony.requestsystem.request.IRequest; +import com.minecolonies.api.colony.requestsystem.requestable.IConcreteDeliverable; import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.crafting.ModCraftingTypes; import com.minecolonies.api.inventory.container.ContainerCraftingFurnace; import com.minecolonies.api.util.ItemStackUtils; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.Network; +import com.minecolonies.core.client.gui.modules.WindowSelectRequest; import com.minecolonies.core.colony.buildings.moduleviews.CraftingModuleView; import com.minecolonies.core.colony.buildings.views.AbstractBuildingView; import com.minecolonies.core.network.messages.server.colony.building.worker.AddRemoveRecipeMessage; +import com.minecolonies.core.util.DomumOrnamentumUtils; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.ImageButton; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -19,12 +24,17 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Blocks; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; -import static com.minecolonies.api.util.constant.translation.BaseGameTranslationConstants.BASE_GUI_DONE; import static com.minecolonies.api.util.constant.TranslationConstants.WARNING_MAXIMUM_NUMBER_RECIPES; +import static com.minecolonies.api.util.constant.WindowConstants.CRAFTING_SWITCH_SIZE; +import static com.minecolonies.api.util.constant.WindowConstants.CRAFTING_SWITCH_TEXTURE; +import static com.minecolonies.api.util.constant.translation.BaseGameTranslationConstants.BASE_GUI_DONE; /** * Furnace crafting gui. @@ -53,6 +63,12 @@ public class WindowFurnaceCrafting extends AbstractContainerScreen, ItemStack> requestables = new HashMap<>(); + /** * Create a crafting gui window. * @@ -103,6 +121,14 @@ protected void init() { doneButton.active = false; } + + final ImageButton requestsButton = new ImageButton(leftPos + REQUEST_X_OFFSET, topPos + REQUEST_Y_OFFSET, CRAFTING_SWITCH_SIZE.width, CRAFTING_SWITCH_SIZE.height, + CRAFTING_SWITCH_SIZE.width + 1, 0, CRAFTING_SWITCH_SIZE.height + 1, CRAFTING_SWITCH_TEXTURE, btn -> + { + requestables.clear(); + new WindowSelectRequest(this.building, this::matchingRequest, this::reopenWithRequest).open(); + }); + this.addRenderableWidget(requestsButton); } public class OnButtonPress implements Button.OnPress @@ -124,6 +150,33 @@ public void onPress(@NotNull final Button button) } } + private boolean matchingRequest(@NotNull final IRequest request) + { + if (!DomumOrnamentumUtils.getRequestedStack(request).isEmpty()) return false; + + if (request.getRequest() instanceof IConcreteDeliverable deliverable) + { + for (final ItemStack stack : deliverable.getRequestedItems()) + { + // todo filter? + requestables.put(request, stack); + return true; + } + } + return false; + } + + private void reopenWithRequest(@Nullable final IRequest request) + { + minecraft.setScreen(this); + + final ItemStack stack = requestables.getOrDefault(request, ItemStack.EMPTY); + if (!stack.isEmpty() && WindowCrafting.JEI_REQUEST_HOOK != null) + { + WindowCrafting.JEI_REQUEST_HOOK.accept(stack); + } + } + /** * Draws the background layer of this container (behind the items). */ diff --git a/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java b/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java index d22acbd8ce5..20ea35d5c68 100644 --- a/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java +++ b/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java @@ -12,6 +12,7 @@ import com.minecolonies.api.util.Log; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.api.util.constant.TranslationConstants; +import com.minecolonies.core.client.gui.containers.WindowCrafting; import com.minecolonies.core.colony.buildings.modules.AnimalHerdingModule; import com.minecolonies.core.colony.crafting.RecipeAnalyzer; import com.minecolonies.core.compatibility.jei.transfer.*; @@ -21,8 +22,11 @@ import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.helpers.IJeiHelpers; import mezz.jei.api.helpers.IModIdHelper; +import mezz.jei.api.recipe.IFocus; +import mezz.jei.api.recipe.RecipeIngredientRole; import mezz.jei.api.recipe.RecipeType; import mezz.jei.api.registration.*; +import mezz.jei.api.runtime.IJeiRuntime; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.network.chat.Component; @@ -31,6 +35,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.function.BiConsumer; @@ -38,6 +43,11 @@ @mezz.jei.api.JeiPlugin public class JEIPlugin implements IModPlugin { + public JEIPlugin() + { + WindowCrafting.JEI_REQUEST_HOOK = this::showOutputStack; + } + @NotNull @Override public ResourceLocation getPluginUid() @@ -46,6 +56,8 @@ public ResourceLocation getPluginUid() } private final List> categories = new ArrayList<>(); + @Nullable + private IJeiRuntime jei; @Override public void registerCategories(@NotNull final IRecipeCategoryRegistration registration) @@ -187,4 +199,25 @@ public void registerGuiHandlers(@NotNull final IGuiHandlerRegistration registrat new FurnaceCraftingGuiHandler(this.categories).register(registration); new BrewingCraftingGuiHandler(this.categories).register(registration); } + + @Override + public void onRuntimeAvailable(@NotNull final IJeiRuntime jeiRuntime) + { + this.jei = jeiRuntime; + } + + @Override + public void onRuntimeUnavailable() + { + this.jei = null; + } + + private void showOutputStack(@NotNull final ItemStack stack) + { + if (this.jei != null) + { + final IFocus focus = this.jei.getJeiHelpers().getFocusFactory().createFocus(RecipeIngredientRole.OUTPUT, VanillaTypes.ITEM_STACK, stack); + this.jei.getRecipesGui().show(focus); + } + } } diff --git a/src/main/resources/assets/minecolonies/textures/gui/craftingswitch.png b/src/main/resources/assets/minecolonies/textures/gui/craftingswitch.png index abdaa9e4717..2085e38f423 100644 Binary files a/src/main/resources/assets/minecolonies/textures/gui/craftingswitch.png and b/src/main/resources/assets/minecolonies/textures/gui/craftingswitch.png differ