From 8eb10d68a8245b28a527aa386c120a4b837a4173 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 27 Oct 2019 03:54:20 +0100 Subject: [PATCH] added gui handlers from the jei api to FlexcrateScreen and SchematicannonScreen, addresses #42 --- .../simibubi/create/compat/jei/CreateJEI.java | 13 ++++++++---- .../simibubi/create/compat/jei/SlotMover.java | 21 +++++++++++++++++++ .../gui/AbstractSimiContainerScreen.java | 10 +++++++++ .../logistics/block/FlexcrateScreen.java | 17 +++++++++++++++ .../block/SchematicannonScreen.java | 17 +++++++++++++++ 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/simibubi/create/compat/jei/SlotMover.java diff --git a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java index d4fbef785..f579a0530 100644 --- a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java +++ b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java @@ -9,12 +9,11 @@ import com.simibubi.create.AllRecipes; import com.simibubi.create.Create; import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.modules.logistics.block.FlexcrateScreen; +import com.simibubi.create.modules.schematics.block.SchematicannonScreen; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; -import mezz.jei.api.registration.IRecipeCatalystRegistration; -import mezz.jei.api.registration.IRecipeCategoryRegistration; -import mezz.jei.api.registration.IRecipeRegistration; -import mezz.jei.api.registration.ISubtypeRegistration; +import mezz.jei.api.registration.*; import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; @@ -90,6 +89,12 @@ public class CreateJEI implements IModPlugin { registration.addRecipeCatalyst(new ItemStack(AllItems.PLACEMENT_HANDGUN.get()), blockzapperCategory.getUid()); } + @Override + public void registerGuiHandlers(IGuiHandlerRegistration registration) { + registration.addGuiContainerHandler(FlexcrateScreen.class, new SlotMover<>()); + registration.addGuiContainerHandler(SchematicannonScreen.class, new SlotMover<>()); + } + private static List> findRecipes(AllRecipes recipe) { return findRecipesByType(recipe.type); } diff --git a/src/main/java/com/simibubi/create/compat/jei/SlotMover.java b/src/main/java/com/simibubi/create/compat/jei/SlotMover.java new file mode 100644 index 000000000..6d1df645e --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/jei/SlotMover.java @@ -0,0 +1,21 @@ +package com.simibubi.create.compat.jei; + +import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; +import mezz.jei.api.gui.handlers.IGuiContainerHandler; +import net.minecraft.client.renderer.Rectangle2d; +import net.minecraft.inventory.container.Container; + +import java.util.List; + +/** + * Allows a {@link AbstractSimiContainerScreen} to specify an area in getExtraArea() that will be avoided by JEI + * + * Name is taken from CoFHCore's 1.12 implementation. + */ +public class SlotMover implements IGuiContainerHandler> { + + @Override + public List getGuiExtraAreas(AbstractSimiContainerScreen containerScreen) { + return containerScreen.getExtraAreas(); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java index b64478e6f..204154ee5 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation.gui; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import com.mojang.blaze3d.platform.GlStateManager; @@ -8,6 +9,7 @@ import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget; import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.client.gui.widget.Widget; +import net.minecraft.client.renderer.Rectangle2d; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.Container; @@ -128,4 +130,12 @@ public abstract class AbstractSimiContainerScreen extends C } } + /** + * Used for moving JEI out of the way of extra things like Flexcrate renders + * + * @return the space that the gui takes up besides the normal rectangle defined by {@link ContainerScreen}. + */ + public List getExtraAreas() { + return Collections.emptyList(); + } } diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateScreen.java b/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateScreen.java index d148a057b..0099a2e0c 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateScreen.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/FlexcrateScreen.java @@ -15,9 +15,13 @@ import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.logistics.packet.ConfigureFlexcratePacket; import net.minecraft.block.BlockState; +import net.minecraft.client.renderer.Rectangle2d; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.text.ITextComponent; +import java.util.ArrayList; +import java.util.List; + public class FlexcrateScreen extends AbstractSimiContainerScreen { private FlexcrateTileEntity te; @@ -25,6 +29,8 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen extraAreas; + private final String title = Lang.translate("gui.flexcrate.title"); private final String storageSpace = Lang.translate("gui.flexcrate.storageSpace"); @@ -47,6 +53,9 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen(); + extraAreas.add(new Rectangle2d(guiLeft + FLEXCRATE.width + 110, guiTop + 46, 71, 70)); } @Override @@ -76,6 +85,10 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen getExtraAreas() { + return extraAreas; + } } diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonScreen.java b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonScreen.java index dea178076..0c4329997 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonScreen.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonScreen.java @@ -1,7 +1,9 @@ package com.simibubi.create.modules.schematics.block; +import static com.simibubi.create.ScreenResources.FLEXCRATE; import static net.minecraft.util.text.TextFormatting.GRAY; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Vector; @@ -22,6 +24,7 @@ import com.simibubi.create.modules.schematics.packet.ConfigureSchematicannonPack import com.simibubi.create.modules.schematics.packet.ConfigureSchematicannonPacket.Option; import net.minecraft.client.gui.widget.Widget; +import net.minecraft.client.renderer.Rectangle2d; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.BlockItem; @@ -46,6 +49,8 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen extraAreas; + private final String title = Lang.translate("gui.schematicannon.title"); private final String settingsTitle = Lang.translate("gui.schematicannon.settingsTitle"); private final String listPrinter = Lang.translate("gui.schematicannon.listPrinter"); @@ -112,6 +117,9 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen(); + extraAreas.add(new Rectangle2d(guiLeft + 240, guiTop + 88, 84, 113)); + tick(); } @@ -219,6 +227,10 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen getExtraAreas() { + return extraAreas; + } + protected void sendOptionUpdate(Option option, boolean set) { AllPackets.channel .sendToServer(ConfigureSchematicannonPacket.setOption(container.getTileEntity().getPos(), option, set));