Import all versions (#8)
* Import all versions * Prepare first workflow * Cleanup build scripts * More cleanup * Cleanup more stuff and 1.7 on server * Run multiple tasks in parallel * Use version in job name * Error on missing files * Backport EULA mixin * Update upload artifact * Prevent build getting stuck * Cleanup code * More code cleanup * Update build.yml * Fix compilation --------- Co-authored-by: Romain Beaumont <romain.rom1@gmail.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
plugins {
|
||||
id 'fabric-loom'
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "u9g"
|
||||
url = "https://maven.u9g.dev"
|
||||
}
|
||||
}
|
||||
|
||||
loom {
|
||||
setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar');
|
||||
customMinecraftManifest.set("https://legacyfabric.u9g.dev/v2/manifest/${minecraft_version}")
|
||||
|
||||
// Required by 1.7.x
|
||||
runs {
|
||||
client {
|
||||
programArgs "--userProperties", "{}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
// Fabric API provides hooks for events, item registration, and more. As most mods will need this, it's included by default.
|
||||
// If you know for a fact you don't, it's not required and can be safely removed.
|
||||
// modImplementation ("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${fabric_version}") {
|
||||
// exclude module: "legacy-fabric-entity-events-v1"
|
||||
// }
|
||||
|
||||
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
|
||||
implementation 'org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209'
|
||||
implementation 'org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209'
|
||||
implementation 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
|
||||
}
|
||||
}
|
||||
|
||||
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
|
||||
configurations.configureEach {
|
||||
resolutionStrategy {
|
||||
dependencySubstitution {
|
||||
substitute module('org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209')
|
||||
substitute module('org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209')
|
||||
}
|
||||
force 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
filteringCharset "UTF-8"
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.version
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# Fabric Properties
|
||||
# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/
|
||||
minecraft_version=1.7
|
||||
yarn_mappings=1.7+build.202206071953
|
||||
loader_version=0.14.3
|
||||
# Dependencies
|
||||
# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
|
||||
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
|
||||
public class BiomeBlockColors {
|
||||
// generated manually from each Biome's Biome#getBlockColor
|
||||
public static int getBlockColor(Block block, Biome biome, int blockData) {
|
||||
if (block instanceof LilyPadBlock) {
|
||||
return 2129968;
|
||||
} else if (block instanceof AbstractFluidBlock && block.getMaterial() == Material.WATER) {
|
||||
int n = 0;
|
||||
int n2 = 0;
|
||||
int n3 = 0;
|
||||
for (int i = -1; i <= 1; ++i) {
|
||||
for (int j = -1; j <= 1; ++j) {
|
||||
int n4 = biome.waterColor;
|
||||
n += (n4 & 0xFF0000) >> 16;
|
||||
n2 += (n4 & 0xFF00) >> 8;
|
||||
n3 += n4 & 0xFF;
|
||||
}
|
||||
}
|
||||
return (n / 9 & 0xFF) << 16 | (n2 / 9 & 0xFF) << 8 | n3 / 9 & 0xFF;
|
||||
} else if (block instanceof AttachedStemBlock) {
|
||||
int n = blockData * 32;
|
||||
int n2 = 255 - blockData * 8;
|
||||
int n3 = blockData * 4;
|
||||
return n << 16 | n2 << 8 | n3;
|
||||
} else if (block instanceof RedstoneWireBlock) {
|
||||
return 0x800000;
|
||||
} else if (block instanceof DoublePlantBlock) {
|
||||
int n = ((DoublePlantBlock) block).method_6478(null, 0, 0, 0);
|
||||
if (n == 2 || n == 3) {
|
||||
return GrassColors.getGrassColor(biome);
|
||||
}
|
||||
} else if (block instanceof GrassBlock) {
|
||||
int n = 0;
|
||||
int n2 = 0;
|
||||
int n3 = 0;
|
||||
for (int i = -1; i <= 1; ++i) {
|
||||
for (int j = -1; j <= 1; ++j) {
|
||||
int n4 = GrassColors.getGrassColor(biome);
|
||||
n += (n4 & 0xFF0000) >> 16;
|
||||
n2 += (n4 & 0xFF00) >> 8;
|
||||
n3 += n4 & 0xFF;
|
||||
}
|
||||
}
|
||||
return (n / 9 & 0xFF) << 16 | (n2 / 9 & 0xFF) << 8 | n3 / 9 & 0xFF;
|
||||
} else if (block instanceof Leaves1Block) {
|
||||
if ((blockData & 3) == 1) {
|
||||
return FoliageColors.getSpruceColor();
|
||||
}
|
||||
if ((blockData & 3) == 2) {
|
||||
return FoliageColors.getBirchColor();
|
||||
}
|
||||
} else if (block instanceof LeavesBlock) {
|
||||
int n = 0;
|
||||
int n2 = 0;
|
||||
int n3 = 0;
|
||||
for (int i = -1; i <= 1; ++i) {
|
||||
for (int j = -1; j <= 1; ++j) {
|
||||
int n4 = FoliageColors.getColor(biome);
|
||||
n += (n4 & 0xFF0000) >> 16;
|
||||
n2 += (n4 & 0xFF00) >> 8;
|
||||
n3 += n4 & 0xFF;
|
||||
}
|
||||
}
|
||||
return (n / 9 & 0xFF) << 16 | (n2 / 9 & 0xFF) << 8 | n3 / 9 & 0xFF;
|
||||
} else if (block instanceof SugarCaneBlock) {
|
||||
return GrassColors.getGrassColor(biome);
|
||||
} else if (block instanceof TallPlantBlock & blockData != 0) {
|
||||
return GrassColors.getGrassColor(biome);
|
||||
} else if (block instanceof VineBlock) {
|
||||
return FoliageColors.getColor(biome);
|
||||
}
|
||||
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
|
||||
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class FoliageColors {
|
||||
private static int[] colorMap = new int[65536];
|
||||
|
||||
public static void setColorMap(int[] pixels) {
|
||||
colorMap = pixels;
|
||||
}
|
||||
|
||||
public static int getColor(double temperature, double humidity) {
|
||||
humidity *= temperature;
|
||||
int i = (int) ((1.0D - temperature) * 255.0D);
|
||||
int j = (int) ((1.0D - humidity) * 255.0D);
|
||||
return colorMap[j << 8 | i];
|
||||
}
|
||||
|
||||
public static int getSpruceColor() {
|
||||
return 6396257;
|
||||
}
|
||||
|
||||
public static int getBirchColor() {
|
||||
return 8431445;
|
||||
}
|
||||
|
||||
public static int getDefaultColor() {
|
||||
return 4764952;
|
||||
}
|
||||
|
||||
public static int getColor(Biome biome) {
|
||||
double d = MathHelper.clamp(biome.temperature, 0.0f, 1.0f);
|
||||
double e = MathHelper.clamp(biome.downfall, 0.0f, 1.0f);
|
||||
return FoliageColors.getColor(d, e);
|
||||
}
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
|
||||
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class GrassColors {
|
||||
private static int[] colorMap = new int[65536];
|
||||
|
||||
public static void setColorMap(int[] map) {
|
||||
colorMap = map;
|
||||
}
|
||||
|
||||
public static int getColor(double temperature, double humidity) {
|
||||
int n = (int) ((1.0 - temperature) * 255.0);
|
||||
int n2 = (int) ((1.0 - (humidity *= temperature)) * 255.0);
|
||||
return colorMap[n2 << 8 | n];
|
||||
}
|
||||
|
||||
public static int getGrassColor(Biome biome) {
|
||||
double d = MathHelper.clamp(biome.temperature, 0.0f, 1.0f);
|
||||
double e = MathHelper.clamp(biome.downfall, 0.0f, 1.0f);
|
||||
return GrassColors.getColor(d, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
|
||||
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public class ServerSideRedstoneWireBlock {
|
||||
public static int getWireColor(int powerLevel) {
|
||||
float f = (float) powerLevel / 15.0F;
|
||||
float g = f * 0.6F + 0.4F;
|
||||
if (powerLevel == 0) {
|
||||
g = 0.3F;
|
||||
}
|
||||
|
||||
float h = f * f * 0.7F - 0.5F;
|
||||
float j = f * f * 0.6F - 0.7F;
|
||||
if (h < 0.0F) {
|
||||
h = 0.0F;
|
||||
}
|
||||
|
||||
if (j < 0.0F) {
|
||||
j = 0.0F;
|
||||
}
|
||||
|
||||
int k = MathHelper.clamp((int) (g * 255.0F), 0, 255);
|
||||
int l = MathHelper.clamp((int) (h * 255.0F), 0, 255);
|
||||
int m = MathHelper.clamp((int) (j * 255.0F), 0, 255);
|
||||
return -16777216 | k << 16 | l << 8 | m;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.u9g.minecraftdatagenerator;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Main implements ModInitializer {
|
||||
public static final Logger LOGGER = Logger.getLogger("mc-data-gen-serv");
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.mixin.accessor.LanguageAccessor;
|
||||
import net.minecraft.util.Language;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AttributesDataGenerator implements IDataGenerator {
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "attributes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement generateDataJson() {
|
||||
Language lang = new Language();
|
||||
Map<String, String> translations = ((LanguageAccessor) lang).translations();
|
||||
JsonArray arr = new JsonArray();
|
||||
for (Map.Entry<String, String> translation : translations.entrySet()) {
|
||||
String key = translation.getKey();
|
||||
if (!key.startsWith("attribute.name.")) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
key = key.replace("attribute.name.", "");
|
||||
obj.addProperty("name", key.split("\\.")[1]);
|
||||
obj.addProperty("resource", key);
|
||||
arr.add(obj);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
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 {
|
||||
|
||||
private static String guessBiomeDimensionFromCategory(Biome biome) {
|
||||
if (biome instanceof NetherBiome) {
|
||||
return "nether";
|
||||
} else if (biome instanceof EndBiome) {
|
||||
return "end";
|
||||
}
|
||||
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("name", String.join("_", ((BiomeAccessor) biome).name().toLowerCase(Locale.ENGLISH).split(" ")));
|
||||
biomeDesc.addProperty("category", category(biome));
|
||||
biomeDesc.addProperty("temperature", biome.temperature);
|
||||
biomeDesc.addProperty("precipitation", precipitation(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("rainfall", biome.downfall);
|
||||
|
||||
return biomeDesc;
|
||||
}
|
||||
|
||||
private static String category(Biome biome) {
|
||||
if (biome instanceof ForestBiome) {
|
||||
return "forest";
|
||||
} else if (biome instanceof OceanBiome) {
|
||||
return "ocean";
|
||||
} else if (biome instanceof PlainsBiome) {
|
||||
return "plains";
|
||||
} else if (biome instanceof DesertBiome) {
|
||||
return "desert";
|
||||
} else if (biome instanceof ExtremeHillsBiome) {
|
||||
return "extreme_hills";
|
||||
} else if (biome instanceof TaigaBiome) {
|
||||
return "taiga";
|
||||
} else if (biome instanceof SwampBiome) {
|
||||
return "swamp";
|
||||
} else if (biome instanceof RiverBiome) {
|
||||
return "river";
|
||||
} else if (biome instanceof NetherBiome) {
|
||||
return "nether";
|
||||
} else if (biome instanceof EndBiome) {
|
||||
return "the_end";
|
||||
} else if (biome instanceof IceBiome) {
|
||||
return "icy";
|
||||
} else if (biome instanceof MushroomBiome) {
|
||||
return "mushroom";
|
||||
} else if (biome instanceof BeachBiome) {
|
||||
return "beach";
|
||||
} else if (biome instanceof JungleBiome) {
|
||||
return "jungle";
|
||||
} else if (biome instanceof SavannaBiome) {
|
||||
return "savanna";
|
||||
} else if (biome instanceof MesaBiome) {
|
||||
return "mesa";
|
||||
} 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());
|
||||
}
|
||||
|
||||
private static String precipitation(Biome biome) {
|
||||
float rainfall = biome.downfall;
|
||||
float temperature = biome.temperature;
|
||||
if (rainfall == 0) {
|
||||
return "none";
|
||||
} else if (temperature < 0.2f) {
|
||||
return "snow";
|
||||
}
|
||||
return "rain";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "biomes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArray generateDataJson() {
|
||||
SortedMap<Integer, JsonObject> biomes = new TreeMap<>();
|
||||
for (Biome biome : Registries.BIOMES) {
|
||||
biomes.put(biome.id, generateBiomeInfo(biome));
|
||||
}
|
||||
JsonArray biomesArray = new JsonArray();
|
||||
biomes.values().forEach(biomesArray::add);
|
||||
return biomesArray;
|
||||
}
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import dev.u9g.minecraftdatagenerator.util.Registries;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Texture;
|
||||
import net.minecraft.util.math.Box;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BlockCollisionShapesDataGenerator implements IDataGenerator {
|
||||
private static final Box ENTITY_BOX = Box.of(0.0D, 0.0D, 0.0D, 1.0D, 2.0D, 1.0D);
|
||||
|
||||
private static String nameOf(Block block) {
|
||||
return Objects.requireNonNull(Registries.BLOCKS.getId(block));
|
||||
}
|
||||
|
||||
private static JsonArray jsonOf(Box box) {
|
||||
JsonArray arr = new JsonArray();
|
||||
if (box == null) return arr;
|
||||
arr.add(new JsonPrimitive(box.minX));
|
||||
arr.add(new JsonPrimitive(box.minY));
|
||||
arr.add(new JsonPrimitive(box.minZ));
|
||||
arr.add(new JsonPrimitive(box.maxX));
|
||||
arr.add(new JsonPrimitive(box.maxY));
|
||||
arr.add(new JsonPrimitive(box.maxZ));
|
||||
return arr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "blockCollisionShapes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject generateDataJson() {
|
||||
ShapeCache shapeCache = new ShapeCache();
|
||||
JsonObject blocksObject = new JsonObject();
|
||||
|
||||
for (Block block : Registries.BLOCKS) {
|
||||
Object val = shapeCache.addShapesFrom(block);
|
||||
if (val instanceof JsonArray) {
|
||||
blocksObject.add(nameOf(block), (JsonElement) val);
|
||||
} else {
|
||||
blocksObject.addProperty(nameOf(block), (Integer) val);
|
||||
}
|
||||
}
|
||||
JsonObject resultObject = new JsonObject();
|
||||
resultObject.add("blocks", blocksObject);
|
||||
resultObject.add("shapes", shapeCache.toJSON());
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
public static class ShapeCache {
|
||||
private final ArrayList<Shapes> shapesCache = new ArrayList<>();
|
||||
|
||||
public Object addShapesFrom(Block block) {
|
||||
List<Integer> indexesOfBoxesInTheShapesCache = new ArrayList<>();
|
||||
for (Field field : block.getClass().getDeclaredFields()) {
|
||||
if (!field.getType().getName().equals("[Lnet.minecraft.client.ItemIcon;")) { // ItemIcon[]
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
Texture[] icons = (Texture[]) field.get(block);
|
||||
return icons.length;
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
}
|
||||
// old way
|
||||
// new Throwable("find block damages based on ItemIcon[]").printStackTrace();
|
||||
// for (BlockState state : block.getStateManager().getBlockStates().reverse()) {
|
||||
// List<Box> boxes = new ArrayList<>();
|
||||
// try {
|
||||
// block.appendCollisionBoxes(DGU.getWorld(), BlockPos.ORIGIN, state, ENTITY_BOX, boxes, null);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// Shapes thisBlockStateShapes = new Shapes(boxes);
|
||||
// int indexOfThisBlockStatesShapes = shapesCache.indexOf(thisBlockStateShapes);
|
||||
// if (indexOfThisBlockStatesShapes != -1) {
|
||||
// indexesOfBoxesInTheShapesCache.add(indexOfThisBlockStatesShapes);
|
||||
// } else {
|
||||
// shapesCache.add(thisBlockStateShapes);
|
||||
// indexesOfBoxesInTheShapesCache.add(shapesCache.size() - 1);
|
||||
// }
|
||||
// }
|
||||
// if (indexesOfBoxesInTheShapesCache.stream().distinct().count() < 2) {
|
||||
// return indexesOfBoxesInTheShapesCache.get(0);
|
||||
// } else {
|
||||
// JsonArray shapeIndexes = new JsonArray();
|
||||
// indexesOfBoxesInTheShapesCache.forEach(shapeIndex -> shapeIndexes.add(new JsonPrimitive(shapeIndex)));
|
||||
// return shapeIndexes;
|
||||
// }
|
||||
return 1;
|
||||
}
|
||||
|
||||
public JsonObject toJSON() {
|
||||
JsonObject shapes = new JsonObject();
|
||||
int i = 0;
|
||||
for (Shapes s : shapesCache) {
|
||||
shapes.add(String.valueOf(i++), s.toJSON());
|
||||
}
|
||||
return shapes;
|
||||
}
|
||||
|
||||
private static class Shapes {
|
||||
final List<Box> boxes;
|
||||
|
||||
public Shapes(List<Box> boxes) {
|
||||
this.boxes = boxes;
|
||||
}
|
||||
|
||||
public JsonArray toJSON() {
|
||||
JsonArray arr = new JsonArray();
|
||||
boxes.forEach(box -> arr.add(jsonOf(box)));
|
||||
return arr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Shapes shapes = (Shapes) o;
|
||||
return Objects.equals(boxes, shapes.boxes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return boxes != null ? boxes.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.Main;
|
||||
import dev.u9g.minecraftdatagenerator.mixin.accessor.BlockAccessor;
|
||||
import dev.u9g.minecraftdatagenerator.mixin.accessor.MiningToolItemAccessor;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import dev.u9g.minecraftdatagenerator.util.Registries;
|
||||
import net.minecraft.block.AirBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.TransparentBlock;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ToolItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class BlocksDataGenerator implements IDataGenerator {
|
||||
|
||||
private static final Logger logger = Main.LOGGER;
|
||||
|
||||
private static List<Item> getItemsEffectiveForBlock(Block block) {
|
||||
List<Item> items = new ArrayList<>();
|
||||
for (Item item : Registries.ITEMS) {
|
||||
if (item instanceof ToolItem && ((MiningToolItemAccessor) item).getEffectiveBlocks().contains(block)) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private static List<ItemStack> populateDropsIfPossible(Item firstToolItem) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public static JsonObject generateBlock(Block block) {
|
||||
JsonObject blockDesc = new JsonObject();
|
||||
|
||||
String registryKey = Registries.BLOCKS.getId(block);
|
||||
List<Item> effectiveTools = getItemsEffectiveForBlock(block);
|
||||
|
||||
blockDesc.addProperty("id", Registries.BLOCKS.getRawId(block));
|
||||
blockDesc.addProperty("name", Objects.requireNonNull(registryKey));
|
||||
if (!block.getTranslatedName().startsWith("tile.")) {
|
||||
blockDesc.addProperty("displayName", block.getTranslatedName());
|
||||
}
|
||||
|
||||
float hardness = block.getHardness(null, 0, 0, 0);
|
||||
|
||||
blockDesc.addProperty("hardness", hardness);
|
||||
blockDesc.addProperty("resistance", ((BlockAccessor) block).getBlastResistance());
|
||||
blockDesc.addProperty("diggable", hardness != -1.0f && !(block instanceof AirBlock));
|
||||
JsonObject effTools = new JsonObject();
|
||||
effectiveTools.forEach(item -> effTools.addProperty(
|
||||
String.valueOf(Registries.ITEMS.getRawId(item)), // key
|
||||
item.getMiningSpeedMultiplier(DGU.stackFor(item), block) // value
|
||||
));
|
||||
blockDesc.add("effectiveTools", effTools);
|
||||
blockDesc.addProperty("transparent", block instanceof TransparentBlock);
|
||||
blockDesc.addProperty("emitLight", block.getLightLevel());
|
||||
blockDesc.addProperty("filterLight", block.getOpacity());
|
||||
|
||||
blockDesc.addProperty("boundingBox", boundingBox(block));
|
||||
|
||||
return blockDesc;
|
||||
}
|
||||
|
||||
private static String boundingBox(Block block) {
|
||||
if (block.getCollisionBox(DGU.getWorld(), 0, 0, 0) == null) {
|
||||
return "empty";
|
||||
}
|
||||
return "block";
|
||||
}
|
||||
|
||||
private static Item getItemFromBlock(Block block) {
|
||||
return Registries.ITEMS.get(Registries.BLOCKS.getId(block));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "blocks";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArray generateDataJson() {
|
||||
JsonArray resultBlocksArray = new JsonArray();
|
||||
for (Block block : Registries.BLOCKS) {
|
||||
resultBlocksArray.add(generateBlock(block));
|
||||
}
|
||||
return resultBlocksArray;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import dev.u9g.minecraftdatagenerator.Main;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class DataGenerators {
|
||||
|
||||
private static final List<IDataGenerator> GENERATORS = new ArrayList<>();
|
||||
private static final Logger logger = Main.LOGGER;
|
||||
|
||||
static {
|
||||
register(new BiomesDataGenerator());
|
||||
// register(new BlockCollisionShapesDataGenerator()); - Needs to be finished
|
||||
register(new BlocksDataGenerator());
|
||||
register(new EffectsDataGenerator());
|
||||
register(new EnchantmentsDataGenerator());
|
||||
register(new EntitiesDataGenerator());
|
||||
register(new FoodsDataGenerator());
|
||||
register(new ItemsDataGenerator());
|
||||
// register(new ParticlesDataGenerator()); - See WorldRenderer#spawnParticle
|
||||
register(new TintsDataGenerator());
|
||||
register(new LanguageDataGenerator());
|
||||
register(new InstrumentsDataGenerator());
|
||||
register(new AttributesDataGenerator());
|
||||
}
|
||||
|
||||
public static void register(IDataGenerator generator) {
|
||||
GENERATORS.add(generator);
|
||||
}
|
||||
|
||||
public static boolean runDataGenerators(Path outputDirectory) {
|
||||
try {
|
||||
Files.createDirectories(outputDirectory);
|
||||
} catch (IOException exception) {
|
||||
logger.log(Level.INFO, "Failed to create data generator output directory at " + outputDirectory);
|
||||
exception.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
int generatorsFailed = 0;
|
||||
logger.log(Level.INFO, MessageFormat.format("Running minecraft data generators, output at {0}", outputDirectory));
|
||||
|
||||
for (IDataGenerator dataGenerator : GENERATORS) {
|
||||
logger.log(Level.INFO, MessageFormat.format("Running generator {0}", dataGenerator.getDataName()));
|
||||
try {
|
||||
String outputFileName = String.format("%s.json", dataGenerator.getDataName());
|
||||
JsonElement outputElement = dataGenerator.generateDataJson();
|
||||
Path outputFilePath = outputDirectory.resolve(outputFileName);
|
||||
|
||||
try (Writer writer = Files.newBufferedWriter(outputFilePath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
|
||||
JsonWriter jsonWriter = new JsonWriter(writer);
|
||||
jsonWriter.setIndent(" ");
|
||||
Streams.write(outputElement, jsonWriter);
|
||||
}
|
||||
logger.log(Level.INFO, MessageFormat.format("Generator: {0} -> {1}", dataGenerator.getDataName(), outputFileName));
|
||||
|
||||
} catch (Throwable exception) {
|
||||
logger.log(Level.INFO, MessageFormat.format("Failed to run data generator {0}", dataGenerator.getDataName()));
|
||||
exception.printStackTrace();
|
||||
generatorsFailed++;
|
||||
}
|
||||
}
|
||||
|
||||
logger.log(Level.INFO, "Finishing running data generators");
|
||||
return generatorsFailed == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.mixin.accessor.StatusEffectAccessor;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import dev.u9g.minecraftdatagenerator.util.Registries;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class EffectsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateEffect(StatusEffect statusEffect) {
|
||||
JsonObject effectDesc = new JsonObject();
|
||||
@NotNull String name = Objects.requireNonNull(Registries.STATUS_EFFECTS.getId(statusEffect));
|
||||
|
||||
effectDesc.addProperty("id", Registries.STATUS_EFFECTS.getRawId(statusEffect));
|
||||
effectDesc.addProperty("name", name);
|
||||
effectDesc.addProperty("displayName", DGU.translateText(statusEffect.getTranslationKey()));
|
||||
|
||||
effectDesc.addProperty("type", !((StatusEffectAccessor) statusEffect).negative() ? "good" : "bad");
|
||||
return effectDesc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "effects";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArray generateDataJson() {
|
||||
JsonArray resultsArray = new JsonArray();
|
||||
for (StatusEffect effect : Registries.STATUS_EFFECTS) {
|
||||
resultsArray.add(generateEffect(effect));
|
||||
}
|
||||
return resultsArray;
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonArray;
|
||||
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.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentTarget;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EnchantmentsDataGenerator implements IDataGenerator {
|
||||
|
||||
private static final ImmutableMap<EnchantmentTarget, String> ENCHANTMENT_TARGET_NAMES = ImmutableMap.<EnchantmentTarget, String>builder()
|
||||
.put(EnchantmentTarget.ARMOR, "armor")
|
||||
.put(EnchantmentTarget.ARMOR_FEET, "armor_feet")
|
||||
.put(EnchantmentTarget.ARMOR_LEGS, "armor_legs")
|
||||
.put(EnchantmentTarget.ARMOR_TORSO, "armor_chest")
|
||||
.put(EnchantmentTarget.ARMOR_HEAD, "armor_head")
|
||||
.put(EnchantmentTarget.WEAPON, "weapon")
|
||||
.put(EnchantmentTarget.DIGGER, "digger")
|
||||
.put(EnchantmentTarget.FISHING_ROD, "fishing_rod")
|
||||
.put(EnchantmentTarget.BREAKABLE, "breakable")
|
||||
.put(EnchantmentTarget.BOW, "bow")
|
||||
.build();
|
||||
|
||||
public static String getEnchantmentTargetName(EnchantmentTarget target) {
|
||||
return ENCHANTMENT_TARGET_NAMES.getOrDefault(target, target.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
// Equation enchantment costs follow is a * level + b, so we can easily retrieve a and b by passing zero level
|
||||
private static JsonObject generateEnchantmentMinPowerCoefficients(Enchantment enchantment) {
|
||||
int b = enchantment.getMinimumPower(0);
|
||||
int a = enchantment.getMinimumPower(1) - b;
|
||||
|
||||
JsonObject resultObject = new JsonObject();
|
||||
resultObject.addProperty("a", a);
|
||||
resultObject.addProperty("b", b);
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
private static JsonObject generateEnchantmentMaxPowerCoefficients(Enchantment enchantment) {
|
||||
int b = enchantment.getMaximumPower(0);
|
||||
int a = enchantment.getMaximumPower(1) - b;
|
||||
|
||||
JsonObject resultObject = new JsonObject();
|
||||
resultObject.addProperty("a", a);
|
||||
resultObject.addProperty("b", b);
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
public static JsonObject generateEnchantment(Enchantment enchantment) {
|
||||
JsonObject enchantmentDesc = new JsonObject();
|
||||
String registryKey = Registries.ENCHANTMENTS.getId(enchantment);
|
||||
|
||||
enchantmentDesc.addProperty("id", Registries.ENCHANTMENTS.getRawId(enchantment));
|
||||
enchantmentDesc.addProperty("name", Objects.requireNonNull(registryKey));
|
||||
enchantmentDesc.addProperty("displayName", DGU.translateText(enchantment.getTranslationKey()));
|
||||
|
||||
enchantmentDesc.addProperty("maxLevel", enchantment.getMaximumLevel());
|
||||
enchantmentDesc.add("minCost", generateEnchantmentMinPowerCoefficients(enchantment));
|
||||
enchantmentDesc.add("maxCost", generateEnchantmentMaxPowerCoefficients(enchantment));
|
||||
|
||||
enchantmentDesc.addProperty("treasureOnly", false); // 1.9 added treasure enchants
|
||||
enchantmentDesc.addProperty("curse", false); // 1.10 added curse enchants
|
||||
|
||||
List<Enchantment> incompatibleEnchantments = new ArrayList<>();
|
||||
for (Enchantment other : Registries.ENCHANTMENTS) {
|
||||
if (!enchantment.differs(other) && !other.differs(enchantment) && other != enchantment) {
|
||||
incompatibleEnchantments.add(other);
|
||||
}
|
||||
}
|
||||
|
||||
JsonArray excludes = new JsonArray();
|
||||
for (Enchantment excludedEnchantment : incompatibleEnchantments) {
|
||||
String otherKey = Registries.ENCHANTMENTS.getId(excludedEnchantment);
|
||||
excludes.add(new JsonPrimitive(Objects.requireNonNull(otherKey)));
|
||||
}
|
||||
enchantmentDesc.add("exclude", excludes);
|
||||
|
||||
enchantmentDesc.addProperty("category", getEnchantmentTargetName(enchantment.target));
|
||||
enchantmentDesc.addProperty("weight", enchantment.getEnchantmentType()); // see AnvilScreenhandler L209
|
||||
enchantmentDesc.addProperty("tradeable", true); // the first non-tradeable enchant came in 1.16, soul speed
|
||||
enchantmentDesc.addProperty("discoverable", true); // the first non-enchantable enchant came in 1.16, soul speed
|
||||
|
||||
return enchantmentDesc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "enchantments";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArray generateDataJson() {
|
||||
JsonArray resultsArray = new JsonArray();
|
||||
for (Enchantment enchantment : Registries.ENCHANTMENTS) {
|
||||
resultsArray.add(generateEnchantment(enchantment));
|
||||
}
|
||||
return resultsArray;
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.mixin.accessor.EntityTypeAccessor;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import dev.u9g.minecraftdatagenerator.util.Registries;
|
||||
import net.minecraft.entity.*;
|
||||
import net.minecraft.entity.mob.AmbientEntity;
|
||||
import net.minecraft.entity.mob.HostileEntity;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class EntitiesDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateEntity(Class<? extends Entity> entityClass) {
|
||||
JsonObject entityDesc = new JsonObject();
|
||||
String registryKey = Registries.ENTITY_TYPES.getId(entityClass);
|
||||
int entityRawId = Registries.ENTITY_TYPES.getRawId(entityClass);
|
||||
@Nullable 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.getTranslatedName() : null;
|
||||
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);
|
||||
|
||||
String entityTypeString = "UNKNOWN";
|
||||
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());
|
||||
}
|
||||
|
||||
private static String getCategoryFrom(@NotNull Class<?> entityClass) {
|
||||
if (entityClass == PlayerEntity.class) return "other"; // fail early for player entities
|
||||
String packageName = entityClass.getPackage().getName();
|
||||
String category = switch (packageName) {
|
||||
case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile";
|
||||
case "net.minecraft.entity.boss", "net.minecraft.entity.mob", "net.minecraft.entity.boss.dragon" ->
|
||||
"Hostile mobs";
|
||||
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);
|
||||
};
|
||||
return category;
|
||||
}
|
||||
|
||||
//Honestly, both "type" and "category" fields in the schema and examples do not contain any useful information
|
||||
//Since category is optional, I will just leave it out, and for type I will assume general entity classification
|
||||
//by the Entity class hierarchy (which has some weirdness too by the way)
|
||||
private static String getEntityTypeForClass(Class<? extends Entity> entityClass) {
|
||||
//Top-level classifications
|
||||
if (WaterCreatureEntity.class.isAssignableFrom(entityClass)) {
|
||||
return "water_creature";
|
||||
}
|
||||
if (AnimalEntity.class.isAssignableFrom(entityClass)) {
|
||||
return "animal";
|
||||
}
|
||||
if (HostileEntity.class.isAssignableFrom(entityClass)) {
|
||||
return "hostile";
|
||||
}
|
||||
if (AmbientEntity.class.isAssignableFrom(entityClass)) {
|
||||
return "ambient";
|
||||
}
|
||||
|
||||
//Second level classifications. PathAwareEntity is not included because it
|
||||
//doesn't really make much sense to categorize by it
|
||||
if (PathAwareEntity.class.isAssignableFrom(entityClass)) {
|
||||
return "passive";
|
||||
}
|
||||
if (MobEntity.class.isAssignableFrom(entityClass)) {
|
||||
return "mob";
|
||||
}
|
||||
|
||||
//Other classifications only include living entities and projectiles. everything else is categorized as other
|
||||
if (LivingEntity.class.isAssignableFrom(entityClass)) {
|
||||
return "living";
|
||||
}
|
||||
if (Projectile.class.isAssignableFrom(entityClass)) {
|
||||
return "projectile";
|
||||
}
|
||||
return "other";
|
||||
}
|
||||
|
||||
private static int entityId(Entity entity) {
|
||||
if (!DGU.getCurrentlyRunningServer().getVersion().equals("1.7")) {
|
||||
throw new Error("These ids were gotten manually for 1.7, remake for " + DGU.getCurrentlyRunningServer().getVersion());
|
||||
}
|
||||
int rawId = Registries.ENTITY_TYPES.getRawId(entity.getClass());
|
||||
if (rawId == -1) { // see TrackedEntityInstance
|
||||
if (entity instanceof ItemEntity) {
|
||||
return 2;
|
||||
} else if (entity instanceof FishingBobberEntity) {
|
||||
return 90;
|
||||
} else {
|
||||
throw new Error("unable to find rawId for entity: " + entity.getClass().getName());
|
||||
}
|
||||
}
|
||||
return rawId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "entities";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArray generateDataJson() {
|
||||
JsonArray resultArray = new JsonArray();
|
||||
for (Class<? extends Entity> entityType : Registries.ENTITY_TYPES) {
|
||||
resultArray.add(generateEntity(entityType));
|
||||
}
|
||||
return resultArray;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import dev.u9g.minecraftdatagenerator.util.Registries;
|
||||
import net.minecraft.item.FoodItem;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class FoodsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateFoodDescriptor(FoodItem foodItem) {
|
||||
JsonObject foodDesc = new JsonObject();
|
||||
String registryKey = Registries.ITEMS.getId(foodItem);
|
||||
|
||||
foodDesc.addProperty("id", Registries.ITEMS.getRawId(foodItem));
|
||||
foodDesc.addProperty("name", Objects.requireNonNull(registryKey).replace("minecraft:", ""));
|
||||
|
||||
foodDesc.addProperty("stackSize", foodItem.getMaxCount());
|
||||
foodDesc.addProperty("displayName", foodItem.getDisplayName(DGU.stackFor(foodItem)));
|
||||
float foodPoints = foodItem.getHungerPoints(DGU.stackFor(foodItem));
|
||||
float saturationRatio = foodItem.getSaturation(DGU.stackFor(foodItem)) * 2.0F;
|
||||
float saturation = foodPoints * saturationRatio;
|
||||
|
||||
foodDesc.addProperty("foodPoints", foodPoints);
|
||||
foodDesc.addProperty("saturation", saturation);
|
||||
|
||||
foodDesc.addProperty("effectiveQuality", foodPoints + saturation);
|
||||
foodDesc.addProperty("saturationRatio", saturationRatio);
|
||||
return foodDesc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "foods";
|
||||
}
|
||||
|
||||
public JsonArray generateDataJson() {
|
||||
JsonArray resultsArray = new JsonArray();
|
||||
for (Item item : Registries.ITEMS) {
|
||||
if (item instanceof FoodItem) {
|
||||
resultsArray.add(generateFoodDescriptor((FoodItem) item));
|
||||
}
|
||||
}
|
||||
return resultsArray;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
public interface IDataGenerator {
|
||||
|
||||
String getDataName();
|
||||
|
||||
JsonElement generateDataJson();
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.block.Material;
|
||||
|
||||
public class InstrumentsDataGenerator implements IDataGenerator {
|
||||
public static Material currentMaterial = null;
|
||||
public static int LAST_WORLD_BLOCKDATA = -1;
|
||||
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "instruments";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement generateDataJson() {
|
||||
JsonArray array = new JsonArray();
|
||||
// copied from NoteBlock#syncedBlockAction
|
||||
array.add(makeInstrumentObj(0, "harp"));
|
||||
array.add(makeInstrumentObj(1, "bd"));
|
||||
array.add(makeInstrumentObj(2, "snare"));
|
||||
array.add(makeInstrumentObj(3, "hat"));
|
||||
array.add(makeInstrumentObj(4, "bassattack"));
|
||||
return array;
|
||||
}
|
||||
|
||||
private JsonObject makeInstrumentObj(int i, String s) {
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.add("id", new JsonPrimitive(i));
|
||||
obj.add("name", new JsonPrimitive(s));
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import dev.u9g.minecraftdatagenerator.mixin.VariantBlockItemAccessor;
|
||||
import dev.u9g.minecraftdatagenerator.mixin.accessor.ItemAccessor;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import dev.u9g.minecraftdatagenerator.util.Registries;
|
||||
import net.minecraft.enchantment.EnchantmentTarget;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.VariantBlockItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemsDataGenerator implements IDataGenerator {
|
||||
|
||||
private static List<Item> calculateItemsToRepairWith(Item sourceItem) {
|
||||
List<Item> items = new ArrayList<>();
|
||||
for (Item otherItem : Registries.ITEMS) {
|
||||
if (sourceItem.canRepair(DGU.stackFor(sourceItem), DGU.stackFor(otherItem))) {
|
||||
items.add(otherItem);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private static List<EnchantmentTarget> getApplicableEnchantmentTargets(Item sourceItem) {
|
||||
List<EnchantmentTarget> targets = new ArrayList<>();
|
||||
for (EnchantmentTarget target : EnchantmentTarget.values()) {
|
||||
if (!target.isCompatible(sourceItem)) continue;
|
||||
targets.add(target);
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
public static JsonObject generateItem(Item item) {
|
||||
JsonObject itemDesc = new JsonObject();
|
||||
|
||||
itemDesc.addProperty("id", Registries.ITEMS.getRawId(item));
|
||||
|
||||
String name = Registries.ITEMS.getId(item);
|
||||
itemDesc.addProperty("name", name == null ? ((ItemAccessor) item).translationKey() : name.replace("minecraft:", ""));
|
||||
|
||||
itemDesc.addProperty("displayName", item.getDisplayName(DGU.stackFor(item)));
|
||||
itemDesc.addProperty("stackSize", item.getMaxCount());
|
||||
|
||||
List<EnchantmentTarget> enchantmentTargets = getApplicableEnchantmentTargets(item);
|
||||
|
||||
if (item.isDamageable()) {
|
||||
JsonArray enchantCategoriesArray = new JsonArray();
|
||||
for (EnchantmentTarget target : enchantmentTargets) {
|
||||
enchantCategoriesArray.add(new JsonPrimitive(EnchantmentsDataGenerator.getEnchantmentTargetName(target)));
|
||||
}
|
||||
if (enchantCategoriesArray.size() > 0) {
|
||||
itemDesc.add("enchantCategories", enchantCategoriesArray);
|
||||
}
|
||||
}
|
||||
|
||||
if (item.isDamageable()) {
|
||||
List<Item> repairWithItems = calculateItemsToRepairWith(item);
|
||||
|
||||
JsonArray fixedWithArray = new JsonArray();
|
||||
for (Item repairWithItem : repairWithItems) {
|
||||
String repairWithName = Registries.ITEMS.getId(repairWithItem);
|
||||
fixedWithArray.add(new JsonPrimitive(Objects.requireNonNull(repairWithName)));
|
||||
}
|
||||
if (fixedWithArray.size() > 0) {
|
||||
itemDesc.add("repairWith", fixedWithArray);
|
||||
}
|
||||
|
||||
int maxDurability = item.getMaxDamage();
|
||||
itemDesc.addProperty("maxDurability", maxDurability);
|
||||
}
|
||||
|
||||
if (item instanceof VariantBlockItem it) {
|
||||
JsonArray variations = new JsonArray();
|
||||
int i = 0;
|
||||
JsonObject obj = new JsonObject();
|
||||
for (String variant : ((VariantBlockItemAccessor) it).variants()) {
|
||||
ItemStack stack = new ItemStack(item, 1, i);
|
||||
obj.add("id", new JsonPrimitive(i));
|
||||
obj.add("name", new JsonPrimitive(variant));
|
||||
obj.add("displayName", new JsonPrimitive(DGU.translateText(it.getTranslationKey(stack) + ".name")));
|
||||
variations.add(obj);
|
||||
i++;
|
||||
}
|
||||
itemDesc.add("variations", variations);
|
||||
}
|
||||
|
||||
return itemDesc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "items";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonArray generateDataJson() {
|
||||
JsonArray resultArray = new JsonArray();
|
||||
for (Item item : Registries.ITEMS) {
|
||||
resultArray.add(generateItem(item));
|
||||
}
|
||||
return resultArray;
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.mixin.accessor.LanguageAccessor;
|
||||
import dev.u9g.minecraftdatagenerator.util.Registries;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class LanguageDataGenerator implements IDataGenerator {
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "language";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement generateDataJson() {
|
||||
try {
|
||||
JsonObject obj = new JsonObject();
|
||||
Map<String, String> translations = ((LanguageAccessor) Registries.LANGUAGE).translations();
|
||||
for (Map.Entry<String, String> entry : translations.entrySet()) {
|
||||
obj.addProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return obj;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
throw new RuntimeException("Failed to generate language file");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
|
||||
public class RecipeDataGenerator implements IDataGenerator {
|
||||
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "recipes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement generateDataJson() {
|
||||
// JsonObject finalObj = new JsonObject();
|
||||
// Multimap<Integer, JsonObject> recipes = ArrayListMultimap.create();
|
||||
// for (Recipe<?> recipe : Objects.requireNonNull(DGU.getWorld()).getRecipeManager().values()) {
|
||||
// if (recipe instanceof ShapedRecipe sr) {
|
||||
// var ingredients = sr.getIngredients();
|
||||
// List<Integer> ingr = new ArrayList<>();
|
||||
// for (int i = 0; i < 9; i++) {
|
||||
// if (i >= ingredients.size()) {
|
||||
// ingr.add(-1);
|
||||
// continue;
|
||||
// }
|
||||
// var stacks = ingredients.get(i);
|
||||
//// var matching = stacks.getMatchingStacks();
|
||||
//// if (matching.length == 0) {
|
||||
//// ingr.add(-1);
|
||||
//// } else {
|
||||
//// ingr.add(getRawIdFor(matching[0].getItem()));
|
||||
//// }
|
||||
// }
|
||||
// Lists.reverse(ingr);
|
||||
//
|
||||
// JsonArray inShape = new JsonArray();
|
||||
//
|
||||
// var iter = ingr.iterator();
|
||||
// for (int y = 0; y < 3; y++) {
|
||||
// var jsonRow = new JsonArray();
|
||||
// int one = iter.next();
|
||||
// int two = iter.next();
|
||||
// int three = iter.next();
|
||||
// if (y > 0 && one == -1 && two == -1 && three == -1) continue;
|
||||
// jsonRow.add(one);
|
||||
// jsonRow.add(two);
|
||||
// jsonRow.add(three);
|
||||
// inShape.add(jsonRow);
|
||||
// }
|
||||
//
|
||||
// JsonObject finalRecipe = new JsonObject();
|
||||
// finalRecipe.add("inShape", inShape);
|
||||
//
|
||||
// var resultObject = new JsonObject();
|
||||
// resultObject.addProperty("id", getRawIdFor(sr.getOutput().getItem()));
|
||||
// resultObject.addProperty("count", sr.getOutput().getCount());
|
||||
// finalRecipe.add("result", resultObject);
|
||||
//
|
||||
// String id = ((Integer) getRawIdFor(sr.getOutput().getItem())).toString();
|
||||
//
|
||||
// if (!finalObj.has(id)) {
|
||||
// finalObj.add(id, new JsonArray());
|
||||
// }
|
||||
// finalObj.get(id).getAsJsonArray().add(finalRecipe);
|
||||
//// var input = new JsonArray();
|
||||
//// var ingredients = sr.getIngredients().stream().toList();
|
||||
//// for (int y = 0; y < sr.getHeight(); y++) {
|
||||
//// var arr = new JsonArray();
|
||||
//// for (int x = 0; x < sr.getWidth(); x++) {
|
||||
//// if ((y*3)+x >= ingredients.size()) {
|
||||
//// arr.add(JsonNull.INSTANCE);
|
||||
//// continue;
|
||||
//// }
|
||||
//// var ingredient = ingredients.get((y*3)+x).getMatchingStacks(); // FIXME: fix when there are more than one matching stack
|
||||
//// if (ingredient.length == 0) {
|
||||
//// arr.add(JsonNull.INSTANCE);
|
||||
//// } else {
|
||||
//// arr.add(getRawIdFor(ingredient[0].getItem()));
|
||||
//// }
|
||||
//// }
|
||||
//// input.add(arr);
|
||||
//// }
|
||||
//// var rootRecipeObject = new JsonObject();
|
||||
//// rootRecipeObject.add("inShape", input);
|
||||
//// var resultObject = new JsonObject();
|
||||
//// resultObject.addProperty("id", getRawIdFor(sr.getOutput().getItem()));
|
||||
//// resultObject.addProperty("count", sr.getOutput().getCount());
|
||||
//// rootRecipeObject.add("result", resultObject);
|
||||
//// recipes.put(getRawIdFor(sr.getOutput().getItem()), rootRecipeObject);
|
||||
// } else if (recipe instanceof ShapelessRecipe sl) {
|
||||
|
||||
// var ingredients = new JsonArray();
|
||||
// for (Ingredient ingredient : sl.getIngredients()) {
|
||||
// if (ingredient.isEmpty()) continue;
|
||||
//// ingredients.add(getRawIdFor(ingredient.getMatchingStacks()[0].getItem()));
|
||||
// }
|
||||
// var rootRecipeObject = new JsonObject();
|
||||
// rootRecipeObject.add("ingredients", ingredients);
|
||||
// var resultObject = new JsonObject();
|
||||
// resultObject.addProperty("id", getRawIdFor(sl.getOutput().getItem()));
|
||||
// resultObject.addProperty("count", sl.getOutput().getCount());
|
||||
// rootRecipeObject.add("result", resultObject);
|
||||
// recipes.put(getRawIdFor(sl.getOutput().getItem()), rootRecipeObject);
|
||||
// }
|
||||
// }
|
||||
// recipes.forEach((a, b) -> {
|
||||
// if (!finalObj.has(a.toString())) {
|
||||
// finalObj.add(a.toString(), new JsonArray());
|
||||
// }
|
||||
// finalObj.get(a.toString()).getAsJsonArray().add(b);
|
||||
// });
|
||||
// return finalObj;
|
||||
return JsonNull.INSTANCE;
|
||||
}
|
||||
//
|
||||
// private static int getRawIdFor (Item item) {
|
||||
// return Registry.ITEM.getRawId(item);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import dev.u9g.minecraftdatagenerator.ClientSideAnnoyances.BiomeBlockColors;
|
||||
import dev.u9g.minecraftdatagenerator.ClientSideAnnoyances.FoliageColors;
|
||||
import dev.u9g.minecraftdatagenerator.ClientSideAnnoyances.GrassColors;
|
||||
import dev.u9g.minecraftdatagenerator.mixin.accessor.BiomeAccessor;
|
||||
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
|
||||
import dev.u9g.minecraftdatagenerator.util.Registries;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TintsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static BiomeTintColors generateBiomeTintColors() {
|
||||
BiomeTintColors colors = new BiomeTintColors();
|
||||
|
||||
for (Biome biome : Registries.BIOMES) {
|
||||
EmptyBlockView bv = new EmptyBlockView() {
|
||||
@Override
|
||||
public Biome getBiome(int x, int z) {
|
||||
return biome;
|
||||
}
|
||||
};
|
||||
int biomeGrassColor = GrassColors.getGrassColor(bv.getBiome(0, 0));
|
||||
int biomeFoliageColor = FoliageColors.getColor(bv.getBiome(0, 0));
|
||||
int biomeWaterColor = ((BiomeAccessor) biome).waterColor();
|
||||
|
||||
colors.grassColoursMap.computeIfAbsent(biomeGrassColor, k -> new ArrayList<>()).add(biome);
|
||||
colors.foliageColoursMap.computeIfAbsent(biomeFoliageColor, k -> new ArrayList<>()).add(biome);
|
||||
colors.waterColourMap.computeIfAbsent(biomeWaterColor, k -> new ArrayList<>()).add(biome);
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
private static int getBlockColor(Block block) {
|
||||
return BiomeBlockColors.getBlockColor(block, EmptyBlockView.INSTANCE.getBiome(0, 0), 0);
|
||||
}
|
||||
|
||||
public static Map<Block, Integer> generateConstantTintColors() {
|
||||
Map<Block, Integer> resultColors = new HashMap<>();
|
||||
// FIXME: ?
|
||||
// resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor());
|
||||
// resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor());
|
||||
|
||||
resultColors.put(Registries.BLOCKS.get("waterlily"), getBlockColor(Blocks.LILY_PAD));
|
||||
// FIXME: ?
|
||||
// resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM, blockColors));
|
||||
// resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM, blockColors));
|
||||
|
||||
//not really constant, depend on the block age, but kinda have to be handled since textures are literally white without them
|
||||
resultColors.put(Registries.BLOCKS.get("melon_stem"), getBlockColor(Blocks.MELON_STEM));
|
||||
resultColors.put(Registries.BLOCKS.get("pumpkin_stem"), getBlockColor(Blocks.PUMPKIN_STEM));
|
||||
|
||||
return resultColors;
|
||||
}
|
||||
|
||||
private static JsonObject encodeBiomeColorMap(Map<Integer, List<Biome>> colorsMap) {
|
||||
JsonArray resultColorsArray = new JsonArray();
|
||||
for (Map.Entry<Integer, List<Biome>> entry : colorsMap.entrySet()) {
|
||||
JsonObject entryObject = new JsonObject();
|
||||
|
||||
JsonArray keysArray = new JsonArray();
|
||||
for (Biome biome : entry.getValue()) {
|
||||
keysArray.add(new JsonPrimitive(biome.name));
|
||||
}
|
||||
|
||||
entryObject.add("keys", keysArray);
|
||||
entryObject.addProperty("color", entry.getKey());
|
||||
resultColorsArray.add(entryObject);
|
||||
}
|
||||
|
||||
JsonObject resultObject = new JsonObject();
|
||||
resultObject.add("data", resultColorsArray);
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
private static JsonObject encodeRedstoneColorMap(Map<Integer, Integer> colorsMap) {
|
||||
JsonArray resultColorsArray = new JsonArray();
|
||||
for (Map.Entry<Integer, Integer> entry : colorsMap.entrySet()) {
|
||||
JsonObject entryObject = new JsonObject();
|
||||
|
||||
JsonArray keysArray = new JsonArray();
|
||||
keysArray.add(new JsonPrimitive(entry.getKey()));
|
||||
|
||||
entryObject.add("keys", keysArray);
|
||||
entryObject.addProperty("color", entry.getValue());
|
||||
resultColorsArray.add(entryObject);
|
||||
}
|
||||
|
||||
JsonObject resultObject = new JsonObject();
|
||||
resultObject.add("data", resultColorsArray);
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
private static JsonObject encodeBlocksColorMap(Map<Block, Integer> colorsMap) {
|
||||
JsonArray resultColorsArray = new JsonArray();
|
||||
for (Map.Entry<Block, Integer> entry : colorsMap.entrySet()) {
|
||||
JsonObject entryObject = new JsonObject();
|
||||
JsonArray keysArray = new JsonArray();
|
||||
String registryKey = Registries.BLOCKS.getId(entry.getKey());
|
||||
keysArray.add(new JsonPrimitive(Objects.requireNonNull(registryKey).replace("minecraft:", "")));
|
||||
|
||||
entryObject.add("keys", keysArray);
|
||||
entryObject.addProperty("color", entry.getValue());
|
||||
resultColorsArray.add(entryObject);
|
||||
}
|
||||
|
||||
JsonObject resultObject = new JsonObject();
|
||||
resultObject.add("data", resultColorsArray);
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataName() {
|
||||
return "tints";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject generateDataJson() {
|
||||
BiomeTintColors biomeTintColors = generateBiomeTintColors();
|
||||
Map<Block, Integer> constantTintColors = generateConstantTintColors();
|
||||
|
||||
JsonObject resultObject = new JsonObject();
|
||||
|
||||
resultObject.add("grass", encodeBiomeColorMap(biomeTintColors.grassColoursMap));
|
||||
resultObject.add("foliage", encodeBiomeColorMap(biomeTintColors.foliageColoursMap));
|
||||
resultObject.add("water", encodeBiomeColorMap(biomeTintColors.waterColourMap));
|
||||
|
||||
resultObject.add("constant", encodeBlocksColorMap(constantTintColors));
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
public static class BiomeTintColors {
|
||||
final Map<Integer, List<Biome>> grassColoursMap = new HashMap<>();
|
||||
final Map<Integer, List<Biome>> foliageColoursMap = new HashMap<>();
|
||||
final Map<Integer, List<Biome>> waterColourMap = new HashMap<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Blocks.class)
|
||||
public class BlocksMixin {
|
||||
@Inject(method = "<clinit>", at = @At("HEAD"))
|
||||
private static void doBlocksStaticCtor(CallbackInfo ci) {
|
||||
// Block.setup();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin;
|
||||
|
||||
import dev.u9g.minecraftdatagenerator.Main;
|
||||
import dev.u9g.minecraftdatagenerator.generators.DataGenerators;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import dev.u9g.minecraftdatagenerator.util.Registries;
|
||||
import net.minecraft.server.dedicated.MinecraftDedicatedServer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@Mixin(MinecraftDedicatedServer.class)
|
||||
public class ReadyMixin {
|
||||
@Inject(method = "setupServer()Z", at = @At("TAIL"))
|
||||
private void init(CallbackInfoReturnable<Boolean> cir) {
|
||||
Registries.init();
|
||||
Main.LOGGER.log(Level.INFO, "Starting data generation!");
|
||||
String versionName = DGU.getCurrentlyRunningServer().getVersion();
|
||||
Path serverRootDirectory = (new File(".")).toPath().toAbsolutePath();
|
||||
Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName);
|
||||
DataGenerators.runDataGenerators(dataDumpDirectory);
|
||||
Main.LOGGER.log(Level.INFO, "Done data generation!");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin;
|
||||
|
||||
import net.minecraft.item.VariantBlockItem;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(VariantBlockItem.class)
|
||||
public interface VariantBlockItemAccessor {
|
||||
@Accessor("field_5448")
|
||||
String[] variants();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin.accessor;
|
||||
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Mixin(Biome.class)
|
||||
public interface BiomeAccessor {
|
||||
@Accessor("BIOMESET")
|
||||
static Set<Biome> BIOMESET() {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
@Accessor("waterColor")
|
||||
int waterColor();
|
||||
|
||||
@Accessor("name")
|
||||
String name();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin.accessor;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(Block.class)
|
||||
public interface BlockAccessor {
|
||||
@Accessor("blastResistance")
|
||||
float getBlastResistance();
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin.accessor;
|
||||
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(Enchantment.class)
|
||||
public interface EnchantmentAccessor {
|
||||
@Accessor("ALL_ENCHANTMENTS")
|
||||
static Enchantment[] ALL_ENCHANTMENTS() {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin.accessor;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(EntityType.class)
|
||||
public interface EntityTypeAccessor {
|
||||
@Accessor("NAME_CLASS_MAP")
|
||||
static Map<String, Class<? extends Entity>> NAME_CLASS_MAP() {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
@Accessor("CLASS_NAME_MAP")
|
||||
static Map<Class<? extends Entity>, String> CLASS_NAME_MAP() {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
@Accessor("ID_CLASS_MAP")
|
||||
static Map<Integer, Class<? extends Entity>> ID_CLASS_MAP() {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
@Accessor("CLASS_ID_MAP")
|
||||
static Map<Class<? extends Entity>, Integer> CLASS_ID_MAP() {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin.accessor;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(Item.class)
|
||||
public interface ItemAccessor {
|
||||
@Accessor("translationKey")
|
||||
String translationKey();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin.accessor;
|
||||
|
||||
import net.minecraft.util.Language;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(Language.class)
|
||||
public interface LanguageAccessor {
|
||||
@Accessor("translations")
|
||||
Map<String, String> translations();
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin.accessor;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ToolItem;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Mixin(ToolItem.class)
|
||||
public interface MiningToolItemAccessor {
|
||||
|
||||
@Accessor
|
||||
Set<Block> getEffectiveBlocks();
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin.accessor;
|
||||
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(StatusEffect.class)
|
||||
public interface StatusEffectAccessor {
|
||||
@Accessor("STATUS_EFFECTS")
|
||||
static StatusEffect[] STATUS_EFFECTS() {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
@Accessor("negative")
|
||||
boolean negative();
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin.overwrite;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
@Mixin(ItemEntity.class)
|
||||
public abstract class ItemEntityOverwrite extends Entity {
|
||||
|
||||
public ItemEntityOverwrite(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author a
|
||||
* @reason a
|
||||
*/
|
||||
@Overwrite
|
||||
public String getTranslatedName() {
|
||||
return super.getTranslatedName();
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package dev.u9g.minecraftdatagenerator.registryview;
|
||||
|
||||
import net.minecraft.util.registry.SimpleRegistry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class RegistryBackedRegistryView<V> implements RegistryView<String, V> {
|
||||
private final SimpleRegistry registry;
|
||||
|
||||
public RegistryBackedRegistryView(SimpleRegistry registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRawId(V value) {
|
||||
return registry.getRawId(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId(V value) {
|
||||
return registry.getId(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getByRawId(int rawId) {
|
||||
return (V) registry.getByRawId(rawId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(String id) {
|
||||
return (V) registry.get(id);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<V> iterator() {
|
||||
return (Iterator<V>) registry.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super V> action) {
|
||||
registry.forEach(value -> action.accept((V) value));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.u9g.minecraftdatagenerator.registryview;
|
||||
|
||||
public interface RegistryView<K, V> extends Iterable<V> {
|
||||
int getRawId(V value);
|
||||
|
||||
K getId(V value);
|
||||
|
||||
V getByRawId(int rawId);
|
||||
|
||||
V get(K id);
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package dev.u9g.minecraftdatagenerator.registryview;
|
||||
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TableBackedRegistryView<K, V> implements RegistryView<K, V> {
|
||||
private final HashBasedTable<K, Integer, V> table;
|
||||
|
||||
protected TableBackedRegistryView(HashBasedTable<K, Integer, V> table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRawId(V value) {
|
||||
for (Map.Entry<K, Map<Integer, V>> row : table.rowMap().entrySet()) {
|
||||
Map.Entry<Integer, V> entry = row.getValue().entrySet().iterator().next();
|
||||
if (Objects.equals(entry.getValue(), value)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
throw new Error("value not in registry.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public K getId(V value) {
|
||||
for (Map.Entry<K, Map<Integer, V>> row : table.rowMap().entrySet()) {
|
||||
Map.Entry<Integer, V> entry = row.getValue().entrySet().iterator().next();
|
||||
if (Objects.equals(entry.getValue(), value)) {
|
||||
return row.getKey();
|
||||
}
|
||||
}
|
||||
throw new Error("value not in registry.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getByRawId(int rawId) {
|
||||
return table.columnMap().get(rawId).entrySet().iterator().next().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(K id) {
|
||||
return table.row(id).entrySet().iterator().next().getValue();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<V> iterator() {
|
||||
return table.values().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer action) {
|
||||
for (V v : this) {
|
||||
action.accept(v);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder<K, V> {
|
||||
private final HashBasedTable<K, Integer, V> table = HashBasedTable.create();
|
||||
|
||||
public Builder<K, V> add(K key, int rawId, V value) {
|
||||
table.put(key, rawId, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TableBackedRegistryView<K, V> build() {
|
||||
return new TableBackedRegistryView<>(table);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package dev.u9g.minecraftdatagenerator.util;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DGU {
|
||||
public static MinecraftServer getCurrentlyRunningServer() {
|
||||
return MinecraftServer.getServer();
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static String translateTextClient(String translationKey) {
|
||||
return I18n.translate(translationKey);
|
||||
}
|
||||
|
||||
private static String translateTextFallback(String translationKey) {
|
||||
try {
|
||||
return Registries.LANGUAGE.translate(translationKey);
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
throw new RuntimeException("Failed to translate: '" + translationKey + "'");
|
||||
}
|
||||
|
||||
public static String translateText(String translationKey) {
|
||||
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
|
||||
if (environmentType == EnvType.CLIENT) {
|
||||
return translateTextClient(translationKey);
|
||||
}
|
||||
return translateTextFallback(translationKey);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static World getWorld() {
|
||||
return getCurrentlyRunningServer().getWorld();
|
||||
}
|
||||
|
||||
public static ItemStack stackFor(Item ic) {
|
||||
return new ItemStack(ic);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package dev.u9g.minecraftdatagenerator.util;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.class_5093;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class EmptyBlockView implements BlockView {
|
||||
public static final EmptyBlockView INSTANCE = new EmptyBlockView();
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity getBlockEntity(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockData(int x, int y, int z) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAir(int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int method_3771() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public class_5093 method_22399() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int method_3719(int i, int j, int k, int l) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int method_3778(int i, int j, int k, int l) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
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;
|
||||
import dev.u9g.minecraftdatagenerator.registryview.RegistryView;
|
||||
import dev.u9g.minecraftdatagenerator.registryview.TableBackedRegistryView;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.Language;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class Registries {
|
||||
public static Language LANGUAGE;
|
||||
public static RegistryView<String, Biome> BIOMES;
|
||||
public static RegistryView<String, Block> BLOCKS;
|
||||
public static RegistryView<String, Item> ITEMS;
|
||||
public static RegistryView<String, StatusEffect> STATUS_EFFECTS;
|
||||
public static RegistryView<String, Enchantment> ENCHANTMENTS;
|
||||
public static RegistryView<String, Class<? extends Entity>> ENTITY_TYPES;
|
||||
|
||||
private static RegistryView<String, Class<? extends Entity>> setupEntityTypesRegistry() {
|
||||
TableBackedRegistryView.Builder<String, Class<? extends Entity>> registry = new TableBackedRegistryView.Builder<>();
|
||||
for (Map.Entry<Integer, Class<? extends Entity>> entry : EntityTypeAccessor.ID_CLASS_MAP().entrySet()) {
|
||||
String name = EntityTypeAccessor.CLASS_NAME_MAP().get(entry.getValue());
|
||||
if (name.equals("Mob") || name.equals("Monster")) {
|
||||
continue;
|
||||
}
|
||||
registry.add(name, entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return registry.build();
|
||||
}
|
||||
|
||||
private static RegistryView<String, Enchantment> setupEnchantmentRegistry() {
|
||||
TableBackedRegistryView.Builder<String, Enchantment> registry = new TableBackedRegistryView.Builder<>();
|
||||
for (Enchantment enchantment : EnchantmentAccessor.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);
|
||||
}
|
||||
return registry.build();
|
||||
}
|
||||
|
||||
private static RegistryView<String, Biome> setupBiomeRegistry() {
|
||||
TableBackedRegistryView.Builder<String, Biome> builder = new TableBackedRegistryView.Builder<>();
|
||||
for (Biome biome : BiomeAccessor.BIOMESET()) {
|
||||
builder.add(biome.name, biome.id, biome);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static RegistryView<String, StatusEffect> setupStatusEffectRegistry() {
|
||||
TableBackedRegistryView.Builder<String, StatusEffect> builder = new TableBackedRegistryView.Builder<>();
|
||||
for (StatusEffect effect : StatusEffectAccessor.STATUS_EFFECTS()) {
|
||||
if (effect == null) continue;
|
||||
String[] words = Registries.LANGUAGE.translate(effect.getTranslationKey()).split(" ");
|
||||
builder.add(StringUtils.join(words, ""), effect.id, effect);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
LANGUAGE = new Language();
|
||||
BIOMES = setupBiomeRegistry();
|
||||
BLOCKS = new RegistryBackedRegistryView<>(Block.REGISTRY);
|
||||
ITEMS = new RegistryBackedRegistryView<>(Item.REGISTRY);
|
||||
STATUS_EFFECTS = setupStatusEffectRegistry();
|
||||
ENCHANTMENTS = setupEnchantmentRegistry();
|
||||
ENTITY_TYPES = setupEntityTypesRegistry();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "minecraft-data-generator",
|
||||
"version": "${version}",
|
||||
"name": "Minecraft Data Generator",
|
||||
"description": "",
|
||||
"authors": [
|
||||
"Archengius",
|
||||
"U9G"
|
||||
],
|
||||
"contact": {},
|
||||
"license": "MIT",
|
||||
"environment": "server",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"dev.u9g.minecraftdatagenerator.Main"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"minecraft-data-generator.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.13.3",
|
||||
"minecraft": ">=1.7"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "dev.u9g.minecraftdatagenerator.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"BlocksMixin",
|
||||
"ReadyMixin",
|
||||
"VariantBlockItemAccessor",
|
||||
"accessor.BiomeAccessor",
|
||||
"accessor.BlockAccessor",
|
||||
"accessor.EnchantmentAccessor",
|
||||
"accessor.EntityTypeAccessor",
|
||||
"accessor.ItemAccessor",
|
||||
"accessor.LanguageAccessor",
|
||||
"accessor.MiningToolItemAccessor",
|
||||
"accessor.StatusEffectAccessor",
|
||||
"overwrite.ItemEntityOverwrite"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user