diff --git a/generator/src/main/java/org/spongepowered/vanilla/generator/GeneratorMain.java b/generator/src/main/java/org/spongepowered/vanilla/generator/GeneratorMain.java index a713491feca..ab702ff2817 100644 --- a/generator/src/main/java/org/spongepowered/vanilla/generator/GeneratorMain.java +++ b/generator/src/main/java/org/spongepowered/vanilla/generator/GeneratorMain.java @@ -25,6 +25,7 @@ package org.spongepowered.vanilla.generator; import com.github.javaparser.utils.Log; +import com.google.common.base.CaseFormat; import com.mojang.datafixers.util.Pair; import com.squareup.javapoet.ParameterizedTypeName; import com.squareup.javapoet.WildcardTypeName; @@ -50,21 +51,33 @@ import net.minecraft.world.damagesource.DamageScaling; import net.minecraft.world.entity.Display; import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.entity.animal.Fox; +import net.minecraft.world.entity.animal.TropicalFish; +import net.minecraft.world.entity.animal.horse.Markings; +import net.minecraft.world.entity.animal.horse.Variant; import net.minecraft.world.entity.vehicle.Boat; import net.minecraft.world.flag.FeatureFlags; +import net.minecraft.world.item.ArmorMaterials; +import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.FireworkRocketItem; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.Rarity; import net.minecraft.world.level.DataPackConfig; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.block.state.properties.BambooLeaves; +import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; import org.tinylog.Logger; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; +import java.util.function.BiConsumer; import java.util.stream.Collectors; /** @@ -198,6 +211,20 @@ private static List generators(final Context context) { CriteriaTriggers.class, "CRITERIA" ), + new MapEntriesValidator<>( + "world.gamerule", + "GameRules", + GameRules.class, + "GAME_RULE_TYPES", + map -> { + final Map out = new HashMap<>(map.size()); + map.forEach((BiConsumer) (k, v) -> { + var key = (GameRules.Key) k; + out.put(new ResourceLocation("sponge:" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, key.getId())), v); + }); + return out; + } + ), new EnumEntriesValidator<>( "item", "FireworkShapes", @@ -219,6 +246,55 @@ private static List generators(final Context context) { "getName", "sponge" ), + new EnumEntriesValidator<>( + "data.type", + "ArmorMaterials", + ArmorMaterials.class, + "getName", + "sponge" + ), + new EnumEntriesValidator<>( + "data.type", + "BambooLeavesTypes", + BambooLeaves.class, + "getSerializedName", + "sponge" + ), + new EnumEntriesValidator<>( + "data.type", + "DyeColors", + DyeColor.class, + "getName", + "sponge" + ), + new EnumEntriesValidator<>( + "data.type", + "FoxTypes", + Fox.Type.class, + "getSerializedName", + "sponge" + ), + new EnumEntriesValidator<>( + "data.type", + "HorseColors", + Variant.class, + "getSerializedName", + "sponge" + ), + new EnumEntriesValidator<>( + "data.type", + "HorseStyles", + Markings.class, + "name", + "sponge" + ), + new EnumEntriesValidator<>( + "data.type", + "InstrumentTypes", + NoteBlockInstrument.class, + "getSerializedName", + "sponge" + ), new EnumEntriesValidator<>( "item", "ItemRarities", @@ -233,6 +309,13 @@ private static List generators(final Context context) { "getName", "sponge" ), + new EnumEntriesValidator<>( + "data.type", + "TropicalFishShapes", + TropicalFish.Pattern.class, + "getSerializedName", + "sponge" + ), new RegistryEntriesGenerator<>( "data.type", "ArtTypes", diff --git a/generator/src/main/java/org/spongepowered/vanilla/generator/MapEntriesValidator.java b/generator/src/main/java/org/spongepowered/vanilla/generator/MapEntriesValidator.java index 2c07efbccf5..8903bb84d56 100644 --- a/generator/src/main/java/org/spongepowered/vanilla/generator/MapEntriesValidator.java +++ b/generator/src/main/java/org/spongepowered/vanilla/generator/MapEntriesValidator.java @@ -46,6 +46,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.function.Function; class MapEntriesValidator implements Generator { @@ -53,17 +54,29 @@ class MapEntriesValidator implements Generator { private final String targetClassSimpleName; private final Class clazz; private final String registry; + private final Function, Map> mapping; MapEntriesValidator( final String targetRelativePackage, final String targetClassSimpleName, final Class clazz, final String registry + ) { + this(targetRelativePackage, targetClassSimpleName, clazz, registry, map -> (Map) map); + } + + MapEntriesValidator( + final String targetRelativePackage, + final String targetClassSimpleName, + final Class clazz, + final String registry, + final Function, Map> mapping ) { this.relativePackageName = targetRelativePackage; this.targetClassSimpleName = targetClassSimpleName; this.clazz = clazz; this.registry = registry; + this.mapping = mapping; } @Override @@ -87,7 +100,7 @@ public void generate(final Context ctx) { if (!(tmp instanceof Map)) { throw new IllegalStateException("registry field is not a map"); } - map = (Map) tmp; + map = this.mapping.apply((Map) tmp); } catch (Exception e) { throw new IllegalStateException("Failed to retrieve registry field in class " + this.clazz.getName(), e); }