Skip to content

Commit

Permalink
DnD big ItemStack; Show green slot highlighting overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
slprime committed Feb 21, 2024
1 parent f7ba34c commit 1a911ca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/main/java/codechicken/nei/LayoutManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -828,11 +828,10 @@ public static void drawButtonBackground(int x, int y, int w, int h, boolean edge
public static void drawItemPresenceOverlay(int slotX, int slotY, boolean isPresent, boolean slotHighlight) {

if (slotHighlight) {
if (isPresent) return;
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glTranslatef(0, 0, -150);
drawRect(slotX, slotY, 16, 16, 0x80AA0000);
drawRect(slotX, slotY, 16, 16, isPresent ? 0x8000AA00 : 0x80AA0000);
GL11.glTranslatef(0, 0, 150);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
Expand Down
35 changes: 26 additions & 9 deletions src/main/java/codechicken/nei/guihook/GuiContainerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.recipe.StackInfo;
import codechicken.nei.util.ReadableNumberConverter;

public class GuiContainerManager {

Expand Down Expand Up @@ -269,17 +270,34 @@ public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer font
boolean glRescale = GL11.glGetBoolean(GL12.GL_RESCALE_NORMAL);

float zLevel = drawItems.zLevel += 100F;
float scale = smallAmount ? 0.5f : 1f;

try {
drawItems.renderItemAndEffectIntoGUI(fontRenderer, renderEngine, itemstack, i, j);

if (stackSize == null) {
stackSize = itemstack.stackSize > 1 ? String.valueOf(itemstack.stackSize) : "";
if (itemstack.stackSize > 1) {
String amountText = ReadableNumberConverter.INSTANCE.toWideReadableForm(itemstack.stackSize);

if (amountText.length() == 3) {
scale = 0.8f;
} else if (amountText.length() == 4) {
scale = 0.6f;
} else if (amountText.length() > 4) {
scale = 0.5f;
}

stackSize = String.valueOf(itemstack.stackSize);
} else {
stackSize = "";
}

}

if (smallAmount) {
if (scale != 1f) {

if (!stackSize.isEmpty()) {
drawBigStackSize(i, j, stackSize);
drawBigStackSize(i, j, stackSize, scale);
}

// stackSize = "". it needed for correct draw item with alpha and blend
Expand Down Expand Up @@ -311,16 +329,15 @@ public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer font
}

// copy from appeng.client.render.AppEngRenderItem
protected static void drawBigStackSize(int offsetX, int offsetY, String stackSize) {
final float scaleFactor = fontRenderer.getUnicodeFlag() ? 0.85f : 0.5f;
final float inverseScaleFactor = 1.0f / scaleFactor;
protected static void drawBigStackSize(int offsetX, int offsetY, String stackSize, float scale) {
final float inverseScaleFactor = 1.0f / scale;

enable2DRender();
GL11.glScaled(scaleFactor, scaleFactor, scaleFactor);
GL11.glScaled(scale, scale, scale);

final int X = (int) (((float) offsetX + 16.0f - fontRenderer.getStringWidth(stackSize) * scaleFactor)
final int X = (int) (((float) offsetX + 16.0f - fontRenderer.getStringWidth(stackSize) * scale)
* inverseScaleFactor);
final int Y = (int) (((float) offsetY + 16.0f - 7.0f * scaleFactor) * inverseScaleFactor);
final int Y = (int) (((float) offsetY + 16.0f - 7.0f * scale) * inverseScaleFactor);
fontRenderer.drawStringWithShadow(stackSize, X, Y, 16777215);

GL11.glScaled(inverseScaleFactor, inverseScaleFactor, inverseScaleFactor);
Expand Down

0 comments on commit 1a911ca

Please sign in to comment.