Reduce duplicate code (#18)

* Reduce duplicate code

* Fix gradle task name

* Revert name changes

* Revert action name

* Cleanup

* Revert to java 17

* Fix generation

* Cleanup

* Simplify code of DGU

* Remove unnecessary annotations

* Remove unused var

* Halt with error on error

* Remove unused mixins

* Update fabric loader

* Ignore success result

* Update gradle and use merged jar

* Implement new client and server merged environment for running fabric

* Set server run dir as asset dir

* More cleanup

* More cleanup 2

* More improvements

* Remove more duplicate code

* Use newer java methods

* More cleanup

* Remove SoundAccessors

* More cleanup

* Use java 21 for build

* Initial work on 1.20.5

* Cleanup a lot of stuff

* Do not generate mod jars to speed up builds

* Override merger on now open classes directly

* Use recommended approach

* Readd custom merger

* Working materials data generator

* Fix inconsistencies

* Fix collision order to be random

* Use LinkedHashMap for more reproducibility

* Fix imports
This commit is contained in:
Alex
2024-07-14 09:23:34 +02:00
committed by GitHub
parent 44f49b4ab5
commit 71070c32bc
459 changed files with 3421 additions and 9078 deletions
+25 -48
View File
@@ -1,54 +1,33 @@
import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask
import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider
plugins {
id 'fabric-loom'
id 'xyz.wagyourtail.unimined'
}
repositories {
maven {
name = "u9g"
url = "https://maven.u9g.dev"
unimined.minecraft {
version "1.7"
mappings {
legacyIntermediary()
legacyYarn(514)
devFallbackNamespace "intermediary"
}
}
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}")
runs.config("server") {
javaVersion = JavaVersion.VERSION_21
}
// Required by 1.7.x
runs {
client {
programArgs "--userProperties", "{}"
}
}
customPatcher(new CustomLegacyFabricMinecraftTransformer(project, delegate as MinecraftProvider)) {
it.loader libs.versions.fabric.loader.get()
}
defaultRemapJar = true
}
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'
}
}
implementation project(":common")
}
processResources {
@@ -59,12 +38,10 @@ processResources {
}
}
tasks.withType(RemapJarTask).configureEach {
onlyIf { false}
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
-7
View File
@@ -1,7 +0,0 @@
# 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/
@@ -1,13 +0,0 @@
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() {
}
}
@@ -1,80 +0,0 @@
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;
}
}
@@ -1,38 +0,0 @@
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);
}
}
@@ -1,27 +0,0 @@
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);
}
}
@@ -1,28 +0,0 @@
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;
}
}
@@ -93,7 +93,7 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator {
// }
// }
// if (indexesOfBoxesInTheShapesCache.stream().distinct().count() < 2) {
// return indexesOfBoxesInTheShapesCache.get(0);
// return indexesOfBoxesInTheShapesCache.getFirst();
// } else {
// JsonArray shapeIndexes = new JsonArray();
// indexesOfBoxesInTheShapesCache.forEach(shapeIndex -> shapeIndexes.add(new JsonPrimitive(shapeIndex)));
@@ -114,18 +114,18 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator {
private record Shapes(List<Box> boxes) {
public JsonArray toJSON() {
JsonArray arr = new JsonArray();
boxes.forEach(box -> arr.add(jsonOf(box)));
return arr;
}
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 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);
}
}
}
@@ -2,7 +2,6 @@ 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;
@@ -17,12 +16,8 @@ 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) {
@@ -49,7 +44,7 @@ public class BlocksDataGenerator implements IDataGenerator {
blockDesc.addProperty("displayName", block.getTranslatedName());
}
float hardness = block.getHardness(null, 0, 0, 0);
float hardness = block.method_471(null, 0, 0, 0);
blockDesc.addProperty("hardness", hardness);
blockDesc.addProperty("resistance", ((BlockAccessor) block).getBlastResistance());
@@ -70,7 +65,7 @@ public class BlocksDataGenerator implements IDataGenerator {
}
private static String boundingBox(Block block) {
if (block.getCollisionBox(DGU.getWorld(), 0, 0, 0) == null) {
if (block.getBoundingBox(DGU.getWorld(), 0, 0, 0) == null) {
return "empty";
}
return "block";
@@ -1,80 +0,0 @@
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.info("Failed to create data generator output directory at " + outputDirectory);
exception.printStackTrace();
return false;
}
int generatorsFailed = 0;
logger.info(MessageFormat.format("Running minecraft data generators, output at {0}", outputDirectory));
for (IDataGenerator dataGenerator : GENERATORS) {
logger.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.info(MessageFormat.format("Generator: {0} -> {1}", dataGenerator.getDataName(), outputFileName));
} catch (Throwable exception) {
logger.info(MessageFormat.format("Failed to run data generator {0}", dataGenerator.getDataName()));
exception.printStackTrace();
generatorsFailed++;
}
}
logger.info("Finishing running data generators");
return generatorsFailed == 0;
}
}
@@ -11,7 +11,6 @@ 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));
@@ -20,7 +20,6 @@ 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);
@@ -31,7 +30,7 @@ public class EntitiesDataGenerator implements IDataGenerator {
entityDesc.addProperty("id", id);
entityDesc.addProperty("internalId", id);
entityDesc.addProperty("name", Objects.requireNonNull(registryKey));
String displayName = entity != null ? entity.getTranslatedName() : null;
String displayName = entity != null ? entity.getTranslationKey() : null;
if (displayName != null && !displayName.startsWith("entity.")) {
entityDesc.addProperty("displayName", displayName);
}
@@ -10,7 +10,6 @@ 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);
@@ -1,10 +0,0 @@
package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonElement;
public interface IDataGenerator {
String getDataName();
JsonElement generateDataJson();
}
@@ -4,7 +4,7 @@ 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;
import net.minecraft.block.material.Material;
public class InstrumentsDataGenerator implements IDataGenerator {
public static Material currentMaterial = null;
@@ -112,6 +112,12 @@ public class RecipeDataGenerator implements IDataGenerator {
// return finalObj;
return JsonNull.INSTANCE;
}
@Override
public boolean isEnabled() {
return false; // TODO: Implement this
}
//
// private static int getRawIdFor (Item item) {
// return Registry.ITEM.getRawId(item);
@@ -3,32 +3,27 @@ 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.client.color.world.FoliageColors;
import net.minecraft.client.color.world.GrassColors;
import net.minecraft.util.math.MathHelper;
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));
double d = MathHelper.clamp(biome.temperature, 0.0f, 1.0f);
double e = MathHelper.clamp(biome.downfall, 0.0f, 1.0f);
int biomeGrassColor = GrassColors.getColor(d, e);
int biomeFoliageColor = FoliageColors.getColor(d, e);
int biomeWaterColor = ((BiomeAccessor) biome).waterColor();
colors.grassColoursMap.computeIfAbsent(biomeGrassColor, k -> new ArrayList<>()).add(biome);
@@ -38,24 +33,20 @@ public class TintsDataGenerator implements IDataGenerator {
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<>();
Map<Block, Integer> resultColors = new LinkedHashMap<>();
// 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));
resultColors.put(Registries.BLOCKS.get("waterlily"), Blocks.LILY_PAD.getColor());
// 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));
// resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM));
// resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM));
//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));
resultColors.put(Registries.BLOCKS.get("melon_stem"), Blocks.MELON_STEM.getColor());
resultColors.put(Registries.BLOCKS.get("pumpkin_stem"), Blocks.PUMPKIN_STEM.getColor());
return resultColors;
}
@@ -138,8 +129,8 @@ public class TintsDataGenerator implements IDataGenerator {
}
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<>();
final Map<Integer, List<Biome>> grassColoursMap = new LinkedHashMap<>();
final Map<Integer, List<Biome>> foliageColoursMap = new LinkedHashMap<>();
final Map<Integer, List<Biome>> waterColourMap = new LinkedHashMap<>();
}
}
@@ -1,15 +0,0 @@
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();
}
}
@@ -1,9 +1,7 @@
package dev.u9g.minecraftdatagenerator.mixin;
import dev.u9g.minecraftdatagenerator.Main;
import dev.u9g.minecraftdatagenerator.generators.DataGenerators;
import dev.u9g.minecraftdatagenerator.MinecraftDataGenerator;
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;
@@ -11,20 +9,15 @@ 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.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.info("Done data generation!");
Runtime.getRuntime().halt(0);
System.setProperty("fabric.development", "false");
MinecraftDataGenerator.start(
DGU.getCurrentlyRunningServer().getVersion(),
(new File(".")).toPath()
);
}
}
@@ -18,7 +18,7 @@ public abstract class ItemEntityOverwrite extends Entity {
* @reason a
*/
@Overwrite
public String getTranslatedName() {
return super.getTranslatedName();
public String getTranslationKey() {
return super.getTranslationKey();
}
}
@@ -1,9 +1,5 @@
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;
@@ -15,26 +11,8 @@ public class DGU {
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);
return Registries.LANGUAGE.translate(translationKey);
}
@NotNull
@@ -1,61 +0,0 @@
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;
}
}
@@ -20,13 +20,23 @@ 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;
public static final Language LANGUAGE;
public static final RegistryView<String, Biome> BIOMES;
public static final RegistryView<String, Block> BLOCKS;
public static final RegistryView<String, Item> ITEMS;
public static final RegistryView<String, StatusEffect> STATUS_EFFECTS;
public static final RegistryView<String, Enchantment> ENCHANTMENTS;
public static final RegistryView<String, Class<? extends Entity>> ENTITY_TYPES;
static {
LANGUAGE = new Language();
BIOMES = setupBiomeRegistry();
BLOCKS = new RegistryBackedRegistryView<>(Block.REGISTRY);
ITEMS = new RegistryBackedRegistryView<>(Item.REGISTRY);
STATUS_EFFECTS = setupStatusEffectRegistry();
ENCHANTMENTS = setupEnchantmentRegistry();
ENTITY_TYPES = setupEntityTypesRegistry();
}
private static RegistryView<String, Class<? extends Entity>> setupEntityTypesRegistry() {
TableBackedRegistryView.Builder<String, Class<? extends Entity>> registry = new TableBackedRegistryView.Builder<>();
@@ -68,14 +78,4 @@ public class Registries {
}
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();
}
}
+2 -8
View File
@@ -10,17 +10,11 @@
],
"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"
"fabricloader": "*",
"minecraft": "*"
}
}
@@ -4,7 +4,6 @@
"package": "dev.u9g.minecraftdatagenerator.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"BlocksMixin",
"ReadyMixin",
"VariantBlockItemAccessor",
"accessor.BiomeAccessor",
@@ -17,8 +16,6 @@
"accessor.StatusEffectAccessor",
"overwrite.ItemEntityOverwrite"
],
"client": [
],
"injectors": {
"defaultRequire": 1
}