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:
+25
-7
@@ -36,6 +36,16 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
|||||||
.add(ImmutableList.of("vine_or_glow_lichen", "plant", makeMaterialNameForTag(BlockTags.AXE_MINEABLE)
|
.add(ImmutableList.of("vine_or_glow_lichen", "plant", makeMaterialNameForTag(BlockTags.AXE_MINEABLE)
|
||||||
)).build();
|
)).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) {
|
private static String makeMaterialNameForTag(TagKey<Block> tag) {
|
||||||
return tag.id().getPath();
|
return tag.id().getPath();
|
||||||
}
|
}
|
||||||
@@ -66,6 +76,16 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
|||||||
allMaterials.put(compositeMaterialName, resultingToolSpeeds);
|
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() {
|
public static List<MaterialInfo> getGlobalMaterialInfo() {
|
||||||
ArrayList<MaterialInfo> resultList = new ArrayList<>();
|
ArrayList<MaterialInfo> resultList = new ArrayList<>();
|
||||||
|
|
||||||
@@ -135,7 +155,6 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
|||||||
materialMiningSpeeds.put("wool", ImmutableMap.of(Items.SHEARS, 5.0f));
|
materialMiningSpeeds.put("wool", ImmutableMap.of(Items.SHEARS, 5.0f));
|
||||||
|
|
||||||
itemRegistry.forEach(item -> {
|
itemRegistry.forEach(item -> {
|
||||||
//Tools are handled rather easily and do not require anything else
|
|
||||||
if (item instanceof MiningToolItem toolItem) {
|
if (item instanceof MiningToolItem toolItem) {
|
||||||
item.getComponents().get(DataComponentTypes.TOOL).rules()
|
item.getComponents().get(DataComponentTypes.TOOL).rules()
|
||||||
.stream().map(ToolComponent.Rule::blocks)
|
.stream().map(ToolComponent.Rule::blocks)
|
||||||
@@ -143,22 +162,21 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
|||||||
Optional<TagKey<Block>> tagKey = blocks.getTagKey();
|
Optional<TagKey<Block>> tagKey = blocks.getTagKey();
|
||||||
if (tagKey.isPresent()) {
|
if (tagKey.isPresent()) {
|
||||||
String materialName = makeMaterialNameForTag(tagKey.get());
|
String materialName = makeMaterialNameForTag(tagKey.get());
|
||||||
|
|
||||||
Map<Item, Float> materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>());
|
Map<Item, Float> materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>());
|
||||||
float miningSpeed = item.getComponents().get(DataComponentTypes.TOOL).defaultMiningSpeed();
|
float baseSpeed = getToolSpeed(item);
|
||||||
materialSpeeds.put(item, miningSpeed);
|
materialSpeeds.put(item, baseSpeed);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
//Swords require special treatment
|
// Add sword speeds for special materials
|
||||||
if (item instanceof SwordItem) {
|
if (item instanceof SwordItem) {
|
||||||
cowebMaterialSpeeds.put(item, 15.0f);
|
cowebMaterialSpeeds.put(item, 15.0f);
|
||||||
plantMaterialSpeeds.put(item, 1.5f);
|
plantMaterialSpeeds.put(item, 1.5f);
|
||||||
leavesMaterialSpeeds.put(item, 1.5f);
|
leavesMaterialSpeeds.put(item, 1.5f);
|
||||||
gourdMaterialSpeeds.put(item, 1.5f);
|
gourdMaterialSpeeds.put(item, 1.5f);
|
||||||
}
|
}
|
||||||
}});
|
});
|
||||||
|
|
||||||
COMPOSITE_MATERIALS.forEach(values -> createCompositeMaterial(materialMiningSpeeds, values));
|
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)
|
.add(ImmutableList.of("vine_or_glow_lichen", "plant", makeMaterialNameForTag(BlockTags.AXE_MINEABLE)
|
||||||
)).build();
|
)).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) {
|
private static String makeMaterialNameForTag(TagKey<Block> tag) {
|
||||||
return tag.id().getPath();
|
return tag.id().getPath();
|
||||||
}
|
}
|
||||||
@@ -144,8 +168,8 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
|||||||
String materialName = makeMaterialNameForTag(tagKey.get());
|
String materialName = makeMaterialNameForTag(tagKey.get());
|
||||||
|
|
||||||
Map<Item, Float> materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>());
|
Map<Item, Float> materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>());
|
||||||
float miningSpeed = item.getComponents().get(DataComponentTypes.TOOL).defaultMiningSpeed();
|
float baseSpeed = getToolSpeed(item);
|
||||||
materialSpeeds.put(item, miningSpeed);
|
materialSpeeds.put(item, baseSpeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
+31
-8
@@ -9,6 +9,7 @@ import net.minecraft.block.Block;
|
|||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.component.DataComponentTypes;
|
import net.minecraft.component.DataComponentTypes;
|
||||||
|
import net.minecraft.component.type.ToolComponent;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.item.MiningToolItem;
|
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)
|
.add(ImmutableList.of("vine_or_glow_lichen", "plant", makeMaterialNameForTag(BlockTags.AXE_MINEABLE)
|
||||||
)).build();
|
)).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) {
|
private static String makeMaterialNameForTag(TagKey<Block> tag) {
|
||||||
return tag.id().getPath();
|
return tag.id().getPath();
|
||||||
}
|
}
|
||||||
@@ -65,6 +76,20 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
|||||||
allMaterials.put(compositeMaterialName, resultingToolSpeeds);
|
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() {
|
public static List<MaterialInfo> getGlobalMaterialInfo() {
|
||||||
ArrayList<MaterialInfo> resultList = new ArrayList<>();
|
ArrayList<MaterialInfo> resultList = new ArrayList<>();
|
||||||
|
|
||||||
@@ -85,7 +110,7 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
|||||||
itemRegistry.forEach(item -> {
|
itemRegistry.forEach(item -> {
|
||||||
if (item instanceof MiningToolItem toolItem) {
|
if (item instanceof MiningToolItem toolItem) {
|
||||||
item.getComponents().get(DataComponentTypes.TOOL).rules()
|
item.getComponents().get(DataComponentTypes.TOOL).rules()
|
||||||
.stream().map(rule -> rule.blocks())
|
.stream().map(ToolComponent.Rule::blocks)
|
||||||
.forEach(blocks -> {
|
.forEach(blocks -> {
|
||||||
Optional<TagKey<Block>> tagKey = blocks.getTagKey();
|
Optional<TagKey<Block>> tagKey = blocks.getTagKey();
|
||||||
if (tagKey.isPresent()) {
|
if (tagKey.isPresent()) {
|
||||||
@@ -134,21 +159,19 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
|||||||
materialMiningSpeeds.put("wool", ImmutableMap.of(Items.SHEARS, 5.0f));
|
materialMiningSpeeds.put("wool", ImmutableMap.of(Items.SHEARS, 5.0f));
|
||||||
|
|
||||||
itemRegistry.forEach(item -> {
|
itemRegistry.forEach(item -> {
|
||||||
//Tools are handled rather easily and do not require anything else
|
|
||||||
if (item instanceof MiningToolItem toolItem) {
|
if (item instanceof MiningToolItem toolItem) {
|
||||||
item.getComponents().get(DataComponentTypes.TOOL).rules()
|
item.getComponents().get(DataComponentTypes.TOOL).rules()
|
||||||
.stream().map(rule -> rule.blocks())
|
.stream().map(ToolComponent.Rule::blocks)
|
||||||
.forEach(blocks -> {
|
.forEach(blocks -> {
|
||||||
Optional<TagKey<Block>> tagKey = blocks.getTagKey();
|
Optional<TagKey<Block>> tagKey = blocks.getTagKey();
|
||||||
if (tagKey.isPresent()) {
|
if (tagKey.isPresent()) {
|
||||||
String materialName = makeMaterialNameForTag(tagKey.get());
|
String materialName = makeMaterialNameForTag(tagKey.get());
|
||||||
|
|
||||||
Map<Item, Float> materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>());
|
Map<Item, Float> materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>());
|
||||||
float miningSpeed = item.getComponents().get(DataComponentTypes.TOOL).defaultMiningSpeed();
|
float baseSpeed = getToolSpeed(item);
|
||||||
materialSpeeds.put(item, miningSpeed);
|
materialSpeeds.put(item, baseSpeed);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
//Swords require special treatment
|
//Swords require special treatment
|
||||||
if (item instanceof SwordItem) {
|
if (item instanceof SwordItem) {
|
||||||
@@ -157,7 +180,7 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
|||||||
leavesMaterialSpeeds.put(item, 1.5f);
|
leavesMaterialSpeeds.put(item, 1.5f);
|
||||||
gourdMaterialSpeeds.put(item, 1.5f);
|
gourdMaterialSpeeds.put(item, 1.5f);
|
||||||
}
|
}
|
||||||
}});
|
});
|
||||||
|
|
||||||
COMPOSITE_MATERIALS.forEach(values -> createCompositeMaterial(materialMiningSpeeds, values));
|
COMPOSITE_MATERIALS.forEach(values -> createCompositeMaterial(materialMiningSpeeds, values));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user