Skip to content

Commit d559d12

Browse files
committed
Fix Support BlockEntityTypes 26.2
1 parent 025c1ff commit d559d12

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

Insights-API/src/main/java/dev/frankheijden/insights/api/reflection/RTileEntityTypes.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public class RTileEntityTypes {
2626
var tileEntityTypesClazz = Class.forName(
2727
"net.minecraft.world.level.block.entity.BlockEntityType"
2828
);
29+
Class<?> tileEntityTypesHolderClazz;
30+
try {
31+
tileEntityTypesHolderClazz = Class.forName(
32+
"net.minecraft.world.level.block.entity.BlockEntityTypes"
33+
);
34+
} catch (ClassNotFoundException ignored) {
35+
tileEntityTypesHolderClazz = tileEntityTypesClazz;
36+
}
2937
var craftBlockDataClazz = Class.forName(
3038
"org.bukkit.craftbukkit.block.data.CraftBlockData"
3139
);
@@ -52,23 +60,30 @@ public class RTileEntityTypes {
5260
}
5361

5462
Set<Material> materials = new HashSet<>();
55-
try {
56-
for (Field field : tileEntityTypesClazz.getFields()) {
57-
if (!Modifier.isStatic(field.getModifiers())) continue;
58-
if (!field.getType().equals(tileEntityTypesClazz)) continue;
63+
for (Field field : tileEntityTypesHolderClazz.getFields()) {
64+
if (!Modifier.isStatic(field.getModifiers())) continue;
65+
if (!field.getType().equals(tileEntityTypesClazz)) continue;
5966

60-
Object tileEntityTypes = field.get(null);
61-
for (Map.Entry<Material, Object> entry : blockStateMap.entrySet()) {
67+
Object tileEntityTypes = field.get(null);
68+
for (Map.Entry<Material, Object> entry : blockStateMap.entrySet()) {
69+
try {
6270
if ((boolean) isValidMethodHandle.invoke(tileEntityTypes, entry.getValue())) {
6371
materials.add(entry.getKey());
6472
}
73+
} catch (Throwable th) {
74+
throw new RuntimeException(th);
6575
}
6676
}
67-
} catch (Throwable th) {
68-
th.printStackTrace();
6977
}
7078

7179
materials.removeIf(Material::isAir);
80+
if (materials.isEmpty()) {
81+
throw new IllegalStateException(
82+
"Could not determine tile entity materials from "
83+
+ tileEntityTypesHolderClazz.getName()
84+
+ " (server version not supported?)"
85+
);
86+
}
7287
TILE_ENTITY_MATERIALS = Collections.unmodifiableSet(EnumSet.copyOf(materials));
7388
TILE_ENTITIES = TILE_ENTITY_MATERIALS.stream()
7489
.map(ScanObject::of)
@@ -96,4 +111,4 @@ public static Set<Material> getTileEntityMaterials() {
96111
public static Set<ScanObject.MaterialObject> getTileEntities() {
97112
return TILE_ENTITIES;
98113
}
99-
}
114+
}

0 commit comments

Comments
 (0)