Merge pull request #43 from Zelophed/master

- Add JEI's gui handlers, addresses #42
This commit is contained in:
simibubi 2019-10-27 11:49:25 +01:00 committed by GitHub
commit 44dc7e054b
Failed to generate hash of commit
5 changed files with 74 additions and 4 deletions

View file

@ -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<IRecipe<?>> findRecipes(AllRecipes recipe) {
return findRecipesByType(recipe.type);
}

View file

@ -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<T extends Container> implements IGuiContainerHandler<AbstractSimiContainerScreen<T>> {
@Override
public List<Rectangle2d> getGuiExtraAreas(AbstractSimiContainerScreen<T> containerScreen) {
return containerScreen.getExtraAreas();
}
}

View file

@ -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<T extends Container> 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<Rectangle2d> getExtraAreas() {
return Collections.emptyList();
}
}

View file

@ -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<FlexcrateContainer> {
private FlexcrateTileEntity te;
@ -25,6 +29,8 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen<FlexcrateContai
private ScrollInput allowedItems;
private int lastModification;
private List<Rectangle2d> 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<FlexcrateContai
allowedItems.onChanged();
widgets.add(allowedItemsLabel);
widgets.add(allowedItems);
extraAreas = new ArrayList<>();
extraAreas.add(new Rectangle2d(guiLeft + FLEXCRATE.width + 110, guiTop + 46, 71, 70));
}
@Override
@ -76,6 +85,10 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen<FlexcrateContai
}
ScreenElementRenderer.renderBlock(this::getRenderedBlock);
//to see or debug the bounds of the extra area uncomment the following lines
//Rectangle2d r = extraAreas.get(0);
//fill(r.getX() + r.getWidth(), r.getY() + r.getHeight(), r.getX(), r.getY(), 0xd3d3d3d3);
}
@Override
@ -101,4 +114,8 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen<FlexcrateContai
return AllBlocks.FLEXCRATE.get().getDefaultState();
}
@Override
public List<Rectangle2d> getExtraAreas() {
return extraAreas;
}
}

View file

@ -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<Schematica
protected IconButton resetButton;
protected Indicator resetIndicator;
private List<Rectangle2d> 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<Schematica
skipTilesIndicator = new Indicator(x + 124, y + 96, "");
Collections.addAll(widgets, skipTilesButton, skipTilesIndicator);
extraAreas = new ArrayList<>();
extraAreas.add(new Rectangle2d(guiLeft + 240, guiTop + 88, 84, 113));
tick();
}
@ -219,6 +227,10 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
font.drawString(settingsTitle, guiLeft + 20 + 13, guiTop + 84, ScreenResources.FONT_COLOR);
font.drawString(playerInventory.getDisplayName().getFormattedText(), guiLeft - 10 + 7, guiTop + 145 + 6,
0x666666);
//to see or debug the bounds of the extra area uncomment the following lines
//Rectangle2d r = extraAreas.get(0);
//fill(r.getX() + r.getWidth(), r.getY() + r.getHeight(), r.getX(), r.getY(), 0xd3d3d3d3);
}
protected void renderCannon() {
@ -323,6 +335,11 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
return super.mouseClicked(x, y, button);
}
@Override
public List<Rectangle2d> getExtraAreas() {
return extraAreas;
}
protected void sendOptionUpdate(Option option, boolean set) {
AllPackets.channel
.sendToServer(ConfigureSchematicannonPacket.setOption(container.getTileEntity().getPos(), option, set));