Skip to content

Commit ae8f312

Browse files
committed
log tool material origin if solving tier failed
1 parent 3b8e17c commit ae8f312

File tree

5 files changed

+61
-13
lines changed

5 files changed

+61
-13
lines changed

src/main/java/mcp/mobius/waila/service/ApiService.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ public List<Tier> getTiers() {
161161

162162
//noinspection ConstantValue
163163
if (tier.getIncorrectBlocksForDrops() == null) {
164-
LOG.warn("Found tier of class [{}] with null inverse tag, skipping", tier.getClass().getName());
164+
LOG.warn("Found tier created on class [{}] with null inverse tag, skipping",
165+
MixinService.TIERS.getOrDefault(tier, tier.getClass()).getName());
165166
continue;
166167
}
167168

@@ -201,25 +202,28 @@ public List<Tier> getTiers() {
201202
The comparison is based on the assumption that lower tier's incorrect block tag contains all entries from higher tier's tag.
202203
This was fine for Vanilla, but might be not match modded behavior.
203204
Please open an issue at {}
204-
Tag [{}] contains:
205+
Tag [{}] created on class [{}] contains:
205206
\t[{}]
206-
Tag [{}] contains:
207+
Tag [{}] created on class [{}] contains:
207208
\t[{}]
208209
""",
209-
tag1.location(), tag2.location(), Waila.ISSUE_URL, tag1.location(), blocks1str, tag2.location(), blocks2str);
210+
tag1.location(), tag2.location(),
211+
Waila.ISSUE_URL,
212+
tag1.location(), MixinService.TIERS.getOrDefault(tier1, tier1.getClass()).getName(), blocks1str,
213+
tag2.location(), MixinService.TIERS.getOrDefault(tier2, tier2.getClass()).getName(), blocks2str);
210214
return 0;
211215
}).toList();
212216
}
213217

214218
public static String concatBlocks(HolderSet<Block> set) {
215-
return String.join("\n\t", set.stream()
216-
.map(it -> it
217-
.unwrapKey()
218-
.orElseThrow()
219-
.location()
220-
.toString())
221-
.sorted()
222-
.toList());
219+
return String.join("\n\t", set.stream()
220+
.map(it -> it
221+
.unwrapKey()
222+
.orElseThrow()
223+
.location()
224+
.toString())
225+
.sorted()
226+
.toList());
223227
}
224228

225229
@Override

src/main/java/mcp/mobius/waila/service/MixinService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package mcp.mobius.waila.service;
22

3+
import java.util.LinkedHashMap;
4+
import java.util.Map;
5+
36
import mcp.mobius.waila.WailaClient;
47
import mcp.mobius.waila.config.JsonConfig;
58
import mcp.mobius.waila.config.PluginConfig;
@@ -9,9 +12,12 @@
912
import net.minecraft.client.DeltaTracker;
1013
import net.minecraft.client.gui.GuiGraphics;
1114
import net.minecraft.core.RegistryAccess;
15+
import net.minecraft.world.item.Tier;
1216

1317
public class MixinService implements IMixinService {
1418

19+
public static final Map<Tier, Class<?>> TIERS = new LinkedHashMap<>();
20+
1521
@Override
1622
public void attachRegistryFilter(RegistryAccess registryAccess) {
1723
RegistryFilter.attach(registryAccess);
@@ -27,6 +33,11 @@ public void onGuiRender(GuiGraphics ctx, DeltaTracker delta) {
2733
TooltipRenderer.render(ctx, delta);
2834
}
2935

36+
@Override
37+
public void addTierInstance(Tier tier, Class<?> caller) {
38+
TIERS.put(tier, caller);
39+
}
40+
3041
@Override
3142
public void onLanguageReloaded() {
3243
JsonConfig.reloadAllInstances();

src/mixin/java/mcp/mobius/waila/mixed/IMixinService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import net.minecraft.client.DeltaTracker;
55
import net.minecraft.client.gui.GuiGraphics;
66
import net.minecraft.core.RegistryAccess;
7+
import net.minecraft.world.item.Tier;
78

89
public interface IMixinService {
910

@@ -15,6 +16,8 @@ public interface IMixinService {
1516

1617
void onGuiRender(GuiGraphics ctx, DeltaTracker delta);
1718

19+
void addTierInstance(Tier tier, Class<?> caller);
20+
1821
void onLanguageReloaded();
1922

2023
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package mcp.mobius.waila.mixin;
2+
3+
import mcp.mobius.waila.mixed.IMixinService;
4+
import net.minecraft.world.item.Tier;
5+
import org.jetbrains.annotations.Nullable;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Pseudo;
8+
import org.spongepowered.asm.mixin.Unique;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
13+
@Pseudo
14+
@Mixin(targets = {
15+
"net.neoforged.neoforge.common.SimpleTier",
16+
"net.minecraftforge.common.ForgeTier",
17+
})
18+
public class SimpleTierMixin {
19+
20+
@Unique
21+
private static @Nullable StackWalker wthit_stackWalker;
22+
23+
@Inject(method = "<init>", at = @At("TAIL"))
24+
private void wthit_init(CallbackInfo ci) {
25+
if (wthit_stackWalker == null) wthit_stackWalker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
26+
IMixinService.INSTANCE.addTierInstance((Tier) this, wthit_stackWalker.getCallerClass());
27+
}
28+
29+
}

src/resources/resources/wthit.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"LecternBlockEntityAccess",
1818
"NoteBlockAccess",
1919
"ReloadableServerResourcesMixin",
20-
"ShearableBlocksMixin"
20+
"ShearableBlocksMixin",
21+
"SimpleTierMixin"
2122
],
2223
"client" : [
2324
"BossHealthOverlayAccess",

0 commit comments

Comments
 (0)