mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-19 19:49:38 +00:00
feat: Cover the default behavior of click on nei items when jeca gui opened
This commit is contained in:
1 parent
1f9879ee92
commit
c7c678ec97
7 files changed
+161
-122
No files matched your search
@@ -1,8 +1,10 @@
|
||||
package me.towdium.jecalculation.event;
|
||||
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import me.towdium.jecalculation.event.handlers.EBEventHandler;
|
||||
import me.towdium.jecalculation.event.handlers.EBusEventHandler;
|
||||
import me.towdium.jecalculation.event.handlers.FMLBusEventHandler;
|
||||
import me.towdium.jecalculation.event.handlers.NEIEventHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -16,11 +18,12 @@ public class Handlers {
|
||||
fmlHandlers.add(new FMLBusEventHandler());
|
||||
|
||||
ebHandlers = new ArrayList<>();
|
||||
ebHandlers.add(new EBEventHandler());
|
||||
ebHandlers.add(new EBusEventHandler());
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
Handlers.fmlHandlers.forEach(FMLCommonHandler.instance().bus()::register);
|
||||
Handlers.ebHandlers.forEach(MinecraftForge.EVENT_BUS::register);
|
||||
GuiContainerManager.addInputHandler(new NEIEventHandler());
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package me.towdium.jecalculation.event.handlers;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.gui.JecaGui;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
|
||||
/**
|
||||
* register to MinecraftForge.EVENT_BUS
|
||||
*/
|
||||
public class EBEventHandler {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onMouseClick(GuiScreenEvent.ActionPerformedEvent.Pre event) {
|
||||
JustEnoughCalculation.logger.info("on gui screen event action performed event pre");
|
||||
if (event.gui instanceof JecaGui) {
|
||||
JustEnoughCalculation.logger.info("on mouse click in gui screen event");
|
||||
JecaGui gui = (JecaGui) event.gui;
|
||||
event.setCanceled(gui.handleMouseEvent());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package me.towdium.jecalculation.event.handlers;
|
||||
|
||||
/**
|
||||
* register to MinecraftForge.EVENT_BUS
|
||||
*/
|
||||
public class EBusEventHandler {
|
||||
|
||||
|
||||
}
|
||||
@@ -10,8 +10,6 @@ import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.data.Controller;
|
||||
import me.towdium.jecalculation.data.label.labels.LPlaceholder;
|
||||
import me.towdium.jecalculation.gui.JecaGui;
|
||||
import me.towdium.jecalculation.gui.guis.GuiCraft;
|
||||
import me.towdium.jecalculation.network.ClientHandler;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
@@ -22,10 +20,15 @@ public class FMLBusEventHandler {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SubscribeEvent(receiveCanceled = true)
|
||||
public void onKey(InputEvent.KeyInputEvent event) {
|
||||
if (ClientHandler.keyOpenGuiCraft.isPressed()) Controller.openGuiCraft();
|
||||
if (ClientHandler.keyOpenGuiMath.isPressed()) Controller.openGuiMath();
|
||||
JecaGui.onKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* No effect at client only
|
||||
*
|
||||
* @param event event
|
||||
*/
|
||||
@Deprecated
|
||||
@SubscribeEvent
|
||||
public void onLogout(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
JustEnoughCalculation.logger.info("on log out event");
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package me.towdium.jecalculation.event.handlers;
|
||||
|
||||
import codechicken.nei.guihook.IContainerInputHandler;
|
||||
import me.towdium.jecalculation.gui.JecaGui;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
|
||||
public class NEIEventHandler implements IContainerInputHandler {
|
||||
@Override
|
||||
public boolean keyTyped(GuiContainer guiContainer, char c, int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyTyped(GuiContainer guiContainer, char c, int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean lastKeyTyped(GuiContainer guiContainer, char c, int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(GuiContainer guiContainer, int mouseX, int mouseY, int button) {
|
||||
return JecaGui.onMouse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseClicked(GuiContainer guiContainer, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseUp(GuiContainer guiContainer, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(GuiContainer guiContainer, int i, int i1, int i2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseScrolled(GuiContainer guiContainer, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseDragged(GuiContainer guiContainer, int i, int i1, int i2, long l) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package me.towdium.jecalculation.gui;
|
||||
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import cpw.mods.fml.client.config.GuiUtils;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.data.Controller;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.data.label.labels.LItemStack;
|
||||
import me.towdium.jecalculation.gui.guis.IGui;
|
||||
import me.towdium.jecalculation.nei.NEIPlugin;
|
||||
import me.towdium.jecalculation.network.ClientHandler;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
@@ -19,6 +21,9 @@ import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
@@ -28,9 +33,9 @@ import org.lwjgl.input.Mouse;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static codechicken.lib.gui.GuiDraw.renderEngine;
|
||||
|
||||
@@ -76,6 +81,48 @@ public class JecaGui extends GuiContainer {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true to terminate further processing of this event.
|
||||
*/
|
||||
public static boolean onMouse() {
|
||||
Optional<JecaGui> optionalJecaGui = currentJecaGui();
|
||||
if(!optionalJecaGui.isPresent()) return false;
|
||||
JecaGui gui = optionalJecaGui.get();
|
||||
int mouseX = getMouseX();
|
||||
int mouseY = getMouseY();
|
||||
int button = Mouse.getEventButton();
|
||||
if (button == -1) {
|
||||
int diff = Mouse.getEventDWheel() / 120;
|
||||
if (diff != 0)
|
||||
gui.root.onScroll(gui, mouseX, mouseY, diff);
|
||||
} else if (Mouse.getEventButtonState()) {
|
||||
if (gui.root.onClicked(gui, mouseX, mouseY, button))
|
||||
return true;
|
||||
else if (gui.hand != ILabel.EMPTY) {
|
||||
gui.hand = ILabel.EMPTY;
|
||||
return true;
|
||||
} else {
|
||||
ILabel e = NEIPlugin.getLabelUnderMouse();
|
||||
if (e != ILabel.EMPTY) {
|
||||
gui.hand = e;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Slot getSlotUnderMouse() {
|
||||
IInventory i = new InventoryBasic("", false, 1);
|
||||
Slot s = new Slot(i, 0, 0, 0);
|
||||
ILabel l = getLabelUnderMouse();
|
||||
if (l instanceof LItemStack)
|
||||
s.putStack(((LItemStack) l).getRep());
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
this.guiLeft = (this.width - this.xSize) / 2;
|
||||
@@ -107,6 +154,15 @@ public class JecaGui extends GuiContainer {
|
||||
r.run();
|
||||
}
|
||||
|
||||
public static Optional<JecaGui> currentJecaGui() {
|
||||
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
|
||||
if (gui instanceof JecaGui) {
|
||||
return Optional.of((JecaGui) gui);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The currently displayed {@link JecaGui}
|
||||
* Make sure the method is called when a {@link JecaGui} is displayed!
|
||||
@@ -119,7 +175,6 @@ public class JecaGui extends GuiContainer {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
private static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, IGui root) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
JecaGui parent;
|
||||
@@ -147,6 +202,23 @@ public class JecaGui extends GuiContainer {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ILabel getLabelUnderMouse() {
|
||||
int xMouse = Mouse.getEventX() * width / mc.displayWidth - guiLeft;
|
||||
int yMouse = height - Mouse.getEventY() * height / mc.displayHeight - 1 - guiTop;
|
||||
return root.getLabelUnderMouse(xMouse, yMouse);
|
||||
}
|
||||
|
||||
/**
|
||||
* called by {@link me.towdium.jecalculation.event.handlers.FMLBusEventHandler}
|
||||
*/
|
||||
public static void onKey() {
|
||||
if (ClientHandler.keyOpenGuiCraft.isPressed())
|
||||
Controller.openGuiCraft();
|
||||
if (ClientHandler.keyOpenGuiMath.isPressed())
|
||||
Controller.openGuiMath();
|
||||
}
|
||||
|
||||
public static void onGameTick() {
|
||||
if (scheduled != null) {
|
||||
if (timeout <= 0) {
|
||||
@@ -238,57 +310,12 @@ public class JecaGui extends GuiContainer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function handles events within the interface.
|
||||
* Specifically, handles mouse wheel within interface.
|
||||
* Different from {@link #handleMouseEvent()}, which is
|
||||
* used to handle mouse event outside.
|
||||
*/
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
int diff = Mouse.getEventDWheel() / 120;
|
||||
if (diff != 0)
|
||||
root.onScroll(this, Mouse.getEventX() * width / mc.displayWidth - guiLeft,
|
||||
height - Mouse.getEventY() * height / mc.displayHeight - 1 - guiTop, diff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the event is canceled
|
||||
* This function handles click outside the rNormal region,
|
||||
* especially the overlap with JEI overlay. It handles
|
||||
* mouse event before JEI.
|
||||
*/
|
||||
public boolean handleMouseEvent() {
|
||||
JustEnoughCalculation.logger.info("handle mouse clicked");
|
||||
int xMouse = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
||||
int yMouse = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
|
||||
int button = Mouse.getEventButton();
|
||||
if (Mouse.getEventButtonState()) {
|
||||
if (hand != ILabel.EMPTY) {
|
||||
hand = ILabel.EMPTY;
|
||||
return true;
|
||||
} else {
|
||||
ILabel e = NEIPlugin.getLabelUnderMouse();
|
||||
if (e != ILabel.EMPTY) {
|
||||
hand = e;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void drawResource(Resource r, int xPos, int yPos) {
|
||||
drawResource(r, xPos, yPos, 0xFFFFFF);
|
||||
}
|
||||
|
||||
public void drawResource(Resource r, int xPos, int yPos, int color) {
|
||||
float red = (color >> 16 & 0xFF) / 255.0F;
|
||||
float green = (color >> 8 & 0xFF) / 255.0F;
|
||||
float blue = (color & 0xFF) / 255.0F;
|
||||
float alpha = (~(color >> 24) & 0xFF) / 255.0F;
|
||||
GlStateManager.color(red, green, blue, alpha);
|
||||
setColor(color);
|
||||
mc.getTextureManager().bindTexture(r.getResourceLocation());
|
||||
drawTexturedModalRect(xPos, yPos, r.getXPos(), r.getYPos(), r.getXSize(), r.getYSize());
|
||||
}
|
||||
@@ -348,16 +375,6 @@ public class JecaGui extends GuiContainer {
|
||||
GlStateManager.enableTexture2D();
|
||||
}
|
||||
|
||||
public void drawOverRectangle(int xPos, int yPos, int xSize, int ySize, int color) {
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.colorMask(true, true, true, false);
|
||||
this.drawGradientRect(xPos, yPos, xPos + xSize, yPos + ySize, color, color);
|
||||
GlStateManager.colorMask(true, true, true, true);
|
||||
GlStateManager.enableLighting();
|
||||
GlStateManager.enableDepth();
|
||||
}
|
||||
|
||||
public int getStringWidth(String s) {
|
||||
return fontRendererObj.getStringWidth(s);
|
||||
}
|
||||
@@ -409,7 +426,7 @@ public class JecaGui extends GuiContainer {
|
||||
}
|
||||
|
||||
public void drawItemStack(int xPos, int yPos, ItemStack is, boolean centred) {
|
||||
if (is.getItem() == null) {
|
||||
if (ItemStackHelper.isEmpty(is)) {
|
||||
return;
|
||||
}
|
||||
if (centred) {
|
||||
@@ -426,15 +443,15 @@ public class JecaGui extends GuiContainer {
|
||||
itemRender.zLevel = zLevel - 100F;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
JustEnoughCalculation.logger.info("mouse clicked");
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
boolean inGui = root.onClicked(this, mouseX - guiLeft, mouseY - guiTop, mouseButton);
|
||||
if (!inGui) {
|
||||
this.handleMouseEvent();
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
// JustEnoughCalculation.logger.info("mouse clicked");
|
||||
// super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
// boolean inGui = root.onClicked(this, mouseX - guiLeft, mouseY - guiTop, mouseButton);
|
||||
// if (!inGui) {
|
||||
// this.handleMouseEvent();
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
@@ -508,27 +525,8 @@ public class JecaGui extends GuiContainer {
|
||||
public static class ContainerNonTransfer extends JecContainer {
|
||||
}
|
||||
|
||||
public int getGuiLeft() {
|
||||
return guiLeft;
|
||||
}
|
||||
|
||||
public int getGuiTop() {
|
||||
return guiTop;
|
||||
}
|
||||
|
||||
public void drawHoveringText(String text, int x, int y) {
|
||||
super.drawHoveringText(Collections.singletonList(text), x, y, fontRendererObj);
|
||||
}
|
||||
|
||||
public void drawHoveringText(List<String> textLines, int x, int y) {
|
||||
super.drawHoveringText(textLines, x, y, fontRendererObj);
|
||||
}
|
||||
|
||||
public int getXSize() {
|
||||
return xSize;
|
||||
}
|
||||
|
||||
public int getYSize() {
|
||||
return ySize;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user