Skip to content

Commit

Permalink
fix: small tweak to item icon rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Jun 17, 2024
1 parent 4b08c0d commit f958e79
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions common/src/main/java/dev/ftb/mods/ftblibrary/icon/ItemIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.architectury.registry.registries.RegistrarManager;
import dev.ftb.mods.ftblibrary.FTBLibrary;
import dev.ftb.mods.ftblibrary.ui.GuiHelper;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down Expand Up @@ -60,9 +61,10 @@ public static Icon getItemIcon(String lazyStackString) {
if (s.length >= 4 && !s[3].equals("null")) {
try {
DataComponentMap.CODEC.parse(NbtOps.INSTANCE, TagParser.parseTag(s[3]))
.ifSuccess(stack::applyComponents);
.resultOrPartial(err -> FTBLibrary.LOGGER.error("can't parse data component map for {}: {}", s[3], err))
.ifPresent(stack::applyComponents);
} catch (CommandSyntaxException ex) {
ex.printStackTrace();
FTBLibrary.LOGGER.error("can't parse data component tag for item icon: {} ({})", lazyStackString, ex.getMessage());
}
}

Expand Down Expand Up @@ -94,11 +96,11 @@ public ItemStack getStack() {
public void draw(GuiGraphics graphics, int x, int y, int w, int h) {
PoseStack poseStack = graphics.pose();
poseStack.pushPose();
poseStack.translate(x + w / 2D, y + h / 2D, 100);
poseStack.translate(x + w / 2D, y + h / 2D, 0);

if (w != 16 || h != 16) {
int s = Math.min(w, h);
poseStack.scale(s / 16F, s / 16F, s / 16F);
float s = Math.min(w, h) / 16F;
poseStack.scale(s, s, s);
}

GuiHelper.drawItem(graphics, getStack(), 0, true, null);
Expand All @@ -110,11 +112,11 @@ public void draw(GuiGraphics graphics, int x, int y, int w, int h) {
public void drawStatic(GuiGraphics graphics, int x, int y, int w, int h) {
PoseStack poseStack = graphics.pose();
poseStack.pushPose();
poseStack.translate(x + w / 2D, y + h / 2D, 100);
poseStack.translate(x + w / 2D, y + h / 2D, 0);

if (w != 16 || h != 16) {
int s = Math.min(w, h);
poseStack.scale(s / 16F, s / 16F, s / 16F);
float s = Math.min(w, h) / 16F;
poseStack.scale(s, s, s);
}

GuiHelper.drawItem(graphics, getStack(), 0, false, null);
Expand Down

0 comments on commit f958e79

Please sign in to comment.