Skip to content

Commit

Permalink
Fixup more code and remove hardcoding
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Jul 14, 2024
1 parent 71070c3 commit 9f2015e
Show file tree
Hide file tree
Showing 110 changed files with 392 additions and 1,275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Identifier, Biome> registry, Biome biome) {
JsonObject biomeDesc = new JsonObject();
Identifier registryKey = registry.getIdentifier(biome);
Expand All @@ -118,7 +32,7 @@ public static JsonObject generateBiomeInfo(SimpleRegistry<Identifier, Biome> 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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,31 +25,32 @@ public class EntitiesDataGenerator implements IDataGenerator {
public static JsonObject generateEntity(Class<? extends Entity> 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));

return entityDesc;
}

private static Entity makeEntity(Class<? extends Entity> 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) {
Expand All @@ -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);
};
}

Expand Down Expand Up @@ -105,7 +107,7 @@ private static String getEntityTypeForClass(Class<? extends Entity> 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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
public interface EntityTypeAccessor {
@Accessor("NAME_CLASS_MAP")
static Map<String, Class<? extends Entity>> NAME_CLASS_MAP() {
throw new Error();
throw new IllegalStateException();
}

@Accessor("CLASS_NAME_MAP")
static Map<Class<? extends Entity>, String> CLASS_NAME_MAP() {
throw new Error();
throw new IllegalStateException();
}

@Accessor("ID_CLASS_MAP")
static Map<Integer, Class<? extends Entity>> ID_CLASS_MAP() {
throw new Error();
throw new IllegalStateException();
}

@Accessor("CLASS_ID_MAP")
static Map<Class<? extends Entity>, Integer> CLASS_ID_MAP() {
throw new Error();
throw new IllegalStateException();
}

@Accessor("NAME_ID_MAP")
static Map<String, Integer> NAME_ID_MAP() {
throw new Error();
throw new IllegalStateException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

@Mixin(MinecraftDedicatedServer.class)
public class ReadyMixin {
@Inject(method = "setupServer()Z", at = @At("HEAD"))
private void updatePort(CallbackInfoReturnable<Boolean> cir) {
((MinecraftDedicatedServer) (Object) this).setServerPort(0);
}

@Inject(method = "setupServer()Z", at = @At("TAIL"))
private void init(CallbackInfoReturnable<Boolean> cir) {
MinecraftDataGenerator.start(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@ public class EntitiesDataGenerator implements IDataGenerator {
public static JsonObject generateEntity(Class<? extends Entity> 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));

Expand All @@ -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);
};
}

Expand Down Expand Up @@ -105,7 +103,7 @@ private static String getEntityTypeForClass(Class<? extends Entity> 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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

@Mixin(MinecraftDedicatedServer.class)
public class ReadyMixin {
@Inject(method = "setupServer()Z", at = @At("HEAD"))
private void updatePort(CallbackInfoReturnable<Boolean> cir) {
((MinecraftDedicatedServer) (Object) this).setServerPort(0);
}

@Inject(method = "setupServer()Z", at = @At("TAIL"))
private void init(CallbackInfoReturnable<Boolean> cir) {
MinecraftDataGenerator.start(
Expand Down
Loading

0 comments on commit 9f2015e

Please sign in to comment.