From 78ed192f26edab9183ac8403240a323c66da4fd5 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:37:52 -0400 Subject: Improve & Fix Compactor Preview --- .../item/tooltip/CompactorDeletorPreview.java | 2 -- .../tooltip/CompactorPreviewTooltipComponent.java | 30 ++++++++-------------- 2 files changed, 11 insertions(+), 21 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorDeletorPreview.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorDeletorPreview.java index 9cf0356b..657db0c9 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorDeletorPreview.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorDeletorPreview.java @@ -60,8 +60,6 @@ public class CompactorDeletorPreview { // Add the preview tooltip component components.add(targetIndex, new CompactorPreviewTooltipComponent(slots, dimensions)); - // Render accompanying text - components.add(targetIndex, TooltipComponent.of(Text.literal("Contents:").asOrderedText())); if (extraAttributes.contains("PERSONAL_DELETOR_ACTIVE")) { components.add(targetIndex, TooltipComponent.of(Text.literal("Active: ") .append(extraAttributes.getBoolean("PERSONAL_DELETOR_ACTIVE") ? Text.literal("YES").formatted(Formatting.BOLD).formatted(Formatting.GREEN) : Text.literal("NO").formatted(Formatting.BOLD).formatted(Formatting.RED)).asOrderedText())); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorPreviewTooltipComponent.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorPreviewTooltipComponent.java index 22498c02..73f77d0a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorPreviewTooltipComponent.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorPreviewTooltipComponent.java @@ -1,6 +1,5 @@ package de.hysky.skyblocker.skyblock.item.tooltip; -import de.hysky.skyblocker.SkyblockerMod; import it.unimi.dsi.fastutil.ints.IntIntPair; import it.unimi.dsi.fastutil.ints.IntObjectPair; import net.minecraft.client.font.TextRenderer; @@ -10,44 +9,37 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; public class CompactorPreviewTooltipComponent implements TooltipComponent { - private static final Identifier INVENTORY_TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/inventory_background.png"); + private static final Identifier TEXTURE = new Identifier("textures/gui/container/generic_54.png"); private final Iterable> items; private final IntIntPair dimensions; - public CompactorPreviewTooltipComponent(Iterable> items, IntIntPair dimensions) { + CompactorPreviewTooltipComponent(Iterable> items, IntIntPair dimensions) { this.items = items; this.dimensions = dimensions; } @Override public int getHeight() { - return dimensions.leftInt() * 18 + 14; + return dimensions.leftInt() * 18 + 17; } @Override public int getWidth(TextRenderer textRenderer) { - return dimensions.rightInt() * 18 + 14; + return 176; } @Override - public void drawItems(TextRenderer textRenderer, int x, int y, DrawContext context) { - context.drawTexture(INVENTORY_TEXTURE, x, y, 0, 0, 7 + dimensions.rightInt() * 18, 7); - context.drawTexture(INVENTORY_TEXTURE, x + 7 + dimensions.rightInt() * 18, y, 169, 0, 7, 7); - - for (int i = 0; i < dimensions.leftInt(); i++) { - context.drawTexture(INVENTORY_TEXTURE, x, y + 7 + i * 18, 0, 7, 7, 18); - for (int j = 0; j < dimensions.rightInt(); j++) { - context.drawTexture(INVENTORY_TEXTURE, x + 7 + j * 18, y + 7 + i * 18, 7, 7, 18, 18); - } - context.drawTexture(INVENTORY_TEXTURE, x + 7 + dimensions.rightInt() * 18, y + 7 + i * 18, 169, 7, 7, 18); - } - context.drawTexture(INVENTORY_TEXTURE, x, y + 7 + dimensions.leftInt() * 18, 0, 25, 7 + dimensions.rightInt() * 18, 7); - context.drawTexture(INVENTORY_TEXTURE, x + 7 + dimensions.rightInt() * 18, y + 7 + dimensions.leftInt() * 18, 169, 25, 7, 7); + public void drawItems(TextRenderer textRenderer, int x, int y, DrawContext context) { + context.drawTexture(TEXTURE, x, y, 0, 0, 176, dimensions.leftInt() * 18 + 17); + context.drawTexture(TEXTURE, x, y + dimensions.leftInt() * 18 + 17, 0, 215, 176, 7); + + //Draw name - I don't think it needs to be translatable + context.drawText(textRenderer, "Contents", x + 8, y + 6, 0x404040, false); for (IntObjectPair entry : items) { if (entry.right() != null) { int itemX = x + entry.leftInt() % dimensions.rightInt() * 18 + 8; - int itemY = y + entry.leftInt() / dimensions.rightInt() * 18 + 8; + int itemY = y + entry.leftInt() / dimensions.rightInt() * 18 + 18; context.drawItem(entry.right(), itemX, itemY); context.drawItemInSlot(textRenderer, entry.right(), itemX, itemY); } -- cgit From b1676db53cb5dde6c0dfd459fd95940fbc7b65d5 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Tue, 21 Nov 2023 19:10:07 -0800 Subject: Update CompactorPreviewTooltipComponent --- .../tooltip/CompactorPreviewTooltipComponent.java | 40 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorPreviewTooltipComponent.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorPreviewTooltipComponent.java index 73f77d0a..8f2c0901 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorPreviewTooltipComponent.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorPreviewTooltipComponent.java @@ -6,16 +6,20 @@ import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.tooltip.TooltipComponent; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.util.Identifier; public class CompactorPreviewTooltipComponent implements TooltipComponent { private static final Identifier TEXTURE = new Identifier("textures/gui/container/generic_54.png"); + private static final ItemStack BLACK_STAINED_GLASS_PANE = new ItemStack(Items.BLACK_STAINED_GLASS_PANE); private final Iterable> items; private final IntIntPair dimensions; + private final int columns; CompactorPreviewTooltipComponent(Iterable> items, IntIntPair dimensions) { this.items = items; this.dimensions = dimensions; + this.columns = Math.max(dimensions.rightInt(), 3); } @Override @@ -25,24 +29,48 @@ public class CompactorPreviewTooltipComponent implements TooltipComponent { @Override public int getWidth(TextRenderer textRenderer) { - return 176; + return columns * 18 + 14; } + /** + * Draws the items in the compactor/deletor. + * + *

Draws items on a background of {@code dimensions.leftInt()} rows and {@code columns} columns. + * Note that the minimum columns is 3 so the text "Contents" fits. + * If the compactor/deletor only has one column, draw a black stained glass pane to fill the first and third columns. + * 2 columns is not currently supported and will have an empty third column. + */ @Override - public void drawItems(TextRenderer textRenderer, int x, int y, DrawContext context) { - context.drawTexture(TEXTURE, x, y, 0, 0, 176, dimensions.leftInt() * 18 + 17); - context.drawTexture(TEXTURE, x, y + dimensions.leftInt() * 18 + 17, 0, 215, 176, 7); + public void drawItems(TextRenderer textRenderer, int x, int y, DrawContext context) { + // Draw the background with `dimensions.leftInt()` rows and `columns` columns with some texture math + context.drawTexture(TEXTURE, x, y, 0, 0, columns * 18 + 7, dimensions.leftInt() * 18 + 17); + context.drawTexture(TEXTURE, x + columns * 18 + 7, y, 169, 0, 7, dimensions.leftInt() * 18 + 17); + context.drawTexture(TEXTURE, x, y + dimensions.leftInt() * 18 + 17, 0, 215, columns * 18 + 7, 7); + context.drawTexture(TEXTURE, x + columns * 18 + 7, y + dimensions.leftInt() * 18 + 17, 169, 215, 7, 7); //Draw name - I don't think it needs to be translatable context.drawText(textRenderer, "Contents", x + 8, y + 6, 0x404040, false); for (IntObjectPair entry : items) { + int itemX = x + entry.leftInt() % dimensions.rightInt() * 18 + 8; + int itemY = y + entry.leftInt() / dimensions.rightInt() * 18 + 18; + + // Draw a black stained glass pane to fill the left slot if there is only one column + if (dimensions.rightInt() == 1) { + context.drawItem(BLACK_STAINED_GLASS_PANE, itemX, itemY); + context.drawItemInSlot(textRenderer, BLACK_STAINED_GLASS_PANE, itemX, itemY); + itemX += 18; + } if (entry.right() != null) { - int itemX = x + entry.leftInt() % dimensions.rightInt() * 18 + 8; - int itemY = y + entry.leftInt() / dimensions.rightInt() * 18 + 18; context.drawItem(entry.right(), itemX, itemY); context.drawItemInSlot(textRenderer, entry.right(), itemX, itemY); } + // Draw a black stained glass pane to fill the right slot if there is only one column + if (dimensions.rightInt() == 1) { + itemX += 18; + context.drawItem(BLACK_STAINED_GLASS_PANE, itemX, itemY); + context.drawItemInSlot(textRenderer, BLACK_STAINED_GLASS_PANE, itemX, itemY); + } } } } -- cgit