diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 79299efe..3075baff 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -6,7 +6,6 @@ import net.minecraft.util.Identifier; import net.minecraft.util.registry.SimpleRegistry; import net.minecraft.world.biome.*; -import org.apache.commons.lang3.StringUtils; import java.util.Locale; @@ -21,91 +20,6 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { return "overworld"; } - private static int getBiomeColorFor(String biomeDisplayNamed) { - if (biomeDisplayNamed.equals("Redwood Taiga Hills M")) { - biomeDisplayNamed = "MegaTaigaHills"; - } - String biomeDisplayName = StringUtils.join(biomeDisplayNamed.split(" "), ""); - return switch (biomeDisplayName) { - case "Ocean" -> 112; - case "Plains" -> 9286496; - case "Desert" -> 16421912; - case "ExtremeHills", "Extreme Hills" -> 6316128; - case "Forest" -> 353825; - case "Taiga" -> 747097; - case "Swampland" -> 522674; - case "River" -> 255; - case "Hell" -> 16711680; - case "TheEnd", "The End" -> 8421631; - case "FrozenOcean", "Frozen Ocean" -> 7368918; - case "FrozenRiver", "Frozen River" -> 10526975; - case "IcePlains", "Ice Plains" -> 16777215; - case "IceMountains", "Ice Mountains" -> 10526880; - case "MushroomIsland", "Mushroom Island" -> 16711935; - case "MushroomIslandShore", "Mushroom Island Shore" -> 10486015; - case "Beach" -> 16440917; - case "DesertHills", "Desert Hills" -> 13786898; - case "ForestHills", "Forest Hills" -> 2250012; - case "TaigaHills", "Taiga Hills" -> 1456435; - case "ExtremeHillsEdge", "Extreme Hills Edge" -> 7501978; - case "Jungle" -> 5470985; - case "JungleHills", "Jungle Hills" -> 2900485; - case "JungleEdge", "Jungle Edge" -> 6458135; - case "DeepOcean", "Deep Ocean" -> 48; - case "StoneBeach", "Stone Beach" -> 10658436; - case "ColdBeach", "Cold Beach" -> 16445632; - case "BirchForest", "Birch Forest" -> 3175492; - case "BirchForestHills", "Birch Forest Hills" -> 2055986; - case "RoofedForest", "Roofed Forest" -> 4215066; - case "ColdTaiga", "Cold Taiga" -> 3233098; - case "ColdTaigaHills", "Cold Taiga Hills" -> 2375478; - case "MegaTaiga", "Mega Taiga" -> 5858897; - case "MegaTaigaHills", "Mega Taiga Hills" -> 4542270; - case "ExtremeHills+", "Extreme Hills+" -> 5271632; - case "Savanna" -> 12431967; - case "SavannaPlateau", "Savanna Plateau" -> 10984804; - case "Mesa" -> 14238997; - case "MesaPlateauF", "Mesa Plateau F" -> 11573093; - case "MesaPlateau", "Mesa Plateau" -> 13274213; - case "TheEnd-Floatingislands", "The End - Floating islands" -> 8421631; - case "TheEnd-Mediumisland", "The End - Medium island" -> 8421631; - case "TheEnd-Highisland", "The End - High island" -> 8421631; - case "TheEnd-Barrenisland", "The End - Barren island" -> 8421631; - case "WarmOcean", "Warm Ocean" -> 172; - case "LukewarmOcean", "Lukewarm Ocean" -> 144; - case "ColdOcean", "Cold Ocean" -> 2105456; - case "WarmDeepOcean", "Warm Deep Ocean" -> 80; - case "LukewarmDeepOcean", "Lukewarm Deep Ocean" -> 64; - case "ColdDeepOcean", "Cold Deep Ocean" -> 2105400; - case "FrozenDeepOcean", "Frozen Deep Ocean" -> 4210832; - case "TheVoid", "The Void" -> 0; - case "SunflowerPlains", "Sunflower Plains" -> 11918216; - case "DesertM", "Desert M" -> 16759872; - case "ExtremeHillsM", "Extreme Hills M" -> 8947848; - case "FlowerForest", "Flower Forest" -> 2985545; - case "TaigaM", "Taiga M" -> 3378817; - case "SwamplandM", "Swampland M" -> 3145690; - case "IcePlainsSpikes", "Ice Plains Spikes" -> 11853020; - case "JungleM", "Jungle M" -> 8102705; - case "JungleEdgeM", "Jungle Edge M" -> 9089855; - case "BirchForestM", "Birch Forest M" -> 5807212; - case "BirchForestHillsM", "Birch Forest Hills M" -> 4687706; - case "RoofedForestM", "Roofed Forest M" -> 6846786; - case "ColdTaigaM", "Cold Taiga M" -> 5864818; - case "MegaSpruceTaiga", "Mega Spruce Taiga" -> 8490617; - case "MegaSpruceTaiga(Hills)", "Mega Spruce Taiga (Hills)" -> 7173990; - case "ExtremeHills+M", "Extreme Hills+ M" -> 7903352; - case "SavannaM", "Savanna M" -> 15063687; - case "SavannaPlateauM", "Savanna Plateau M" -> 13616524; - case "Mesa(Bryce)", "Mesa (Bryce)" -> 16739645; - case "MesaPlateauFM", "Mesa Plateau F M" -> 14204813; - case "MesaPlateauM", "Mesa Plateau M" -> 15905933; - case "BambooJungle", "Bamboo Jungle" -> 7769620; - case "BambooJungleHills", "Bamboo Jungle Hills" -> 3884810; - default -> throw new Error("Unexpected biome, with name: '" + biomeDisplayName + "'"); - }; - } - public static JsonObject generateBiomeInfo(SimpleRegistry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); Identifier registryKey = registry.getIdentifier(biome); @@ -118,7 +32,7 @@ public static JsonObject generateBiomeInfo(SimpleRegistry reg biomeDesc.addProperty("depth", biome.getDepth()); biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", ((BiomeAccessor) biome).name()); - biomeDesc.addProperty("color", getBiomeColorFor(((BiomeAccessor) biome).name())); + biomeDesc.addProperty("color", biome.getSkyColor(biome.getTemperature())); biomeDesc.addProperty("rainfall", biome.getRainfall()); return biomeDesc; @@ -160,7 +74,7 @@ private static String category(Biome biome) { } else if (biome instanceof StoneBeachBiome || biome instanceof VoidBiome) { return "none"; // Should StoneBeachBiome be beach too? this is how it is now in mcdata } - throw new Error("Unable to find biome category for " + biome.getClass().getName()); + throw new IllegalStateException("Unable to find biome category for " + biome.getClass().getName()); } private static String precipitation(Biome biome) { diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 1ec40aea..621ec79d 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -127,10 +127,6 @@ private static String boundingBox(Block block, BlockState state) { return "block"; } - private static Item getItemFromBlock(Block block) { - return Registries.ITEMS.get(Registries.BLOCKS.getIdentifier(block)); - } - @Override public String getDataName() { return "blocks"; diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 18bbee55..e37f50f7 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -15,6 +15,7 @@ import net.minecraft.entity.projectile.FishingBobberEntity; import net.minecraft.entity.projectile.Projectile; import net.minecraft.util.Identifier; +import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,22 +25,20 @@ public class EntitiesDataGenerator implements IDataGenerator { public static JsonObject generateEntity(Class entityClass) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass); - int entityRawId = Registries.ENTITY_TYPES.getRawId(entityClass); - @Nullable Entity entity = makeEntity(entityClass); + Entity entity = makeEntity(entityClass); // FIXME: ENTITY ID IS WRONG int id = entityId(entity); entityDesc.addProperty("id", id); entityDesc.addProperty("internalId", id); entityDesc.addProperty("name", Objects.requireNonNull(registryKey).getPath()); - String displayName = entity != null ? DGU.translateText(entity.getTranslationKey()) : null; + String displayName = DGU.translateText(entity.getTranslationKey()); if (displayName != null && !displayName.startsWith("entity.")) { entityDesc.addProperty("displayName", displayName); } - entityDesc.addProperty("width", entity == null ? 0 : entity.width); - entityDesc.addProperty("height", entity == null ? 0 : entity.height); + entityDesc.addProperty("width", entity.width); + entityDesc.addProperty("height", entity.height); - String entityTypeString = "UNKNOWN"; - entityTypeString = getEntityTypeForClass(entityClass); + String entityTypeString = getEntityTypeForClass(entityClass); entityDesc.addProperty("type", entityTypeString); entityDesc.addProperty("category", getCategoryFrom(entityClass)); @@ -47,8 +46,11 @@ public static JsonObject generateEntity(Class entityClass) { } private static Entity makeEntity(Class type) { - String name = EntityTypeAccessor.CLASS_NAME_MAP().get(type); - return EntityType.createInstanceFromName(name, DGU.getWorld()); + try { + return type.getConstructor(World.class).newInstance(DGU.getWorld()); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } } private static String getCategoryFrom(@NotNull Class entityClass) { @@ -62,7 +64,7 @@ private static String getCategoryFrom(@NotNull Class entityClass) { case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; case "net.minecraft.entity" -> "other"; - default -> throw new Error("Unexpected entity type: " + packageName); + default -> throw new IllegalStateException("Unexpected entity type: " + packageName); }; } @@ -105,7 +107,7 @@ private static String getEntityTypeForClass(Class entityClass) private static int entityId(Entity entity) { if (!DGU.getCurrentlyRunningServer().getVersion().equals("1.10.2")) { - throw new Error("These ids were gotten manually for 1.10.2, remake for " + DGU.getCurrentlyRunningServer().getVersion()); + throw new IllegalStateException("These ids were gotten manually for 1.10.2, remake for " + DGU.getCurrentlyRunningServer().getVersion()); } int rawId = Registries.ENTITY_TYPES.getRawId(entity.getClass()); if (rawId == -1) { // see TrackedEntityInstance @@ -114,7 +116,7 @@ private static int entityId(Entity entity) { } else if (entity instanceof FishingBobberEntity) { return 90; } else { - throw new Error("unable to find rawId for entity: " + entity.getEntityName()); + throw new IllegalStateException("unable to find rawId for entity: " + entity.getEntityName()); } } return rawId; diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 88e8d2fb..f481c08a 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -22,8 +22,8 @@ public JsonElement generateDataJson() { obj.addProperty(entry.getKey(), entry.getValue()); } return obj; - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java index 60386ba8..d772d280 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java @@ -11,26 +11,26 @@ public interface EntityTypeAccessor { @Accessor("NAME_CLASS_MAP") static Map> NAME_CLASS_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("CLASS_NAME_MAP") static Map, String> CLASS_NAME_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("ID_CLASS_MAP") static Map> ID_CLASS_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("CLASS_ID_MAP") static Map, Integer> CLASS_ID_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("NAME_ID_MAP") static Map NAME_ID_MAP() { - throw new Error(); + throw new IllegalStateException(); } } diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index c1d96581..8e82cee6 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -10,6 +10,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 1433d785..a27885b9 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -73,7 +73,7 @@ private static String category(Biome biome) { } else if (biome instanceof StoneBeachBiome || biome instanceof VoidBiome) { return "none"; // Should StoneBeachBiome be beach too? this is how it is now in mcdata } - throw new Error("Unable to find biome category for " + biome.getClass().getName()); + throw new IllegalStateException("Unable to find biome category for " + biome.getClass().getName()); } private static String precipitation(Biome biome) { diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 419f3246..40affe59 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -27,20 +27,18 @@ public class EntitiesDataGenerator implements IDataGenerator { public static JsonObject generateEntity(Class entityClass) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass); - int entityRawId = Registries.ENTITY_TYPES.getRawId(entityClass); - @Nullable Entity entity = makeEntity(entityClass); + Entity entity = makeEntity(entityClass); // FIXME: ENTITY ID IS WRONG int id = entityId(entity); entityDesc.addProperty("id", id); entityDesc.addProperty("internalId", id); entityDesc.addProperty("name", Objects.requireNonNull(registryKey).getPath()); - if (entity != null) entityDesc.addProperty("displayName", DGU.translateText(entity.getTranslationKey())); - entityDesc.addProperty("width", entity == null ? 0 : entity.width); - entityDesc.addProperty("height", entity == null ? 0 : entity.height); + entityDesc.addProperty("displayName", DGU.translateText(entity.getTranslationKey())); + entityDesc.addProperty("width", entity.width); + entityDesc.addProperty("height", entity.height); - String entityTypeString = "UNKNOWN"; - entityTypeString = getEntityTypeForClass(entityClass); + String entityTypeString = getEntityTypeForClass(entityClass); entityDesc.addProperty("type", entityTypeString); entityDesc.addProperty("category", getCategoryFrom(entityClass)); @@ -62,7 +60,7 @@ private static String getCategoryFrom(@NotNull Class entityClass) { case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; case "net.minecraft.entity" -> "other"; - default -> throw new Error("Unexpected entity type: " + packageName); + default -> throw new IllegalStateException("Unexpected entity type: " + packageName); }; } @@ -105,7 +103,7 @@ private static String getEntityTypeForClass(Class entityClass) private static int entityId(Entity entity) { if (!DGU.getCurrentlyRunningServer().getVersion().equals("1.11.2")) { - throw new Error("These ids were gotten manually for 1.11.2, remake for " + DGU.getCurrentlyRunningServer().getVersion()); + throw new IllegalStateException("These ids were gotten manually for 1.11.2, remake for " + DGU.getCurrentlyRunningServer().getVersion()); } int rawId = Registries.ENTITY_TYPES.getRawId(entity.getClass()); if (rawId == -1) { // see TrackedEntityInstance @@ -114,7 +112,7 @@ private static int entityId(Entity entity) { } else if (entity instanceof FishingBobberEntity) { return 90; } else { - throw new Error("unable to find rawId for entity: " + entity.getEntityName()); + throw new IllegalStateException("unable to find rawId for entity: " + entity.getEntityName()); } } return rawId; diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 88e8d2fb..f481c08a 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -22,8 +22,8 @@ public JsonElement generateDataJson() { obj.addProperty(entry.getKey(), entry.getValue()); } return obj; - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index c1d96581..8e82cee6 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -10,6 +10,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 8fa1f8d4..85783eca 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -6,7 +6,6 @@ import net.minecraft.util.Identifier; import net.minecraft.util.registry.SimpleRegistry; import net.minecraft.world.biome.*; -import org.apache.commons.lang3.StringUtils; import java.util.Locale; @@ -21,91 +20,6 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { return "overworld"; } - private static int getBiomeColorFor(String biomeDisplayNamed) { - if (biomeDisplayNamed.equals("Redwood Taiga Hills M")) { - biomeDisplayNamed = "MegaTaigaHills"; - } - String biomeDisplayName = StringUtils.join(biomeDisplayNamed.split(" "), ""); - return switch (biomeDisplayName) { - case "Ocean" -> 112; - case "Plains" -> 9286496; - case "Desert" -> 16421912; - case "ExtremeHills", "Extreme Hills" -> 6316128; - case "Forest" -> 353825; - case "Taiga" -> 747097; - case "Swampland" -> 522674; - case "River" -> 255; - case "Hell" -> 16711680; - case "TheEnd", "The End" -> 8421631; - case "FrozenOcean", "Frozen Ocean" -> 7368918; - case "FrozenRiver", "Frozen River" -> 10526975; - case "IcePlains", "Ice Plains" -> 16777215; - case "IceMountains", "Ice Mountains" -> 10526880; - case "MushroomIsland", "Mushroom Island" -> 16711935; - case "MushroomIslandShore", "Mushroom Island Shore" -> 10486015; - case "Beach" -> 16440917; - case "DesertHills", "Desert Hills" -> 13786898; - case "ForestHills", "Forest Hills" -> 2250012; - case "TaigaHills", "Taiga Hills" -> 1456435; - case "ExtremeHillsEdge", "Extreme Hills Edge" -> 7501978; - case "Jungle" -> 5470985; - case "JungleHills", "Jungle Hills" -> 2900485; - case "JungleEdge", "Jungle Edge" -> 6458135; - case "DeepOcean", "Deep Ocean" -> 48; - case "StoneBeach", "Stone Beach" -> 10658436; - case "ColdBeach", "Cold Beach" -> 16445632; - case "BirchForest", "Birch Forest" -> 3175492; - case "BirchForestHills", "Birch Forest Hills" -> 2055986; - case "RoofedForest", "Roofed Forest" -> 4215066; - case "ColdTaiga", "Cold Taiga" -> 3233098; - case "ColdTaigaHills", "Cold Taiga Hills" -> 2375478; - case "MegaTaiga", "Mega Taiga" -> 5858897; - case "MegaTaigaHills", "Mega Taiga Hills" -> 4542270; - case "ExtremeHills+", "Extreme Hills+" -> 5271632; - case "Savanna" -> 12431967; - case "SavannaPlateau", "Savanna Plateau" -> 10984804; - case "Mesa" -> 14238997; - case "MesaPlateauF", "Mesa Plateau F" -> 11573093; - case "MesaPlateau", "Mesa Plateau" -> 13274213; - case "TheEnd-Floatingislands", "The End - Floating islands" -> 8421631; - case "TheEnd-Mediumisland", "The End - Medium island" -> 8421631; - case "TheEnd-Highisland", "The End - High island" -> 8421631; - case "TheEnd-Barrenisland", "The End - Barren island" -> 8421631; - case "WarmOcean", "Warm Ocean" -> 172; - case "LukewarmOcean", "Lukewarm Ocean" -> 144; - case "ColdOcean", "Cold Ocean" -> 2105456; - case "WarmDeepOcean", "Warm Deep Ocean" -> 80; - case "LukewarmDeepOcean", "Lukewarm Deep Ocean" -> 64; - case "ColdDeepOcean", "Cold Deep Ocean" -> 2105400; - case "FrozenDeepOcean", "Frozen Deep Ocean" -> 4210832; - case "TheVoid", "The Void" -> 0; - case "SunflowerPlains", "Sunflower Plains" -> 11918216; - case "DesertM", "Desert M" -> 16759872; - case "ExtremeHillsM", "Extreme Hills M" -> 8947848; - case "FlowerForest", "Flower Forest" -> 2985545; - case "TaigaM", "Taiga M" -> 3378817; - case "SwamplandM", "Swampland M" -> 3145690; - case "IcePlainsSpikes", "Ice Plains Spikes" -> 11853020; - case "JungleM", "Jungle M" -> 8102705; - case "JungleEdgeM", "Jungle Edge M" -> 9089855; - case "BirchForestM", "Birch Forest M" -> 5807212; - case "BirchForestHillsM", "Birch Forest Hills M" -> 4687706; - case "RoofedForestM", "Roofed Forest M" -> 6846786; - case "ColdTaigaM", "Cold Taiga M" -> 5864818; - case "MegaSpruceTaiga", "Mega Spruce Taiga" -> 8490617; - case "MegaSpruceTaiga(Hills)", "Mega Spruce Taiga (Hills)" -> 7173990; - case "ExtremeHills+M", "Extreme Hills+ M" -> 7903352; - case "SavannaM", "Savanna M" -> 15063687; - case "SavannaPlateauM", "Savanna Plateau M" -> 13616524; - case "Mesa(Bryce)", "Mesa (Bryce)" -> 16739645; - case "MesaPlateauFM", "Mesa Plateau F M" -> 14204813; - case "MesaPlateauM", "Mesa Plateau M" -> 15905933; - case "BambooJungle", "Bamboo Jungle" -> 7769620; - case "BambooJungleHills", "Bamboo Jungle Hills" -> 3884810; - default -> throw new Error("Unexpected biome, with name: '" + biomeDisplayName + "'"); - }; - } - public static JsonObject generateBiomeInfo(SimpleRegistry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); Identifier registryKey = registry.getIdentifier(biome); @@ -120,7 +34,7 @@ public static JsonObject generateBiomeInfo(SimpleRegistry reg biomeDesc.addProperty("depth", biome.getDepth()); biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", displayName); - biomeDesc.addProperty("color", getBiomeColorFor(displayName)); + biomeDesc.addProperty("color", biome.getSkyColor(biome.getTemperature())); biomeDesc.addProperty("rainfall", biome.getRainfall()); return biomeDesc; @@ -162,7 +76,7 @@ private static String category(Biome biome) { } else if (biome instanceof StoneBeachBiome || biome instanceof VoidBiome) { return "none"; // Should StoneBeachBiome be beach too? this is how it is now in mcdata } - throw new Error("Unable to find biome category for " + biome.getClass().getName()); + throw new IllegalStateException("Unable to find biome category for " + biome.getClass().getName()); } private static String precipitation(Biome biome) { diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 4c2fd2ea..2c8a1bac 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -39,8 +39,7 @@ public static JsonObject generateEntity(Class entityClass) { entityDesc.addProperty("width", entity == null ? 0 : entity.width); entityDesc.addProperty("height", entity == null ? 0 : entity.height); - String entityTypeString = "UNKNOWN"; - entityTypeString = getEntityTypeForClass(entityClass); + String entityTypeString = getEntityTypeForClass(entityClass); entityDesc.addProperty("type", entityTypeString); entityDesc.addProperty("category", getCategoryFrom(entityClass)); @@ -62,7 +61,7 @@ private static String getCategoryFrom(@NotNull Class entityClass) { case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; case "net.minecraft.entity" -> "other"; - default -> throw new Error("Unexpected entity type: " + packageName); + default -> throw new IllegalStateException("Unexpected entity type: " + packageName); }; } @@ -105,7 +104,7 @@ private static String getEntityTypeForClass(Class entityClass) private static int entityId(Entity entity) { if (!DGU.getCurrentlyRunningServer().getVersion().equals("1.12.2")) { - throw new Error("These ids were gotten manually for 1.12.2, remake for " + DGU.getCurrentlyRunningServer().getVersion()); + throw new IllegalStateException("These ids were gotten manually for 1.12.2, remake for " + DGU.getCurrentlyRunningServer().getVersion()); } int rawId = Registries.ENTITY_TYPES.getRawId(entity.getClass()); if (rawId == -1) { // see TrackedEntityInstance @@ -114,7 +113,7 @@ private static int entityId(Entity entity) { } else if (entity instanceof FishingBobberEntity) { return 90; } else { - throw new Error("unable to find rawId for entity: " + entity.getEntityName()); + throw new IllegalStateException("unable to find rawId for entity: " + entity.getEntityName()); } } return rawId; diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 88e8d2fb..f481c08a 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -22,8 +22,8 @@ public JsonElement generateDataJson() { obj.addProperty(entry.getKey(), entry.getValue()); } return obj; - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index c1d96581..8e82cee6 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -10,6 +10,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 1de3cf31..92e93e67 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -20,88 +20,6 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { }; } - private static int getBiomeColorFor(String biomeName) { - return switch (biomeName) { - case "ocean" -> 112; - case "plains" -> 9286496; - case "desert" -> 16421912; - case "mountains" -> 6316128; - case "forest" -> 353825; - case "taiga" -> 747097; - case "swamp" -> 522674; - case "river" -> 255; - case "nether_wastes" -> 12532539; - case "the_end" -> 8421631; - case "frozen_ocean" -> 7368918; - case "frozen_river" -> 10526975; - case "snowy_tundra" -> 16777215; - case "snowy_mountains" -> 10526880; - case "mushroom_fields" -> 16711935; - case "mushroom_field_shore" -> 10486015; - case "beach" -> 16440917; - case "desert_hills" -> 13786898; - case "wooded_hills" -> 2250012; - case "taiga_hills" -> 1456435; - case "mountain_edge" -> 7501978; - case "jungle" -> 5470985; - case "jungle_hills" -> 2900485; - case "jungle_edge" -> 6458135; - case "deep_ocean" -> 48; - case "stone_shore" -> 10658436; - case "snowy_beach" -> 16445632; - case "birch_forest" -> 3175492; - case "birch_forest_hills" -> 2055986; - case "dark_forest" -> 4215066; - case "snowy_taiga" -> 3233098; - case "snowy_taiga_hills" -> 2375478; - case "giant_tree_taiga" -> 5858897; - case "giant_tree_taiga_hills" -> 4542270; - case "wooded_mountains" -> 5271632; - case "savanna" -> 12431967; - case "savanna_plateau" -> 10984804; - case "badlands" -> 14238997; - case "wooded_badlands_plateau" -> 11573093; - case "badlands_plateau" -> 13274213; - case "small_end_islands" -> 42; - case "end_midlands" -> 15464630; - case "end_highlands" -> 12828041; - case "end_barrens" -> 9474162; - case "warm_ocean" -> 172; - case "lukewarm_ocean" -> 144; - case "cold_ocean" -> 2105456; - case "deep_warm_ocean" -> 80; - case "deep_lukewarm_ocean" -> 64; - case "deep_cold_ocean" -> 2105400; - case "deep_frozen_ocean" -> 4210832; - case "the_void" -> 0; - case "sunflower_plains" -> 11918216; - case "desert_lakes" -> 16759872; - case "gravelly_mountains" -> 8947848; - case "flower_forest" -> 2985545; - case "taiga_mountains" -> 3378817; - case "swamp_hills" -> 3145690; - case "ice_spikes" -> 11853020; - case "modified_jungle" -> 8102705; - case "modified_jungle_edge" -> 9089855; - case "tall_birch_forest" -> 5807212; - case "tall_birch_hills" -> 4687706; - case "dark_forest_hills" -> 6846786; - case "snowy_taiga_mountains" -> 5864818; - case "giant_spruce_taiga" -> 8490617; - case "giant_spruce_taiga_hills" -> 7173990; - case "modified_gravelly_mountains" -> 7903352; - case "shattered_savanna" -> 15063687; - case "shattered_savanna_plateau" -> 13616524; - case "eroded_badlands" -> 16739645; - case "modified_wooded_badlands_plateau" -> 14204813; - case "modified_badlands_plateau" -> 15905933; - case "bamboo_jungle" -> 7769620; - case "bamboo_jungle_hills" -> 3884810; - case "nether" -> 16711680; - default -> throw new Error("Unexpected biome, with name: '" + biomeName + "'"); - }; - } - public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); Identifier registryKey = registry.getId(biome); @@ -116,7 +34,7 @@ public static JsonObject generateBiomeInfo(Registry registry, Biome biome biomeDesc.addProperty("depth", biome.getDepth()); biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); - biomeDesc.addProperty("color", getBiomeColorFor(registryKey.getPath())); + biomeDesc.addProperty("color", biome.getSkyColor(biome.getTemperature())); biomeDesc.addProperty("rainfall", biome.getRainfall()); return biomeDesc; diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index b1fc0395..95991f5b 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -2,7 +2,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -17,10 +16,7 @@ import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Field; -import java.lang.reflect.ParameterizedType; import java.util.Objects; public class EntitiesDataGenerator implements IDataGenerator { @@ -28,8 +24,7 @@ public static JsonObject generateEntity(Registry> entityRegistry, JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getId(entityType); int entityRawId = entityRegistry.getRawId(entityType); - Class entityClass = getEntityClass(entityType); - @Nullable Entity entity = makeEntity(entityType); + Entity entity = entityType.spawn(DGU.getWorld()); entityDesc.addProperty("id", entityRawId); entityDesc.addProperty("internalId", entityRawId); @@ -39,42 +34,15 @@ public static JsonObject generateEntity(Registry> entityRegistry, entityDesc.addProperty("width", entity == null ? 0 : entity.width); entityDesc.addProperty("height", entity == null ? 0 : entity.height); - String entityTypeString = "UNKNOWN"; - entityTypeString = getEntityTypeForClass(entityClass); + String entityTypeString = getEntityTypeForClass(entityType.entityClass()); entityDesc.addProperty("type", entityTypeString); entityDesc.addProperty("category", getCategoryFrom(entityType)); return entityDesc; } - private static Entity makeEntity(EntityType type) { - Entity entity; - try { - entity = type.spawn(DGU.getWorld()); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - return entity; - } - - private static Class getEntityClass(EntityType entityType) { - Class entityClazz = null; - try { - for (Field field : EntityType.class.getFields()) - if (entityType == field.get(EntityType.class)) - entityClazz = (Class) ((ParameterizedType) TypeToken.get(field.getGenericType()).getType()).getActualTypeArguments()[0]; - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - if (entityClazz == null) throw new RuntimeException("Shouldn't be null..."); - return entityClazz; - } - private static String getCategoryFrom(@NotNull EntityType entityType) { - if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities - Class entityClazz = getEntityClass(entityType); + Class entityClazz = entityType.entityClass(); String packageName = entityClazz.getPackage().getName(); return switch (packageName) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -83,8 +51,8 @@ private static String getCategoryFrom(@NotNull EntityType entityType) { case "net.minecraft.entity.projectile", "net.minecraft.entity.thrown" -> "Projectiles"; case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; - case "net.minecraft.entity" -> "other"; - default -> throw new Error("Unexpected entity type: " + packageName); + case "net.minecraft.entity.player", "net.minecraft.entity" -> "other"; + default -> throw new IllegalStateException("Unexpected entity type: " + packageName); }; } diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index c1d96581..8e82cee6 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -10,6 +10,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index bbaccfaf..37a91380 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -18,88 +18,6 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { }; } - private static int getBiomeColorFor(String biomeName) { - return switch (biomeName) { - case "ocean" -> 112; - case "plains" -> 9286496; - case "desert" -> 16421912; - case "mountains" -> 6316128; - case "forest" -> 353825; - case "taiga" -> 747097; - case "swamp" -> 522674; - case "river" -> 255; - case "nether_wastes" -> 12532539; - case "the_end" -> 8421631; - case "frozen_ocean" -> 7368918; - case "frozen_river" -> 10526975; - case "snowy_tundra" -> 16777215; - case "snowy_mountains" -> 10526880; - case "mushroom_fields" -> 16711935; - case "mushroom_field_shore" -> 10486015; - case "beach" -> 16440917; - case "desert_hills" -> 13786898; - case "wooded_hills" -> 2250012; - case "taiga_hills" -> 1456435; - case "mountain_edge" -> 7501978; - case "jungle" -> 5470985; - case "jungle_hills" -> 2900485; - case "jungle_edge" -> 6458135; - case "deep_ocean" -> 48; - case "stone_shore" -> 10658436; - case "snowy_beach" -> 16445632; - case "birch_forest" -> 3175492; - case "birch_forest_hills" -> 2055986; - case "dark_forest" -> 4215066; - case "snowy_taiga" -> 3233098; - case "snowy_taiga_hills" -> 2375478; - case "giant_tree_taiga" -> 5858897; - case "giant_tree_taiga_hills" -> 4542270; - case "wooded_mountains" -> 5271632; - case "savanna" -> 12431967; - case "savanna_plateau" -> 10984804; - case "badlands" -> 14238997; - case "wooded_badlands_plateau" -> 11573093; - case "badlands_plateau" -> 13274213; - case "small_end_islands" -> 42; - case "end_midlands" -> 15464630; - case "end_highlands" -> 12828041; - case "end_barrens" -> 9474162; - case "warm_ocean" -> 172; - case "lukewarm_ocean" -> 144; - case "cold_ocean" -> 2105456; - case "deep_warm_ocean" -> 80; - case "deep_lukewarm_ocean" -> 64; - case "deep_cold_ocean" -> 2105400; - case "deep_frozen_ocean" -> 4210832; - case "the_void" -> 0; - case "sunflower_plains" -> 11918216; - case "desert_lakes" -> 16759872; - case "gravelly_mountains" -> 8947848; - case "flower_forest" -> 2985545; - case "taiga_mountains" -> 3378817; - case "swamp_hills" -> 3145690; - case "ice_spikes" -> 11853020; - case "modified_jungle" -> 8102705; - case "modified_jungle_edge" -> 9089855; - case "tall_birch_forest" -> 5807212; - case "tall_birch_hills" -> 4687706; - case "dark_forest_hills" -> 6846786; - case "snowy_taiga_mountains" -> 5864818; - case "giant_spruce_taiga" -> 8490617; - case "giant_spruce_taiga_hills" -> 7173990; - case "modified_gravelly_mountains" -> 7903352; - case "shattered_savanna" -> 15063687; - case "shattered_savanna_plateau" -> 13616524; - case "eroded_badlands" -> 16739645; - case "modified_wooded_badlands_plateau" -> 14204813; - case "modified_badlands_plateau" -> 15905933; - case "bamboo_jungle" -> 7769620; - case "bamboo_jungle_hills" -> 3884810; - case "nether" -> 16711680; - default -> throw new Error("Unexpected biome, with name: '" + biomeName + "'"); - }; - } - public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); Identifier registryKey = registry.getId(biome); @@ -114,7 +32,7 @@ public static JsonObject generateBiomeInfo(Registry registry, Biome biome biomeDesc.addProperty("depth", biome.getDepth()); biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); - biomeDesc.addProperty("color", getBiomeColorFor(registryKey.getPath())); + biomeDesc.addProperty("color", biome.getSkyColor(biome.getTemperature())); biomeDesc.addProperty("rainfall", biome.getRainfall()); return biomeDesc; diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index f14df2c6..54085393 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -33,9 +33,8 @@ public static JsonObject generateEntity(Registry> entityRegistry, entityDesc.addProperty("width", entityType.getWidth()); entityDesc.addProperty("height", entityType.getHeight()); - String entityTypeString = "UNKNOWN"; Entity entityObject = entityType.create(DGU.getWorld()); - entityTypeString = entityObject != null ? getEntityTypeForClass(entityObject.getClass()) : "player"; + String entityTypeString = entityObject != null ? getEntityTypeForClass(entityObject.getClass()) : "player"; entityDesc.addProperty("type", entityTypeString); entityDesc.addProperty("category", getCategoryFrom(entityType)); @@ -43,10 +42,10 @@ public static JsonObject generateEntity(Registry> entityRegistry, } private static String getCategoryFrom(@NotNull EntityType entityType) { - if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities + if (entityType == EntityType.PLAYER) return "UNKNOWN"; // fail early for player entities Entity entity = entityType.create(DGU.getWorld()); if (entity == null) - throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.remove(); return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -55,8 +54,8 @@ private static String getCategoryFrom(@NotNull EntityType entityType) { case "net.minecraft.entity.projectile", "net.minecraft.entity.thrown" -> "Projectiles"; case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; - case "net.minecraft.entity" -> "other"; - default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + case "net.minecraft.entity.player", "net.minecraft.entity" -> "UNKNOWN"; + default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index af7e9c10..33550c6e 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -11,6 +11,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 7a66dbf6..87fe46d0 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -19,88 +19,6 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { }; } - private static int getBiomeColorFor(String biomeName) { - return switch (biomeName) { - case "ocean" -> 112; - case "plains" -> 9286496; - case "desert" -> 16421912; - case "mountains" -> 6316128; - case "forest" -> 353825; - case "taiga" -> 747097; - case "swamp" -> 522674; - case "river" -> 255; - case "nether_wastes" -> 12532539; - case "the_end" -> 8421631; - case "frozen_ocean" -> 7368918; - case "frozen_river" -> 10526975; - case "snowy_tundra" -> 16777215; - case "snowy_mountains" -> 10526880; - case "mushroom_fields" -> 16711935; - case "mushroom_field_shore" -> 10486015; - case "beach" -> 16440917; - case "desert_hills" -> 13786898; - case "wooded_hills" -> 2250012; - case "taiga_hills" -> 1456435; - case "mountain_edge" -> 7501978; - case "jungle" -> 5470985; - case "jungle_hills" -> 2900485; - case "jungle_edge" -> 6458135; - case "deep_ocean" -> 48; - case "stone_shore" -> 10658436; - case "snowy_beach" -> 16445632; - case "birch_forest" -> 3175492; - case "birch_forest_hills" -> 2055986; - case "dark_forest" -> 4215066; - case "snowy_taiga" -> 3233098; - case "snowy_taiga_hills" -> 2375478; - case "giant_tree_taiga" -> 5858897; - case "giant_tree_taiga_hills" -> 4542270; - case "wooded_mountains" -> 5271632; - case "savanna" -> 12431967; - case "savanna_plateau" -> 10984804; - case "badlands" -> 14238997; - case "wooded_badlands_plateau" -> 11573093; - case "badlands_plateau" -> 13274213; - case "small_end_islands" -> 42; - case "end_midlands" -> 15464630; - case "end_highlands" -> 12828041; - case "end_barrens" -> 9474162; - case "warm_ocean" -> 172; - case "lukewarm_ocean" -> 144; - case "cold_ocean" -> 2105456; - case "deep_warm_ocean" -> 80; - case "deep_lukewarm_ocean" -> 64; - case "deep_cold_ocean" -> 2105400; - case "deep_frozen_ocean" -> 4210832; - case "the_void" -> 0; - case "sunflower_plains" -> 11918216; - case "desert_lakes" -> 16759872; - case "gravelly_mountains" -> 8947848; - case "flower_forest" -> 2985545; - case "taiga_mountains" -> 3378817; - case "swamp_hills" -> 3145690; - case "ice_spikes" -> 11853020; - case "modified_jungle" -> 8102705; - case "modified_jungle_edge" -> 9089855; - case "tall_birch_forest" -> 5807212; - case "tall_birch_hills" -> 4687706; - case "dark_forest_hills" -> 6846786; - case "snowy_taiga_mountains" -> 5864818; - case "giant_spruce_taiga" -> 8490617; - case "giant_spruce_taiga_hills" -> 7173990; - case "modified_gravelly_mountains" -> 7903352; - case "shattered_savanna" -> 15063687; - case "shattered_savanna_plateau" -> 13616524; - case "eroded_badlands" -> 16739645; - case "modified_wooded_badlands_plateau" -> 14204813; - case "modified_badlands_plateau" -> 15905933; - case "bamboo_jungle" -> 7769620; - case "bamboo_jungle_hills" -> 3884810; - case "nether" -> 16711680; - default -> throw new Error("Unexpected biome, with name: '" + biomeName + "'"); - }; - } - public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); Identifier registryKey = registry.getId(biome); @@ -114,7 +32,7 @@ public static JsonObject generateBiomeInfo(Registry registry, Biome biome biomeDesc.addProperty("depth", biome.getDepth()); biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); - biomeDesc.addProperty("color", getBiomeColorFor(registryKey.getPath())); + biomeDesc.addProperty("color", biome.getSkyColor()); biomeDesc.addProperty("rainfall", biome.getRainfall()); return biomeDesc; diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 0f052253..7e0c4878 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -43,10 +43,10 @@ public static JsonObject generateEntity(Registry> entityRegistry, } private static String getCategoryFrom(@NotNull EntityType entityType) { - if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities + if (entityType == EntityType.PLAYER) return "UNKNOWN"; // fail early for player entities Entity entity = entityType.create(DGU.getWorld()); if (entity == null) - throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.remove(); return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -56,8 +56,8 @@ private static String getCategoryFrom(@NotNull EntityType entityType) { "net.minecraft.entity.thrown" -> "Projectiles"; case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; - case "net.minecraft.entity" -> "other"; - default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + case "net.minecraft.entity.player", "net.minecraft.entity" -> "UNKNOWN"; + default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index a489cdbb..215d5be3 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -2,7 +2,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView; import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; @@ -49,7 +48,7 @@ public static Map generateRedstoneTintColors() { } private static int getBlockColor(Block block) { - return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); + return BlockColors.create().getColor(block.getDefaultState(), null, BlockPos.ORIGIN, 0xFFFFFF); } public static Map generateConstantTintColors() { diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index af7e9c10..33550c6e 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -11,6 +11,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyRenderBlockView.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyRenderBlockView.java deleted file mode 100644 index 87acd3dc..00000000 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyRenderBlockView.java +++ /dev/null @@ -1,59 +0,0 @@ -package dev.u9g.minecraftdatagenerator.util; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.fluid.FluidState; -import net.minecraft.fluid.Fluids; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import net.minecraft.world.LightType; -import net.minecraft.world.biome.Biomes; -import net.minecraft.world.chunk.light.LightingProvider; -import net.minecraft.world.level.ColorResolver; -import org.jetbrains.annotations.Nullable; - -public enum EmptyRenderBlockView implements BlockRenderView { - INSTANCE; - - @Nullable - public BlockEntity getBlockEntity(BlockPos pos) { - return null; - } - - public BlockState getBlockState(BlockPos pos) { - return Blocks.AIR.getDefaultState(); - } - - public FluidState getFluidState(BlockPos pos) { - return Fluids.EMPTY.getDefaultState(); - } - - public int getBottomY() { - return 0; - } - - public int getHeight() { - return 0; - } - - @Override - public LightingProvider getLightingProvider() { - return null; - } - - @Override - public int getColor(BlockPos pos, ColorResolver colorResolver) { - return colorResolver.getColor(Biomes.PLAINS, pos.getX(), pos.getY()); - } - - @Override - public int getLightLevel(LightType type, BlockPos pos) { - return type == LightType.SKY ? getMaxLightLevel() : 0; - } - - @Override - public int getBaseLightLevel(BlockPos pos, int ambientDarkness) { - return ambientDarkness; - } -} diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index e8ad9e04..202fee50 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -17,91 +17,6 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { }; } - private static int getBiomeColorFor(String biomeName) { - return switch (biomeName) { - case "ocean" -> 112; - case "plains" -> 9286496; - case "desert" -> 16421912; - case "mountains" -> 6316128; - case "forest" -> 353825; - case "taiga" -> 747097; - case "swamp" -> 522674; - case "river" -> 255; - case "nether_wastes" -> 12532539; - case "the_end" -> 8421631; - case "frozen_ocean" -> 7368918; - case "frozen_river" -> 10526975; - case "snowy_tundra" -> 16777215; - case "snowy_mountains" -> 10526880; - case "mushroom_fields" -> 16711935; - case "mushroom_field_shore" -> 10486015; - case "beach" -> 16440917; - case "desert_hills" -> 13786898; - case "wooded_hills" -> 2250012; - case "taiga_hills" -> 1456435; - case "mountain_edge" -> 7501978; - case "jungle" -> 5470985; - case "jungle_hills" -> 2900485; - case "jungle_edge" -> 6458135; - case "deep_ocean" -> 48; - case "stone_shore" -> 10658436; - case "snowy_beach" -> 16445632; - case "birch_forest" -> 3175492; - case "birch_forest_hills" -> 2055986; - case "dark_forest" -> 4215066; - case "snowy_taiga" -> 3233098; - case "snowy_taiga_hills" -> 2375478; - case "giant_tree_taiga" -> 5858897; - case "giant_tree_taiga_hills" -> 4542270; - case "wooded_mountains" -> 5271632; - case "savanna" -> 12431967; - case "savanna_plateau" -> 10984804; - case "badlands" -> 14238997; - case "wooded_badlands_plateau" -> 11573093; - case "badlands_plateau" -> 13274213; - case "small_end_islands" -> 42; - case "end_midlands" -> 15464630; - case "end_highlands" -> 12828041; - case "end_barrens" -> 9474162; - case "warm_ocean" -> 172; - case "lukewarm_ocean" -> 144; - case "cold_ocean" -> 2105456; - case "deep_warm_ocean" -> 80; - case "deep_lukewarm_ocean" -> 64; - case "deep_cold_ocean" -> 2105400; - case "deep_frozen_ocean" -> 4210832; - case "the_void" -> 0; - case "sunflower_plains" -> 11918216; - case "desert_lakes" -> 16759872; - case "gravelly_mountains" -> 8947848; - case "flower_forest" -> 2985545; - case "taiga_mountains" -> 3378817; - case "swamp_hills" -> 3145690; - case "ice_spikes" -> 11853020; - case "modified_jungle" -> 8102705; - case "modified_jungle_edge" -> 9089855; - case "tall_birch_forest" -> 5807212; - case "tall_birch_hills" -> 4687706; - case "dark_forest_hills" -> 6846786; - case "snowy_taiga_mountains" -> 5864818; - case "giant_spruce_taiga" -> 8490617; - case "giant_spruce_taiga_hills" -> 7173990; - case "modified_gravelly_mountains" -> 7903352; - case "shattered_savanna" -> 15063687; - case "shattered_savanna_plateau" -> 13616524; - case "eroded_badlands" -> 16739645; - case "modified_wooded_badlands_plateau" -> 14204813; - case "modified_badlands_plateau" -> 15905933; - case "bamboo_jungle" -> 7769620; - case "bamboo_jungle_hills" -> 3884810; - case "soul_sand_valley" -> 6174768; - case "crimson_forest" -> 14485512; - case "warped_forest" -> 4821115; - case "basalt_deltas" -> 4208182; - default -> throw new Error("Unexpected biome, with name: '" + biomeName + "'"); - }; - } - public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); Identifier registryKey = registry.getKey(biome).orElseThrow().getValue(); @@ -116,7 +31,7 @@ public static JsonObject generateBiomeInfo(Registry registry, Biome biome biomeDesc.addProperty("depth", biome.getDepth()); biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); - biomeDesc.addProperty("color", getBiomeColorFor(registryKey.getPath())); + biomeDesc.addProperty("color", biome.getSkyColor()); biomeDesc.addProperty("rainfall", biome.getRainfall()); return biomeDesc; diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 61e1b9e6..d6691e26 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,7 +12,10 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class BlockCollisionShapesDataGenerator implements IDataGenerator { diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 207ee737..a238828b 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -43,10 +43,10 @@ public static JsonObject generateEntity(Registry> entityRegistry, } private static String getCategoryFrom(@NotNull EntityType entityType) { - if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities + if (entityType == EntityType.PLAYER) return "UNKNOWN"; // fail early for player entities Entity entity = entityType.create(DGU.getWorld()); if (entity == null) - throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.remove(); return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -55,8 +55,8 @@ private static String getCategoryFrom(@NotNull EntityType entityType) { case "net.minecraft.entity.projectile", "net.minecraft.entity.projectile.thrown" -> "Projectiles"; case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; - case "net.minecraft.entity" -> "other"; - default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + case "net.minecraft.entity.player", "net.minecraft.entity" -> "UNKNOWN"; + default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index 4ba04e43..d5730e45 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -11,6 +11,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 259df88f..7798b499 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -18,73 +18,6 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { }; } - private static int getBiomeColorFor(String biomeName) { - return switch (biomeName) { - case "the_void" -> 0; - case "plains" -> 9286496; - case "sunflower_plains" -> 11918216; - case "snowy_plains" -> 16777215; - case "ice_spikes" -> 11853020; - case "desert" -> 16421912; - case "swamp" -> 522674; - case "forest" -> 353825; - case "flower_forest" -> 2985545; - case "birch_forest" -> 3175492; - case "dark_forest" -> 4215066; - case "old_growth_birch_forest" -> 5807212; - case "old_growth_pine_taiga" -> 5858897; - case "old_growth_spruce_taiga" -> 8490617; - case "taiga" -> 747097; - case "snowy_taiga" -> 3233098; - case "savanna" -> 12431967; - case "savanna_plateau" -> 10984804; - case "windswept_hills" -> 6316128; - case "windswept_gravelly_hills" -> 8947848; - case "windswept_forest" -> 2250012; - case "windswept_savanna" -> 15063687; - case "jungle" -> 5470985; - case "sparse_jungle" -> 6458135; - case "bamboo_jungle" -> 7769620; - case "badlands" -> 14238997; - case "eroded_badlands" -> 16739645; - case "wooded_badlands" -> 11573093; - case "meadow" -> 9217136; - case "grove" -> 14675173; - case "snowy_slopes" -> 14348785; - case "frozen_peaks" -> 15399931; - case "jagged_peaks" -> 14937325; - case "stony_peaks" -> 13750737; - case "river" -> 255; - case "frozen_river" -> 10526975; - case "beach" -> 16440917; - case "snowy_beach" -> 16445632; - case "stony_shore" -> 10658436; - case "warm_ocean" -> 172; - case "lukewarm_ocean" -> 144; - case "deep_lukewarm_ocean" -> 64; - case "ocean" -> 112; - case "deep_ocean" -> 48; - case "cold_ocean" -> 2105456; - case "deep_cold_ocean" -> 2105400; - case "frozen_ocean" -> 7368918; - case "deep_frozen_ocean" -> 4210832; - case "mushroom_fields" -> 16711935; - case "dripstone_caves" -> 12690831; - case "lush_caves" -> 14652980; - case "nether_wastes" -> 12532539; - case "warped_forest" -> 4821115; - case "crimson_forest" -> 14485512; - case "soul_sand_valley" -> 6174768; - case "basalt_deltas" -> 4208182; - case "the_end" -> 8421631; - case "end_highlands" -> 12828041; - case "end_midlands" -> 15464630; - case "small_end_islands" -> 42; - case "end_barrens" -> 9474162; - default -> throw new Error("Unexpected biome, with name: '" + biomeName + "'"); - }; - } - public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); Identifier registryKey = registry.getKey(biome).orElseThrow().getValue(); @@ -99,7 +32,7 @@ public static JsonObject generateBiomeInfo(Registry registry, Biome biome biomeDesc.addProperty("depth", biome.getDepth()); biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); - biomeDesc.addProperty("color", getBiomeColorFor(registryKey.getPath())); + biomeDesc.addProperty("color", biome.getSkyColor()); biomeDesc.addProperty("rainfall", biome.getDownfall()); return biomeDesc; diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 61e1b9e6..d6691e26 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,7 +12,10 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class BlockCollisionShapesDataGenerator implements IDataGenerator { diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 29e7ee2b..753d79ba 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -48,7 +48,7 @@ private static String getCategoryFrom(EntityType entityType) { if (entityType == EntityType.PLAYER) return "UNKNOWN"; // fail early for player entities Entity entity = EntityType.createInstanceFromId(Registry.ENTITY_TYPE.getRawId(entityType), DGU.getWorld()); if (entity == null) - throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -58,7 +58,7 @@ private static String getCategoryFrom(EntityType entityType) { case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; case "net.minecraft.entity" -> "UNKNOWN"; - default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index 759563e2..a0e8d81b 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -11,6 +11,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 76e948a1..1d890f67 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -18,73 +18,6 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { }; } - private static int getBiomeColorFor(String biomeName) { - return switch (biomeName) { - case "the_void" -> 0; - case "plains" -> 9286496; - case "sunflower_plains" -> 11918216; - case "snowy_plains" -> 16777215; - case "ice_spikes" -> 11853020; - case "desert" -> 16421912; - case "swamp" -> 522674; - case "forest" -> 353825; - case "flower_forest" -> 2985545; - case "birch_forest" -> 3175492; - case "dark_forest" -> 4215066; - case "old_growth_birch_forest" -> 5807212; - case "old_growth_pine_taiga" -> 5858897; - case "old_growth_spruce_taiga" -> 8490617; - case "taiga" -> 747097; - case "snowy_taiga" -> 3233098; - case "savanna" -> 12431967; - case "savanna_plateau" -> 10984804; - case "windswept_hills" -> 6316128; - case "windswept_gravelly_hills" -> 8947848; - case "windswept_forest" -> 2250012; - case "windswept_savanna" -> 15063687; - case "jungle" -> 5470985; - case "sparse_jungle" -> 6458135; - case "bamboo_jungle" -> 7769620; - case "badlands" -> 14238997; - case "eroded_badlands" -> 16739645; - case "wooded_badlands" -> 11573093; - case "meadow" -> 9217136; - case "grove" -> 14675173; - case "snowy_slopes" -> 14348785; - case "frozen_peaks" -> 15399931; - case "jagged_peaks" -> 14937325; - case "stony_peaks" -> 13750737; - case "river" -> 255; - case "frozen_river" -> 10526975; - case "beach" -> 16440917; - case "snowy_beach" -> 16445632; - case "stony_shore" -> 10658436; - case "warm_ocean" -> 172; - case "lukewarm_ocean" -> 144; - case "deep_lukewarm_ocean" -> 64; - case "ocean" -> 112; - case "deep_ocean" -> 48; - case "cold_ocean" -> 2105456; - case "deep_cold_ocean" -> 2105400; - case "frozen_ocean" -> 7368918; - case "deep_frozen_ocean" -> 4210832; - case "mushroom_fields" -> 16711935; - case "dripstone_caves" -> 12690831; - case "lush_caves" -> 14652980; - case "nether_wastes" -> 12532539; - case "warped_forest" -> 4821115; - case "crimson_forest" -> 14485512; - case "soul_sand_valley" -> 6174768; - case "basalt_deltas" -> 4208182; - case "the_end" -> 8421631; - case "end_highlands" -> 12828041; - case "end_midlands" -> 15464630; - case "small_end_islands" -> 42; - case "end_barrens" -> 9474162; - default -> throw new Error("Unexpected biome, with name: '" + biomeName + "'"); - }; - } - public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); Identifier registryKey = registry.getKey(biome).orElseThrow().getValue(); @@ -99,7 +32,7 @@ public static JsonObject generateBiomeInfo(Registry registry, Biome biome //biomeDesc.addProperty("depth", biome.getDepth()); - Doesn't exist anymore in minecraft source biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); - biomeDesc.addProperty("color", getBiomeColorFor(registryKey.getPath())); + biomeDesc.addProperty("color", biome.getSkyColor()); biomeDesc.addProperty("rainfall", biome.getDownfall()); return biomeDesc; diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 61e1b9e6..d6691e26 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,7 +12,10 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class BlockCollisionShapesDataGenerator implements IDataGenerator { diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 29e7ee2b..753d79ba 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -48,7 +48,7 @@ private static String getCategoryFrom(EntityType entityType) { if (entityType == EntityType.PLAYER) return "UNKNOWN"; // fail early for player entities Entity entity = EntityType.createInstanceFromId(Registry.ENTITY_TYPE.getRawId(entityType), DGU.getWorld()); if (entity == null) - throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -58,7 +58,7 @@ private static String getCategoryFrom(EntityType entityType) { case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; case "net.minecraft.entity" -> "UNKNOWN"; - default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index c904c153..078754ff 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -11,6 +11,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index e53f198b..2daf3a43 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -13,13 +13,15 @@ public class BiomesDataGenerator implements IDataGenerator { private static String guessBiomeDimensionFromCategory(RegistryKey biome) { - var biomeRegistry = BuiltinRegistries.BIOME; - if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_NETHER)) { + var entry = BuiltinRegistries.BIOME.getEntry(biome).orElseThrow(); + if (entry.isIn(BiomeTags.IS_OVERWORLD)) { + return "overworld"; + } else if (entry.isIn(BiomeTags.IS_NETHER)) { return "nether"; - } else if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_END)) { + } else if (entry.isIn(BiomeTags.IS_END)) { return "end"; } else { - return "overworld"; + throw new IllegalStateException("Biome is not in any dimension: " + biome); } } @@ -30,10 +32,6 @@ private static String guessCategoryBasedOnName(String name, String dimension) { return "the_end"; } - if (name.contains("end")) { - System.out.println(); - } - if (name.contains("hills")) { return "extreme_hills"; } else if (name.contains("ocean")) { diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 61e1b9e6..d6691e26 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,7 +12,10 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class BlockCollisionShapesDataGenerator implements IDataGenerator { diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 703aeade..df71586a 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -48,7 +48,7 @@ private static String getCategoryFrom(EntityType entityType) { if (entityType == EntityType.PLAYER) return "UNKNOWN"; Entity entity = entityType.create(DGU.getWorld()); if (entity == null) - throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -58,7 +58,7 @@ private static String getCategoryFrom(EntityType entityType) { case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; case "net.minecraft.entity" -> "UNKNOWN"; - default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 5cd4ad15..1ba7b0b2 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -14,7 +14,10 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class TintsDataGenerator implements IDataGenerator { public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index c904c153..078754ff 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -11,6 +11,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index d80bf03e..b5b42261 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -11,13 +11,15 @@ public class BiomesDataGenerator implements IDataGenerator { private static String guessBiomeDimensionFromCategory(RegistryKey biome) { - var biomeRegistry = BuiltinRegistries.BIOME; - if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_NETHER)) { + var entry = BuiltinRegistries.BIOME.getEntry(biome).orElseThrow(); + if (entry.isIn(BiomeTags.IS_OVERWORLD)) { + return "overworld"; + } else if (entry.isIn(BiomeTags.IS_NETHER)) { return "nether"; - } else if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_END)) { + } else if (entry.isIn(BiomeTags.IS_END)) { return "end"; } else { - return "overworld"; + throw new IllegalStateException("Biome is not in any dimension: " + biome); } } @@ -28,10 +30,6 @@ private static String guessCategoryBasedOnName(String name, String dimension) { return "the_end"; } - if (name.contains("end")) { - System.out.println(); - } - if (name.contains("hills")) { return "extreme_hills"; } else if (name.contains("ocean")) { diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 61e1b9e6..d6691e26 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,7 +12,10 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class BlockCollisionShapesDataGenerator implements IDataGenerator { diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 703aeade..df71586a 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -48,7 +48,7 @@ private static String getCategoryFrom(EntityType entityType) { if (entityType == EntityType.PLAYER) return "UNKNOWN"; Entity entity = entityType.create(DGU.getWorld()); if (entity == null) - throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -58,7 +58,7 @@ private static String getCategoryFrom(EntityType entityType) { case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; case "net.minecraft.entity" -> "UNKNOWN"; - default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 5cd4ad15..1ba7b0b2 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -14,7 +14,10 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class TintsDataGenerator implements IDataGenerator { public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index c904c153..078754ff 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -11,6 +11,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index a1b3b732..b9d1378d 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -12,13 +12,15 @@ public class BiomesDataGenerator implements IDataGenerator { private static String guessBiomeDimensionFromCategory(Biome biome) { - var biomeRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME); - if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_NETHER)) { + var entry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME).getEntry(biome); + if (entry.isIn(BiomeTags.IS_OVERWORLD)) { + return "overworld"; + } else if (entry.isIn(BiomeTags.IS_NETHER)) { return "nether"; - } else if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_END)) { + } else if (entry.isIn(BiomeTags.IS_END)) { return "end"; } else { - return "overworld"; + throw new IllegalStateException("Biome is not in any dimension: " + biome); } } @@ -29,10 +31,6 @@ private static String guessCategoryBasedOnName(String name, String dimension) { return "the_end"; } - if (name.contains("end")) { - System.out.println(); - } - if (name.contains("hills")) { return "extreme_hills"; } else if (name.contains("ocean")) { diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 68a169cd..e9094610 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -14,7 +14,10 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class BlockCollisionShapesDataGenerator implements IDataGenerator { diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 71c5ca7e..e5176110 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -53,7 +53,7 @@ private static String getCategoryFrom(EntityType entityType) { if (entityType == EntityType.PLAYER) return "UNKNOWN"; Entity entity = entityType.create(DGU.getWorld()); if (entity == null) - throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -63,7 +63,7 @@ private static String getCategoryFrom(EntityType entityType) { case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; case "net.minecraft.entity" -> "UNKNOWN"; - default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 5c21246b..a7b400c1 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -16,7 +16,10 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.biome.Biome; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class TintsDataGenerator implements IDataGenerator { public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index cf8d9ffc..078754ff 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -11,6 +11,10 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index a1b3b732..b9d1378d 100644 --- a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -12,13 +12,15 @@ public class BiomesDataGenerator implements IDataGenerator { private static String guessBiomeDimensionFromCategory(Biome biome) { - var biomeRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME); - if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_NETHER)) { + var entry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME).getEntry(biome); + if (entry.isIn(BiomeTags.IS_OVERWORLD)) { + return "overworld"; + } else if (entry.isIn(BiomeTags.IS_NETHER)) { return "nether"; - } else if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_END)) { + } else if (entry.isIn(BiomeTags.IS_END)) { return "end"; } else { - return "overworld"; + throw new IllegalStateException("Biome is not in any dimension: " + biome); } } @@ -29,10 +31,6 @@ private static String guessCategoryBasedOnName(String name, String dimension) { return "the_end"; } - if (name.contains("end")) { - System.out.println(); - } - if (name.contains("hills")) { return "extreme_hills"; } else if (name.contains("ocean")) { diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 68a169cd..e9094610 100644 --- a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -14,7 +14,10 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class BlockCollisionShapesDataGenerator implements IDataGenerator { diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 70a88040..f27ac7a0 100644 --- a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -53,7 +53,7 @@ private static String getCategoryFrom(EntityType entityType) { if (entityType == EntityType.PLAYER) return "UNKNOWN"; Entity entity = entityType.create(DGU.getWorld()); if (entity == null) - throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -63,7 +63,7 @@ private static String getCategoryFrom(EntityType entityType) { case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; case "net.minecraft.entity" -> "UNKNOWN"; - default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java index 46e42b47..a76cf154 100644 --- a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java @@ -157,7 +157,8 @@ public JsonElement generateDataJson() { leavesMaterialSpeeds.put(item, 1.5f); gourdMaterialSpeeds.put(item, 1.5f); } - }}); + } + }); COMPOSITE_MATERIALS.forEach(values -> createCompositeMaterial(materialMiningSpeeds, values)); diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 5c21246b..a7b400c1 100644 --- a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -16,7 +16,10 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.biome.Biome; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class TintsDataGenerator implements IDataGenerator { public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index cf8d9ffc..078754ff 100644 --- a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -11,6 +11,10 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index a1b3b732..b9d1378d 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -12,13 +12,15 @@ public class BiomesDataGenerator implements IDataGenerator { private static String guessBiomeDimensionFromCategory(Biome biome) { - var biomeRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME); - if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_NETHER)) { + var entry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME).getEntry(biome); + if (entry.isIn(BiomeTags.IS_OVERWORLD)) { + return "overworld"; + } else if (entry.isIn(BiomeTags.IS_NETHER)) { return "nether"; - } else if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_END)) { + } else if (entry.isIn(BiomeTags.IS_END)) { return "end"; } else { - return "overworld"; + throw new IllegalStateException("Biome is not in any dimension: " + biome); } } @@ -29,10 +31,6 @@ private static String guessCategoryBasedOnName(String name, String dimension) { return "the_end"; } - if (name.contains("end")) { - System.out.println(); - } - if (name.contains("hills")) { return "extreme_hills"; } else if (name.contains("ocean")) { diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 68a169cd..e9094610 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -14,7 +14,10 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class BlockCollisionShapesDataGenerator implements IDataGenerator { diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 94a0ca61..dbadcb70 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -49,7 +49,7 @@ private static String getCategoryFrom(EntityType entityType) { if (entityType == EntityType.PLAYER) return "UNKNOWN"; Entity entity = entityType.create(DGU.getWorld()); if (entity == null) - throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -59,7 +59,7 @@ private static String getCategoryFrom(EntityType entityType) { case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; case "net.minecraft.entity" -> "UNKNOWN"; - default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 5c21246b..a7b400c1 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -16,7 +16,10 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.biome.Biome; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class TintsDataGenerator implements IDataGenerator { public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index c904c153..078754ff 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -11,6 +11,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 3c61ebcd..01c7ad03 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -3,13 +3,9 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.mixin.accessor.BiomeAccessor; -import dev.u9g.minecraftdatagenerator.util.Registries; import net.minecraft.world.biome.*; -import org.apache.commons.lang3.StringUtils; import java.util.Locale; -import java.util.SortedMap; -import java.util.TreeMap; public class BiomesDataGenerator implements IDataGenerator { @@ -22,95 +18,10 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { return "overworld"; } - private static int getBiomeColorFor(String biomeDisplayNamed) { - if (biomeDisplayNamed.equals("Redwood Taiga Hills M")) { - biomeDisplayNamed = "MegaTaigaHills"; - } - String biomeDisplayName = StringUtils.join(biomeDisplayNamed.split(" "), ""); - return switch (biomeDisplayName) { - case "Ocean" -> 112; - case "Plains" -> 9286496; - case "Desert" -> 16421912; - case "ExtremeHills", "Extreme Hills" -> 6316128; - case "Forest" -> 353825; - case "Taiga" -> 747097; - case "Swampland" -> 522674; - case "River" -> 255; - case "Hell" -> 16711680; - case "TheEnd", "The End" -> 8421631; - case "FrozenOcean", "Frozen Ocean" -> 7368918; - case "FrozenRiver", "Frozen River" -> 10526975; - case "IcePlains", "Ice Plains" -> 16777215; - case "IceMountains", "Ice Mountains" -> 10526880; - case "MushroomIsland", "Mushroom Island" -> 16711935; - case "MushroomIslandShore", "Mushroom Island Shore" -> 10486015; - case "Beach" -> 16440917; - case "DesertHills", "Desert Hills" -> 13786898; - case "ForestHills", "Forest Hills" -> 2250012; - case "TaigaHills", "Taiga Hills" -> 1456435; - case "ExtremeHillsEdge", "Extreme Hills Edge" -> 7501978; - case "Jungle" -> 5470985; - case "JungleHills", "Jungle Hills" -> 2900485; - case "JungleEdge", "Jungle Edge" -> 6458135; - case "DeepOcean", "Deep Ocean" -> 48; - case "StoneBeach", "Stone Beach" -> 10658436; - case "ColdBeach", "Cold Beach" -> 16445632; - case "BirchForest", "Birch Forest" -> 3175492; - case "BirchForestHills", "Birch Forest Hills" -> 2055986; - case "RoofedForest", "Roofed Forest" -> 4215066; - case "ColdTaiga", "Cold Taiga" -> 3233098; - case "ColdTaigaHills", "Cold Taiga Hills" -> 2375478; - case "MegaTaiga", "Mega Taiga" -> 5858897; - case "MegaTaigaHills", "Mega Taiga Hills" -> 4542270; - case "ExtremeHills+", "Extreme Hills+" -> 5271632; - case "Savanna" -> 12431967; - case "SavannaPlateau", "Savanna Plateau" -> 10984804; - case "Mesa" -> 14238997; - case "MesaPlateauF", "Mesa Plateau F" -> 11573093; - case "MesaPlateau", "Mesa Plateau" -> 13274213; - case "TheEnd-Floatingislands", "The End - Floating islands" -> 8421631; - case "TheEnd-Mediumisland", "The End - Medium island" -> 8421631; - case "TheEnd-Highisland", "The End - High island" -> 8421631; - case "TheEnd-Barrenisland", "The End - Barren island" -> 8421631; - case "WarmOcean", "Warm Ocean" -> 172; - case "LukewarmOcean", "Lukewarm Ocean" -> 144; - case "ColdOcean", "Cold Ocean" -> 2105456; - case "WarmDeepOcean", "Warm Deep Ocean" -> 80; - case "LukewarmDeepOcean", "Lukewarm Deep Ocean" -> 64; - case "ColdDeepOcean", "Cold Deep Ocean" -> 2105400; - case "FrozenDeepOcean", "Frozen Deep Ocean" -> 4210832; - case "TheVoid", "The Void" -> 0; - case "SunflowerPlains", "Sunflower Plains" -> 11918216; - case "DesertM", "Desert M" -> 16759872; - case "ExtremeHillsM", "Extreme Hills M" -> 8947848; - case "FlowerForest", "Flower Forest" -> 2985545; - case "TaigaM", "Taiga M" -> 3378817; - case "SwamplandM", "Swampland M" -> 3145690; - case "IcePlainsSpikes", "Ice Plains Spikes" -> 11853020; - case "JungleM", "Jungle M" -> 8102705; - case "JungleEdgeM", "Jungle Edge M" -> 9089855; - case "BirchForestM", "Birch Forest M" -> 5807212; - case "BirchForestHillsM", "Birch Forest Hills M" -> 4687706; - case "RoofedForestM", "Roofed Forest M" -> 6846786; - case "ColdTaigaM", "Cold Taiga M" -> 5864818; - case "MegaSpruceTaiga", "Mega Spruce Taiga" -> 8490617; - case "MegaSpruceTaiga(Hills)", "Mega Spruce Taiga (Hills)" -> 7173990; - case "ExtremeHills+M", "Extreme Hills+ M" -> 7903352; - case "SavannaM", "Savanna M" -> 15063687; - case "SavannaPlateauM", "Savanna Plateau M" -> 13616524; - case "Mesa(Bryce)", "Mesa (Bryce)" -> 16739645; - case "MesaPlateauFM", "Mesa Plateau F M" -> 14204813; - case "MesaPlateauM", "Mesa Plateau M" -> 15905933; - case "BambooJungle", "Bamboo Jungle" -> 7769620; - case "BambooJungleHills", "Bamboo Jungle Hills" -> 3884810; - default -> throw new Error("Unexpected biome, with name: '" + biomeDisplayName + "'"); - }; - } - public static JsonObject generateBiomeInfo(Biome biome) { JsonObject biomeDesc = new JsonObject(); - biomeDesc.addProperty("id", Registries.BIOMES.getRawId(biome)); + biomeDesc.addProperty("id", biome.id); biomeDesc.addProperty("name", String.join("_", ((BiomeAccessor) biome).name().toLowerCase(Locale.ENGLISH).split(" "))); biomeDesc.addProperty("category", category(biome)); biomeDesc.addProperty("temperature", biome.temperature); @@ -118,7 +29,7 @@ public static JsonObject generateBiomeInfo(Biome biome) { biomeDesc.addProperty("depth", biome.depth); biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", ((BiomeAccessor) biome).name()); - biomeDesc.addProperty("color", getBiomeColorFor(((BiomeAccessor) biome).name())); + biomeDesc.addProperty("color", biome.getSkyColor(biome.temperature)); biomeDesc.addProperty("rainfall", biome.downfall); return biomeDesc; @@ -160,7 +71,7 @@ private static String category(Biome biome) { } else if (biome instanceof StoneBeachBiome) { return "none"; // Should StoneBeachBiome be beach too? this is how it is now in mcdata } - throw new Error("Unable to find biome category for " + biome.getClass().getName()); + throw new IllegalStateException("Unable to find biome category for " + biome.getClass().getName()); } private static String precipitation(Biome biome) { @@ -181,12 +92,12 @@ public String getDataName() { @Override public JsonArray generateDataJson() { - SortedMap biomes = new TreeMap<>(); - for (Biome biome : Registries.BIOMES) { - biomes.put(biome.id, generateBiomeInfo(biome)); - } JsonArray biomesArray = new JsonArray(); - biomes.values().forEach(biomesArray::add); + + for (Object object : Biome.BIOMESET) { + Biome biome = (Biome) object; + biomesArray.add(generateBiomeInfo(biome)); + } return biomesArray; } } diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index c42ab27c..ab00b8d4 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -71,10 +71,6 @@ private static String boundingBox(Block block) { return "block"; } - private static Item getItemFromBlock(Block block) { - return Registries.ITEMS.get(Registries.BLOCKS.getId(block)); - } - @Override public String getDataName() { return "blocks"; diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 166b12f1..cf7a5188 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -11,34 +11,39 @@ import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.WaterCreatureEntity; import net.minecraft.entity.passive.AnimalEntity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.FishingBobberEntity; import net.minecraft.entity.projectile.Projectile; +import net.minecraft.network.Packet; +import net.minecraft.network.packet.s2c.play.EntityAttributesS2CPacket; +import net.minecraft.network.packet.s2c.play.EntityS2CPacket; +import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; +import net.minecraft.network.packet.s2c.play.MobSpawnS2CPacket; +import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.Objects; public class EntitiesDataGenerator implements IDataGenerator { public static JsonObject generateEntity(Class entityClass) { JsonObject entityDesc = new JsonObject(); String registryKey = Registries.ENTITY_TYPES.getId(entityClass); - int entityRawId = Registries.ENTITY_TYPES.getRawId(entityClass); - @Nullable Entity entity = makeEntity(entityClass); + Entity entity = makeEntity(entityClass); // FIXME: ENTITY ID IS WRONG int id = entityId(entity); entityDesc.addProperty("id", id); entityDesc.addProperty("internalId", id); entityDesc.addProperty("name", Objects.requireNonNull(registryKey)); - String displayName = entity != null ? entity.getTranslationKey() : null; + String displayName = entity.getTranslationKey(); if (displayName != null && !displayName.startsWith("entity.")) { entityDesc.addProperty("displayName", displayName); } - entityDesc.addProperty("width", entity == null ? 0 : entity.width); - entityDesc.addProperty("height", entity == null ? 0 : entity.height); + entityDesc.addProperty("width", entity.width); + entityDesc.addProperty("height", entity.height); - String entityTypeString = "UNKNOWN"; - entityTypeString = getEntityTypeForClass(entityClass); + String entityTypeString = getEntityTypeForClass(entityClass); entityDesc.addProperty("type", entityTypeString); entityDesc.addProperty("category", getCategoryFrom(entityClass)); @@ -46,12 +51,14 @@ public static JsonObject generateEntity(Class entityClass) { } private static Entity makeEntity(Class type) { - String name = EntityTypeAccessor.CLASS_NAME_MAP().get(type); - return EntityType.createInstanceFromName(name, DGU.getWorld()); + try { + return type.getConstructor(World.class).newInstance(DGU.getWorld()); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } } private static String getCategoryFrom(@NotNull Class entityClass) { - if (entityClass == PlayerEntity.class) return "other"; // fail early for player entities String packageName = entityClass.getPackage().getName(); return switch (packageName) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -60,8 +67,8 @@ private static String getCategoryFrom(@NotNull Class entityClass) { case "net.minecraft.entity.projectile", "net.minecraft.entity.thrown" -> "Projectiles"; case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; - case "net.minecraft.entity" -> "other"; - default -> throw new Error("Unexpected entity type: " + packageName); + case "net.minecraft.entity.player", "net.minecraft.entity" -> "other"; + default -> throw new IllegalStateException("Unexpected entity type: " + packageName); }; } diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 866f9d1f..4d09fde0 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -22,8 +22,8 @@ public JsonElement generateDataJson() { obj.addProperty(entry.getKey(), entry.getValue()); } return obj; - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index fc1385c9..987abef3 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -18,7 +18,9 @@ public class TintsDataGenerator implements IDataGenerator { public static BiomeTintColors generateBiomeTintColors() { BiomeTintColors colors = new BiomeTintColors(); - for (Biome biome : Registries.BIOMES) { + for (Object object : Biome.BIOMESET) { + Biome biome = (Biome) object; + double d = MathHelper.clamp(biome.temperature, 0.0f, 1.0f); double e = MathHelper.clamp(biome.downfall, 0.0f, 1.0f); diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index d70a0299..64180681 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -12,9 +12,13 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { - System.setProperty("fabric.development", "false"); MinecraftDataGenerator.start( DGU.getCurrentlyRunningServer().getVersion(), (new File(".")).toPath() diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/BiomeAccessor.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/BiomeAccessor.java index 04a1a7ff..e66f4cfe 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/BiomeAccessor.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/BiomeAccessor.java @@ -10,7 +10,7 @@ public interface BiomeAccessor { @Accessor("BIOMESET") static Set BIOMESET() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("waterColor") diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/EnchantmentAccessor.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/EnchantmentAccessor.java index d69c22e3..8e7cc180 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/EnchantmentAccessor.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/EnchantmentAccessor.java @@ -8,6 +8,6 @@ public interface EnchantmentAccessor { @Accessor("ALL_ENCHANTMENTS") static Enchantment[] ALL_ENCHANTMENTS() { - throw new Error(); + throw new IllegalStateException(); } } diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/EntityTypeAccessor.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/EntityTypeAccessor.java index 17b42f40..816b2c6c 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/EntityTypeAccessor.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/EntityTypeAccessor.java @@ -9,23 +9,13 @@ @Mixin(EntityType.class) public interface EntityTypeAccessor { - @Accessor("NAME_CLASS_MAP") - static Map> NAME_CLASS_MAP() { - throw new Error(); - } - @Accessor("CLASS_NAME_MAP") static Map, String> CLASS_NAME_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("ID_CLASS_MAP") static Map> ID_CLASS_MAP() { - throw new Error(); - } - - @Accessor("CLASS_ID_MAP") - static Map, Integer> CLASS_ID_MAP() { - throw new Error(); + throw new IllegalStateException(); } } diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/StatusEffectAccessor.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/StatusEffectAccessor.java index debed94c..dca0536f 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/StatusEffectAccessor.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/accessor/StatusEffectAccessor.java @@ -8,7 +8,7 @@ public interface StatusEffectAccessor { @Accessor("STATUS_EFFECTS") static StatusEffect[] STATUS_EFFECTS() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("negative") diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/registryview/TableBackedRegistryView.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/registryview/TableBackedRegistryView.java index a89014de..1e482463 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/registryview/TableBackedRegistryView.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/registryview/TableBackedRegistryView.java @@ -23,7 +23,7 @@ public int getRawId(V value) { return entry.getKey(); } } - throw new Error("value not in registry."); + throw new IllegalStateException("value not in registry."); } @Override @@ -34,7 +34,7 @@ public K getId(V value) { return row.getKey(); } } - throw new Error("value not in registry."); + throw new IllegalStateException("value not in registry."); } @Override diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java index 976e8d11..e5253d9d 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java @@ -1,7 +1,6 @@ package dev.u9g.minecraftdatagenerator.util; import dev.u9g.minecraftdatagenerator.mixin.accessor.BiomeAccessor; -import dev.u9g.minecraftdatagenerator.mixin.accessor.EnchantmentAccessor; import dev.u9g.minecraftdatagenerator.mixin.accessor.EntityTypeAccessor; import dev.u9g.minecraftdatagenerator.mixin.accessor.StatusEffectAccessor; import dev.u9g.minecraftdatagenerator.registryview.RegistryBackedRegistryView; @@ -20,8 +19,7 @@ import java.util.Map; public class Registries { - public static final Language LANGUAGE; - public static final RegistryView BIOMES; + public static final Language LANGUAGE = new Language(); public static final RegistryView BLOCKS; public static final RegistryView ITEMS; public static final RegistryView STATUS_EFFECTS; @@ -29,8 +27,6 @@ public class Registries { public static final RegistryView> ENTITY_TYPES; static { - LANGUAGE = new Language(); - BIOMES = setupBiomeRegistry(); BLOCKS = new RegistryBackedRegistryView<>(Block.REGISTRY); ITEMS = new RegistryBackedRegistryView<>(Item.REGISTRY); STATUS_EFFECTS = setupStatusEffectRegistry(); @@ -53,7 +49,7 @@ private static RegistryView> setupEntityTypesReg private static RegistryView setupEnchantmentRegistry() { TableBackedRegistryView.Builder registry = new TableBackedRegistryView.Builder<>(); - for (Enchantment enchantment : EnchantmentAccessor.ALL_ENCHANTMENTS()) { + for (Enchantment enchantment : Enchantment.ALL_ENCHANTMENTS) { if (enchantment == null) continue; String translatedName = Registries.LANGUAGE.translate(enchantment.getTranslationKey()); registry.add(String.join("", translatedName.toLowerCase(Locale.ENGLISH).split(" ")), enchantment.id, enchantment); @@ -61,14 +57,6 @@ private static RegistryView setupEnchantmentRegistry() { return registry.build(); } - private static RegistryView setupBiomeRegistry() { - TableBackedRegistryView.Builder builder = new TableBackedRegistryView.Builder<>(); - for (Biome biome : BiomeAccessor.BIOMESET()) { - builder.add(biome.name, biome.id, biome); - } - return builder.build(); - } - private static RegistryView setupStatusEffectRegistry() { TableBackedRegistryView.Builder builder = new TableBackedRegistryView.Builder<>(); for (StatusEffect effect : StatusEffectAccessor.STATUS_EFFECTS()) { diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 24ce0d6f..817df82b 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -3,7 +3,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor; -import dev.u9g.minecraftdatagenerator.util.Registries; import net.minecraft.world.biome.*; import java.util.Locale; @@ -23,7 +22,7 @@ public static JsonObject generateBiomeInfo(Biome biome) { JsonObject biomeDesc = new JsonObject(); // Identifier registryKey = registry.getIdentifier(biome); - biomeDesc.addProperty("id", Registries.BIOMES.getRawId(biome)); + biomeDesc.addProperty("id", biome.id); biomeDesc.addProperty("name", String.join("_", ((BiomeAccessor) biome).name().toLowerCase(Locale.ENGLISH).split(" "))); biomeDesc.addProperty("category", category(biome)); biomeDesc.addProperty("temperature", biome.temperature); @@ -73,7 +72,7 @@ private static String category(Biome biome) { } else if (biome instanceof StoneBeachBiome) { return "none"; // Should StoneBeachBiome be beach too? this is how it is now in mcdata } - throw new Error("Unable to find biome category for " + biome.getClass().getName()); + throw new IllegalStateException("Unable to find biome category for " + biome.getClass().getName()); } private static String precipitation(Biome biome) { @@ -96,7 +95,7 @@ public String getDataName() { public JsonArray generateDataJson() { JsonArray biomesArray = new JsonArray(); - for (Biome biome : Registries.BIOMES) { + for (Biome biome : Biome.BIOMESET) { biomesArray.add(generateBiomeInfo(biome)); } return biomesArray; diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 411a4666..2c84eda6 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -5,7 +5,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import dev.u9g.minecraftdatagenerator.util.DGU; -import dev.u9g.minecraftdatagenerator.util.Registries; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; @@ -19,7 +18,7 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator { private static final Box ENTITY_BOX = new Box(0.0D, 0.0D, 0.0D, 1.0D, 2.0D, 1.0D); private static String nameOf(Block block) { - return Objects.requireNonNull(Registries.BLOCKS.getIdentifier(block)).getPath(); + return Objects.requireNonNull(Block.REGISTRY.getIdentifier(block)).getPath(); } private static JsonArray jsonOf(Box box) { @@ -43,7 +42,7 @@ public String getDataName() { public JsonObject generateDataJson() { ShapeCache shapeCache = new ShapeCache(); JsonObject blocksObject = new JsonObject(); - for (Block block : Registries.BLOCKS) { + for (Block block : Block.REGISTRY) { Object val = shapeCache.addShapesFrom(block); if (val instanceof JsonArray) { blocksObject.add(nameOf(block), (JsonElement) val); diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 1262f5f5..c042f398 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -84,10 +84,10 @@ public static JsonObject generateBlock(Block block) { List blockStates = block.getStateManager().getBlockStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = Registries.BLOCKS.getIdentifier(block); + Identifier registryKey = Block.REGISTRY.getIdentifier(block); List effectiveTools = getItemsEffectiveForBlock(block); - blockDesc.addProperty("id", Registries.BLOCKS.getRawId(block)); + blockDesc.addProperty("id", Block.REGISTRY.getRawId(block)); blockDesc.addProperty("name", Objects.requireNonNull(registryKey).getPath()); if (!block.getTranslatedName().startsWith("tile.")) { blockDesc.addProperty("displayName", block.getTranslatedName()); @@ -126,10 +126,6 @@ private static String boundingBox(Block block, BlockState state) { return "block"; } - private static Item getItemFromBlock(Block block) { - return Registries.ITEMS.get(Registries.BLOCKS.getIdentifier(block)); - } - @Override public String getDataName() { return "blocks"; @@ -138,7 +134,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultBlocksArray = new JsonArray(); - for (Block block : Registries.BLOCKS) { + for (Block block : Block.REGISTRY) { resultBlocksArray.add(generateBlock(block)); } return resultBlocksArray; diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index a14483d7..553281ae 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -11,10 +11,10 @@ import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.WaterCreatureEntity; import net.minecraft.entity.passive.AnimalEntity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.FishingBobberEntity; import net.minecraft.entity.projectile.Projectile; import net.minecraft.util.Identifier; +import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,22 +24,20 @@ public class EntitiesDataGenerator implements IDataGenerator { public static JsonObject generateEntity(Class entityClass) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass); - int entityRawId = Registries.ENTITY_TYPES.getRawId(entityClass); - @Nullable Entity entity = makeEntity(entityClass); + Entity entity = makeEntity(entityClass); // FIXME: ENTITY ID IS WRONG int id = entityId(entity); entityDesc.addProperty("id", id); entityDesc.addProperty("internalId", id); entityDesc.addProperty("name", Objects.requireNonNull(registryKey).getPath()); - String displayName = entity != null ? entity.getTranslationKey() : null; + String displayName = entity.getTranslationKey(); if (displayName != null && !displayName.startsWith("entity.")) { entityDesc.addProperty("displayName", displayName); } - entityDesc.addProperty("width", entity == null ? 0 : entity.width); - entityDesc.addProperty("height", entity == null ? 0 : entity.height); + entityDesc.addProperty("width", entity.width); + entityDesc.addProperty("height", entity.height); - String entityTypeString = "UNKNOWN"; - entityTypeString = getEntityTypeForClass(entityClass); + String entityTypeString = getEntityTypeForClass(entityClass); entityDesc.addProperty("type", entityTypeString); entityDesc.addProperty("category", getCategoryFrom(entityClass)); @@ -47,12 +45,14 @@ public static JsonObject generateEntity(Class entityClass) { } private static Entity makeEntity(Class type) { - String name = EntityTypeAccessor.CLASS_NAME_MAP().get(type); - return EntityType.createInstanceFromName(name, DGU.getWorld()); + try { + return type.getConstructor(World.class).newInstance(DGU.getWorld()); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } } private static String getCategoryFrom(@NotNull Class entityClass) { - if (entityClass == PlayerEntity.class) return "other"; // fail early for player entities String packageName = entityClass.getPackage().getName(); return switch (packageName) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -61,8 +61,8 @@ private static String getCategoryFrom(@NotNull Class entityClass) { case "net.minecraft.entity.projectile", "net.minecraft.entity.thrown" -> "Projectiles"; case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; - case "net.minecraft.entity" -> "other"; - default -> throw new Error("Unexpected entity type: " + packageName); + case "net.minecraft.entity.player", "net.minecraft.entity" -> "other"; + default -> throw new IllegalStateException("Unexpected entity type: " + packageName); }; } @@ -105,7 +105,7 @@ private static String getEntityTypeForClass(Class entityClass) private static int entityId(Entity entity) { if (!DGU.getCurrentlyRunningServer().getVersion().equals("1.8.9")) { - throw new Error("These ids were gotten manually for 1.8.9, remake for " + DGU.getCurrentlyRunningServer().getVersion()); + throw new IllegalStateException("These ids were gotten manually for 1.8.9, remake for " + DGU.getCurrentlyRunningServer().getVersion()); } int rawId = Registries.ENTITY_TYPES.getRawId(entity.getClass()); if (rawId == -1) { // see TrackedEntityInstance @@ -114,7 +114,7 @@ private static int entityId(Entity entity) { } else if (entity instanceof FishingBobberEntity) { return 90; } else { - throw new Error("unable to find rawId for entity: " + entity.getEntity().getClass().getName()); + throw new IllegalStateException("unable to find rawId for entity: " + entity.getEntity().getClass().getName()); } } return rawId; diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 88e8d2fb..f481c08a 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -22,8 +22,8 @@ public JsonElement generateDataJson() { obj.addProperty(entry.getKey(), entry.getValue()); } return obj; - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index cddf868a..fb63bd27 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -4,7 +4,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor; -import dev.u9g.minecraftdatagenerator.util.Registries; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.RedstoneWireBlock; @@ -21,7 +20,7 @@ public class TintsDataGenerator implements IDataGenerator { public static BiomeTintColors generateBiomeTintColors() { BiomeTintColors colors = new BiomeTintColors(); - for (Biome biome : Registries.BIOMES) { + for (Biome biome : Biome.BIOMESET) { double d = MathHelper.clamp(biome.temperature, 0.0F, 1.0F); double e = MathHelper.clamp(biome.downfall, 0.0F, 1.0F); @@ -115,7 +114,7 @@ private static JsonObject encodeBlocksColorMap(Map colorsMap) { for (Map.Entry entry : colorsMap.entrySet()) { JsonObject entryObject = new JsonObject(); JsonArray keysArray = new JsonArray(); - Identifier registryKey = Registries.BLOCKS.getIdentifier(entry.getKey()); + Identifier registryKey = Block.REGISTRY.getIdentifier(entry.getKey()); keysArray.add(new JsonPrimitive(Objects.requireNonNull(registryKey).getPath())); entryObject.add("keys", keysArray); diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/BiomeAccessor.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/BiomeAccessor.java index dd813619..324a8d98 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/BiomeAccessor.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/BiomeAccessor.java @@ -10,7 +10,7 @@ public interface BiomeAccessor { @Accessor("BIOMESET") static Set BIOMESET() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("waterColor") diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EnchantmentAccessor.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EnchantmentAccessor.java index 1daf881c..011a0982 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EnchantmentAccessor.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EnchantmentAccessor.java @@ -11,6 +11,6 @@ public interface EnchantmentAccessor { @Accessor("ENCHANTMENT_MAP") static Map ENCHANTMENT_MAP() { - throw new Error(); + throw new IllegalStateException(); } } diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java index 60386ba8..d772d280 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java @@ -11,26 +11,26 @@ public interface EntityTypeAccessor { @Accessor("NAME_CLASS_MAP") static Map> NAME_CLASS_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("CLASS_NAME_MAP") static Map, String> CLASS_NAME_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("ID_CLASS_MAP") static Map> ID_CLASS_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("CLASS_ID_MAP") static Map, Integer> CLASS_ID_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("NAME_ID_MAP") static Map NAME_ID_MAP() { - throw new Error(); + throw new IllegalStateException(); } } diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index c1d96581..8e82cee6 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -10,6 +10,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/StatusEffectAccessor.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/StatusEffectAccessor.java index 09985fe0..dd1eb764 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/StatusEffectAccessor.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/StatusEffectAccessor.java @@ -11,7 +11,7 @@ public interface StatusEffectAccessor { @Accessor("STATUS_EFFECTS_BY_ID") static Map STATUS_EFFECTS_BY_ID() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("negative") diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyBlockView.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyBlockView.java deleted file mode 100644 index 2fbb489b..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyBlockView.java +++ /dev/null @@ -1,54 +0,0 @@ -package dev.u9g.minecraftdatagenerator.util; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.BlockView; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.level.LevelGeneratorType; -import org.jetbrains.annotations.Nullable; - -public class EmptyBlockView implements BlockView { - public static final EmptyBlockView INSTANCE = new EmptyBlockView(); - - @Nullable - public BlockEntity getBlockEntity(BlockPos pos) { - return null; - } - - @Override - public int getLight(BlockPos pos, int minBlockLight) { - return 0; - } - - public BlockState getBlockState(BlockPos pos) { - return Blocks.AIR.getDefaultState(); - } - - @Override - public boolean isAir(BlockPos pos) { - return false; - } - - @Override - public Biome getBiome(BlockPos pos) { - return null; - } - - @Override - public boolean isEmpty() { - return false; - } - - @Override - public int getStrongRedstonePower(BlockPos pos, Direction direction) { - return 0; - } - - @Override - public LevelGeneratorType getGeneratorType() { - return null; - } -} diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java index 5039f75c..45e01da3 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java @@ -1,10 +1,8 @@ package dev.u9g.minecraftdatagenerator.util; -import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor; import dev.u9g.minecraftdatagenerator.mixin.EnchantmentAccessor; import dev.u9g.minecraftdatagenerator.mixin.EntityTypeAccessor; import dev.u9g.minecraftdatagenerator.mixin.StatusEffectAccessor; -import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.StatusEffect; @@ -12,13 +10,10 @@ import net.minecraft.util.Identifier; import net.minecraft.util.Language; import net.minecraft.util.registry.SimpleRegistry; -import net.minecraft.world.biome.Biome; import java.util.Map; public class Registries { - public static final SimpleRegistry BIOMES = setupBiomeRegistry(); - public static final SimpleRegistry BLOCKS = Block.REGISTRY; public static final SimpleRegistry ITEMS = Item.REGISTRY; public static final SimpleRegistry STATUS_EFFECTS = setupStatusEffectRegistry(); public static final SimpleRegistry ENCHANTMENTS = setupEnchantmentRegistry(); @@ -46,14 +41,6 @@ private static SimpleRegistry setupEnchantmentRegistry( return registry; } - private static SimpleRegistry setupBiomeRegistry() { - SimpleRegistry registry = new SimpleRegistry<>(); - for (Biome biome : BiomeAccessor.BIOMESET()) { - registry.add(biome.id, biome.name, biome); - } - return registry; - } - private static SimpleRegistry setupStatusEffectRegistry() { SimpleRegistry registry = new SimpleRegistry<>(); for (Map.Entry entry : StatusEffectAccessor.STATUS_EFFECTS_BY_ID().entrySet()) { diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 79299efe..3075baff 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -6,7 +6,6 @@ import net.minecraft.util.Identifier; import net.minecraft.util.registry.SimpleRegistry; import net.minecraft.world.biome.*; -import org.apache.commons.lang3.StringUtils; import java.util.Locale; @@ -21,91 +20,6 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { return "overworld"; } - private static int getBiomeColorFor(String biomeDisplayNamed) { - if (biomeDisplayNamed.equals("Redwood Taiga Hills M")) { - biomeDisplayNamed = "MegaTaigaHills"; - } - String biomeDisplayName = StringUtils.join(biomeDisplayNamed.split(" "), ""); - return switch (biomeDisplayName) { - case "Ocean" -> 112; - case "Plains" -> 9286496; - case "Desert" -> 16421912; - case "ExtremeHills", "Extreme Hills" -> 6316128; - case "Forest" -> 353825; - case "Taiga" -> 747097; - case "Swampland" -> 522674; - case "River" -> 255; - case "Hell" -> 16711680; - case "TheEnd", "The End" -> 8421631; - case "FrozenOcean", "Frozen Ocean" -> 7368918; - case "FrozenRiver", "Frozen River" -> 10526975; - case "IcePlains", "Ice Plains" -> 16777215; - case "IceMountains", "Ice Mountains" -> 10526880; - case "MushroomIsland", "Mushroom Island" -> 16711935; - case "MushroomIslandShore", "Mushroom Island Shore" -> 10486015; - case "Beach" -> 16440917; - case "DesertHills", "Desert Hills" -> 13786898; - case "ForestHills", "Forest Hills" -> 2250012; - case "TaigaHills", "Taiga Hills" -> 1456435; - case "ExtremeHillsEdge", "Extreme Hills Edge" -> 7501978; - case "Jungle" -> 5470985; - case "JungleHills", "Jungle Hills" -> 2900485; - case "JungleEdge", "Jungle Edge" -> 6458135; - case "DeepOcean", "Deep Ocean" -> 48; - case "StoneBeach", "Stone Beach" -> 10658436; - case "ColdBeach", "Cold Beach" -> 16445632; - case "BirchForest", "Birch Forest" -> 3175492; - case "BirchForestHills", "Birch Forest Hills" -> 2055986; - case "RoofedForest", "Roofed Forest" -> 4215066; - case "ColdTaiga", "Cold Taiga" -> 3233098; - case "ColdTaigaHills", "Cold Taiga Hills" -> 2375478; - case "MegaTaiga", "Mega Taiga" -> 5858897; - case "MegaTaigaHills", "Mega Taiga Hills" -> 4542270; - case "ExtremeHills+", "Extreme Hills+" -> 5271632; - case "Savanna" -> 12431967; - case "SavannaPlateau", "Savanna Plateau" -> 10984804; - case "Mesa" -> 14238997; - case "MesaPlateauF", "Mesa Plateau F" -> 11573093; - case "MesaPlateau", "Mesa Plateau" -> 13274213; - case "TheEnd-Floatingislands", "The End - Floating islands" -> 8421631; - case "TheEnd-Mediumisland", "The End - Medium island" -> 8421631; - case "TheEnd-Highisland", "The End - High island" -> 8421631; - case "TheEnd-Barrenisland", "The End - Barren island" -> 8421631; - case "WarmOcean", "Warm Ocean" -> 172; - case "LukewarmOcean", "Lukewarm Ocean" -> 144; - case "ColdOcean", "Cold Ocean" -> 2105456; - case "WarmDeepOcean", "Warm Deep Ocean" -> 80; - case "LukewarmDeepOcean", "Lukewarm Deep Ocean" -> 64; - case "ColdDeepOcean", "Cold Deep Ocean" -> 2105400; - case "FrozenDeepOcean", "Frozen Deep Ocean" -> 4210832; - case "TheVoid", "The Void" -> 0; - case "SunflowerPlains", "Sunflower Plains" -> 11918216; - case "DesertM", "Desert M" -> 16759872; - case "ExtremeHillsM", "Extreme Hills M" -> 8947848; - case "FlowerForest", "Flower Forest" -> 2985545; - case "TaigaM", "Taiga M" -> 3378817; - case "SwamplandM", "Swampland M" -> 3145690; - case "IcePlainsSpikes", "Ice Plains Spikes" -> 11853020; - case "JungleM", "Jungle M" -> 8102705; - case "JungleEdgeM", "Jungle Edge M" -> 9089855; - case "BirchForestM", "Birch Forest M" -> 5807212; - case "BirchForestHillsM", "Birch Forest Hills M" -> 4687706; - case "RoofedForestM", "Roofed Forest M" -> 6846786; - case "ColdTaigaM", "Cold Taiga M" -> 5864818; - case "MegaSpruceTaiga", "Mega Spruce Taiga" -> 8490617; - case "MegaSpruceTaiga(Hills)", "Mega Spruce Taiga (Hills)" -> 7173990; - case "ExtremeHills+M", "Extreme Hills+ M" -> 7903352; - case "SavannaM", "Savanna M" -> 15063687; - case "SavannaPlateauM", "Savanna Plateau M" -> 13616524; - case "Mesa(Bryce)", "Mesa (Bryce)" -> 16739645; - case "MesaPlateauFM", "Mesa Plateau F M" -> 14204813; - case "MesaPlateauM", "Mesa Plateau M" -> 15905933; - case "BambooJungle", "Bamboo Jungle" -> 7769620; - case "BambooJungleHills", "Bamboo Jungle Hills" -> 3884810; - default -> throw new Error("Unexpected biome, with name: '" + biomeDisplayName + "'"); - }; - } - public static JsonObject generateBiomeInfo(SimpleRegistry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); Identifier registryKey = registry.getIdentifier(biome); @@ -118,7 +32,7 @@ public static JsonObject generateBiomeInfo(SimpleRegistry reg biomeDesc.addProperty("depth", biome.getDepth()); biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", ((BiomeAccessor) biome).name()); - biomeDesc.addProperty("color", getBiomeColorFor(((BiomeAccessor) biome).name())); + biomeDesc.addProperty("color", biome.getSkyColor(biome.getTemperature())); biomeDesc.addProperty("rainfall", biome.getRainfall()); return biomeDesc; @@ -160,7 +74,7 @@ private static String category(Biome biome) { } else if (biome instanceof StoneBeachBiome || biome instanceof VoidBiome) { return "none"; // Should StoneBeachBiome be beach too? this is how it is now in mcdata } - throw new Error("Unable to find biome category for " + biome.getClass().getName()); + throw new IllegalStateException("Unable to find biome category for " + biome.getClass().getName()); } private static String precipitation(Biome biome) { diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index f61dc62d..3409cb08 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -127,10 +127,6 @@ private static String boundingBox(Block block, BlockState state) { return "block"; } - private static Item getItemFromBlock(Block block) { - return Registries.ITEMS.get(Registries.BLOCKS.getIdentifier(block)); - } - @Override public String getDataName() { return "blocks"; diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 2554af41..f9c3721a 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -11,10 +11,10 @@ import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.WaterCreatureEntity; import net.minecraft.entity.passive.AnimalEntity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.FishingBobberEntity; import net.minecraft.entity.projectile.Projectile; import net.minecraft.util.Identifier; +import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,22 +24,20 @@ public class EntitiesDataGenerator implements IDataGenerator { public static JsonObject generateEntity(Class entityClass) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass); - int entityRawId = Registries.ENTITY_TYPES.getRawId(entityClass); - @Nullable Entity entity = makeEntity(entityClass); + Entity entity = makeEntity(entityClass); // FIXME: ENTITY ID IS WRONG int id = entityId(entity); entityDesc.addProperty("id", id); entityDesc.addProperty("internalId", id); entityDesc.addProperty("name", Objects.requireNonNull(registryKey).getPath()); - String displayName = entity != null ? DGU.translateText(entity.getTranslationKey()) : null; + String displayName = DGU.translateText(entity.getTranslationKey()); if (displayName != null && !displayName.startsWith("entity.")) { entityDesc.addProperty("displayName", displayName); } - entityDesc.addProperty("width", entity == null ? 0 : entity.width); - entityDesc.addProperty("height", entity == null ? 0 : entity.height); + entityDesc.addProperty("width", entity.width); + entityDesc.addProperty("height", entity.height); - String entityTypeString = "UNKNOWN"; - entityTypeString = getEntityTypeForClass(entityClass); + String entityTypeString = getEntityTypeForClass(entityClass); entityDesc.addProperty("type", entityTypeString); entityDesc.addProperty("category", getCategoryFrom(entityClass)); @@ -47,12 +45,14 @@ public static JsonObject generateEntity(Class entityClass) { } private static Entity makeEntity(Class type) { - String name = EntityTypeAccessor.CLASS_NAME_MAP().get(type); - return EntityType.createInstanceFromName(name, DGU.getWorld()); + try { + return type.getConstructor(World.class).newInstance(DGU.getWorld()); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } } private static String getCategoryFrom(@NotNull Class entityClass) { - if (entityClass == PlayerEntity.class) return "other"; // fail early for player entities String packageName = entityClass.getPackage().getName(); return switch (packageName) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -61,8 +61,8 @@ private static String getCategoryFrom(@NotNull Class entityClass) { case "net.minecraft.entity.projectile", "net.minecraft.entity.thrown" -> "Projectiles"; case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; - case "net.minecraft.entity" -> "other"; - default -> throw new Error("Unexpected entity type: " + packageName); + case "net.minecraft.entity.player", "net.minecraft.entity" -> "other"; + default -> throw new IllegalStateException("Unexpected entity type: " + packageName); }; } @@ -105,7 +105,7 @@ private static String getEntityTypeForClass(Class entityClass) private static int entityId(Entity entity) { if (!DGU.getCurrentlyRunningServer().getVersion().equals("1.9.4")) { - throw new Error("These ids were gotten manually for 1.9.4, remake for " + DGU.getCurrentlyRunningServer().getVersion()); + throw new IllegalStateException("These ids were gotten manually for 1.9.4, remake for " + DGU.getCurrentlyRunningServer().getVersion()); } int rawId = Registries.ENTITY_TYPES.getRawId(entity.getClass()); if (rawId == -1) { // see TrackedEntityInstance @@ -114,7 +114,7 @@ private static int entityId(Entity entity) { } else if (entity instanceof FishingBobberEntity) { return 90; } else { - throw new Error("unable to find rawId for entity: " + entity.getEntityName()); + throw new IllegalStateException("unable to find rawId for entity: " + entity.getEntityName()); } } return rawId; diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 88e8d2fb..f481c08a 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -22,8 +22,8 @@ public JsonElement generateDataJson() { obj.addProperty(entry.getKey(), entry.getValue()); } return obj; - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java index 60386ba8..d772d280 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java @@ -11,26 +11,26 @@ public interface EntityTypeAccessor { @Accessor("NAME_CLASS_MAP") static Map> NAME_CLASS_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("CLASS_NAME_MAP") static Map, String> CLASS_NAME_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("ID_CLASS_MAP") static Map> ID_CLASS_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("CLASS_ID_MAP") static Map, Integer> CLASS_ID_MAP() { - throw new Error(); + throw new IllegalStateException(); } @Accessor("NAME_ID_MAP") static Map NAME_ID_MAP() { - throw new Error(); + throw new IllegalStateException(); } } diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index c1d96581..8e82cee6 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -10,6 +10,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start( diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 0dca8c4a..77173f56 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -13,13 +13,15 @@ public class BiomesDataGenerator implements IDataGenerator { private static String guessBiomeDimensionFromCategory(RegistryKey biome) { - var biomeRegistry = BuiltinRegistries.BIOME; - if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_NETHER)) { + var entry = BuiltinRegistries.BIOME.getEntry(biome).orElseThrow(); + if (entry.isIn(BiomeTags.IS_OVERWORLD)) { + return "overworld"; + } else if (entry.isIn(BiomeTags.IS_NETHER)) { return "nether"; - } else if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_END)) { + } else if (entry.isIn(BiomeTags.IS_END)) { return "end"; } else { - return "overworld"; + throw new IllegalStateException("Biome is not in any dimension: " + biome); } } diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 61e1b9e6..d6691e26 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,7 +12,10 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class BlockCollisionShapesDataGenerator implements IDataGenerator { diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index d1973e75..75eb3bd6 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -45,10 +45,10 @@ public static JsonObject generateEntity(Registry> entityRegistry, } private static String getCategoryFrom(EntityType entityType) { - if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities + if (entityType == EntityType.PLAYER) return "UNKNOWN"; // fail early for player entities Entity entity = entityType.create(DGU.getWorld()); if (entity == null) - throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; @@ -57,8 +57,8 @@ private static String getCategoryFrom(EntityType entityType) { case "net.minecraft.entity.projectile", "net.minecraft.entity.projectile.thrown" -> "Projectiles"; case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; - case "net.minecraft.entity" -> "UNKNOWN"; - default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + case "net.minecraft.entity.player", "net.minecraft.entity" -> "UNKNOWN"; + default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java index 7a3c6ced..4f5583c0 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -20,8 +20,8 @@ public JsonElement generateDataJson() { try { InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - } catch (Exception ignored) { + } catch (Exception e) { + throw new IllegalStateException("Failed to generate language file", e); } - throw new RuntimeException("Failed to generate language file"); } } diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index c904c153..078754ff 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -11,6 +11,11 @@ @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { + @Inject(method = "setupServer()Z", at = @At("HEAD")) + private void updatePort(CallbackInfoReturnable cir) { + ((MinecraftDedicatedServer) (Object) this).setServerPort(0); + } + @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { MinecraftDataGenerator.start(