Skip to content

Commit

Permalink
Add JEI plugin to tell it about the sidebars in our computer/robot UIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnuecke committed Feb 7, 2022
1 parent 684c27b commit e1b6fc2
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
import li.cil.oc2.common.util.TooltipUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.Inventory;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.ArrayList;
import java.util.List;

import static java.util.Arrays.asList;
Expand All @@ -38,6 +40,25 @@ public AbstractMachineInventoryScreen(final T container, final Inventory playerI

///////////////////////////////////////////////////////////////////

public List<Rect2i> getExtraAreas() {
final List<Rect2i> list = new ArrayList<>();
list.add(new Rect2i(
leftPos - Sprites.SIDEBAR_2.width, topPos + CONTROLS_TOP,
Sprites.SIDEBAR_2.width, Sprites.SIDEBAR_2.height
));

if (shouldRenderEnergyBar()) {
list.add(new Rect2i(
leftPos - Sprites.SIDEBAR_2.width, topPos + ENERGY_TOP,
Sprites.SIDEBAR_2.width, Sprites.SIDEBAR_2.height
));
}

return list;
}

///////////////////////////////////////////////////////////////////

@Override
protected void init() {
super.init();
Expand Down Expand Up @@ -77,8 +98,6 @@ public void onPress() {
}.withTooltip(new TranslatableComponent(Constants.MACHINE_OPEN_TERMINAL_CAPTION)));
}

///////////////////////////////////////////////////////////////////

@Override
protected void renderBg(final PoseStack stack, final float partialTicks, final int mouseX, final int mouseY) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import li.cil.oc2.common.util.TooltipUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.TextComponent;
Expand All @@ -19,6 +20,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.ArrayList;
import java.util.List;

import static java.util.Arrays.asList;
Expand Down Expand Up @@ -48,6 +50,23 @@ public static boolean isInputCaptureEnabled() {
return isInputCaptureEnabled;
}

public List<Rect2i> getExtraAreas() {
final List<Rect2i> list = new ArrayList<>();
list.add(new Rect2i(
leftPos - Sprites.SIDEBAR_3.width, topPos + CONTROLS_TOP,
Sprites.SIDEBAR_3.width, Sprites.SIDEBAR_3.height
));

if (shouldRenderEnergyBar()) {
list.add(new Rect2i(
leftPos - Sprites.SIDEBAR_2.width, topPos + ENERGY_TOP,
Sprites.SIDEBAR_2.width, Sprites.SIDEBAR_2.height
));
}

return list;
}

@Override
public void containerTick() {
super.containerTick();
Expand Down Expand Up @@ -171,7 +190,7 @@ protected void renderFg(final PoseStack stack, final float partialTicks, final i

@Override
protected void renderBg(final PoseStack stack, final float partialTicks, final int mouseX, final int mouseY) {
Sprites.SIDEBAR_3.draw(stack, leftPos - Sprites.SIDEBAR_2.width, topPos + CONTROLS_TOP);
Sprites.SIDEBAR_3.draw(stack, leftPos - Sprites.SIDEBAR_3.width, topPos + CONTROLS_TOP);

if (shouldRenderEnergyBar()) {
final int x = leftPos - Sprites.SIDEBAR_2.width;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* SPDX-License-Identifier: MIT */

package li.cil.oc2.common.integration.jei;

import li.cil.oc2.api.API;
import li.cil.oc2.client.gui.AbstractMachineInventoryScreen;
import li.cil.oc2.client.gui.AbstractMachineTerminalScreen;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.gui.handlers.IGuiContainerHandler;
import mezz.jei.api.registration.IGuiHandlerRegistration;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.resources.ResourceLocation;

import java.util.List;

@JeiPlugin
public class ExtraGuiAreasJEIPlugin implements IModPlugin {
@Override
public ResourceLocation getPluginUid() {
return new ResourceLocation(API.MOD_ID, "extra_gui_areas");
}

@Override
public void registerGuiHandlers(final IGuiHandlerRegistration registration) {
registration.addGenericGuiContainerHandler(AbstractMachineInventoryScreen.class, new AbstractMachineInventoryScreenGuiContainerHandler());
registration.addGenericGuiContainerHandler(AbstractMachineTerminalScreen.class, new AbstractMachineTerminalScreenGuiContainerHandler());
}

private static final class AbstractMachineInventoryScreenGuiContainerHandler implements IGuiContainerHandler<AbstractMachineInventoryScreen<?>> {
@Override
public List<Rect2i> getGuiExtraAreas(final AbstractMachineInventoryScreen<?> screen) {
return screen.getExtraAreas();
}
}

private static final class AbstractMachineTerminalScreenGuiContainerHandler implements IGuiContainerHandler<AbstractMachineTerminalScreen<?>> {
@Override
public List<Rect2i> getGuiExtraAreas(final AbstractMachineTerminalScreen<?> screen) {
return screen.getExtraAreas();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* SPDX-License-Identifier: MIT */

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package li.cil.oc2.common.integration.jei;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;

0 comments on commit e1b6fc2

Please sign in to comment.