Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ public enum DataGenType {
COMMAND_ARGUMENTS("command_arguments", new GenericRegistryArrayGenerator<>(BuiltInRegistries.COMMAND_ARGUMENT_TYPE)),
CONSUME_EFFECT("consume_effects", new GenericRegistryArrayGenerator<>(BuiltInRegistries.CONSUME_EFFECT_TYPE)),
CUSTOM_STATISTICS("custom_stat", new CustomStatisticGenerator()),
ARMOR_TYPES("armor_types", new ArmorTypeGenerator()),
ARMOR_MATERIALS("armor_materials", new ArmorMaterialGenerator()),
BLOCK_FAMILIES("block_families", new BlockFamilyGenerator()),
COLOR_COLLECTIONS("color_collections", new ColorCollectionGenerator()),
DYE_COLORS("dye_colors", new DyeColorGenerator()),
MAP_COLORS("map_colors", new MapColorGenerator()),
PARTICLES("particle_type", new ParticleGenerator()),
TOOL_MATERIALS("tool_materials", new ToolMaterialGenerator()),
WORLD_EVENTS("world_events", new WorldEventGenerator()),
RECIPE_BOOK_CATEGORY("recipe_book_categories", new GenericRegistryArrayGenerator<>(BuiltInRegistries.RECIPE_BOOK_CATEGORY)),
RECIPE_DISPLAY_TYPE("recipe_display_types", new GenericRegistryArrayGenerator<>(BuiltInRegistries.RECIPE_DISPLAY)),
Expand Down Expand Up @@ -98,4 +103,4 @@ public String getFileName() {
public DataGenerator getGenerator() {
return generator;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.minestom.generators;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.world.item.equipment.ArmorMaterial;
import net.minecraft.world.item.equipment.ArmorMaterials;
import net.minecraft.world.item.equipment.ArmorType;
import net.minestom.datagen.DataGenerator;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;

public final class ArmorMaterialGenerator extends DataGenerator {
@Override
public JsonArray generate() {
var armorMaterials = new JsonArray();
var id = 0;

var fields = Arrays.stream(ArmorMaterials.class.getDeclaredFields())
.filter(field -> field.getType() == ArmorMaterial.class)
.filter(field -> Modifier.isStatic(field.getModifiers()))
.toList();

try {
for (var field : fields) {
var material = (ArmorMaterial) field.get(null);
var materialJson = new JsonObject();
var defense = new JsonObject();

materialJson.addProperty("id", id++);
materialJson.addProperty("name", field.getName());
materialJson.addProperty("durability", material.durability());
materialJson.addProperty("enchantmentValue", material.enchantmentValue());
materialJson.addProperty("equipSound", material.equipSound().getRegisteredName());
materialJson.addProperty("toughness", material.toughness());
materialJson.addProperty("knockbackResistance", material.knockbackResistance());
materialJson.addProperty("repairIngredient", material.repairIngredient().location().toString());
materialJson.addProperty("assetId", material.assetId().identifier().toString());

for (var armorType : ArmorType.values()) {
var value = material.defense().get(armorType);

if (value != null) {
defense.addProperty(armorType.name(), value);
}
}

materialJson.add("defense", defense);
armorMaterials.add(materialJson);
}
} catch (IllegalAccessException exception) {
throw new IllegalStateException("Unable to read vanilla armor materials", exception);
}

return armorMaterials;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.minestom.generators;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.world.item.equipment.ArmorType;
import net.minestom.datagen.DataGenerator;

public final class ArmorTypeGenerator extends DataGenerator {
@Override
public JsonArray generate() {
var armorTypes = new JsonArray();
var id = 0;

for (var armorType : ArmorType.values()) {
var armorTypeJson = new JsonObject();
armorTypeJson.addProperty("id", id++);
armorTypeJson.addProperty("name", armorType.name());
armorTypeJson.addProperty("serializedName", armorType.getName());
armorTypeJson.addProperty("slot", armorType.getSlot().getName());
armorTypeJson.addProperty("unitDurability", armorType.getDurability(1));
armorTypes.add(armorTypeJson);
}

return armorTypes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.minestom.generators;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.BlockFamilies;
import net.minestom.datagen.DataGenerator;

import java.util.Comparator;

public final class BlockFamilyGenerator extends DataGenerator {
@Override
public JsonArray generate() {
var families = new JsonArray();

for (var family : BlockFamilies.getAllFamilies()
.sorted(Comparator.comparingInt(family -> BuiltInRegistries.BLOCK.getId(family.getBaseBlock())))
.toList()) {
var base = BuiltInRegistries.BLOCK.getKey(family.getBaseBlock());
var familyJson = new JsonObject();

familyJson.addProperty("id", BuiltInRegistries.BLOCK.getId(family.getBaseBlock()));
familyJson.addProperty("name", base.toString());

var variants = new JsonObject();

for (var entry : family.getVariants().entrySet().stream()
.sorted(Comparator.comparingInt(entry -> entry.getKey().ordinal()))
.toList()) {
variants.addProperty(entry.getKey().name(), BuiltInRegistries.BLOCK.getKey(entry.getValue()).toString());
}

familyJson.add("variants", variants);
families.add(familyJson);
}

return families;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.minestom.generators;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.DyeColor;
import net.minestom.datagen.DataGenerator;

import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;

public final class ColorCollectionGenerator extends DataGenerator {
@Override
public JsonObject generate() {
var collections = new JsonObject();
collections.add("blocks", generateCollections(BuiltInRegistries.BLOCK));
collections.add("items", generateCollections(BuiltInRegistries.ITEM));
return collections;
}

private <T> JsonArray generateCollections(Registry<T> registry) {
var candidates = new TreeMap<String, Map<String, Identifier>>();

for (var identifier : registry.keySet()) {
for (var color : DyeColor.values()) {
var prefix = color.getName() + "_";
if (!identifier.getPath().startsWith(prefix)) continue;

var alias = identifier.getPath().substring(prefix.length());
candidates.computeIfAbsent(alias, ignored -> new TreeMap<>()).put(color.name(), identifier);
break;
}
}

var collections = new JsonArray();

for (var entry : candidates.entrySet()) {
var alias = entry.getKey();
var values = entry.getValue();

if (values.size() != DyeColor.values().length) {
continue;
}

var collection = new JsonObject();
collection.addProperty("name", alias.toUpperCase(Locale.ROOT).replace('-', '_'));
var valueJson = new JsonObject();
values.forEach((color, identifier) -> valueJson.addProperty(color, identifier.toString()));
collection.add("values", valueJson);
collections.add(collection);
}

return collections;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.minestom.generators;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.world.item.ToolMaterial;
import net.minestom.datagen.DataGenerator;

import java.lang.reflect.Modifier;
import java.util.Arrays;

public final class ToolMaterialGenerator extends DataGenerator {
@Override
public JsonArray generate() {
var toolMaterials = new JsonArray();
var id = 0;

var fields = Arrays.stream(ToolMaterial.class.getDeclaredFields())
.filter(field -> field.getType() == ToolMaterial.class)
.filter(field -> Modifier.isStatic(field.getModifiers()))
.toList();

try {
for (var field : fields) {
var material = (ToolMaterial) field.get(null);
var materialJson = new JsonObject();

materialJson.addProperty("id", id++);
materialJson.addProperty("name", field.getName());
materialJson.addProperty("incorrectBlocksForDrops", material.incorrectBlocksForDrops().location().toString());
materialJson.addProperty("durability", material.durability());
materialJson.addProperty("speed", material.speed());
materialJson.addProperty("attackDamageBonus", material.attackDamageBonus());
materialJson.addProperty("enchantmentValue", material.enchantmentValue());
materialJson.addProperty("repairItems", material.repairItems().location().toString());

toolMaterials.add(materialJson);
}
} catch (IllegalAccessException exception) {
throw new IllegalStateException("Unable to read vanilla tool materials", exception);
}

return toolMaterials;
}
}