Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NEI optional again #23

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/com/enderio/core/EnderCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
import com.enderio.core.common.util.EnderFileUtils;
import com.enderio.core.common.util.PermanentCache;
import com.enderio.core.common.util.TextureErrorRemover;
import com.enderio.core.compat.nei.EnderCoreContainerObjectHandler;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;

import codechicken.nei.guihook.GuiContainerManager;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent;
Expand Down Expand Up @@ -63,6 +66,8 @@ public class EnderCore implements IEnderMod {
@SidedProxy(serverSide = "com.enderio.core.common.CommonProxy", clientSide = "com.enderio.core.client.ClientProxy")
public static CommonProxy proxy;

public static boolean isNEILoaded;

public List<IConfigHandler> configs = Lists.newArrayList();

@EventHandler
Expand All @@ -74,8 +79,13 @@ public void preInit(FMLPreInitializationEvent event) {
lang.localize("error.ttcore.3"));
}

isNEILoaded = Loader.isModLoaded("NotEnoughItems");

if (event.getSide().isClient()) {
TextureErrorRemover.beginIntercepting();
if (isNEILoaded) {
registerNEICompat();
}
}

ConfigHandler.configFolder = event.getModConfigurationDirectory();
Expand Down Expand Up @@ -156,4 +166,9 @@ public String name() {
public String version() {
return EnderCoreTags.VERSION;
}

@Optional.Method(modid = "NotEnoughItems")
private void registerNEICompat() {
GuiContainerManager.addObjectHandler(new EnderCoreContainerObjectHandler());
}
}
54 changes: 4 additions & 50 deletions src/main/java/com/enderio/core/client/gui/GuiContainerBase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enderio.core.client.gui;

import static com.enderio.core.EnderCore.isNEILoaded;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -34,15 +36,10 @@
import codechicken.nei.VisiblityData;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerObjectHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Optional;

@Optional.InterfaceList({ @Optional.Interface(iface = "codechicken.nei.api.INEIGuiHandler", modid = "NotEnoughItems"),
@Optional.Interface(iface = "codechicken.nei.guihook.IContainerObjectHandler", modid = "NotEnoughItems") })
public abstract class GuiContainerBase extends GuiContainer
implements ToolTipRenderer, IGuiScreen, INEIGuiHandler, IContainerObjectHandler {
@Optional.Interface(iface = "codechicken.nei.api.INEIGuiHandler", modid = "NotEnoughItems")
public abstract class GuiContainerBase extends GuiContainer implements ToolTipRenderer, IGuiScreen, INEIGuiHandler {

protected ToolTipManager ttMan = new ToolTipManager();
protected List<IGuiOverlay> overlays = Lists.newArrayList();
Expand All @@ -58,9 +55,6 @@ public abstract class GuiContainerBase extends GuiContainer

protected VScrollbar draggingScrollbar;

protected static boolean registeredNEIHandler;
protected final boolean isNEILoaded = Loader.isModLoaded("NotEnoughItems");

protected GuiContainerBase(Container par1Container) {
super(par1Container);
}
Expand All @@ -75,11 +69,6 @@ public void initGui() {
for (TextFieldEnder f : textFields) {
f.init(this);
}

if (isNEILoaded && !registeredNEIHandler) {
GuiContainerManager.addObjectHandler(this);
registeredNEIHandler = true;
}
}

protected void fixupGuiPosition() {}
Expand Down Expand Up @@ -706,39 +695,4 @@ public boolean handleDragNDrop(GuiContainer gc, int x, int y, ItemStack is, int
public boolean hideItemPanelSlot(GuiContainer gc, int x, int y, int w, int h) {
return false;
}

// IContainerObjectHandler

@Override
@Optional.Method(modid = "NotEnoughItems")
public void guiTick(GuiContainer guiContainer) {}

@Override
@Optional.Method(modid = "NotEnoughItems")
public void refresh(GuiContainer guiContainer) {}

@Override
@Optional.Method(modid = "NotEnoughItems")
public void load(GuiContainer guiContainer) {}

@Override
@Optional.Method(modid = "NotEnoughItems")
public ItemStack getStackUnderMouse(GuiContainer guiContainer, int mouseX, int mouseY) {
if (guiContainer instanceof GuiContainerBase) {
return ((GuiContainerBase) guiContainer).getHoveredStack(mouseX, mouseY);
}
return null;
}

@Override
@Optional.Method(modid = "NotEnoughItems")
public boolean objectUnderMouse(GuiContainer guiContainer, int mouseX, int mouseY) {
return false;
}

@Override
@Optional.Method(modid = "NotEnoughItems")
public boolean shouldShowTooltip(GuiContainer guiContainer) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;

Expand All @@ -12,6 +15,7 @@
public class EnderCorePlugin implements IFMLLoadingPlugin {

public static boolean runtimeDeobfEnabled = false;
public static final Logger logger = LogManager.getLogger("EnderCore");

@Override
public String[] getASMTransformerClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.VarInsnNode;

import com.enderio.core.EnderCore;

import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;

@MCVersion(value = "1.7.10")
Expand Down Expand Up @@ -289,7 +287,7 @@ void transform(Iterator<MethodNode> methods) {

protected final byte[] transform(byte[] classBytes, String className, ObfSafeName methodName,
Transform transformer) {
EnderCore.logger.info("Transforming Class [" + className + "], Method [" + methodName.getName() + "]");
EnderCorePlugin.logger.info("Transforming Class [" + className + "], Method [" + methodName.getName() + "]");

ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(classBytes);
Expand All @@ -301,7 +299,7 @@ protected final byte[] transform(byte[] classBytes, String className, ObfSafeNam

ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(cw);
EnderCore.logger.info("Transforming " + className + " Finished.");
EnderCorePlugin.logger.info("Transforming " + className + " Finished.");
return cw.toByteArray();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.enderio.core.compat.nei;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;

import com.enderio.core.client.gui.GuiContainerBase;

import codechicken.nei.guihook.IContainerObjectHandler;

public class EnderCoreContainerObjectHandler implements IContainerObjectHandler {

@Override
public void guiTick(GuiContainer guiContainer) {}

@Override
public void refresh(GuiContainer guiContainer) {}

@Override
public void load(GuiContainer guiContainer) {}

@Override
public ItemStack getStackUnderMouse(GuiContainer guiContainer, int mouseX, int mouseY) {
if (guiContainer instanceof GuiContainerBase) {
return ((GuiContainerBase) guiContainer).getHoveredStack(mouseX, mouseY);
}
return null;
}

@Override
public boolean objectUnderMouse(GuiContainer guiContainer, int mouseX, int mouseY) {
return false;
}

@Override
public boolean shouldShowTooltip(GuiContainer guiContainer) {
return true;
}
}