diff options
author | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2023-11-23 02:21:19 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-23 02:21:19 -0500 |
commit | 2af269f2dc21f298af66db69332b1997625b96d9 (patch) | |
tree | 4a02ea235861e8fd3e7f301ba9644ab3b1c012c7 /src | |
parent | 1591de0824fe0e7acd5657db79b2977ee7b08437 (diff) | |
parent | b1676db53cb5dde6c0dfd459fd95940fbc7b65d5 (diff) | |
download | Skyblocker-2af269f2dc21f298af66db69332b1997625b96d9.tar.gz Skyblocker-2af269f2dc21f298af66db69332b1997625b96d9.tar.bz2 Skyblocker-2af269f2dc21f298af66db69332b1997625b96d9.zip |
Merge pull request #397 from AzureAaron/fix-compactor-tex
Improve & Fix Compactor Preview
Diffstat (limited to 'src')
2 files changed, 38 insertions, 20 deletions
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..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 @@ -1,56 +1,76 @@ 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; 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 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 static final ItemStack BLACK_STAINED_GLASS_PANE = new ItemStack(Items.BLACK_STAINED_GLASS_PANE); private final Iterable<IntObjectPair<ItemStack>> items; private final IntIntPair dimensions; + private final int columns; - public CompactorPreviewTooltipComponent(Iterable<IntObjectPair<ItemStack>> items, IntIntPair dimensions) { + CompactorPreviewTooltipComponent(Iterable<IntObjectPair<ItemStack>> items, IntIntPair dimensions) { this.items = items; this.dimensions = dimensions; + this.columns = Math.max(dimensions.rightInt(), 3); } @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 columns * 18 + 14; } + /** + * Draws the items in the compactor/deletor. + * + * <p>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(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); + // 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); - 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); + //Draw name - I don't think it needs to be translatable + context.drawText(textRenderer, "Contents", x + 8, y + 6, 0x404040, false); for (IntObjectPair<ItemStack> 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 + 8; 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); + } } } } |