Skip to content

Commit

Permalink
add NEI handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilzinsel64 committed Jan 7, 2025
1 parent cdda3ac commit 3c4818c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/zerofall/ezstorage/EZStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import com.zerofall.ezstorage.events.XEventHandler;
import com.zerofall.ezstorage.gui.GuiHandler;
import com.zerofall.ezstorage.init.EZBlocks;
import com.zerofall.ezstorage.nei.NeiHandler;
import com.zerofall.ezstorage.network.MyMessage;
import com.zerofall.ezstorage.network.PacketHandler;
import com.zerofall.ezstorage.network.RecipeMessage;
import com.zerofall.ezstorage.network.RecipePacketHandler;
import com.zerofall.ezstorage.proxy.CommonProxy;

import codechicken.nei.guihook.GuiContainerManager;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
Expand Down Expand Up @@ -56,5 +58,6 @@ public void preInit(FMLPreInitializationEvent event) {
public void init(FMLInitializationEvent event) {
proxy.registerRenders();
EZBlocks.registerRecipes();
GuiContainerManager.addObjectHandler(new NeiHandler());
}
}
21 changes: 15 additions & 6 deletions src/main/java/com/zerofall/ezstorage/gui/GuiStorageCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class GuiStorageCore extends GuiContainer {
private float currentScroll;
private GuiTextField searchField;
private List<ItemGroup> filteredList;
private ItemStack mouseOverItem;

@Override
public void initGui() {
Expand Down Expand Up @@ -163,20 +164,24 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
cacheMouseOverItem(mouseX, mouseY);
}

protected void cacheMouseOverItem(int mouseX, int mouseY) {
Integer slot = getSlotAt(mouseX, mouseY);

if (slot != null) {
int index = this.tileEntity.inventory.slotCount();
if (slot < this.filteredList.size()) {
ItemGroup group = this.filteredList.get(slot);

if (group != null) {
index = this.tileEntity.inventory.inventory.indexOf(group);
if (index < 0) {
return;
}
this.renderToolTip(group.itemStack, mouseX, mouseY);
mouseOverItem = group.itemStack;
return;
}
}
}

mouseOverItem = null;
}

@Override
Expand Down Expand Up @@ -360,4 +365,8 @@ protected ResourceLocation getBackground() {
public int rowsVisible() {
return 6;
}

public ItemStack getMouseOverItem() {
return mouseOverItem;
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/zerofall/ezstorage/nei/NeiHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.zerofall.ezstorage.nei;

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

import com.zerofall.ezstorage.gui.GuiStorageCore;

import codechicken.nei.guihook.IContainerObjectHandler;
import cpw.mods.fml.common.Optional.Interface;

@Interface(iface = "codechicken.nei.guihook.IContainerObjectHandler", modid = "NotEnoughItems")
public class NeiHandler implements IContainerObjectHandler {

@Override
public void guiTick(GuiContainer gui) {}

@Override
public void refresh(GuiContainer gui) {}

@Override
public void load(GuiContainer gui) {}

@Override
public ItemStack getStackUnderMouse(GuiContainer gui, int mousex, int mousey) {
if (gui instanceof GuiStorageCore guiStorageCore) {
return guiStorageCore.getMouseOverItem();
}
return null;
}

@Override
public boolean objectUnderMouse(GuiContainer gui, int mousex, int mousey) {
return gui instanceof GuiStorageCore guiStorageCore && guiStorageCore.getMouseOverItem() != null;
}

@Override
public boolean shouldShowTooltip(GuiContainer gui) {
return gui instanceof GuiStorageCore guiStorageCore && guiStorageCore.getMouseOverItem() != null;
}
}

0 comments on commit 3c4818c

Please sign in to comment.