2022-05-27 07:42:41 -04:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
import java.util.Collection;
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-05-27 07:42:41 -04:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
import net.minecraft.client.entity.EntityPlayerSP;
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.client.renderer.InventoryEffectRenderer;
|
|
|
|
|
import net.minecraft.potion.PotionEffect;
|
|
|
|
|
|
|
|
|
|
import codechicken.lib.vec.Rectangle4i;
|
|
|
|
|
import codechicken.nei.api.INEIGuiAdapter;
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-05-27 07:42:41 -04:00
|
|
|
/**
|
|
|
|
|
* Inspired by InventoryEffectRendererGuiHandler.java in JEI
|
|
|
|
|
*/
|
|
|
|
|
public class NEIPotionGuiHandler extends INEIGuiAdapter {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-05-27 07:42:41 -04:00
|
|
|
@Override
|
|
|
|
|
public boolean hideItemPanelSlot(GuiContainer guiContainer, int slotX, int slotY, int slotW, int slotH) {
|
2022-05-31 23:38:14 +09:00
|
|
|
if (NEIClientConfig.ignorePotionOverlap()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (guiContainer instanceof InventoryEffectRenderer) {
|
2022-05-27 07:42:41 -04:00
|
|
|
int x = guiContainer.guiLeft - 124;
|
|
|
|
|
int y = guiContainer.guiTop;
|
|
|
|
|
Minecraft minecraft = guiContainer.mc;
|
|
|
|
|
if (minecraft == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
EntityPlayerSP player = minecraft.thePlayer;
|
|
|
|
|
if (player == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Collection<PotionEffect> activePotionEffects = player.getActivePotionEffects();
|
|
|
|
|
if (activePotionEffects.isEmpty()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
int height = 33;
|
|
|
|
|
if (activePotionEffects.size() > 5) {
|
|
|
|
|
height = 132 / (activePotionEffects.size() - 1);
|
|
|
|
|
}
|
|
|
|
|
Rectangle4i slotRect = new Rectangle4i(slotX, slotY, slotW, slotH);
|
|
|
|
|
for (PotionEffect potioneffect : activePotionEffects) {
|
|
|
|
|
Rectangle4i box = new Rectangle4i(x, y, 140, 32);
|
2022-06-24 12:32:13 +01:00
|
|
|
if (box.intersects(slotRect)) return true;
|
2022-05-27 07:42:41 -04:00
|
|
|
y += height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|