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:
+37
-19
@@ -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));
|
||||
|
||||
|
||||
+26
-2
@@ -35,6 +35,30 @@ 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 float getToolSpeed(Item item) {
|
||||
String itemName = item.toString().toLowerCase();
|
||||
// Remove minecraft: prefix if present
|
||||
if (itemName.startsWith("minecraft:")) {
|
||||
itemName = itemName.substring("minecraft:".length());
|
||||
}
|
||||
for (Map.Entry<String, Float> entry : TOOL_SPEEDS.entrySet()) {
|
||||
if (itemName.startsWith(entry.getKey())) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
private static String makeMaterialNameForTag(TagKey<Block> tag) {
|
||||
return tag.id().getPath();
|
||||
}
|
||||
@@ -144,8 +168,8 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
||||
String materialName = makeMaterialNameForTag(tagKey.get());
|
||||
|
||||
Map<Item, Float> materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>());
|
||||
float miningSpeed = item.getComponents().get(DataComponentTypes.TOOL).defaultMiningSpeed();
|
||||
materialSpeeds.put(item, miningSpeed);
|
||||
float baseSpeed = getToolSpeed(item);
|
||||
materialSpeeds.put(item, baseSpeed);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
+44
-21
@@ -9,6 +9,7 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.ToolComponent;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.MiningToolItem;
|
||||
@@ -35,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();
|
||||
}
|
||||
@@ -65,6 +76,20 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
||||
allMaterials.put(compositeMaterialName, resultingToolSpeeds);
|
||||
}
|
||||
|
||||
private static float getToolSpeed(Item item) {
|
||||
String itemName = item.toString().toLowerCase();
|
||||
// Remove minecraft: prefix if present
|
||||
if (itemName.startsWith("minecraft:")) {
|
||||
itemName = itemName.substring("minecraft:".length());
|
||||
}
|
||||
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<>();
|
||||
|
||||
@@ -85,7 +110,7 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
||||
itemRegistry.forEach(item -> {
|
||||
if (item instanceof MiningToolItem toolItem) {
|
||||
item.getComponents().get(DataComponentTypes.TOOL).rules()
|
||||
.stream().map(rule -> rule.blocks())
|
||||
.stream().map(ToolComponent.Rule::blocks)
|
||||
.forEach(blocks -> {
|
||||
Optional<TagKey<Block>> tagKey = blocks.getTagKey();
|
||||
if (tagKey.isPresent()) {
|
||||
@@ -134,30 +159,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(rule -> rule.blocks())
|
||||
.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);
|
||||
}
|
||||
}});
|
||||
//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);
|
||||
}
|
||||
});
|
||||
|
||||
COMPOSITE_MATERIALS.forEach(values -> createCompositeMaterial(materialMiningSpeeds, values));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user