Fix Some Rendering

This commit is contained in:
Kam committed 2025-02-21 19:37:57 -05:00
1 parent a37b32c1a5
commit 1c190fe5c4
2 files changed
+25 -15

No files matched your search

@@ -81,9 +81,9 @@ public class GuiCNPCInventory extends GuiNPCInterface {
clientButton.renderResource = specialIcons;
addSideButton(clientButton);
int effectBarX = guiLeft + xSize + 65;
int effectBarX = guiLeft - 40;
int effectBarY = guiTop + 10;
int effectBarWidth = 20;
int effectBarWidth = 28;
int effectBarHeight = ySize;
effectBar = new GuiEffectBar(effectBarX, effectBarY, effectBarWidth, effectBarHeight);
}
@@ -108,23 +108,24 @@ public class GuiCNPCInventory extends GuiNPCInterface {
updateEffectBar();
super.drawScreen(mouseX, mouseY, partialTicks);
if (!ConfigClient.HideEffectsBar && effectBar != null && !effectBar.entries.isEmpty()) {
effectBar.drawScreen(mouseX, mouseY, partialTicks);
if(activeTab != -100)
effectBar.drawScreen(mouseX, mouseY, partialTicks);
}
}
@Override
public void handleMouseInput() {
super.handleMouseInput();
int delta = Mouse.getDWheel();
if (delta != 0 && effectBar != null) {
int mouseX = Mouse.getX() * width / mc.displayWidth;
int mouseY = height - Mouse.getY() * height / mc.displayHeight - 1;
// Only scroll the effect bar if the mouse is over its area.
int mouseX = Mouse.getX() * this.width / mc.displayWidth;
int mouseY = this.height - Mouse.getY() * this.height / mc.displayHeight - 1;
if (mouseX >= effectBar.x && mouseX < effectBar.x + effectBar.width &&
mouseY >= effectBar.y && mouseY < effectBar.y + effectBar.height) {
effectBar.mouseScrolled(delta > 0 ? 1 : -1);
// Use delta/120 to convert the typical scroll wheel values to ±1
effectBar.mouseScrolled(delta / 120);
}
}
super.handleMouseInput();
}
@@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.renderer.ImageData;
@@ -19,7 +20,7 @@ import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIc
public class GuiEffectBar extends GuiScreen {
public int x, y, width, height;
public int scrollY = 0; // Tracks vertical scrolling
public int entryHeight = 20; // Height for each effect slot
public int entryHeight = 28; // Height for each effect slot
public List<EffectEntry> entries = new ArrayList<>();
public FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
@@ -55,8 +56,10 @@ public class GuiEffectBar extends GuiScreen {
int scissorH = height * scaleFactor;
GL11.glScissor(scissorX, scissorY, scissorW, scissorH);
int iconRenderSize = 16;
int iconRenderSize = 24;
int padding = 1;
// Calculate vertical offset to center the icon in the slot
int iconYOffset = (entryHeight - iconRenderSize) / 2;
int startIndex = scrollY / (entryHeight + padding);
int endIndex = Math.min(entries.size(), startIndex + height / (entryHeight + padding) + 1);
@@ -79,15 +82,16 @@ public class GuiEffectBar extends GuiScreen {
int iconHeight = entry.effect.getHeight();
int texWidth = imageData.getTotalWidth();
func_152125_a(x + 2, drawY + 2, iconU, iconV, iconWidth, iconHeight, iconRenderSize, iconRenderSize, texWidth, texWidth);
// Use iconYOffset to vertically center the icon
func_152125_a(x + 2, drawY + iconYOffset, iconU, iconV, iconWidth, iconHeight, iconRenderSize, iconRenderSize, texWidth, texWidth);
GL11.glDisable(GL11.GL_DEPTH_TEST);
minecraft.getTextureManager().bindTexture(specialIcons);
func_152125_a(x + 2, drawY + 2, 0, 224, 16, 16, iconRenderSize, iconRenderSize, 256, 256);
Minecraft.getMinecraft().getTextureManager().bindTexture(specialIcons);
func_152125_a(x + 2, drawY + iconYOffset, 0, 224, 16, 16, iconRenderSize, iconRenderSize, 256, 256);
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
// If mouse hovers over this effect, save tooltip info
// Mouse hover logic remains unchanged
if (mouseX >= x && mouseX < x + width &&
mouseY >= drawY && mouseY < drawY + entryHeight) {
int seconds = entry.playerEffect.duration;
@@ -126,7 +130,8 @@ public class GuiEffectBar extends GuiScreen {
* Adjusted scrolling to move up and down instead of left and right.
*/
public void mouseScrolled(int delta) {
int totalHeight = entries.size() * entryHeight;
int padding = 1;
int totalHeight = entries.size() * (entryHeight + padding);
scrollY -= delta * 10; // Adjust scroll speed as needed.
if (scrollY < 0) scrollY = 0;
if (scrollY > totalHeight - height) scrollY = Math.max(totalHeight - height, 0);
@@ -155,6 +160,7 @@ public class GuiEffectBar extends GuiScreen {
int screenWidth = Minecraft.getMinecraft().currentScreen.width;
int screenHeight = Minecraft.getMinecraft().currentScreen.height;
TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
int tooltipX = x + 12;
int tooltipY = y - 12;
@@ -188,7 +194,10 @@ public class GuiEffectBar extends GuiScreen {
func_152125_a(tooltipX + (maxWidth - iconSize) / 2, textY + 4, hoveredEffect.iconX, hoveredEffect.iconY, hoveredEffect.getWidth(), hoveredEffect.getHeight(), iconSize, iconSize, imageData.getTotalWidth(), imageData.getTotalWidth());
}
textureManager.bindTexture(specialIcons);
func_152125_a(tooltipX + (maxWidth - iconSize) / 2, textY + 4, 0, 224, 16, 16, iconSize, iconSize, 256, 256);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glPopMatrix();
GL11.glPopAttrib();
}