From b7ec81a42dfd1b741631f0576e19d1a174fcbc55 Mon Sep 17 00:00:00 2001 From: MehVahdJukaar Date: Thu, 23 May 2024 12:01:09 +0200 Subject: [PATCH] stat fix --- changelog.md | 2 +- .../advframes/blocks/StatFrameBlock.java | 5 +++-- .../advframes/client/StatSelectScreen.java | 14 ++++++++++---- gradle.properties | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index 376ebef..1b4b457 100644 --- a/changelog.md +++ b/changelog.md @@ -1 +1 @@ -replaced mixins with access wideners \ No newline at end of file +fixed block stat type \ No newline at end of file diff --git a/common/src/main/java/net/mehvahdjukaar/advframes/blocks/StatFrameBlock.java b/common/src/main/java/net/mehvahdjukaar/advframes/blocks/StatFrameBlock.java index 3bb1296..262505d 100644 --- a/common/src/main/java/net/mehvahdjukaar/advframes/blocks/StatFrameBlock.java +++ b/common/src/main/java/net/mehvahdjukaar/advframes/blocks/StatFrameBlock.java @@ -22,6 +22,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; @@ -122,9 +123,9 @@ public static MutableComponent getStatComponent(Stat stat) { Object value = stat.getValue(); MutableComponent text; ResourceLocation statId = BuiltInRegistries.STAT_TYPE.getKey(type); - if (value instanceof Item i) { + if (value instanceof ItemLike i) { text = Component.translatable( - "stat.advancementframes." + statId.getPath(), i.getDescription().getString()); + "stat.advancementframes." + statId.getPath(), i.asItem().getDescription().getString()); } else if (value instanceof EntityType e) { text = Component.translatable( diff --git a/common/src/main/java/net/mehvahdjukaar/advframes/client/StatSelectScreen.java b/common/src/main/java/net/mehvahdjukaar/advframes/client/StatSelectScreen.java index 610e5a9..6dd069b 100644 --- a/common/src/main/java/net/mehvahdjukaar/advframes/client/StatSelectScreen.java +++ b/common/src/main/java/net/mehvahdjukaar/advframes/client/StatSelectScreen.java @@ -427,7 +427,7 @@ public int compare(ItemStatisticsList.ItemRow row1, ItemStatisticsList.ItemRow r private class ItemRow extends ObjectSelectionList.Entry { private final Item item; - private Stat hovered = null; + private Stat hovered = null; ItemRow(Item item) { this.item = item; @@ -442,9 +442,10 @@ public void render(GuiGraphics guiGraphics, int index, int top, int left, int wi int mouseX, int mouseY, boolean isMouseOver, float partialTicks) { blitSlot(guiGraphics, left + 40, top, this.item); hovered = null; + int p; for (p = 0; p < itemStatsList.blockColumns.size(); ++p) { - Stat stat; + Stat stat; if (this.item instanceof BlockItem bi) { stat = (itemStatsList.blockColumns.get(p)).get(bi.getBlock()); } else { @@ -463,7 +464,7 @@ public void render(GuiGraphics guiGraphics, int index, int top, int left, int wi } - protected void renderStat(GuiGraphics guiGraphics, @Nullable Stat stat, int x, int y, + protected void renderStat(GuiGraphics guiGraphics, @Nullable Stat stat, int x, int y, boolean odd, boolean isMouseOver, int mouseX) { String string = stat == null ? "-" : stat.format(stats.getValue(stat)); guiGraphics.drawString(font, string, x - font.width(string), y + 5, odd ? 16777215 : 9474192); @@ -479,7 +480,12 @@ protected void renderStat(GuiGraphics guiGraphics, @Nullable Stat stat, in @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (hovered != null) { - selectStat(hovered.getType(), item); + StatType type = hovered.getType(); + if (type.getRegistry() == BuiltInRegistries.BLOCK) { + selectStat((StatType) type, ((BlockItem) item).getBlock()); + } else { + selectStat((StatType) type, item); + } } return false; } diff --git a/gradle.properties b/gradle.properties index 6121c34..7f7dc85 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ mod_id=advancementframes minecraft_version=1.20.1 enabled_platforms=fabric,forge -mod_version=1.20-2.2.6 +mod_version=1.20-2.2.7 maven_group=net.mehvahdjukaar project_id = 556795