Skip to content

Commit

Permalink
stat fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MehVahdJukaar committed May 23, 2024
1 parent dfdfb46 commit b7ec81a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
replaced mixins with access wideners
fixed block stat type
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public int compare(ItemStatisticsList.ItemRow row1, ItemStatisticsList.ItemRow r
private class ItemRow extends ObjectSelectionList.Entry<ItemStatisticsList.ItemRow> {
private final Item item;

private Stat<Item> hovered = null;
private Stat<?> hovered = null;

ItemRow(Item item) {
this.item = item;
Expand All @@ -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 {
Expand All @@ -463,7 +464,7 @@ public void render(GuiGraphics guiGraphics, int index, int top, int left, int wi

}

protected void renderStat(GuiGraphics guiGraphics, @Nullable Stat<Item> 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);
Expand All @@ -479,7 +480,12 @@ protected void renderStat(GuiGraphics guiGraphics, @Nullable Stat<Item> 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<Block>) type, ((BlockItem) item).getBlock());
} else {
selectStat((StatType<Item>) type, item);
}
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b7ec81a

Please sign in to comment.