fixed 1.20.5 and 1.21 and 1.21.3 pulling incorrect materials.json data (#42)

* data generator for 1.20.5 should be correct now

* comments

* update 1.21 data generator

* update 1.21.3 materials data generator
This commit is contained in:
Madlykeanu
2025-01-26 23:15:08 +01:00
committed by GitHub
parent 73cbac110a
commit 4ea199aa5a
3 changed files with 107 additions and 42 deletions
@@ -36,6 +36,16 @@ public class MaterialsDataGenerator implements IDataGenerator {
.add(ImmutableList.of("vine_or_glow_lichen", "plant", makeMaterialNameForTag(BlockTags.AXE_MINEABLE)
)).build();
private static final Map<String, Float> TOOL_SPEEDS = new HashMap<>() {{
// Base speeds for each tool type
put("wooden", 2.0f);
put("stone", 4.0f);
put("iron", 6.0f);
put("diamond", 8.0f);
put("netherite", 9.0f);
put("golden", 12.0f);
}};
private static String makeMaterialNameForTag(TagKey<Block> tag) {
return tag.id().getPath();
}
@@ -66,6 +76,16 @@ public class MaterialsDataGenerator implements IDataGenerator {
allMaterials.put(compositeMaterialName, resultingToolSpeeds);
}
private static float getToolSpeed(Item item) {
String itemName = item.toString().toLowerCase();
for (Map.Entry<String, Float> entry : TOOL_SPEEDS.entrySet()) {
if (itemName.startsWith(entry.getKey())) {
return entry.getValue();
}
}
return 1.0f;
}
public static List<MaterialInfo> getGlobalMaterialInfo() {
ArrayList<MaterialInfo> resultList = new ArrayList<>();
@@ -135,30 +155,28 @@ public class MaterialsDataGenerator implements IDataGenerator {
materialMiningSpeeds.put("wool", ImmutableMap.of(Items.SHEARS, 5.0f));
itemRegistry.forEach(item -> {
//Tools are handled rather easily and do not require anything else
if (item instanceof MiningToolItem toolItem) {
item.getComponents().get(DataComponentTypes.TOOL).rules()
.stream().map(ToolComponent.Rule::blocks)
.forEach(blocks -> {
Optional<TagKey<Block>> tagKey = blocks.getTagKey();
if (tagKey.isPresent()) {
String materialName = makeMaterialNameForTag(tagKey.get());
Optional<TagKey<Block>> tagKey = blocks.getTagKey();
if (tagKey.isPresent()) {
String materialName = makeMaterialNameForTag(tagKey.get());
Map<Item, Float> materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>());
float baseSpeed = getToolSpeed(item);
materialSpeeds.put(item, baseSpeed);
}
});
}
Map<Item, Float> materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>());
float miningSpeed = item.getComponents().get(DataComponentTypes.TOOL).defaultMiningSpeed();
materialSpeeds.put(item, miningSpeed);
}
}
);
//Swords require special treatment
if (item instanceof SwordItem) {
cowebMaterialSpeeds.put(item, 15.0f);
plantMaterialSpeeds.put(item, 1.5f);
leavesMaterialSpeeds.put(item, 1.5f);
gourdMaterialSpeeds.put(item, 1.5f);
}
}});
// Add sword speeds for special materials
if (item instanceof SwordItem) {
cowebMaterialSpeeds.put(item, 15.0f);
plantMaterialSpeeds.put(item, 1.5f);
leavesMaterialSpeeds.put(item, 1.5f);
gourdMaterialSpeeds.put(item, 1.5f);
}
});
COMPOSITE_MATERIALS.forEach(values -> createCompositeMaterial(materialMiningSpeeds, values));