diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c1bb07f4..a6ec2a5b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,26 @@ jobs: build: strategy: matrix: - version: ["1.7", "1.8.9", "1.9.4", "1.10.2", "1.11.2", "1.12.2", "1.13", "1.14", "1.15", "1.16", "1.17", "1.18", "22w19a", "1.19", "1.19.2", "1.20", "1.20.4"] + version: [ + "1.7", + "1.8.9", + "1.9.4", + "1.10.2", + "1.11.2", + "1.12.2", + "1.13", + "1.14", + "1.15", + "1.16", + "1.17", + "1.18", + "22w19a", + "1.19", + "1.19.2", + "1.20", + "1.20.4", + "1.20.5" + ] name: Build ${{ matrix.version }} timeout-minutes: 10 @@ -25,10 +44,10 @@ jobs: - name: Validate Gradle wrapper uses: gradle/wrapper-validation-action@v1 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: Generate ${{ matrix.version }} @@ -40,5 +59,5 @@ jobs: uses: actions/upload-artifact@v4 with: name: data-${{ matrix.version }} - path: ${{ matrix.version }}/run/minecraft-data + path: ${{ matrix.version }}/run/server/minecraft-data if-no-files-found: error diff --git a/1.10.2/build.gradle b/1.10.2/build.gradle index 057916c6..a25cddde 100644 --- a/1.10.2/build.gradle +++ b/1.10.2/build.gradle @@ -1,47 +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 = "legacy-fabric" - url = "https://maven.legacyfabric.net" +unimined.minecraft { + version "1.10.2" + + mappings { + legacyIntermediary() + legacyYarn(541) + + devFallbackNamespace "intermediary" } -} -loom { - setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar'); - customMinecraftManifest.set("https://meta.legacyfabric.net/v2/manifest/${minecraft_version}") -} + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } -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' + customPatcher(new CustomLegacyFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() } + + defaultRemapJar = true } -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' - } - } +dependencies { + implementation project(":common") } processResources { @@ -52,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.10.2/gradle.properties b/1.10.2/gradle.properties deleted file mode 100644 index 335785fc..00000000 --- a/1.10.2/gradle.properties +++ /dev/null @@ -1,7 +0,0 @@ -# Fabric Properties -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ -minecraft_version=1.10.2 -yarn_mappings=1.10.2+build.202206020145 -loader_version=0.14.3 -# Dependencies -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index d23c5ba2..00000000 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -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() { - } -} diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java deleted file mode 100644 index f42641fb..00000000 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java +++ /dev/null @@ -1,47 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.biome.Biome; - -import java.util.Iterator; - -public class BiomeColors { - private static final ColorProvider GRASS_COLOR = Biome::getGrassColor; - private static final ColorProvider FOLIAGE_COLOR = Biome::getFoliageColor; - private static final ColorProvider WATER_COLOR = (biome, pos) -> biome.getWaterColor(); - - private static int getColor(EmptyBlockView view, BlockPos pos, ColorProvider provider) { - int i = 0; - int j = 0; - int k = 0; - - int l; - for (Iterator iterator = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); iterator.hasNext(); k += l & 255) { - BlockPos.Mutable mutable = (BlockPos.Mutable) iterator.next(); - l = provider.getColorAtPos(view.getBiome(mutable), mutable); - i += (l & 16711680) >> 16; - j += (l & '\uff00') >> 8; - } - - return (i / 9 & 255) << 16 | (j / 9 & 255) << 8 | k / 9 & 255; - } - - public static int getGrassColor(EmptyBlockView view, BlockPos pos) { - return getColor(view, pos, GRASS_COLOR); - } - - public static int getFoliageColor(EmptyBlockView view, BlockPos pos) { - return getColor(view, pos, FOLIAGE_COLOR); - } - - public static int getWaterColor(EmptyBlockView view, BlockPos pos) { - return getColor(view, pos, WATER_COLOR); - } - - interface ColorProvider { - int getColorAtPos(Biome biome, BlockPos pos); - } -} - - diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java deleted file mode 100644 index b6819227..00000000 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.Nullable; - -public interface BlockColorable { - int method_12155(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i); -} diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java deleted file mode 100644 index 2bd090ca..00000000 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java +++ /dev/null @@ -1,96 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; -import net.minecraft.block.*; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.FlowerPotBlockEntity; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.util.collection.IdList; -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.Nullable; - -public class BlockColors { - private final IdList BlockColor2Id = new IdList<>(32); - - public BlockColors() { - } - - public static BlockColors create() { - final BlockColors blockColors = new BlockColors(); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - DoublePlantBlock.DoublePlantType doublePlantType = blockState.get(DoublePlantBlock.VARIANT); - return blockView == null || blockPos == null || doublePlantType != DoublePlantBlock.DoublePlantType.GRASS && doublePlantType != DoublePlantBlock.DoublePlantType.FERN ? -1 : BiomeColors.getGrassColor(blockView, blockPos); - }, Blocks.DOUBLE_PLANT); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - if (blockView != null && blockPos != null) { - BlockEntity blockEntity = blockView.getBlockEntity(blockPos); - if (blockEntity instanceof FlowerPotBlockEntity) { - Item item = ((FlowerPotBlockEntity) blockEntity).getItem(); - if (item instanceof BlockItem) { - BlockState blockState2 = Block.getBlockFromItem(item).getDefaultState(); - return blockColors.method_12157(blockState2, blockView, blockPos, i); - } - } - } - - return -1; - }, Blocks.FLOWER_POT); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : GrassColors.getColor(0.5D, 1.0D), Blocks.GRASS); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - PlanksBlock.WoodType woodType = blockState.get(Leaves1Block.VARIANT); - if (woodType == PlanksBlock.WoodType.SPRUCE) { - return FoliageColors.getSpruceColor(); - } else if (woodType == PlanksBlock.WoodType.BIRCH) { - return FoliageColors.getBirchColor(); - } else { - return blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(); - } - }, Blocks.LEAVES); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.LEAVES2); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getWaterColor(blockView, blockPos) : -1, Blocks.WATER, Blocks.FLOWING_WATER); - blockColors.method_12158((blockState, blockView, blockPos, i) -> RedstoneWireBlock.method_8877(blockState.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : -1, Blocks.SUGARCANE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - int j = blockState.get(AttachedStemBlock.AGE); - int k = j * 32; - int l = 255 - j * 8; - int m = j * 4; - return k << 16 | l << 8 | m; - }, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - if (blockView != null && blockPos != null) { - return BiomeColors.getGrassColor(blockView, blockPos); - } else { - return blockState.get(TallPlantBlock.TYPE) == TallPlantBlock.GrassType.DEAD_BUSH ? 16777215 : GrassColors.getColor(0.5D, 1.0D); - } - }, Blocks.TALLGRASS); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.VINE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? 2129968 : 7455580, Blocks.LILY_PAD); - return blockColors; - } - - public int method_13410(BlockState blockState) { - BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock())); - if (blockColorable != null) { - return blockColorable.method_12155(blockState, null, null, 0); - } else { - MaterialColor materialColor = blockState.getMaterialColor(); - return materialColor != null ? materialColor.color : -1; - } - } - - public int method_12157(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i) { - BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock())); - return blockColorable == null ? -1 : blockColorable.method_12155(blockState, blockView, blockPos, i); - } - - public void method_12158(BlockColorable blockColorable, Block... blocks) { - int i = blocks.length; - - for (Block block : blocks) { - this.BlockColor2Id.set(blockColorable, Block.getIdByBlock(block)); - } - - } -} diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java deleted file mode 100644 index b63e543b..00000000 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java +++ /dev/null @@ -1,37 +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 getFoliageColor(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0F, 1.0F); - double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F); - return FoliageColors.getColor(d, e); - } -} diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java deleted file mode 100644 index afee2b70..00000000 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java +++ /dev/null @@ -1,29 +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) { - humidity *= temperature; - int i = (int) ((1.0D - temperature) * 255.0D); - int j = (int) ((1.0D - humidity) * 255.0D); - int k = j << 8 | i; - return k > colorMap.length ? -65281 : colorMap[k]; - } - - public static int getGrassColor(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0F, 1.0F); - double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F); - return GrassColors.getColor(d, e); - } -} - - - diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java deleted file mode 100644 index 75c9f89c..00000000 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java +++ /dev/null @@ -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; - } -} diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 2bb5a0be..02fd69a6 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -79,7 +79,7 @@ public Object addShapesFrom(Block block) { } } 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))); @@ -99,18 +99,18 @@ public JsonObject toJSON() { private record Shapes(List 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); + } } } diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 284f566f..1ec40aea 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -4,7 +4,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import dev.u9g.minecraftdatagenerator.Main; import dev.u9g.minecraftdatagenerator.mixin.BlockAccessor; import dev.u9g.minecraftdatagenerator.mixin.MiningToolItemAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -28,12 +27,8 @@ import java.util.Collection; 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 getItemsEffectiveForBlock(Block block) { List items = new ArrayList<>(); for (Item item : Registries.ITEMS) { diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index c89d0777..00000000 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -1,81 +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 GENERATORS = new ArrayList<>(); - private static final Logger logger = Main.LOGGER; - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new AttributesDataGenerator()); - register(new SoundsDataGenerator()); - } - - 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; - } -} diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 6aba51e0..ea880e45 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -16,7 +16,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); @NotNull Identifier registryKey = Objects.requireNonNull(Registries.STATUS_EFFECTS.getIdentifier(statusEffect)); diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 3703b843..18bbee55 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -21,7 +21,6 @@ import java.util.Objects; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Class entityClass) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass); diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index fd68583a..f2ad50b6 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(FoodItem foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = Registries.ITEMS.getIdentifier(foodItem); diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java index 3aa51c41..dcb6c5be 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java @@ -4,8 +4,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.mixin.NoteBlockAccessor; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; -import net.minecraft.client.sound.SoundEvent; +import net.minecraft.sound.Sound; import java.util.Objects; @@ -19,10 +18,10 @@ public String getDataName() { public JsonElement generateDataJson() { JsonArray array = new JsonArray(); int i = 0; - for (SoundEvent sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) { + for (Sound sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) { JsonObject object = new JsonObject(); object.addProperty("id", i++); - object.addProperty("name", ((SoundAccessor) sound).id().getPath().split("\\.")[2]); + object.addProperty("name", sound.getId().getPath().split("\\.")[2]); array.add(object); } return array; diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 2b1a5085..36025a4d 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -5,7 +5,6 @@ import net.minecraft.client.particle.ParticleType; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(int id, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java index 32498dfa..553fbdf6 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -112,6 +112,11 @@ public JsonElement generateDataJson() { // 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); diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index 9429a29a..88e0e8a8 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -2,17 +2,14 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; -import net.minecraft.client.sound.SoundEvent; - +import net.minecraft.sound.Sound; public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(SoundEvent soundEvent) { + public static JsonObject generateSound(Sound soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", SoundEvent.REGISTRY.getRawId(soundEvent)); - soundDesc.addProperty("name", ((SoundAccessor) soundEvent).id().getPath()); + soundDesc.addProperty("id", Sound.REGISTRY.getRawId(soundEvent)); + soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; } @@ -25,7 +22,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - SoundEvent.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound))); + Sound.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 8d1b2a84..3923b2e1 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -3,38 +3,30 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.BlockColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.GrassColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock; import dev.u9g.minecraftdatagenerator.mixin.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.block.RedstoneWireBlock; +import net.minecraft.client.BlockColors; +import net.minecraft.client.color.world.FoliageColors; +import net.minecraft.client.color.world.GrassColors; import net.minecraft.util.Identifier; -import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.biome.Biome; import java.util.*; public class TintsDataGenerator implements IDataGenerator { - - private static final BlockColors blockColors = BlockColors.create(); - public static BiomeTintColors generateBiomeTintColors() { BiomeTintColors colors = new BiomeTintColors(); for (Biome biome : Registries.BIOMES) { - EmptyBlockView bv = new EmptyBlockView() { - @Override - public Biome getBiome(BlockPos pos) { - return biome; - } - }; - int biomeGrassColor = GrassColors.getGrassColor(bv.getBiome(BlockPos.ORIGIN)); - int biomeFoliageColor = FoliageColors.getFoliageColor(bv.getBiome(BlockPos.ORIGIN)); + double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); + double e = MathHelper.clamp(biome.getRainfall(), 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); @@ -45,30 +37,29 @@ public Biome getBiome(BlockPos pos) { } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { - int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel); + int color = RedstoneWireBlock.getColorIntensity(redstoneLevel); resultColors.put(redstoneLevel, color); } return resultColors; } private static int getBlockColor(Block block) { - return blockColors.method_13410(block.getDefaultState()); + return BlockColors.create().method_13410(block.getDefaultState()); } public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); // FIXME: ? // resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); // resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); resultColors.put(Blocks.LILY_PAD, 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)); + // 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); @@ -158,8 +149,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java index 4bc3bcb9..688aa1c6 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java @@ -1,7 +1,7 @@ package dev.u9g.minecraftdatagenerator.mixin; import net.minecraft.block.NoteBlock; -import net.minecraft.client.sound.SoundEvent; +import net.minecraft.sound.Sound; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @@ -10,7 +10,7 @@ @Mixin(NoteBlock.class) public interface NoteBlockAccessor { @Accessor("TUNES") - static List TUNES() { + static List TUNES() { return null; } } diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index f5608f0a..c1d96581 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.server.dedicated.MinecraftDedicatedServer; import org.spongepowered.asm.mixin.Mixin; @@ -9,19 +8,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -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 cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = DGU.getCurrentlyRunningServer().getVersion(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + DGU.getCurrentlyRunningServer().getVersion(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java deleted file mode 100644 index fe505910..00000000 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.minecraft.client.sound.SoundEvent; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(SoundEvent.class) -public interface SoundAccessor { - @Accessor("id") - Identifier id(); -} diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index bf7137e6..95094eea 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -1,82 +1,20 @@ package dev.u9g.minecraftdatagenerator.util; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.TypeAdapters; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -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; -import java.io.IOException; - public class DGU { - - public static Gson gson = new GsonBuilder().registerTypeAdapterFactory(TypeAdapters.newFactory(double.class, Double.class, new TypeAdapter() { - @Override - public Number read(JsonReader in) throws IOException { - if (in.peek() == JsonToken.NULL) { - in.nextNull(); - return null; - } - return in.nextDouble(); - } - - @Override - public void write(JsonWriter out, Number value) throws IOException { - out.value(value); - } - })).create(); - - @Environment(EnvType.CLIENT) - private static MinecraftServer getCurrentlyRunningServerClient() { - return MinecraftClient.getInstance().getServer(); - } - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return getCurrentlyRunningServerClient(); - } else if (environmentType == EnvType.SERVER) { - return getCurrentlyRunningServerDedicated(); - } - throw new UnsupportedOperationException(); - } - - @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 ignored) { - } - throw new RuntimeException("Failed to translate: '" + translationKey + "'"); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } 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 diff --git a/1.10.2/src/main/resources/fabric.mod.json b/1.10.2/src/main/resources/fabric.mod.json index a73252d3..ffac96b0 100644 --- a/1.10.2/src/main/resources/fabric.mod.json +++ b/1.10.2/src/main/resources/fabric.mod.json @@ -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.10" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/1.10.2/src/main/resources/minecraft-data-generator.mixins.json b/1.10.2/src/main/resources/minecraft-data-generator.mixins.json index 4dd13158..3ed82340 100644 --- a/1.10.2/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.10.2/src/main/resources/minecraft-data-generator.mixins.json @@ -14,11 +14,8 @@ "MiningToolItemAccessor", "NoteBlockAccessor", "ReadyMixin", - "SoundAccessor", "StatusEffectAccessor" ], - "client": [ - ], "injectors": { "defaultRequire": 1 }, diff --git a/1.11.2/build.gradle b/1.11.2/build.gradle index 057916c6..87ed5b49 100644 --- a/1.11.2/build.gradle +++ b/1.11.2/build.gradle @@ -1,47 +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 = "legacy-fabric" - url = "https://maven.legacyfabric.net" +unimined.minecraft { + version "1.11.2" + + mappings { + legacyIntermediary() + legacyYarn(541) + + devFallbackNamespace "intermediary" } -} -loom { - setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar'); - customMinecraftManifest.set("https://meta.legacyfabric.net/v2/manifest/${minecraft_version}") -} + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } -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' + customPatcher(new CustomLegacyFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() } + + defaultRemapJar = true } -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' - } - } +dependencies { + implementation project(":common") } processResources { @@ -52,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.11.2/gradle.properties b/1.11.2/gradle.properties deleted file mode 100644 index ff8f56c6..00000000 --- a/1.11.2/gradle.properties +++ /dev/null @@ -1,7 +0,0 @@ -# Fabric Properties -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ -minecraft_version=1.11.2 -yarn_mappings=1.11.2+build.202206020145 -loader_version=0.14.3 -# Dependencies -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index d23c5ba2..00000000 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -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() { - } -} diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java deleted file mode 100644 index eb56ce44..00000000 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java +++ /dev/null @@ -1,55 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.biome.Biome; - -import java.util.Iterator; - -public class BiomeColors { - private static final ColorProvider GRASS_COLOR = (biome, pos) -> { - double d = MathHelper.clamp(biome.getTemperature(pos), 0.0F, 1.0F); - double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F); - return GrassColors.getColor(d, e); - }; - private static final ColorProvider FOLIAGE_COLOR = (biome, pos) -> { - double d = MathHelper.clamp(biome.getTemperature(pos), 0.0F, 1.0F); - double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F); - return FoliageColors.getColor(d, e); - }; - private static final ColorProvider WATER_COLOR = (biome, pos) -> biome.getWaterColor(); - - private static int getColor(EmptyBlockView view, BlockPos pos, ColorProvider provider) { - int i = 0; - int j = 0; - int k = 0; - - int l; - for (Iterator var6 = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); var6.hasNext(); k += l & 255) { - BlockPos.Mutable mutable = (BlockPos.Mutable) var6.next(); - l = provider.getColorAtPos(view.getBiome(mutable), mutable); - i += (l & 16711680) >> 16; - j += (l & '\uff00') >> 8; - } - - return (i / 9 & 255) << 16 | (j / 9 & 255) << 8 | k / 9 & 255; - } - - public static int getGrassColor(EmptyBlockView view, BlockPos pos) { - return getColor(view, pos, GRASS_COLOR); - } - - public static int getFoliageColor(EmptyBlockView view, BlockPos pos) { - return getColor(view, pos, FOLIAGE_COLOR); - } - - public static int getWaterColor(EmptyBlockView view, BlockPos pos) { - return getColor(view, pos, WATER_COLOR); - } - - interface ColorProvider { - int getColorAtPos(Biome biome, BlockPos pos); - } -} - diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java deleted file mode 100644 index b6819227..00000000 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.Nullable; - -public interface BlockColorable { - int method_12155(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i); -} diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java deleted file mode 100644 index 5053ac73..00000000 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java +++ /dev/null @@ -1,95 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; -import net.minecraft.block.*; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.FlowerPotBlockEntity; -import net.minecraft.item.Item; -import net.minecraft.util.collection.IdList; -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.Nullable; - -public class BlockColors { - private final IdList BlockColor2Id = new IdList<>(32); - - public BlockColors() { - } - - public static BlockColors create() { - final BlockColors blockColors = new BlockColors(); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - DoublePlantBlock.DoublePlantType doublePlantType = blockState.get(DoublePlantBlock.VARIANT); - return blockView != null && blockPos != null && (doublePlantType == DoublePlantBlock.DoublePlantType.GRASS || doublePlantType == DoublePlantBlock.DoublePlantType.FERN) ? BiomeColors.getGrassColor(blockView, blockState.get(DoublePlantBlock.HALF) == DoublePlantBlock.HalfType.UPPER ? blockPos.down() : blockPos) : -1; - }, Blocks.DOUBLE_PLANT); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - if (blockView != null && blockPos != null) { - BlockEntity blockEntity = blockView.getBlockEntity(blockPos); - if (blockEntity instanceof FlowerPotBlockEntity) { - Item item = ((FlowerPotBlockEntity) blockEntity).getItem(); - BlockState blockState2 = Block.getBlockFromItem(item).getDefaultState(); - return blockColors.method_12157(blockState2, blockView, blockPos, i); - } else { - return -1; - } - } else { - return -1; - } - }, Blocks.FLOWER_POT); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : GrassColors.getColor(0.5D, 1.0D), Blocks.GRASS); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - PlanksBlock.WoodType woodType = blockState.get(Leaves1Block.VARIANT); - if (woodType == PlanksBlock.WoodType.SPRUCE) { - return net.minecraft.client.color.world.FoliageColors.getSpruceColor(); - } else if (woodType == PlanksBlock.WoodType.BIRCH) { - return net.minecraft.client.color.world.FoliageColors.getBirchColor(); - } else { - return blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(); - } - }, Blocks.LEAVES); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.LEAVES2); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getWaterColor(blockView, blockPos) : -1, Blocks.WATER, Blocks.FLOWING_WATER); - blockColors.method_12158((blockState, blockView, blockPos, i) -> RedstoneWireBlock.method_8877(blockState.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : -1, Blocks.SUGARCANE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - int j = blockState.get(AttachedStemBlock.AGE); - int k = j * 32; - int l = 255 - j * 8; - int m = j * 4; - return k << 16 | l << 8 | m; - }, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - if (blockView != null && blockPos != null) { - return BiomeColors.getGrassColor(blockView, blockPos); - } else { - return blockState.get(TallPlantBlock.TYPE) == TallPlantBlock.GrassType.DEAD_BUSH ? 16777215 : GrassColors.getColor(0.5D, 1.0D); - } - }, Blocks.TALLGRASS); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.VINE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? 2129968 : 7455580, Blocks.LILY_PAD); - return blockColors; - } - - public int method_13410(BlockState blockState) { - BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock())); - if (blockColorable != null) { - return blockColorable.method_12155(blockState, null, null, 0); - } else { - MaterialColor materialColor = blockState.getMaterialColor(); - return materialColor != null ? materialColor.color : -1; - } - } - - public int method_12157(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i) { - BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock())); - return blockColorable == null ? -1 : blockColorable.method_12155(blockState, blockView, blockPos, i); - } - - public void method_12158(BlockColorable blockColorable, Block... blocks) { - int var4 = blocks.length; - - for (Block block : blocks) { - this.BlockColor2Id.set(blockColorable, Block.getIdByBlock(block)); - } - - } -} diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java deleted file mode 100644 index f4d20ec2..00000000 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -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; - } -} diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java deleted file mode 100644 index 0528f394..00000000 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java +++ /dev/null @@ -1,19 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -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) { - humidity *= temperature; - int i = (int) ((1.0D - temperature) * 255.0D); - int j = (int) ((1.0D - humidity) * 255.0D); - int k = j << 8 | i; - return k > colorMap.length ? -65281 : colorMap[k]; - } -} - - diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java deleted file mode 100644 index 75c9f89c..00000000 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java +++ /dev/null @@ -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; - } -} diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/SkyColor.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/SkyColor.java deleted file mode 100644 index fd0b7ae7..00000000 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/SkyColor.java +++ /dev/null @@ -1,74 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.biome.Biome; - -public class SkyColor { - public static int getSkyColor(Biome biome) { - return realSkyColor(biome.getTemperature()); - } - - private static int realSkyColor(float temperature) { - temperature /= 3.0F; - temperature = MathHelper.clamp(temperature, -1.0F, 1.0F); - return hsvToRgb(0.62222224F - temperature * 0.05F, 0.5F + temperature * 0.1F, 1.0F); - } - - public static int hsvToRgb(float hue, float saturation, float value) { - int i = (int) (hue * 6.0F) % 6; - float f = hue * 6.0F - (float) i; - float g = value * (1.0F - saturation); - float h = value * (1.0F - f * saturation); - float j = value * (1.0F - (1.0F - f) * saturation); - float k; - float l; - float m; - switch (i) { - case 0: - k = value; - l = j; - m = g; - break; - case 1: - k = h; - l = value; - m = g; - break; - case 2: - k = g; - l = value; - m = j; - break; - case 3: - k = g; - l = h; - m = value; - break; - case 4: - k = j; - l = g; - m = value; - break; - case 5: - k = value; - l = g; - m = h; - break; - default: - throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + ", " + value); - } - - int n = clamp((int) (k * 255.0F), 0, 255); - int o = clamp((int) (l * 255.0F), 0, 255); - int p = clamp((int) (m * 255.0F), 0, 255); - return n << 16 | o << 8 | p; - } - - public static int clamp(int value, int min, int max) { - if (value < min) { - return min; - } else { - return Math.min(value, max); - } - } -} diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 1453aa27..1433d785 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -2,7 +2,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.SkyColor; import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor; import net.minecraft.util.Identifier; import net.minecraft.util.registry.SimpleRegistry; @@ -23,7 +22,6 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { public static JsonObject generateBiomeInfo(SimpleRegistry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); - Identifier registryKey = registry.getIdentifier(biome); biomeDesc.addProperty("id", registry.getRawId(biome)); biomeDesc.addProperty("name", String.join("_", ((BiomeAccessor) biome).name().toLowerCase(Locale.ENGLISH).split(" "))); @@ -33,7 +31,7 @@ public static JsonObject generateBiomeInfo(SimpleRegistry reg biomeDesc.addProperty("depth", biome.getDepth()); biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", ((BiomeAccessor) biome).name()); - biomeDesc.addProperty("color", SkyColor.getSkyColor(biome)); + biomeDesc.addProperty("color", biome.getSkyColor(biome.getTemperature())); biomeDesc.addProperty("rainfall", biome.getRainfall()); return biomeDesc; diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 47cac43b..df1d5540 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -6,11 +6,14 @@ import com.google.gson.JsonPrimitive; import dev.u9g.minecraftdatagenerator.util.DGU; import dev.u9g.minecraftdatagenerator.util.Registries; -import net.minecraft.block.*; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; public class BlockCollisionShapesDataGenerator implements IDataGenerator { private static final Box ENTITY_BOX = new Box(0.0D, 0.0D, 0.0D, 1.0D, 2.0D, 1.0D); @@ -76,7 +79,7 @@ public Object addShapesFrom(Block block) { } } 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))); @@ -96,18 +99,18 @@ public JsonObject toJSON() { private record Shapes(List 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); + } } } diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 17c00e52..cb2c36ff 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -4,7 +4,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import dev.u9g.minecraftdatagenerator.Main; import dev.u9g.minecraftdatagenerator.mixin.BlockAccessor; import dev.u9g.minecraftdatagenerator.mixin.MiningToolItemAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -28,12 +27,8 @@ import java.util.Collection; 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 getItemsEffectiveForBlock(Block block) { List items = new ArrayList<>(); for (Item item : Registries.ITEMS) { diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index c89d0777..00000000 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -1,81 +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 GENERATORS = new ArrayList<>(); - private static final Logger logger = Main.LOGGER; - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new AttributesDataGenerator()); - register(new SoundsDataGenerator()); - } - - 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; - } -} diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 6aba51e0..ea880e45 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -16,7 +16,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); @NotNull Identifier registryKey = Objects.requireNonNull(Registries.STATUS_EFFECTS.getIdentifier(statusEffect)); diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java index cbfff2db..bd6cfcc9 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -6,10 +6,14 @@ import com.google.gson.JsonPrimitive; import dev.u9g.minecraftdatagenerator.util.DGU; import dev.u9g.minecraftdatagenerator.util.Registries; -import net.minecraft.enchantment.*; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentTarget; import net.minecraft.util.Identifier; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Objects; public class EnchantmentsDataGenerator implements IDataGenerator { diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index b1b24cf8..419f3246 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -4,8 +4,14 @@ import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.DGU; import dev.u9g.minecraftdatagenerator.util.Registries; -import net.minecraft.entity.*; -import net.minecraft.entity.mob.*; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.LivingEntity; +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.passive.PassiveEntity; import net.minecraft.entity.player.PlayerEntity; @@ -18,7 +24,6 @@ import java.util.Objects; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Class entityClass) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass); diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index 66c53790..a5b65ce6 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(FoodItem foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = Registries.ITEMS.getIdentifier(foodItem); diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java index 3aa51c41..dcb6c5be 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java @@ -4,8 +4,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.mixin.NoteBlockAccessor; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; -import net.minecraft.client.sound.SoundEvent; +import net.minecraft.sound.Sound; import java.util.Objects; @@ -19,10 +18,10 @@ public String getDataName() { public JsonElement generateDataJson() { JsonArray array = new JsonArray(); int i = 0; - for (SoundEvent sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) { + for (Sound sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) { JsonObject object = new JsonObject(); object.addProperty("id", i++); - object.addProperty("name", ((SoundAccessor) sound).id().getPath().split("\\.")[2]); + object.addProperty("name", sound.getId().getPath().split("\\.")[2]); array.add(object); } return array; diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 2b1a5085..36025a4d 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -5,7 +5,6 @@ import net.minecraft.client.particle.ParticleType; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(int id, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java index 32498dfa..553fbdf6 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -112,6 +112,11 @@ public JsonElement generateDataJson() { // 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); diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index 9429a29a..88e0e8a8 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -2,17 +2,14 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; -import net.minecraft.client.sound.SoundEvent; - +import net.minecraft.sound.Sound; public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(SoundEvent soundEvent) { + public static JsonObject generateSound(Sound soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", SoundEvent.REGISTRY.getRawId(soundEvent)); - soundDesc.addProperty("name", ((SoundAccessor) soundEvent).id().getPath()); + soundDesc.addProperty("id", Sound.REGISTRY.getRawId(soundEvent)); + soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; } @@ -25,7 +22,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - SoundEvent.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound))); + Sound.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 401c2c5a..3923b2e1 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -3,37 +3,30 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.BiomeColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.BlockColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock; import dev.u9g.minecraftdatagenerator.mixin.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.block.RedstoneWireBlock; +import net.minecraft.client.BlockColors; +import net.minecraft.client.color.world.FoliageColors; +import net.minecraft.client.color.world.GrassColors; import net.minecraft.util.Identifier; -import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.biome.Biome; import java.util.*; public class TintsDataGenerator implements IDataGenerator { - - private static final BlockColors blockColors = BlockColors.create(); - public static BiomeTintColors generateBiomeTintColors() { BiomeTintColors colors = new BiomeTintColors(); for (Biome biome : Registries.BIOMES) { - EmptyBlockView bv = new EmptyBlockView() { - @Override - public Biome getBiome(BlockPos pos) { - return biome; - } - }; - int biomeGrassColor = BiomeColors.getGrassColor(bv, BlockPos.ORIGIN); - int biomeFoliageColor = BiomeColors.getFoliageColor(bv, BlockPos.ORIGIN); + double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); + double e = MathHelper.clamp(biome.getRainfall(), 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); @@ -44,30 +37,29 @@ public Biome getBiome(BlockPos pos) { } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { - int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel); + int color = RedstoneWireBlock.getColorIntensity(redstoneLevel); resultColors.put(redstoneLevel, color); } return resultColors; } private static int getBlockColor(Block block) { - return blockColors.method_13410(block.getDefaultState()); + return BlockColors.create().method_13410(block.getDefaultState()); } public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); // FIXME: ? // resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); // resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); resultColors.put(Blocks.LILY_PAD, 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)); + // 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); @@ -157,8 +149,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java index 4bc3bcb9..688aa1c6 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java @@ -1,7 +1,7 @@ package dev.u9g.minecraftdatagenerator.mixin; import net.minecraft.block.NoteBlock; -import net.minecraft.client.sound.SoundEvent; +import net.minecraft.sound.Sound; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @@ -10,7 +10,7 @@ @Mixin(NoteBlock.class) public interface NoteBlockAccessor { @Accessor("TUNES") - static List TUNES() { + static List TUNES() { return null; } } diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index f5608f0a..c1d96581 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.server.dedicated.MinecraftDedicatedServer; import org.spongepowered.asm.mixin.Mixin; @@ -9,19 +8,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -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 cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = DGU.getCurrentlyRunningServer().getVersion(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + DGU.getCurrentlyRunningServer().getVersion(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java deleted file mode 100644 index fe505910..00000000 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.minecraft.client.sound.SoundEvent; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(SoundEvent.class) -public interface SoundAccessor { - @Accessor("id") - Identifier id(); -} diff --git a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index bf7137e6..95094eea 100644 --- a/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.11.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -1,82 +1,20 @@ package dev.u9g.minecraftdatagenerator.util; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.TypeAdapters; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -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; -import java.io.IOException; - public class DGU { - - public static Gson gson = new GsonBuilder().registerTypeAdapterFactory(TypeAdapters.newFactory(double.class, Double.class, new TypeAdapter() { - @Override - public Number read(JsonReader in) throws IOException { - if (in.peek() == JsonToken.NULL) { - in.nextNull(); - return null; - } - return in.nextDouble(); - } - - @Override - public void write(JsonWriter out, Number value) throws IOException { - out.value(value); - } - })).create(); - - @Environment(EnvType.CLIENT) - private static MinecraftServer getCurrentlyRunningServerClient() { - return MinecraftClient.getInstance().getServer(); - } - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return getCurrentlyRunningServerClient(); - } else if (environmentType == EnvType.SERVER) { - return getCurrentlyRunningServerDedicated(); - } - throw new UnsupportedOperationException(); - } - - @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 ignored) { - } - throw new RuntimeException("Failed to translate: '" + translationKey + "'"); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } 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 diff --git a/1.11.2/src/main/resources/fabric.mod.json b/1.11.2/src/main/resources/fabric.mod.json index 03fbafe0..ffac96b0 100644 --- a/1.11.2/src/main/resources/fabric.mod.json +++ b/1.11.2/src/main/resources/fabric.mod.json @@ -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.11" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/1.11.2/src/main/resources/minecraft-data-generator.mixins.json b/1.11.2/src/main/resources/minecraft-data-generator.mixins.json index fcdcd1a0..cd1d518d 100644 --- a/1.11.2/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.11.2/src/main/resources/minecraft-data-generator.mixins.json @@ -12,11 +12,8 @@ "MiningToolItemAccessor", "NoteBlockAccessor", "ReadyMixin", - "SoundAccessor", "StatusEffectAccessor" ], - "client": [ - ], "injectors": { "defaultRequire": 1 }, diff --git a/1.12.2/build.gradle b/1.12.2/build.gradle index 057916c6..300b1a8e 100644 --- a/1.12.2/build.gradle +++ b/1.12.2/build.gradle @@ -1,47 +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 = "legacy-fabric" - url = "https://maven.legacyfabric.net" +unimined.minecraft { + version "1.12.2" + + mappings { + legacyIntermediary() + legacyYarn(541) + + devFallbackNamespace "intermediary" } -} -loom { - setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar'); - customMinecraftManifest.set("https://meta.legacyfabric.net/v2/manifest/${minecraft_version}") -} + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } -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' + customPatcher(new CustomLegacyFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() } + + defaultRemapJar = true } -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' - } - } +dependencies { + implementation project(":common") } processResources { @@ -52,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.12.2/gradle.properties b/1.12.2/gradle.properties deleted file mode 100644 index bf25787b..00000000 --- a/1.12.2/gradle.properties +++ /dev/null @@ -1,7 +0,0 @@ -# Fabric Properties -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ -minecraft_version=1.12.2 -yarn_mappings=1.12.2+build.202206020145 -loader_version=0.14.3 -# Dependencies -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index d23c5ba2..00000000 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -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() { - } -} diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java deleted file mode 100644 index 874569b3..00000000 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java +++ /dev/null @@ -1,46 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import net.minecraft.world.biome.Biome; - -import java.util.Iterator; - -public class BiomeColors { - private static final ColorProvider GRASS_COLOR = Biome::getGrassColor; - private static final ColorProvider FOLIAGE_COLOR = Biome::getFoliageColor; - private static final ColorProvider WATER_COLOR = (biome, pos) -> biome.getWaterColor(); - - private static int getColor(BlockView view, BlockPos pos, ColorProvider provider) { - int i = 0; - int j = 0; - int k = 0; - - int l; - for (Iterator var6 = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); var6.hasNext(); k += l & 255) { - BlockPos.Mutable mutable = var6.next(); - l = provider.getColorAtPos(view.getBiome(mutable), mutable); - i += (l & 16711680) >> 16; - j += (l & '\uff00') >> 8; - } - - return (i / 9 & 255) << 16 | (j / 9 & 255) << 8 | k / 9 & 255; - } - - public static int getGrassColor(BlockView view, BlockPos pos) { - return getColor(view, pos, GRASS_COLOR); - } - - public static int getFoliageColor(BlockView view, BlockPos pos) { - return getColor(view, pos, FOLIAGE_COLOR); - } - - public static int getWaterColor(BlockView view, BlockPos pos) { - return getColor(view, pos, WATER_COLOR); - } - - interface ColorProvider { - int getColorAtPos(Biome biome, BlockPos pos); - } -} - diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java deleted file mode 100644 index 64809900..00000000 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import org.jetbrains.annotations.Nullable; - -public interface BlockColorable { - int method_12155(BlockState blockState, @Nullable BlockView blockView, @Nullable BlockPos blockPos, int i); -} diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java deleted file mode 100644 index 51bf78c8..00000000 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java +++ /dev/null @@ -1,98 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import net.minecraft.block.*; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.FlowerPotBlockEntity; -import net.minecraft.item.Item; -import net.minecraft.util.collection.IdList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -public class BlockColors { - private final IdList BlockColor2Id = new IdList<>(32); - - public BlockColors() { - } - - public static BlockColors create() { - final BlockColors blockColors = new BlockColors(); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - DoublePlantBlock.DoublePlantType doublePlantType = blockState.get(DoublePlantBlock.VARIANT); - return blockView != null && blockPos != null && - (doublePlantType == DoublePlantBlock.DoublePlantType.GRASS || doublePlantType == DoublePlantBlock.DoublePlantType.FERN) ? - BiomeColors.getGrassColor(blockView, blockState.get(DoublePlantBlock.HALF) == DoublePlantBlock.HalfType.UPPER ? blockPos.down() : blockPos) : -1; - }, Blocks.DOUBLE_PLANT); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - if (blockView != null && blockPos != null) { - BlockEntity blockEntity = blockView.getBlockEntity(blockPos); - if (blockEntity instanceof FlowerPotBlockEntity) { - Item item = ((FlowerPotBlockEntity) blockEntity).getItem(); - BlockState blockState2 = Block.getBlockFromItem(item).getDefaultState(); - return blockColors.method_12157(blockState2, blockView, blockPos, i); - } else { - return -1; - } - } else { - return -1; - } - }, Blocks.FLOWER_POT); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : GrassColors.getColor(0.5D, 1.0D), Blocks.GRASS); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - PlanksBlock.WoodType woodType = blockState.get(Leaves1Block.VARIANT); - if (woodType == PlanksBlock.WoodType.SPRUCE) { - return FoliageColors.getSpruceColor(); - } else if (woodType == PlanksBlock.WoodType.BIRCH) { - return FoliageColors.getBirchColor(); - } else { - return blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(); - } - }, Blocks.LEAVES); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.LEAVES2); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getWaterColor(blockView, blockPos) : -1, Blocks.WATER, Blocks.FLOWING_WATER); - blockColors.method_12158((blockState, blockView, blockPos, i) -> RedstoneWireBlock.method_8877(blockState.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : -1, Blocks.SUGARCANE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - int j = blockState.get(AttachedStemBlock.AGE); - int k = j * 32; - int l = 255 - j * 8; - int m = j * 4; - return k << 16 | l << 8 | m; - }, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); -// blockColors.method_12158((blockState, blockView, blockPos, i) -> { -// if (blockView != null && blockPos != null) { -// return BiomeColors.getGrassColor(blockView, blockPos); -// } else { -// return blockState.get(TallPlantBlock.TYPE) == TallPlantBlock.GrassType.DEAD_BUSH ? 16777215 : GrassColors.getColor(0.5D, 1.0D); -// } -// }, Blocks.TALLGRASS); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : blockState.get(TallPlantBlock.TYPE) == TallPlantBlock.GrassType.DEAD_BUSH ? 16777215 : GrassColors.getColor(0.5D, 1.0D), Blocks.TALLGRASS); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.VINE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? 2129968 : 7455580, Blocks.LILY_PAD); - return blockColors; - } - - public int method_13410(BlockState blockState, World world, BlockPos blockPos) { - BlockColorable blockColorable = BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock())); - if (blockColorable != null) { - return blockColorable.method_12155(blockState, null, null, 0); - } else { - MaterialColor materialColor = blockState.getMaterialColor(world, blockPos); - return materialColor != null ? materialColor.color : -1; - } - } - - public int method_12157(BlockState blockState, @Nullable BlockView blockView, @Nullable BlockPos blockPos, int i) { - net.minecraft.client.BlockColorable blockColorable = (net.minecraft.client.BlockColorable) this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock())); - return blockColorable == null ? -1 : blockColorable.method_12155(blockState, blockView, blockPos, i); - } - - public void method_12158(BlockColorable blockColorable, Block... blocks) { - int var4 = blocks.length; - - for (Block block : blocks) { - this.BlockColor2Id.set(blockColorable, Block.getIdByBlock(block)); - } - } -} diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java deleted file mode 100644 index 1d3f9480..00000000 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java +++ /dev/null @@ -1,36 +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; - } - - private static int getColor(double temperature, double humidity) { - int i = (int) ((1.0 - temperature) * 255.0); - int j = (int) ((1.0 - (humidity *= temperature)) * 255.0); - return colorMap[j << 8 | i]; - } - - public static int getSpruceColor() { - return 0x619961; - } - - public static int getBirchColor() { - return 8431445; - } - - public static int getDefaultColor() { - return 4764952; - } - - public static int getFoliageColor(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); - double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); - return getColor(d, e); - } -} diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java deleted file mode 100644 index 9d653723..00000000 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java +++ /dev/null @@ -1,29 +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 j = (int) ((1.0 - (humidity *= temperature)) * 255.0); - int i = (int) ((1.0 - temperature) * 255.0); - int k = j << 8 | i; - if (k > colorMap.length) { - return -65281; - } - return colorMap[k]; - } - - public static int getGrassColor(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); - double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); - return getColor(d, e); - } -} - diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java deleted file mode 100644 index f733e90f..00000000 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java +++ /dev/null @@ -1,25 +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 0xFF000000 | k << 16 | l << 8 | m; - } -} diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index f6870455..ba757ead 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -78,7 +78,7 @@ public Object addShapesFrom(Block block) { } } if (indexesOfBoxesInTheShapesCache.stream().distinct().count() < 2) { - return indexesOfBoxesInTheShapesCache.get(0); + return indexesOfBoxesInTheShapesCache.getFirst(); } else { JsonArray shapeIndexes = new JsonArray(); indexesOfBoxesInTheShapesCache.forEach(shapeIndexes::add); @@ -98,18 +98,18 @@ public JsonObject toJSON() { private record Shapes(List 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); + } } } diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index cdc6711d..ef5406f2 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -3,7 +3,6 @@ import com.google.common.base.CaseFormat; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.Main; import dev.u9g.minecraftdatagenerator.mixin.BlockAccessor; import dev.u9g.minecraftdatagenerator.mixin.MiningToolItemAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -27,12 +26,8 @@ import java.util.Collection; 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 getItemsEffectiveForBlock(Block block) { List items = new ArrayList<>(); for (Item item : Registries.ITEMS) { diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index c89d0777..00000000 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -1,81 +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 GENERATORS = new ArrayList<>(); - private static final Logger logger = Main.LOGGER; - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new AttributesDataGenerator()); - register(new SoundsDataGenerator()); - } - - 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; - } -} diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 6aba51e0..ea880e45 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -16,7 +16,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); @NotNull Identifier registryKey = Objects.requireNonNull(Registries.STATUS_EFFECTS.getIdentifier(statusEffect)); diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 5528e0b7..4c2fd2ea 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -24,7 +24,6 @@ import java.util.Objects; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Class entityClass) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass); diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index 66c53790..a5b65ce6 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(FoodItem foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = Registries.ITEMS.getIdentifier(foodItem); diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java index 3aa51c41..dcb6c5be 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java @@ -4,8 +4,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.mixin.NoteBlockAccessor; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; -import net.minecraft.client.sound.SoundEvent; +import net.minecraft.sound.Sound; import java.util.Objects; @@ -19,10 +18,10 @@ public String getDataName() { public JsonElement generateDataJson() { JsonArray array = new JsonArray(); int i = 0; - for (SoundEvent sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) { + for (Sound sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) { JsonObject object = new JsonObject(); object.addProperty("id", i++); - object.addProperty("name", ((SoundAccessor) sound).id().getPath().split("\\.")[2]); + object.addProperty("name", sound.getId().getPath().split("\\.")[2]); array.add(object); } return array; diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 2b1a5085..36025a4d 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -5,7 +5,6 @@ import net.minecraft.client.particle.ParticleType; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(int id, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java index 32498dfa..553fbdf6 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -112,6 +112,11 @@ public JsonElement generateDataJson() { // 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); diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index 2fced082..88e0e8a8 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -2,18 +2,14 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; -import net.minecraft.client.sound.SoundEvent; - - +import net.minecraft.sound.Sound; public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(SoundEvent soundEvent) { + public static JsonObject generateSound(Sound soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", SoundEvent.REGISTRY.getRawId(soundEvent)); - soundDesc.addProperty("name", ((SoundAccessor) soundEvent).id().getPath()); + soundDesc.addProperty("id", Sound.REGISTRY.getRawId(soundEvent)); + soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; } @@ -26,7 +22,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - SoundEvent.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound))); + Sound.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 72c79511..72fc3d93 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -2,32 +2,32 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.BlockColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.GrassColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock; import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; import dev.u9g.minecraftdatagenerator.util.Registries; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.RedstoneWireBlock; +import net.minecraft.client.BlockColors; +import net.minecraft.client.color.world.FoliageColors; +import net.minecraft.client.color.world.GrassColors; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.biome.Biome; import java.util.*; public class TintsDataGenerator implements IDataGenerator { - - private static final BlockColors blockColors = BlockColors.create(); - public static BiomeTintColors generateBiomeTintColors() { BiomeTintColors colors = new BiomeTintColors(); for (Biome biome : Registries.BIOMES) { - int biomeGrassColor = GrassColors.getGrassColor(biome); - int biomeFoliageColor = FoliageColors.getFoliageColor(biome); + double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); + double e = MathHelper.clamp(biome.getRainfall(), 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,30 +38,29 @@ public static BiomeTintColors generateBiomeTintColors() { } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { - int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel); + int color = RedstoneWireBlock.getColorIntensity(redstoneLevel); resultColors.put(redstoneLevel, color); } return resultColors; } private static int getBlockColor(Block block) { - return blockColors.method_13410(block.getDefaultState(), DGU.getWorld(), BlockPos.ORIGIN); + return BlockColors.create().method_13410(block.getDefaultState(), DGU.getWorld(), BlockPos.ORIGIN); } public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); // FIXME: ? // resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); // resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); resultColors.put(Blocks.LILY_PAD, 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)); + // 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); @@ -152,8 +151,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java index 4bc3bcb9..688aa1c6 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java @@ -1,7 +1,7 @@ package dev.u9g.minecraftdatagenerator.mixin; import net.minecraft.block.NoteBlock; -import net.minecraft.client.sound.SoundEvent; +import net.minecraft.sound.Sound; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @@ -10,7 +10,7 @@ @Mixin(NoteBlock.class) public interface NoteBlockAccessor { @Accessor("TUNES") - static List TUNES() { + static List TUNES() { return null; } } diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index f5608f0a..c1d96581 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.server.dedicated.MinecraftDedicatedServer; import org.spongepowered.asm.mixin.Mixin; @@ -9,19 +8,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -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 cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = DGU.getCurrentlyRunningServer().getVersion(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + DGU.getCurrentlyRunningServer().getVersion(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java deleted file mode 100644 index fe505910..00000000 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.minecraft.client.sound.SoundEvent; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(SoundEvent.class) -public interface SoundAccessor { - @Accessor("id") - Identifier id(); -} diff --git a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index bf7137e6..95094eea 100644 --- a/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.12.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -1,82 +1,20 @@ package dev.u9g.minecraftdatagenerator.util; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.TypeAdapters; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -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; -import java.io.IOException; - public class DGU { - - public static Gson gson = new GsonBuilder().registerTypeAdapterFactory(TypeAdapters.newFactory(double.class, Double.class, new TypeAdapter() { - @Override - public Number read(JsonReader in) throws IOException { - if (in.peek() == JsonToken.NULL) { - in.nextNull(); - return null; - } - return in.nextDouble(); - } - - @Override - public void write(JsonWriter out, Number value) throws IOException { - out.value(value); - } - })).create(); - - @Environment(EnvType.CLIENT) - private static MinecraftServer getCurrentlyRunningServerClient() { - return MinecraftClient.getInstance().getServer(); - } - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return getCurrentlyRunningServerClient(); - } else if (environmentType == EnvType.SERVER) { - return getCurrentlyRunningServerDedicated(); - } - throw new UnsupportedOperationException(); - } - - @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 ignored) { - } - throw new RuntimeException("Failed to translate: '" + translationKey + "'"); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } 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 diff --git a/1.12.2/src/main/resources/fabric.mod.json b/1.12.2/src/main/resources/fabric.mod.json index 57c11135..ffac96b0 100644 --- a/1.12.2/src/main/resources/fabric.mod.json +++ b/1.12.2/src/main/resources/fabric.mod.json @@ -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.12" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/1.12.2/src/main/resources/minecraft-data-generator.mixins.json b/1.12.2/src/main/resources/minecraft-data-generator.mixins.json index fcdcd1a0..cd1d518d 100644 --- a/1.12.2/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.12.2/src/main/resources/minecraft-data-generator.mixins.json @@ -12,11 +12,8 @@ "MiningToolItemAccessor", "NoteBlockAccessor", "ReadyMixin", - "SoundAccessor", "StatusEffectAccessor" ], - "client": [ - ], "injectors": { "defaultRequire": 1 }, diff --git a/1.13/build.gradle b/1.13/build.gradle index 057916c6..1048f501 100644 --- a/1.13/build.gradle +++ b/1.13/build.gradle @@ -1,47 +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 = "legacy-fabric" - url = "https://maven.legacyfabric.net" +unimined.minecraft { + version "1.13.2" + + mappings { + legacyIntermediary() + legacyYarn(541) + + devFallbackNamespace "intermediary" } -} -loom { - setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar'); - customMinecraftManifest.set("https://meta.legacyfabric.net/v2/manifest/${minecraft_version}") -} + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } -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' + customPatcher(new CustomLegacyFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() } + + defaultRemapJar = true } -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' - } - } +dependencies { + implementation project(":common") } processResources { @@ -52,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.13/gradle.properties b/1.13/gradle.properties deleted file mode 100644 index 495d46f4..00000000 --- a/1.13/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Fabric Properties -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ -minecraft_version=1.13.2 -yarn_mappings=1.13.2+build.202206020145 -loader_version=0.14.3 -# Dependencies -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ -fabric_version = 1.4.2+1.8.9 diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index d23c5ba2..00000000 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -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() { - } -} diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java deleted file mode 100644 index a661211e..00000000 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java +++ /dev/null @@ -1,49 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.RenderBlockView; -import net.minecraft.world.biome.Biome; - -import java.util.Iterator; - -public class BiomeColors { - private static final ColorProvider field_21146 = Biome::getGrassColor; - private static final ColorProvider field_21147 = Biome::getFoliageColor; - private static final ColorProvider field_21148 = (biome, blockPos) -> biome.getWaterColor(); - private static final ColorProvider field_21149 = (biome, blockPos) -> biome.method_16447(); - - private static int method_19682(RenderBlockView renderBlockView, BlockPos blockPos, ColorProvider colorProvider) { - int i = 0; - int j = 0; - int k = 0; - int l = MinecraftClient.getInstance().options.field_19979; - int m = (l * 2 + 1) * (l * 2 + 1); - - int n; - for (Iterator var8 = BlockPos.mutableIterate(blockPos.getX() - l, blockPos.getY(), blockPos.getZ() - l, blockPos.getX() + l, blockPos.getY(), blockPos.getZ() + l).iterator(); var8.hasNext(); k += n & 255) { - BlockPos.Mutable mutable = var8.next(); - n = colorProvider.getColor(renderBlockView.method_8577(mutable), mutable); - i += (n & 16711680) >> 16; - j += (n & '\uff00') >> 8; - } - - return (i / m & 255) << 16 | (j / m & 255) << 8 | k / m & 255; - } - - public static int method_19681(RenderBlockView renderBlockView, BlockPos blockPos) { - return method_19682(renderBlockView, blockPos, field_21146); - } - - public static int method_19684(RenderBlockView renderBlockView, BlockPos blockPos) { - return method_19682(renderBlockView, blockPos, field_21147); - } - - public static int method_19686(RenderBlockView renderBlockView, BlockPos blockPos) { - return method_19682(renderBlockView, blockPos, field_21148); - } - - interface ColorProvider { - int getColor(Biome biome, BlockPos blockPos); - } -} diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java deleted file mode 100644 index f6baf129..00000000 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.RenderBlockView; -import org.jetbrains.annotations.Nullable; - -public interface BlockColorable { - int getColor(BlockState state, @Nullable RenderBlockView renderView, @Nullable BlockPos pos, int i); -} diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java deleted file mode 100644 index a372bf64..00000000 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java +++ /dev/null @@ -1,65 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import net.minecraft.block.*; -import net.minecraft.class_2181; -import net.minecraft.class_3721; -import net.minecraft.util.collection.IdList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.RenderBlockView; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -public class BlockColors { - private final IdList BlockColor2Id = new IdList<>(32); - - public BlockColors() { - } - - public static BlockColors create() { - BlockColors blockColors = new BlockColors(); - blockColors.method_12158((blockState, renderBlockView, blockPos, i) -> renderBlockView != null && blockPos != null ? BiomeColors.method_19681(renderBlockView, blockState.getProperty(class_3721.field_18472) == class_2181.field_9374 ? blockPos.down() : blockPos) : -1, Blocks.LARGE_FERN, Blocks.TALL_GRASS); - blockColors.method_12158((blockState, renderBlockView, blockPos, i) -> renderBlockView != null && blockPos != null ? BiomeColors.method_19681(renderBlockView, blockPos) : GrassColors.getColor(0.5D, 1.0D), Blocks.GRASS_BLOCK, Blocks.FERN, Blocks.GRASS, Blocks.POTTED_FERN); - blockColors.method_12158((blockState, renderBlockView, blockPos, i) -> net.minecraft.client.color.world.FoliageColors.getSpruceColor(), Blocks.SPRUCE_LEAVES); - blockColors.method_12158((blockState, renderBlockView, blockPos, i) -> net.minecraft.client.color.world.FoliageColors.getBirchColor(), Blocks.BIRCH_LEAVES); - blockColors.method_12158((blockState, renderBlockView, blockPos, i) -> renderBlockView != null && blockPos != null ? BiomeColors.method_19684(renderBlockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.OAK_LEAVES, Blocks.JUNGLE_LEAVES, Blocks.ACACIA_LEAVES, Blocks.DARK_OAK_LEAVES, Blocks.VINE); - blockColors.method_12158((blockState, renderBlockView, blockPos, i) -> renderBlockView != null && blockPos != null ? BiomeColors.method_19686(renderBlockView, blockPos) : -1, Blocks.WATER, Blocks.BUBBLE_COLUMN, Blocks.CAULDRON); - blockColors.method_12158((blockState, renderBlockView, blockPos, i) -> RedstoneWireBlock.method_8877(blockState.getProperty(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE); - blockColors.method_12158((blockState, renderBlockView, blockPos, i) -> renderBlockView != null && blockPos != null ? BiomeColors.method_19681(renderBlockView, blockPos) : -1, Blocks.SUGAR_CANE); - blockColors.method_12158((blockState, renderBlockView, blockPos, i) -> 14731036, Blocks.ATTACHED_MELON_STEM, Blocks.ATTACHED_PUMPKIN_STEM); - blockColors.method_12158((blockState, renderBlockView, blockPos, i) -> { - int j = blockState.getProperty(AttachedStemBlock.field_18518); - int k = j * 32; - int l = 255 - j * 8; - int m = j * 4; - return k << 16 | l << 8 | m; - }, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.method_12158((blockState, renderBlockView, blockPos, i) -> renderBlockView != null && blockPos != null ? 2129968 : 7455580, Blocks.LILY_PAD); - return blockColors; - } - - public int method_13410(BlockState blockState, World world, BlockPos blockPos) { - BlockColorable blockColorable = this.BlockColor2Id.fromId(Registry.BLOCK.getRawId(blockState.getBlock())); - if (blockColorable != null) { - return blockColorable.getColor(blockState, null, null, 0); - } else { - MaterialColor materialColor = blockState.method_16892(world, blockPos); - return materialColor != null ? materialColor.color : -1; - } - } - - public int method_18332(BlockState blockState, @Nullable RenderBlockView renderBlockView, @Nullable BlockPos blockPos, int i) { - BlockColorable blockColorable = this.BlockColor2Id.fromId(Registry.BLOCK.getRawId(blockState.getBlock())); - return blockColorable == null ? -1 : blockColorable.getColor(blockState, renderBlockView, blockPos, i); - } - - public void method_12158(BlockColorable blockColorable, Block... blocks) { - int var4 = blocks.length; - - for (Block block : blocks) { - this.BlockColor2Id.set(blockColorable, Registry.BLOCK.getRawId(block)); - } - - } -} - diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java deleted file mode 100644 index 1d3f9480..00000000 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java +++ /dev/null @@ -1,36 +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; - } - - private static int getColor(double temperature, double humidity) { - int i = (int) ((1.0 - temperature) * 255.0); - int j = (int) ((1.0 - (humidity *= temperature)) * 255.0); - return colorMap[j << 8 | i]; - } - - public static int getSpruceColor() { - return 0x619961; - } - - public static int getBirchColor() { - return 8431445; - } - - public static int getDefaultColor() { - return 4764952; - } - - public static int getFoliageColor(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); - double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); - return getColor(d, e); - } -} diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java deleted file mode 100644 index 9d653723..00000000 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java +++ /dev/null @@ -1,29 +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 j = (int) ((1.0 - (humidity *= temperature)) * 255.0); - int i = (int) ((1.0 - temperature) * 255.0); - int k = j << 8 | i; - if (k > colorMap.length) { - return -65281; - } - return colorMap[k]; - } - - public static int getGrassColor(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); - double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); - return getColor(d, e); - } -} - diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java deleted file mode 100644 index f733e90f..00000000 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java +++ /dev/null @@ -1,25 +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 0xFF000000 | k << 16 | l << 8 | m; - } -} diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 573ffce4..7aa4b763 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -38,8 +38,8 @@ public JsonObject generateDataJson() { } private static class BlockShapesCache { - public final Map uniqueBlockShapes = new HashMap<>(); - public final Map> blockCollisionShapes = new HashMap<>(); + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); private int lastCollisionShapeId = 0; public void processBlock(Block block) { @@ -68,7 +68,7 @@ public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { long distinctShapesCount = blockCollisions.stream().distinct().count(); JsonElement blockCollision; if (distinctShapesCount == 1L) { - blockCollision = new JsonPrimitive(blockCollisions.get(0)); + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); } else { blockCollision = new JsonArray(); for (int collisionId : blockCollisions) { diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index d9d29c7a..97ed20c7 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -3,7 +3,6 @@ import com.google.common.base.CaseFormat; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.Main; import dev.u9g.minecraftdatagenerator.mixin.MiningToolItemAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; @@ -26,13 +25,9 @@ import java.util.Collection; import java.util.List; import java.util.Objects; -import java.util.logging.Logger; import java.util.stream.Collectors; public class BlocksDataGenerator implements IDataGenerator { - - private static final Logger logger = Main.LOGGER; - private static List getItemsEffectiveForBlock(Block block) { return Registry.ITEM.stream() .filter(item -> item instanceof ToolItem) @@ -81,16 +76,16 @@ private static > JsonObject generateStateProperty(Proper return propertyObject; } - public static JsonObject generateBlock(Registry blockRegistry, Block block) { + public static JsonObject generateBlock(Block block) { JsonObject blockDesc = new JsonObject(); List blockStates = block.getStateManager().getBlockStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = blockRegistry.getId(block); + Identifier registryKey = Registry.BLOCK.getId(block); String localizationKey = block.getTranslationKey(); List effectiveTools = getItemsEffectiveForBlock(block); - blockDesc.addProperty("id", blockRegistry.getRawId(block)); + blockDesc.addProperty("id", Registry.BLOCK.getRawId(block)); blockDesc.addProperty("name", Objects.requireNonNull(registryKey).getPath()); blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); @@ -112,8 +107,8 @@ public static JsonObject generateBlock(Registry blockRegistry, Block bloc blockDesc.addProperty("filterLight", block.getLightSubtracted(block.getDefaultState(), EmptyBlockView.INSTANCE, BlockPos.ORIGIN)); blockDesc.addProperty("defaultState", Block.getRawIdFromState(defaultState)); - blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.get(0))); - blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.get(blockStates.size() - 1))); + blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.getFirst())); + blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.getLast())); JsonArray stateProperties = new JsonArray(); for (Property property : block.getStateManager().getProperties()) { stateProperties.add(generateStateProperty(property)); @@ -136,7 +131,7 @@ public JsonArray generateDataJson() { JsonArray resultBlocksArray = new JsonArray(); Registry blockRegistry = Registry.BLOCK; for (Block block : (Iterable) blockRegistry) { - resultBlocksArray.add(generateBlock(blockRegistry, block)); + resultBlocksArray.add(generateBlock(block)); } return resultBlocksArray; } diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index 40660b6c..00000000 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -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 GENERATORS = new ArrayList<>(); - private static final Logger logger = Main.LOGGER; - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new SoundsDataGenerator()); - } - - 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; - } -} diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 33d93eb2..3ceb1045 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -16,7 +16,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); @NotNull Identifier registryKey = Objects.requireNonNull(registry.getId(statusEffect)); diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index d2db88de..b1fc0395 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -24,7 +24,6 @@ import java.util.Objects; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getId(entityType); diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index 7ae7adfd..9ae80460 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -12,7 +12,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(Registry registry, FoodItem foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = registry.getId(foodItem); diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 20f0b729..9ceabf1d 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -9,12 +9,11 @@ import java.util.Objects; public class ParticlesDataGenerator implements IDataGenerator { - - public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { + public static JsonObject generateParticleType(ParticleType particleType) { JsonObject effectDesc = new JsonObject(); - Identifier registryKey = registry.getId(particleType); + Identifier registryKey = Registry.PARTICLE_TYPE.getId(particleType); - effectDesc.addProperty("id", registry.getRawId(particleType)); + effectDesc.addProperty("id", Registry.PARTICLE_TYPE.getRawId(particleType)); effectDesc.addProperty("name", Objects.requireNonNull(registryKey).getPath()); return effectDesc; } @@ -24,13 +23,12 @@ public String getDataName() { return "particles"; } + @SuppressWarnings("unchecked") @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - Registry> particleTypeRegistry = Registry.PARTICLE_TYPE; - for (ParticleType particleType : (Iterable) particleTypeRegistry) { - resultsArray.add(generateParticleType(particleTypeRegistry, particleType)); - } + Registry.PARTICLE_TYPE.forEach(particleType -> + resultsArray.add(generateParticleType((ParticleType) particleType))); return resultsArray; } } diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java index 5e4587dd..5017a289 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -118,4 +118,9 @@ public JsonElement generateDataJson() { // return finalObj; return JsonNull.INSTANCE; } + + @Override + public boolean isEnabled() { + return false; // TODO: Implement this + } } diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index a6f36606..9fe0343f 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -2,18 +2,15 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; -import net.minecraft.client.sound.SoundEvent; +import net.minecraft.sound.Sound; import net.minecraft.util.registry.Registry; - public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(Registry registry, SoundEvent soundEvent) { + public static JsonObject generateSound(Registry registry, Sound soundEvent) { JsonObject soundDesc = new JsonObject(); soundDesc.addProperty("id", registry.getRawId(soundEvent)); - soundDesc.addProperty("name", ((SoundAccessor)soundEvent).id().getPath()); + soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; } @@ -26,8 +23,8 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - Registry soundEventRegistry = Registry.SOUND_EVENT; - soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, (SoundEvent) sound))); + Registry soundEventRegistry = Registry.SOUND_EVENT; + soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, (Sound) sound))); return resultsArray; } } diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 07935d7f..f9fb265a 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -2,28 +2,30 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.BlockColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.GrassColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.RedstoneWireBlock; +import net.minecraft.client.BlockColors; +import net.minecraft.client.color.world.FoliageColors; +import net.minecraft.client.color.world.GrassColors; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; import java.util.*; public class TintsDataGenerator implements IDataGenerator { - public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { BiomeTintColors colors = new BiomeTintColors(); for (Biome biome : (Iterable) biomeRegistry) { - int biomeGrassColor = GrassColors.getGrassColor(biome); - int biomeFoliageColor = FoliageColors.getFoliageColor(biome); + double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); + double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); + + int biomeGrassColor = GrassColors.getColor(d, e); + int biomeFoliageColor = FoliageColors.getColor(d, e); int biomeWaterColor = biome.getWaterColor(); colors.grassColoursMap.computeIfAbsent(biomeGrassColor, k -> new ArrayList<>()).add(biome); @@ -34,33 +36,32 @@ public static BiomeTintColors generateBiomeTintColors(Registry biomeRegis } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { - int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel); + int color = RedstoneWireBlock.getColorIntensity(redstoneLevel); resultColors.put(redstoneLevel, color); } return resultColors; } - private static int getBlockColor(Block block, BlockColors blockColors) { - return blockColors.method_13410(block.getDefaultState(), DGU.getWorld(), BlockPos.ORIGIN); + private static int getBlockColor(Block block) { + return BlockColors.create().method_13410(block.getDefaultState(), DGU.getWorld(), BlockPos.ORIGIN); } public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors)); - 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.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors)); + resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); return resultColors; } @@ -151,8 +152,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index f5608f0a..c1d96581 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.server.dedicated.MinecraftDedicatedServer; import org.spongepowered.asm.mixin.Mixin; @@ -9,19 +8,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -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 cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = DGU.getCurrentlyRunningServer().getVersion(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + DGU.getCurrentlyRunningServer().getVersion(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java deleted file mode 100644 index fe505910..00000000 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.minecraft.client.sound.SoundEvent; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(SoundEvent.class) -public interface SoundAccessor { - @Accessor("id") - Identifier id(); -} diff --git a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index 4ce9292c..96e72af5 100644 --- a/1.13/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.13/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -1,10 +1,6 @@ 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.MinecraftClient; -import net.minecraft.client.resource.language.I18n; import net.minecraft.item.ItemStack; import net.minecraft.item.Itemable; import net.minecraft.server.MinecraftServer; @@ -14,48 +10,13 @@ import org.jetbrains.annotations.NotNull; public class DGU { - - private static final Language language = Language.getInstance(); - - @Environment(EnvType.CLIENT) - private static MinecraftServer getCurrentlyRunningServerClient() { - return MinecraftClient.getInstance().getServer(); - } - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return getCurrentlyRunningServerClient(); - } else if (environmentType == EnvType.SERVER) { - return getCurrentlyRunningServerDedicated(); - } - throw new UnsupportedOperationException(); - } - - @Environment(EnvType.CLIENT) - private static String translateTextClient(String translationKey) { - return I18n.translate(translationKey); - } - - private static String translateTextFallback(String translationKey) { - try { - return language.translate(translationKey); - } catch (Exception ignored) { - } - throw new RuntimeException("Failed to translate: '" + translationKey + "'"); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } public static String translateText(String translationKey) { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return translateTextClient(translationKey); - } - return translateTextFallback(translationKey); + return Language.getInstance().translate(translationKey); } @NotNull diff --git a/1.13/src/main/resources/fabric.mod.json b/1.13/src/main/resources/fabric.mod.json index 1bd022a0..ffac96b0 100644 --- a/1.13/src/main/resources/fabric.mod.json +++ b/1.13/src/main/resources/fabric.mod.json @@ -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.13" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/1.13/src/main/resources/minecraft-data-generator.mixins.json b/1.13/src/main/resources/minecraft-data-generator.mixins.json index 1024905e..12957a17 100644 --- a/1.13/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.13/src/main/resources/minecraft-data-generator.mixins.json @@ -6,11 +6,8 @@ "mixins": [ "MiningToolItemAccessor", "ReadyMixin", - "SoundAccessor", "StatusEffectAccessor" ], - "client": [ - ], "injectors": { "defaultRequire": 1 }, diff --git a/1.14/build.gradle b/1.14/build.gradle index d7f2e703..6d2f96b7 100644 --- a/1.14/build.gradle +++ b/1.14/build.gradle @@ -1,15 +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' } -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +unimined.minecraft { + version "1.14" + + mappings { + intermediary() + yarnv1(21) + + devFallbackNamespace "intermediary" + } + + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } + + customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() + } - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + defaultRemapJar = true +} + +dependencies { + implementation project(":common") } processResources { @@ -20,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.14/gradle.properties b/1.14/gradle.properties deleted file mode 100644 index 8986e709..00000000 --- a/1.14/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.14 -yarn_mappings=1.14+build.21 -loader_version=0.13.3 -# Dependencies -# check this on https://modmuss50.me/fabric.html -fabric_version=0.3.0-pre+build.156 diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index 52a20201..00000000 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -1,14 +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() { - - } -} diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java deleted file mode 100644 index f1068ebd..00000000 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java +++ /dev/null @@ -1,36 +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) { - int i = (int) ((1.0 - temperature) * 255.0); - int j = (int) ((1.0 - (humidity *= temperature)) * 255.0); - return colorMap[j << 8 | i]; - } - - public static int getSpruceColor() { - return 0x619961; - } - - public static int getBirchColor() { - return 8431445; - } - - public static int getDefaultColor() { - return 4764952; - } - - public static int getFoliageColor(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); - double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); - return getColor(d, e); - } -} diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java deleted file mode 100644 index 91270912..00000000 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java +++ /dev/null @@ -1,29 +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[] is) { - colorMap = is; - } - - public static int getColor(double d, double e) { - int j = (int) ((1.0 - (e *= d)) * 255.0); - int i = (int) ((1.0 - d) * 255.0); - int k = j << 8 | i; - if (k > colorMap.length) { - return -65281; - } - return colorMap[k]; - } - - public static int getGrassColorAt(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); - double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); - return getColor(d, e); - } -} - diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java deleted file mode 100644 index f733e90f..00000000 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java +++ /dev/null @@ -1,25 +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 0xFF000000 | k << 16 | l << 8 | m; - } -} diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index f7c4d666..bbaccfaf 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -10,7 +10,6 @@ import java.util.Objects; public class BiomesDataGenerator implements IDataGenerator { - private static String guessBiomeDimensionFromCategory(Biome biome) { return switch (biome.getCategory()) { case NETHER -> "nether"; diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 6f0d2d43..8c96da91 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -37,8 +37,8 @@ public JsonObject generateDataJson() { } private static class BlockShapesCache { - public final Map uniqueBlockShapes = new HashMap<>(); - public final Map> blockCollisionShapes = new HashMap<>(); + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); private int lastCollisionShapeId = 0; public void processBlock(Block block) { @@ -67,7 +67,7 @@ public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { long distinctShapesCount = blockCollisions.stream().distinct().count(); JsonElement blockCollision; if (distinctShapesCount == 1L) { - blockCollision = new JsonPrimitive(blockCollisions.get(0)); + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); } else { blockCollision = new JsonArray(); for (int collisionId : blockCollisions) { diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 6c47c0e2..e30871ec 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -3,7 +3,6 @@ import com.google.common.base.CaseFormat; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.Main; import dev.u9g.minecraftdatagenerator.mixin.MiningToolItemAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.block.AirBlock; @@ -29,13 +28,9 @@ import java.util.Collection; import java.util.List; import java.util.Objects; -import java.util.logging.Logger; import java.util.stream.Collectors; public class BlocksDataGenerator implements IDataGenerator { - - private static final Logger logger = Main.LOGGER; - private static List getItemsEffectiveForBlock(Block block) { return Registry.ITEM.stream() .filter(item -> item instanceof MiningToolItem) @@ -90,16 +85,16 @@ private static > JsonObject generateStateProperty(Proper return propertyObject; } - public static JsonObject generateBlock(Registry blockRegistry, Block block) { + public static JsonObject generateBlock(Block block) { JsonObject blockDesc = new JsonObject(); List blockStates = block.getStateFactory().getStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = blockRegistry.getId(block); + Identifier registryKey = Registry.BLOCK.getId(block); String localizationKey = block.getTranslationKey(); List effectiveTools = getItemsEffectiveForBlock(block); - blockDesc.addProperty("id", blockRegistry.getRawId(block)); + blockDesc.addProperty("id", Registry.BLOCK.getRawId(block)); blockDesc.addProperty("name", Objects.requireNonNull(registryKey).getPath()); blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); @@ -121,8 +116,8 @@ public static JsonObject generateBlock(Registry blockRegistry, Block bloc blockDesc.addProperty("filterLight", block.getLightSubtracted(block.getDefaultState(), EmptyBlockView.INSTANCE, BlockPos.ORIGIN)); blockDesc.addProperty("defaultState", Block.getRawIdFromState(defaultState)); - blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.get(0))); - blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.get(blockStates.size() - 1))); + blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.getFirst())); + blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.getLast())); JsonArray stateProperties = new JsonArray(); for (Property property : block.getStateFactory().getProperties()) { stateProperties.add(generateStateProperty(property)); @@ -149,9 +144,8 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultBlocksArray = new JsonArray(); - Registry blockRegistry = Registry.BLOCK; - blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, block))); + Registry.BLOCK.forEach(block -> resultBlocksArray.add(generateBlock(block))); return resultBlocksArray; } } diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index 40660b6c..00000000 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -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 GENERATORS = new ArrayList<>(); - private static final Logger logger = Main.LOGGER; - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new SoundsDataGenerator()); - } - - 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; - } -} diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 87620c01..52382cd3 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -15,7 +15,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getId(statusEffect); diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java index 3df0725e..e6158649 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -16,19 +16,6 @@ public class EnchantmentsDataGenerator implements IDataGenerator { private static final ImmutableMap ENCHANTMENT_TARGET_NAMES = ImmutableMap.builder() - .put(EnchantmentTarget.ARMOR, "armor") - .put(EnchantmentTarget.ARMOR_FEET, "armor_feet") - .put(EnchantmentTarget.ARMOR_LEGS, "armor_legs") - .put(EnchantmentTarget.ARMOR_CHEST, "armor_chest") - .put(EnchantmentTarget.ARMOR_HEAD, "armor_head") - .put(EnchantmentTarget.WEAPON, "weapon") - .put(EnchantmentTarget.DIGGER, "digger") - .put(EnchantmentTarget.FISHING_ROD, "fishing_rod") - .put(EnchantmentTarget.TRIDENT, "trident") - .put(EnchantmentTarget.BREAKABLE, "breakable") - .put(EnchantmentTarget.BOW, "bow") - .put(EnchantmentTarget.WEARABLE, "wearable") - .put(EnchantmentTarget.CROSSBOW, "crossbow") .put(EnchantmentTarget.ALL, "vanishable") // according to VanishingCurseEnchantment .build(); diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 1ab7c94d..f14df2c6 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -2,7 +2,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -18,11 +17,9 @@ import net.minecraft.util.registry.Registry; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.ParameterizedType; import java.util.Objects; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getId(entityType); @@ -47,17 +44,11 @@ public static JsonObject generateEntity(Registry> entityRegistry, private static String getCategoryFrom(@NotNull EntityType entityType) { if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities - Class entityClazz = null; - try { - for (var field : EntityType.class.getFields()) - if (entityType == field.get(EntityType.class)) - entityClazz = (Class) ((ParameterizedType) TypeToken.get(field.getGenericType()).getType()).getActualTypeArguments()[0]; - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - if (entityClazz == null) throw new RuntimeException("Shouldn't be null..."); - return switch (entityClazz.getPackageName()) { + Entity entity = entityType.create(DGU.getWorld()); + if (entity == null) + throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + entity.remove(); + return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; case "net.minecraft.entity.boss", "net.minecraft.entity.mob", "net.minecraft.entity.boss.dragon" -> "Hostile mobs"; @@ -65,7 +56,7 @@ private static String getCategoryFrom(@NotNull EntityType entityType) { 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: " + entityClazz.getPackageName()); + default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index 2a0c137e..4dc099c1 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -10,7 +10,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(Registry registry, Item foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = registry.getId(foodItem); diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index d537280d..de81a65c 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -9,7 +9,6 @@ import java.util.Objects; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getId(particleType); diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java index 5e4587dd..5017a289 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -118,4 +118,9 @@ public JsonElement generateDataJson() { // return finalObj; return JsonNull.INSTANCE; } + + @Override + public boolean isEnabled() { + return false; // TODO: Implement this + } } diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index 6fdecd68..585eb218 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -2,18 +2,15 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; import net.minecraft.sound.SoundEvent; import net.minecraft.util.registry.Registry; - public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(Registry registry, SoundEvent soundEvent) { + public static JsonObject generateSound(SoundEvent soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", registry.getRawId(soundEvent)); - soundDesc.addProperty("name", ((SoundAccessor)soundEvent).id().getPath()); + soundDesc.addProperty("id", Registry.SOUND_EVENT.getRawId(soundEvent)); + soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; } @@ -26,8 +23,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - Registry soundEventRegistry = Registry.SOUND_EVENT; - soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, sound))); + Registry.SOUND_EVENT.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 8ae3fdad..33fa26b5 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -2,9 +2,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.GrassColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock; import dev.u9g.minecraftdatagenerator.util.DGU; import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; @@ -12,21 +9,26 @@ import net.minecraft.block.Blocks; import net.minecraft.block.RedstoneWireBlock; import net.minecraft.client.color.block.BlockColors; +import net.minecraft.client.color.world.FoliageColors; +import net.minecraft.client.color.world.GrassColors; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; import java.util.*; public class TintsDataGenerator implements IDataGenerator { - public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { BiomeTintColors colors = new BiomeTintColors(); biomeRegistry.forEach(biome -> { - int biomeGrassColor = GrassColors.getGrassColorAt(biome); - int biomeFoliageColor = FoliageColors.getFoliageColor(biome); + double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); + double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); + + int biomeGrassColor = GrassColors.getColor(d, e); + int biomeFoliageColor = FoliageColors.getColor(d, e); int biomeWaterColor = biome.getWaterColor(); colors.grassColoursMap.computeIfAbsent(biomeGrassColor, k -> new ArrayList<>()).add(biome); @@ -37,33 +39,32 @@ public static BiomeTintColors generateBiomeTintColors(Registry biomeRegis } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { - int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel); + int color = RedstoneWireBlock.getWireColor(redstoneLevel); resultColors.put(redstoneLevel, color); } return resultColors; } - private static int getBlockColor(Block block, BlockColors blockColors) { - return blockColors.getColor(block.getDefaultState(), DGU.getWorld(), BlockPos.ORIGIN); + private static int getBlockColor(Block block) { + return BlockColors.create().getColor(block.getDefaultState(), DGU.getWorld(), BlockPos.ORIGIN); } public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors)); - 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.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors)); + resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); return resultColors; } @@ -159,8 +160,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index 53d51123..af7e9c10 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.MinecraftVersion; import net.minecraft.server.dedicated.MinecraftDedicatedServer; @@ -10,19 +9,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -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 cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = MinecraftVersion.create().getName(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + MinecraftVersion.create().getName(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java deleted file mode 100644 index 34b44bc5..00000000 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - - -import net.minecraft.sound.SoundEvent; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(SoundEvent.class) -public interface SoundAccessor { - @Accessor("id") - Identifier id(); -} diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index d85a31d6..1ad169d7 100644 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -1,10 +1,6 @@ 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.MinecraftClient; -import net.minecraft.client.resource.language.I18n; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; @@ -14,48 +10,13 @@ import org.jetbrains.annotations.NotNull; public class DGU { - - private static final Language language = Language.getInstance(); - - @Environment(EnvType.CLIENT) - private static MinecraftServer getCurrentlyRunningServerClient() { - return MinecraftClient.getInstance().getServer(); - } - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return getCurrentlyRunningServerClient(); - } else if (environmentType == EnvType.SERVER) { - return getCurrentlyRunningServerDedicated(); - } - throw new UnsupportedOperationException(); - } - - @Environment(EnvType.CLIENT) - private static String translateTextClient(String translationKey) { - return I18n.translate(translationKey); - } - - private static String translateTextFallback(String translationKey) { - try { - return language.translate(translationKey); - } catch (Exception ignored) { - } - throw new RuntimeException("Failed to translate: '" + translationKey + "'"); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } public static String translateText(String translationKey) { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return translateTextClient(translationKey); - } - return translateTextFallback(translationKey); + return Language.getInstance().translate(translationKey); } @NotNull diff --git a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyRenderBlockView.java b/1.14/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyRenderBlockView.java deleted file mode 100644 index b9d28648..00000000 --- a/1.14/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyRenderBlockView.java +++ /dev/null @@ -1,57 +0,0 @@ -//package dev.u9g.minecraftdatagenerator.util; -// -//import net.minecraft.block.BlockState; -//import net.minecraft.block.Blocks; -//import net.minecraft.block.entity.BlockEntity; -//import net.minecraft.fluid.FluidState; -//import net.minecraft.fluid.Fluids; -//import net.minecraft.util.math.BlockPos; -//import net.minecraft.world.LightType; -//import net.minecraft.world.biome.Biomes; -//import net.minecraft.world.chunk.light.LightingProvider; -//import org.jetbrains.annotations.Nullable; -// -//public enum EmptyRenderBlockView implements BlockRenderView { -// INSTANCE; -// -// @Nullable -// public BlockEntity getBlockEntity(BlockPos pos) { -// return null; -// } -// -// public BlockState getBlockState(BlockPos pos) { -// return Blocks.AIR.getDefaultState(); -// } -// -// public FluidState getFluidState(BlockPos pos) { -// return Fluids.EMPTY.getDefaultState(); -// } -// -// public int getBottomY() { -// return 0; -// } -// -// public int getHeight() { -// return 0; -// } -// -// @Override -// public LightingProvider getLightingProvider() { -// return null; -// } -// -// @Override -// public int getColor(BlockPos pos, ColorResolver colorResolver) { -// return colorResolver.getColor(Biomes.PLAINS, pos.getX(), pos.getY()); -// } -// -// @Override -// public int getLightLevel(LightType type, BlockPos pos) { -// return type == LightType.SKY ? getMaxLightLevel() : 0; -// } -// -// @Override -// public int getBaseLightLevel(BlockPos pos, int ambientDarkness) { -// return ambientDarkness; -// } -//} diff --git a/1.14/src/main/resources/fabric.mod.json b/1.14/src/main/resources/fabric.mod.json index 060b2637..ffac96b0 100644 --- a/1.14/src/main/resources/fabric.mod.json +++ b/1.14/src/main/resources/fabric.mod.json @@ -10,18 +10,11 @@ ], "contact": {}, "license": "MIT", - "environment": "server", - "entrypoints": { - "main": [ - "dev.u9g.minecraftdatagenerator.Main" - ] - }, "mixins": [ "minecraft-data-generator.mixins.json" ], "depends": { - "fabricloader": ">=0.13.3", - "fabric": "*", - "minecraft": "1.14" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/1.14/src/main/resources/minecraft-data-generator.mixins.json b/1.14/src/main/resources/minecraft-data-generator.mixins.json index 1024905e..ea255f59 100644 --- a/1.14/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.14/src/main/resources/minecraft-data-generator.mixins.json @@ -6,7 +6,6 @@ "mixins": [ "MiningToolItemAccessor", "ReadyMixin", - "SoundAccessor", "StatusEffectAccessor" ], "client": [ diff --git a/1.15/build.gradle b/1.15/build.gradle index e85de392..bf10cc6e 100644 --- a/1.15/build.gradle +++ b/1.15/build.gradle @@ -1,15 +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' } -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +unimined.minecraft { + version "1.15" + + mappings { + intermediary() + yarn(2) + + devFallbackNamespace "intermediary" + } + + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } + + customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() + } - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + defaultRemapJar = true +} + +dependencies { + implementation project(":common") } processResources { @@ -20,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.15/gradle.properties b/1.15/gradle.properties deleted file mode 100644 index 055fa5cf..00000000 --- a/1.15/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.15 -yarn_mappings=1.15+build.2 -loader_version=0.13.3 -# Dependencies -# check this on https://modmuss50.me/fabric.html -fabric_version=0.28.5+1.15 diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index 52a20201..00000000 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -1,14 +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() { - - } -} diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java deleted file mode 100644 index f1068ebd..00000000 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java +++ /dev/null @@ -1,36 +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) { - int i = (int) ((1.0 - temperature) * 255.0); - int j = (int) ((1.0 - (humidity *= temperature)) * 255.0); - return colorMap[j << 8 | i]; - } - - public static int getSpruceColor() { - return 0x619961; - } - - public static int getBirchColor() { - return 8431445; - } - - public static int getDefaultColor() { - return 4764952; - } - - public static int getFoliageColor(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); - double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); - return getColor(d, e); - } -} diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java deleted file mode 100644 index ee6a498a..00000000 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java +++ /dev/null @@ -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) { - humidity *= temperature; - int i = (int) ((1.0D - temperature) * 255.0D); - int j = (int) ((1.0D - humidity) * 255.0D); - int k = j << 8 | i; - return k > colorMap.length ? -65281 : colorMap[k]; - } - - public static int getGrassColorAt(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); - double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); - return getColor(d, e); - } -} - diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java deleted file mode 100644 index 5a21ac15..00000000 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import net.minecraft.client.util.math.Vector3f; -import net.minecraft.util.math.MathHelper; - -public class ServerSideRedstoneWireBlock { - private static final Vector3f[] data = new Vector3f[16]; - - static { - for (int i = 0; i <= 15; ++i) { - float f = 0; - float g = f * 0.6f + ((f = (float) i / 15.0f) > 0.0f ? 0.4f : 0.3f); - float h = MathHelper.clamp(f * f * 0.7f - 0.5f, 0.0f, 1.0f); - float j = MathHelper.clamp(f * f * 0.6f - 0.7f, 0.0f, 1.0f); - data[i] = new Vector3f(g, h, j); - } - } - - public static int getWireColor(int powerLevel) { - Vector3f vector3f = data[powerLevel]; - return packRgb(vector3f.getX(), vector3f.getY(), vector3f.getZ()); - } - - private static int packRgb(float r, float g, float b) { - return packRgb(MathHelper.floor(r * 255.0f), MathHelper.floor(g * 255.0f), MathHelper.floor(b * 255.0f)); - } - - private static int packRgb(int r, int g, int b) { - int i = r; - i = (i << 8) + g; - i = (i << 8) + b; - return i; - } -} diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 7bd1ec44..49ea2168 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -37,8 +37,8 @@ public JsonObject generateDataJson() { } private static class BlockShapesCache { - public final Map uniqueBlockShapes = new HashMap<>(); - public final Map> blockCollisionShapes = new HashMap<>(); + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); private int lastCollisionShapeId = 0; public void processBlock(Block block) { @@ -67,7 +67,7 @@ public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { long distinctShapesCount = blockCollisions.stream().distinct().count(); JsonElement blockCollision; if (distinctShapesCount == 1L) { - blockCollision = new JsonPrimitive(blockCollisions.get(0)); + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); } else { blockCollision = new JsonArray(); for (int collisionId : blockCollisions) { diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index e20bb439..6d056d75 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -3,7 +3,6 @@ import com.google.common.base.CaseFormat; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.Main; import dev.u9g.minecraftdatagenerator.mixin.MiningToolItemAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.block.AirBlock; @@ -26,13 +25,9 @@ import java.util.Collection; import java.util.List; -import java.util.logging.Logger; import java.util.stream.Collectors; public class BlocksDataGenerator implements IDataGenerator { - - private static final Logger logger = Main.LOGGER; - private static List getItemsEffectiveForBlock(Block block) { return Registry.ITEM.stream() .filter(item -> item instanceof MiningToolItem) @@ -85,16 +80,16 @@ private static > JsonObject generateStateProperty(Proper return propertyObject; } - public static JsonObject generateBlock(Registry blockRegistry, Block block) { + public static JsonObject generateBlock(Block block) { JsonObject blockDesc = new JsonObject(); List blockStates = block.getStateManager().getStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = blockRegistry.getId(block); + Identifier registryKey = Registry.BLOCK.getId(block); String localizationKey = block.getTranslationKey(); List effectiveTools = getItemsEffectiveForBlock(block); - blockDesc.addProperty("id", blockRegistry.getRawId(block)); + blockDesc.addProperty("id", Registry.BLOCK.getRawId(block)); blockDesc.addProperty("name", registryKey.getPath()); blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); @@ -116,8 +111,8 @@ public static JsonObject generateBlock(Registry blockRegistry, Block bloc blockDesc.addProperty("filterLight", defaultState.getOpacity(EmptyBlockView.INSTANCE, BlockPos.ORIGIN)); blockDesc.addProperty("defaultState", Block.getRawIdFromState(defaultState)); - blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.get(0))); - blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.get(blockStates.size() - 1))); + blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.getFirst())); + blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.getLast())); JsonArray stateProperties = new JsonArray(); for (Property property : block.getStateManager().getProperties()) { stateProperties.add(generateStateProperty(property)); @@ -144,9 +139,8 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultBlocksArray = new JsonArray(); - Registry blockRegistry = Registry.BLOCK; - blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, block))); + Registry.BLOCK.forEach(block -> resultBlocksArray.add(generateBlock(block))); return resultBlocksArray; } } diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index 40660b6c..00000000 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -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 GENERATORS = new ArrayList<>(); - private static final Logger logger = Main.LOGGER; - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new SoundsDataGenerator()); - } - - 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; - } -} diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 87620c01..52382cd3 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -15,7 +15,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getId(statusEffect); diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java index f4f067b8..eb586c7b 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -16,19 +16,6 @@ public class EnchantmentsDataGenerator implements IDataGenerator { private static final ImmutableMap ENCHANTMENT_TARGET_NAMES = ImmutableMap.builder() - .put(EnchantmentTarget.ARMOR, "armor") - .put(EnchantmentTarget.ARMOR_FEET, "armor_feet") - .put(EnchantmentTarget.ARMOR_LEGS, "armor_legs") - .put(EnchantmentTarget.ARMOR_CHEST, "armor_chest") - .put(EnchantmentTarget.ARMOR_HEAD, "armor_head") - .put(EnchantmentTarget.WEAPON, "weapon") - .put(EnchantmentTarget.DIGGER, "digger") - .put(EnchantmentTarget.FISHING_ROD, "fishing_rod") - .put(EnchantmentTarget.TRIDENT, "trident") - .put(EnchantmentTarget.BREAKABLE, "breakable") - .put(EnchantmentTarget.BOW, "bow") - .put(EnchantmentTarget.WEARABLE, "wearable") - .put(EnchantmentTarget.CROSSBOW, "crossbow") .put(EnchantmentTarget.ALL, "vanishable") // according to VanishingCurseEnchantment .build(); diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index e80cded5..0f052253 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -2,7 +2,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -18,11 +17,9 @@ import net.minecraft.util.registry.Registry; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.ParameterizedType; import java.util.Objects; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getId(entityType); @@ -47,26 +44,20 @@ public static JsonObject generateEntity(Registry> entityRegistry, private static String getCategoryFrom(@NotNull EntityType entityType) { if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities - Class entityClazz = null; - try { - for (var field : EntityType.class.getFields()) - if (entityType == field.get(EntityType.class)) - entityClazz = (Class) ((ParameterizedType) TypeToken.get(field.getGenericType()).getType()).getActualTypeArguments()[0]; - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - if (entityClazz == null) throw new RuntimeException("Shouldn't be null..."); - return switch (entityClazz.getPackageName()) { + Entity entity = entityType.create(DGU.getWorld()); + if (entity == null) + throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + entity.remove(); + return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; case "net.minecraft.entity.boss", "net.minecraft.entity.mob", "net.minecraft.entity.boss.dragon" -> "Hostile mobs"; - case "net.minecraft.entity.projectile", "net.minecraft.entity.projectile.thrown", "net.minecraft.entity.thrown" -> - "Projectiles"; + case "net.minecraft.entity.projectile", "net.minecraft.entity.projectile.thrown", + "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: " + entityClazz.getPackageName()); + default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index fc494d1e..d7e163ea 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(Registry registry, Item foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = registry.getId(foodItem); diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index d537280d..de81a65c 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -9,7 +9,6 @@ import java.util.Objects; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getId(particleType); diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java index 5e4587dd..5017a289 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -118,4 +118,9 @@ public JsonElement generateDataJson() { // return finalObj; return JsonNull.INSTANCE; } + + @Override + public boolean isEnabled() { + return false; // TODO: Implement this + } } diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index 6fdecd68..585eb218 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -2,18 +2,15 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; import net.minecraft.sound.SoundEvent; import net.minecraft.util.registry.Registry; - public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(Registry registry, SoundEvent soundEvent) { + public static JsonObject generateSound(SoundEvent soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", registry.getRawId(soundEvent)); - soundDesc.addProperty("name", ((SoundAccessor)soundEvent).id().getPath()); + soundDesc.addProperty("id", Registry.SOUND_EVENT.getRawId(soundEvent)); + soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; } @@ -26,8 +23,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - Registry soundEventRegistry = Registry.SOUND_EVENT; - soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, sound))); + Registry.SOUND_EVENT.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 07926410..a489cdbb 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -2,32 +2,33 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.GrassColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock; import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView; import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.RedstoneWireBlock; import net.minecraft.client.color.block.BlockColors; +import net.minecraft.client.color.world.FoliageColors; +import net.minecraft.client.color.world.GrassColors; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; import java.util.*; public class TintsDataGenerator implements IDataGenerator { - public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { BiomeTintColors colors = new BiomeTintColors(); biomeRegistry.forEach(biome -> { - int biomeGrassColor = GrassColors.getGrassColorAt(biome); - int biomeFoliageColor = FoliageColors.getFoliageColor(biome); + double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); + double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); + + int biomeGrassColor = GrassColors.getColor(d, e); + int biomeFoliageColor = FoliageColors.getColor(d, e); int biomeWaterColor = biome.getWaterColor(); colors.grassColoursMap.computeIfAbsent(biomeGrassColor, k -> new ArrayList<>()).add(biome); @@ -38,35 +39,32 @@ public static BiomeTintColors generateBiomeTintColors(Registry biomeRegis } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { - int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel); + int color = RedstoneWireBlock.getWireColor(redstoneLevel); resultColors.put(redstoneLevel, color); } return resultColors; } - @Environment(EnvType.CLIENT) - private static int getBlockColor(Block block, BlockColors blockColors) { - return blockColors.getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); + private static int getBlockColor(Block block) { + return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); } - @Environment(EnvType.CLIENT) public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors)); - 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.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors)); + resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); return resultColors; } @@ -162,8 +160,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index 53d51123..af7e9c10 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.MinecraftVersion; import net.minecraft.server.dedicated.MinecraftDedicatedServer; @@ -10,19 +9,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -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 cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = MinecraftVersion.create().getName(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + MinecraftVersion.create().getName(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java deleted file mode 100644 index 34b44bc5..00000000 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - - -import net.minecraft.sound.SoundEvent; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(SoundEvent.class) -public interface SoundAccessor { - @Accessor("id") - Identifier id(); -} diff --git a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index c5cdc360..f1ef2772 100644 --- a/1.15/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.15/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -1,10 +1,6 @@ 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.MinecraftClient; -import net.minecraft.client.resource.language.I18n; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; @@ -14,48 +10,13 @@ import org.jetbrains.annotations.NotNull; public class DGU { - - private static final Language language = Language.getInstance(); - - @Environment(EnvType.CLIENT) - private static MinecraftServer getCurrentlyRunningServerClient() { - return MinecraftClient.getInstance().getServer(); - } - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return getCurrentlyRunningServerClient(); - } else if (environmentType == EnvType.SERVER) { - return getCurrentlyRunningServerDedicated(); - } - throw new UnsupportedOperationException(); - } - - @Environment(EnvType.CLIENT) - private static String translateTextClient(String translationKey) { - return I18n.translate(translationKey); - } - - private static String translateTextFallback(String translationKey) { - try { - return language.translate(translationKey); - } catch (Exception ignored) { - } - throw new RuntimeException("Failed to translate: '" + translationKey + "'"); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } public static String translateText(String translationKey) { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return translateTextClient(translationKey); - } - return translateTextFallback(translationKey); + return Language.getInstance().translate(translationKey); } @NotNull diff --git a/1.15/src/main/resources/fabric.mod.json b/1.15/src/main/resources/fabric.mod.json index 3ee60ac5..ffac96b0 100644 --- a/1.15/src/main/resources/fabric.mod.json +++ b/1.15/src/main/resources/fabric.mod.json @@ -10,18 +10,11 @@ ], "contact": {}, "license": "MIT", - "environment": "server", - "entrypoints": { - "main": [ - "dev.u9g.minecraftdatagenerator.Main" - ] - }, "mixins": [ "minecraft-data-generator.mixins.json" ], "depends": { - "fabricloader": ">=0.13.3", - "fabric": "*", - "minecraft": "1.15" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/1.15/src/main/resources/minecraft-data-generator.mixins.json b/1.15/src/main/resources/minecraft-data-generator.mixins.json index 1024905e..ea255f59 100644 --- a/1.15/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.15/src/main/resources/minecraft-data-generator.mixins.json @@ -6,7 +6,6 @@ "mixins": [ "MiningToolItemAccessor", "ReadyMixin", - "SoundAccessor", "StatusEffectAccessor" ], "client": [ diff --git a/1.16/build.gradle b/1.16/build.gradle index e85de392..d97c3a52 100644 --- a/1.16/build.gradle +++ b/1.16/build.gradle @@ -1,15 +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' } -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +unimined.minecraft { + version "1.16" + + mappings { + intermediary() + yarn(4) + + devFallbackNamespace "intermediary" + } + + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } + + customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() + } - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + defaultRemapJar = true +} + +dependencies { + implementation project(":common") } processResources { @@ -20,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.16/gradle.properties b/1.16/gradle.properties deleted file mode 100644 index 3fe3c1b0..00000000 --- a/1.16/gradle.properties +++ /dev/null @@ -1,9 +0,0 @@ -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.16 -yarn_mappings=1.16+build.4 -loader_version=0.13.3 -# Dependencies -# check this on https://modmuss50.me/fabric.html -# fabric_version=0.36.0+1.17 -fabric_version=0.13.1+build.370-1.16 diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index 52a20201..00000000 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -1,14 +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() { - - } -} diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java deleted file mode 100644 index f1068ebd..00000000 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java +++ /dev/null @@ -1,36 +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) { - int i = (int) ((1.0 - temperature) * 255.0); - int j = (int) ((1.0 - (humidity *= temperature)) * 255.0); - return colorMap[j << 8 | i]; - } - - public static int getSpruceColor() { - return 0x619961; - } - - public static int getBirchColor() { - return 8431445; - } - - public static int getDefaultColor() { - return 4764952; - } - - public static int getFoliageColor(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); - double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); - return getColor(d, e); - } -} diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java deleted file mode 100644 index 9452d37a..00000000 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java +++ /dev/null @@ -1,29 +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 j = (int) ((1.0 - (humidity *= temperature)) * 255.0); - int i = (int) ((1.0 - temperature) * 255.0); - int k = j << 8 | i; - if (k > colorMap.length) { - return -65281; - } - return colorMap[k]; - } - - public static int getGrassColorAt(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); - double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); - return getColor(d, e); - } -} - diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java deleted file mode 100644 index 5a21ac15..00000000 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import net.minecraft.client.util.math.Vector3f; -import net.minecraft.util.math.MathHelper; - -public class ServerSideRedstoneWireBlock { - private static final Vector3f[] data = new Vector3f[16]; - - static { - for (int i = 0; i <= 15; ++i) { - float f = 0; - float g = f * 0.6f + ((f = (float) i / 15.0f) > 0.0f ? 0.4f : 0.3f); - float h = MathHelper.clamp(f * f * 0.7f - 0.5f, 0.0f, 1.0f); - float j = MathHelper.clamp(f * f * 0.6f - 0.7f, 0.0f, 1.0f); - data[i] = new Vector3f(g, h, j); - } - } - - public static int getWireColor(int powerLevel) { - Vector3f vector3f = data[powerLevel]; - return packRgb(vector3f.getX(), vector3f.getY(), vector3f.getZ()); - } - - private static int packRgb(float r, float g, float b) { - return packRgb(MathHelper.floor(r * 255.0f), MathHelper.floor(g * 255.0f), MathHelper.floor(b * 255.0f)); - } - - private static int packRgb(int r, int g, int b) { - int i = r; - i = (i << 8) + g; - i = (i << 8) + b; - return i; - } -} diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 52c3181d..61e1b9e6 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,10 +12,7 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class BlockCollisionShapesDataGenerator implements IDataGenerator { @@ -40,8 +37,8 @@ public JsonObject generateDataJson() { } private static class BlockShapesCache { - public final Map uniqueBlockShapes = new HashMap<>(); - public final Map> blockCollisionShapes = new HashMap<>(); + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); private int lastCollisionShapeId = 0; public void processBlock(Block block) { @@ -70,7 +67,7 @@ public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { long distinctShapesCount = blockCollisions.stream().distinct().count(); JsonElement blockCollision; if (distinctShapesCount == 1L) { - blockCollision = new JsonPrimitive(blockCollisions.get(0)); + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); } else { blockCollision = new JsonArray(); for (int collisionId : blockCollisions) { diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index d5c7ca00..2eba27c3 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -3,7 +3,6 @@ import com.google.common.base.CaseFormat; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.Main; import dev.u9g.minecraftdatagenerator.mixin.MiningToolItemAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.block.AirBlock; @@ -29,13 +28,9 @@ import java.util.Collection; import java.util.List; -import java.util.logging.Logger; import java.util.stream.Collectors; public class BlocksDataGenerator implements IDataGenerator { - - private static final Logger logger = Main.LOGGER; - private static List getItemsEffectiveForBlock(Block block) { return Registry.ITEM.stream() .filter(item -> item instanceof MiningToolItem) @@ -92,16 +87,16 @@ private static > JsonObject generateStateProperty(Proper return propertyObject; } - public static JsonObject generateBlock(Registry blockRegistry, Block block) { + public static JsonObject generateBlock(Block block) { JsonObject blockDesc = new JsonObject(); List blockStates = block.getStateManager().getStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = blockRegistry.getKey(block).orElseThrow().getValue(); + Identifier registryKey = Registry.BLOCK.getKey(block).orElseThrow().getValue(); String localizationKey = block.getTranslationKey(); List effectiveTools = getItemsEffectiveForBlock(block); - blockDesc.addProperty("id", blockRegistry.getRawId(block)); + blockDesc.addProperty("id", Registry.BLOCK.getRawId(block)); blockDesc.addProperty("name", registryKey.getPath()); blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); @@ -123,8 +118,8 @@ public static JsonObject generateBlock(Registry blockRegistry, Block bloc blockDesc.addProperty("filterLight", defaultState.getOpacity(EmptyBlockView.INSTANCE, BlockPos.ORIGIN)); blockDesc.addProperty("defaultState", Block.getRawIdFromState(defaultState)); - blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.get(0))); - blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.get(blockStates.size() - 1))); + blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.getFirst())); + blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.getLast())); JsonArray stateProperties = new JsonArray(); for (Property property : block.getStateManager().getProperties()) { stateProperties.add(generateStateProperty(property)); @@ -151,9 +146,8 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultBlocksArray = new JsonArray(); - Registry blockRegistry = Registry.BLOCK; - blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, block))); + Registry.BLOCK.forEach(block -> resultBlocksArray.add(generateBlock(block))); return resultBlocksArray; } } diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index 40660b6c..00000000 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -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 GENERATORS = new ArrayList<>(); - private static final Logger logger = Main.LOGGER; - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new SoundsDataGenerator()); - } - - 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; - } -} diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 18a9dcdb..3ae99a65 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -15,7 +15,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(statusEffect).orElseThrow().getValue(); diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java index e27fb68f..44449345 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.collect.ImmutableMap; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -11,29 +10,10 @@ import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; public class EnchantmentsDataGenerator implements IDataGenerator { - - private static final ImmutableMap ENCHANTMENT_TARGET_NAMES = ImmutableMap.builder() - .put(EnchantmentTarget.ARMOR, "armor") - .put(EnchantmentTarget.ARMOR_FEET, "armor_feet") - .put(EnchantmentTarget.ARMOR_LEGS, "armor_legs") - .put(EnchantmentTarget.ARMOR_CHEST, "armor_chest") - .put(EnchantmentTarget.ARMOR_HEAD, "armor_head") - .put(EnchantmentTarget.WEAPON, "weapon") - .put(EnchantmentTarget.DIGGER, "digger") - .put(EnchantmentTarget.FISHING_ROD, "fishing_rod") - .put(EnchantmentTarget.TRIDENT, "trident") - .put(EnchantmentTarget.BREAKABLE, "breakable") - .put(EnchantmentTarget.BOW, "bow") - .put(EnchantmentTarget.WEARABLE, "wearable") - .put(EnchantmentTarget.CROSSBOW, "crossbow") - .put(EnchantmentTarget.VANISHABLE, "vanishable") - .build(); - public static String getEnchantmentTargetName(EnchantmentTarget target) { - return ENCHANTMENT_TARGET_NAMES.getOrDefault(target, target.name().toLowerCase(Locale.ROOT)); + return 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 diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index d0edd6c3..207ee737 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -2,7 +2,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -19,10 +18,7 @@ import net.minecraft.util.registry.Registry; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.ParameterizedType; - public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getKey(entityType).orElseThrow().getValue(); @@ -48,17 +44,11 @@ public static JsonObject generateEntity(Registry> entityRegistry, private static String getCategoryFrom(@NotNull EntityType entityType) { if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities - Class entityClazz = null; - try { - for (var field : EntityType.class.getFields()) - if (entityType == field.get(EntityType.class)) - entityClazz = (Class) ((ParameterizedType) TypeToken.get(field.getGenericType()).getType()).getActualTypeArguments()[0]; - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - if (entityClazz == null) throw new RuntimeException("Shouldn't be null..."); - return switch (entityClazz.getPackageName()) { + Entity entity = entityType.create(DGU.getWorld()); + if (entity == null) + throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + entity.remove(); + return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; case "net.minecraft.entity.boss", "net.minecraft.entity.mob", "net.minecraft.entity.boss.dragon" -> "Hostile mobs"; @@ -66,7 +56,7 @@ private static String getCategoryFrom(@NotNull EntityType entityType) { 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: " + entityClazz.getPackageName()); + default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index 45a0b35f..de659be9 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(Registry registry, Item foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = registry.getKey(foodItem).orElseThrow().getValue(); diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 5a6b1081..80cca516 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -7,7 +7,6 @@ import net.minecraft.util.registry.Registry; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(particleType).orElseThrow().getValue(); diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java index 5e4587dd..5017a289 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -118,4 +118,9 @@ public JsonElement generateDataJson() { // return finalObj; return JsonNull.INSTANCE; } + + @Override + public boolean isEnabled() { + return false; // TODO: Implement this + } } diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index 6fdecd68..585eb218 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -2,18 +2,15 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; import net.minecraft.sound.SoundEvent; import net.minecraft.util.registry.Registry; - public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(Registry registry, SoundEvent soundEvent) { + public static JsonObject generateSound(SoundEvent soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", registry.getRawId(soundEvent)); - soundDesc.addProperty("name", ((SoundAccessor)soundEvent).id().getPath()); + soundDesc.addProperty("id", Registry.SOUND_EVENT.getRawId(soundEvent)); + soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; } @@ -26,8 +23,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - Registry soundEventRegistry = Registry.SOUND_EVENT; - soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, sound))); + Registry.SOUND_EVENT.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index f480e930..689b5ac9 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -2,33 +2,34 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.GrassColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock; import dev.u9g.minecraftdatagenerator.mixin.BiomeEffectsAccessor; import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView; import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.RedstoneWireBlock; import net.minecraft.client.color.block.BlockColors; +import net.minecraft.client.color.world.FoliageColors; +import net.minecraft.client.color.world.GrassColors; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; import java.util.*; public class TintsDataGenerator implements IDataGenerator { - public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { BiomeTintColors colors = new BiomeTintColors(); biomeRegistry.forEach(biome -> { - int biomeGrassColor = GrassColors.getGrassColorAt(biome); - int biomeFoliageColor = FoliageColors.getFoliageColor(biome); + double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); + double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f); + + int biomeGrassColor = GrassColors.getColor(d, e); + int biomeFoliageColor = FoliageColors.getColor(d, e); int biomeWaterColor = ((BiomeEffectsAccessor) biome.getEffects()).waterColor(); colors.grassColoursMap.computeIfAbsent(biomeGrassColor, k -> new ArrayList<>()).add(biome); @@ -39,35 +40,32 @@ public static BiomeTintColors generateBiomeTintColors(Registry biomeRegis } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { - int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel); + int color = RedstoneWireBlock.getWireColor(redstoneLevel); resultColors.put(redstoneLevel, color); } return resultColors; } - @Environment(EnvType.CLIENT) - private static int getBlockColor(Block block, BlockColors blockColors) { - return blockColors.getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); + private static int getBlockColor(Block block) { + return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); } - @Environment(EnvType.CLIENT) public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors)); - 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.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors)); + resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); return resultColors; } @@ -163,8 +161,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index 3fe886a3..4ba04e43 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.MinecraftVersion; import net.minecraft.server.dedicated.MinecraftDedicatedServer; @@ -10,19 +9,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -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 cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = MinecraftVersion.field_25319.getName(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + MinecraftVersion.field_25319.getName(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java deleted file mode 100644 index 34b44bc5..00000000 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - - -import net.minecraft.sound.SoundEvent; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(SoundEvent.class) -public interface SoundAccessor { - @Accessor("id") - Identifier id(); -} diff --git a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index 91eed91b..af2897ad 100644 --- a/1.16/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.16/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -1,58 +1,19 @@ 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.MinecraftClient; -import net.minecraft.client.resource.language.I18n; import net.minecraft.server.MinecraftServer; import net.minecraft.util.Language; import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; public class DGU { - - private static final Language language = Language.getInstance(); - - @Environment(EnvType.CLIENT) - private static MinecraftServer getCurrentlyRunningServerClient() { - return MinecraftClient.getInstance().getServer(); - } - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return getCurrentlyRunningServerClient(); - } else if (environmentType == EnvType.SERVER) { - return getCurrentlyRunningServerDedicated(); - } - throw new UnsupportedOperationException(); - } - - @Environment(EnvType.CLIENT) - private static String translateTextClient(String translationKey) { - return I18n.translate(translationKey); - } - - private static String translateTextFallback(String translationKey) { - try { - return language.get(translationKey); - } catch (Exception ignored) { - } - throw new RuntimeException("Failed to translate: '" + translationKey + "'"); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } public static String translateText(String translationKey) { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return translateTextClient(translationKey); - } - return translateTextFallback(translationKey); + return Language.getInstance().get(translationKey); } @NotNull diff --git a/1.16/src/main/resources/fabric.mod.json b/1.16/src/main/resources/fabric.mod.json index 9d668672..ffac96b0 100644 --- a/1.16/src/main/resources/fabric.mod.json +++ b/1.16/src/main/resources/fabric.mod.json @@ -10,18 +10,11 @@ ], "contact": {}, "license": "MIT", - "environment": "server", - "entrypoints": { - "main": [ - "dev.u9g.minecraftdatagenerator.Main" - ] - }, "mixins": [ "minecraft-data-generator.mixins.json" ], "depends": { - "fabricloader": ">=0.13.3", - "fabric": "*", - "minecraft": "1.16" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/1.16/src/main/resources/minecraft-data-generator.mixins.json b/1.16/src/main/resources/minecraft-data-generator.mixins.json index 95ede1ce..7154c902 100644 --- a/1.16/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.16/src/main/resources/minecraft-data-generator.mixins.json @@ -8,7 +8,6 @@ "EULAMixin", "MiningToolItemAccessor", "ReadyMixin", - "SoundAccessor", "StatusEffectAccessor" ], "client": [ diff --git a/1.17/build.gradle b/1.17/build.gradle index e85de392..71a36438 100644 --- a/1.17/build.gradle +++ b/1.17/build.gradle @@ -1,15 +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' } -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +unimined.minecraft { + version "1.17" + + mappings { + intermediary() + yarn(9) + + devFallbackNamespace "intermediary" + } + + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } + + customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() + } - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + defaultRemapJar = true +} + +dependencies { + implementation project(":common") } processResources { @@ -20,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.17/gradle.properties b/1.17/gradle.properties deleted file mode 100644 index e181bfd6..00000000 --- a/1.17/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.17 -yarn_mappings=1.17+build.13 -loader_version=0.13.3 -# Dependencies -# check this on https://modmuss50.me/fabric.html -fabric_version=0.36.0+1.17 diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index f8d17372..00000000 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.u9g.minecraftdatagenerator; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Main implements ModInitializer { - public static final Logger LOGGER = LoggerFactory.getLogger("mc-data-gen-serv"); - - @Override - public void onInitialize() { - - } -} diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 52c3181d..61e1b9e6 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,10 +12,7 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class BlockCollisionShapesDataGenerator implements IDataGenerator { @@ -40,8 +37,8 @@ public JsonObject generateDataJson() { } private static class BlockShapesCache { - public final Map uniqueBlockShapes = new HashMap<>(); - public final Map> blockCollisionShapes = new HashMap<>(); + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); private int lastCollisionShapeId = 0; public void processBlock(Block block) { @@ -70,7 +67,7 @@ public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { long distinctShapesCount = blockCollisions.stream().distinct().count(); JsonElement blockCollision; if (distinctShapesCount == 1L) { - blockCollision = new JsonPrimitive(blockCollisions.get(0)); + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); } else { blockCollision = new JsonArray(); for (int collisionId : blockCollisions) { diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 51139655..cb407427 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -105,7 +105,7 @@ private static String findMatchingBlockMaterial(BlockState blockState, List 1) { - var firstMaterial = matchingMaterials.get(0); + var firstMaterial = matchingMaterials.getFirst(); var otherMaterials = matchingMaterials.subList(1, matchingMaterials.size()); if (!otherMaterials.stream().allMatch(firstMaterial::includesMaterial)) { @@ -115,19 +115,19 @@ private static String findMatchingBlockMaterial(BlockState blockState, List blockRegistry, List materials, Block block) { + public static JsonObject generateBlock(List materials, Block block) { JsonObject blockDesc = new JsonObject(); List blockStates = block.getStateManager().getStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = blockRegistry.getKey(block).orElseThrow().getValue(); + Identifier registryKey = Registry.BLOCK.getKey(block).orElseThrow().getValue(); String localizationKey = block.getTranslationKey(); List effectiveTools = getItemsEffectiveForBlock(defaultState); - blockDesc.addProperty("id", blockRegistry.getRawId(block)); + blockDesc.addProperty("id", Registry.BLOCK.getRawId(block)); blockDesc.addProperty("name", registryKey.getPath()); blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); @@ -148,8 +148,8 @@ public static JsonObject generateBlock(Registry blockRegistry, List property : block.getStateManager().getProperties()) { @@ -167,7 +167,7 @@ public static JsonObject generateBlock(Registry blockRegistry, List actualBlockDrops = new ArrayList<>(); - populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.get(0), actualBlockDrops); + populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.getFirst(), actualBlockDrops); JsonArray dropsArray = new JsonArray(); for (ItemStack dropStack : actualBlockDrops) { @@ -192,7 +192,7 @@ public JsonArray generateDataJson() { Registry blockRegistry = Registry.BLOCK; List availableMaterials = MaterialsDataGenerator.getGlobalMaterialInfo(); - blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, availableMaterials, block))); + blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(availableMaterials, block))); return resultBlocksArray; } } diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index 04792b72..00000000 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -1,79 +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 org.lwjgl.system.CallbackI; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -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.util.ArrayList; -import java.util.List; - -public class DataGenerators { - - private static final Logger logger = LoggerFactory.getLogger(DataGenerators.class); - private static final List GENERATORS = new ArrayList<>(); - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new MaterialsDataGenerator()); -// register(new RecipeDataGenerator()); - On hold until mcdata supports multiple materials for a recipe - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new SoundsDataGenerator()); - } - - public static void register(IDataGenerator generator) { - GENERATORS.add(generator); - } - - public static boolean runDataGenerators(Path outputDirectory) { - try { - Files.createDirectories(outputDirectory); - } catch (IOException exception) { - logger.error("Failed to create data generator output directory at {}", outputDirectory, exception); - return false; - } - - int generatorsFailed = 0; - logger.info("Running minecraft data generators, output at {}", outputDirectory); - - for (IDataGenerator dataGenerator : GENERATORS) { - logger.info("Running generator {}", 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("Generator: {} -> {}", dataGenerator.getDataName(), outputFileName); - - } catch (Throwable exception) { - logger.error("Failed to run data generator {}", dataGenerator.getDataName(), exception); - generatorsFailed++; - } - } - - logger.info("Finishing running data generators"); - return generatorsFailed == 0; - } -} diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 1c9849e6..9b4beb53 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -13,7 +13,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(statusEffect).orElseThrow().getValue(); diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java index e27fb68f..44449345 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.collect.ImmutableMap; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -11,29 +10,10 @@ import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; public class EnchantmentsDataGenerator implements IDataGenerator { - - private static final ImmutableMap ENCHANTMENT_TARGET_NAMES = ImmutableMap.builder() - .put(EnchantmentTarget.ARMOR, "armor") - .put(EnchantmentTarget.ARMOR_FEET, "armor_feet") - .put(EnchantmentTarget.ARMOR_LEGS, "armor_legs") - .put(EnchantmentTarget.ARMOR_CHEST, "armor_chest") - .put(EnchantmentTarget.ARMOR_HEAD, "armor_head") - .put(EnchantmentTarget.WEAPON, "weapon") - .put(EnchantmentTarget.DIGGER, "digger") - .put(EnchantmentTarget.FISHING_ROD, "fishing_rod") - .put(EnchantmentTarget.TRIDENT, "trident") - .put(EnchantmentTarget.BREAKABLE, "breakable") - .put(EnchantmentTarget.BOW, "bow") - .put(EnchantmentTarget.WEARABLE, "wearable") - .put(EnchantmentTarget.CROSSBOW, "crossbow") - .put(EnchantmentTarget.VANISHABLE, "vanishable") - .build(); - public static String getEnchantmentTargetName(EnchantmentTarget target) { - return ENCHANTMENT_TARGET_NAMES.getOrDefault(target, target.name().toLowerCase(Locale.ROOT)); + return 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 diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 8d94a6b7..29e7ee2b 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -18,7 +18,6 @@ import net.minecraft.util.registry.Registry; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getKey(entityType).orElseThrow().getValue(); diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index 45a0b35f..de659be9 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(Registry registry, Item foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = registry.getKey(foodItem).orElseThrow().getValue(); diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java index 3b96085d..9c5bfd7e 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.gson.JsonElement; @@ -41,7 +40,7 @@ private static String makeMaterialNameForTag(Tag tag) { } private static void createCompositeMaterialInfo(List allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); List mappedMaterials = combinedMaterials.stream() .map(otherName -> allMaterials.stream() @@ -53,13 +52,13 @@ private static void createCompositeMaterialInfo(List allMaterials, mappedMaterials.stream().allMatch(it -> it.getPredicate().test(blockState)); MaterialInfo materialInfo = new MaterialInfo(compositeMaterialName, compositePredicate).includes(mappedMaterials); - allMaterials.add(0, materialInfo); + allMaterials.addFirst(materialInfo); } private static void createCompositeMaterial(Map> allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); - Map resultingToolSpeeds = new HashMap<>(); + Map resultingToolSpeeds = new LinkedHashMap<>(); combinedMaterials.stream() .map(allMaterials::get) .forEach(resultingToolSpeeds::putAll); @@ -106,14 +105,14 @@ public String getDataName() { public JsonElement generateDataJson() { Registry itemRegistry = Registry.ITEM; - Map> materialMiningSpeeds = new HashMap<>(); + Map> materialMiningSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put("default", ImmutableMap.of()); //Special materials used for shears and swords special mining speed logic - Map leavesMaterialSpeeds = new HashMap<>(); - Map cowebMaterialSpeeds = new HashMap<>(); - Map plantMaterialSpeeds = new HashMap<>(); - Map gourdMaterialSpeeds = new HashMap<>(); + Map leavesMaterialSpeeds = new LinkedHashMap<>(); + Map cowebMaterialSpeeds = new LinkedHashMap<>(); + Map plantMaterialSpeeds = new LinkedHashMap<>(); + Map gourdMaterialSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put(makeMaterialNameForTag(BlockTags.LEAVES), leavesMaterialSpeeds); materialMiningSpeeds.put("coweb", cowebMaterialSpeeds); @@ -132,7 +131,7 @@ public JsonElement generateDataJson() { Tag effectiveBlocks = ((MiningToolItemAccessor) toolItem).getEffectiveBlocks(); String materialName = makeMaterialNameForTag(effectiveBlocks); - Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new HashMap<>()); + Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>()); float miningSpeed = ((MiningToolItemAccessor) toolItem).getMiningSpeed(); materialSpeeds.put(item, miningSpeed); } diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 5a6b1081..80cca516 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -7,7 +7,6 @@ import net.minecraft.util.registry.Registry; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(particleType).orElseThrow().getValue(); diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index 6fdecd68..585eb218 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -2,18 +2,15 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; import net.minecraft.sound.SoundEvent; import net.minecraft.util.registry.Registry; - public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(Registry registry, SoundEvent soundEvent) { + public static JsonObject generateSound(SoundEvent soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", registry.getRawId(soundEvent)); - soundDesc.addProperty("name", ((SoundAccessor)soundEvent).id().getPath()); + soundDesc.addProperty("id", Registry.SOUND_EVENT.getRawId(soundEvent)); + soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; } @@ -26,8 +23,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - Registry soundEventRegistry = Registry.SOUND_EVENT; - soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, sound))); + Registry.SOUND_EVENT.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 3ceef91b..5a287186 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -4,7 +4,6 @@ import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView; import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; import net.minecraft.block.Blocks; @@ -20,7 +19,6 @@ import java.util.*; public class TintsDataGenerator implements IDataGenerator { - public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { BiomeTintColors colors = new BiomeTintColors(); @@ -37,7 +35,7 @@ public static BiomeTintColors generateBiomeTintColors(Registry biomeRegis } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { int color = RedstoneWireBlock.getWireColor(redstoneLevel); @@ -46,26 +44,23 @@ public static Map generateRedstoneTintColors() { return resultColors; } - @Environment(EnvType.CLIENT) - private static int getBlockColor(Block block, BlockColors blockColors) { - return blockColors.getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); + private static int getBlockColor(Block block) { + return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); } - @Environment(EnvType.CLIENT) public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors)); - 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.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors)); + resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); return resultColors; } @@ -161,8 +156,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ClientPlayerInteractionManagerMixin.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ClientPlayerInteractionManagerMixin.java deleted file mode 100644 index 40e926af..00000000 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ClientPlayerInteractionManagerMixin.java +++ /dev/null @@ -1,57 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import com.google.common.base.Preconditions; -import net.minecraft.block.BlockState; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerInteractionManager; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ClientPlayerInteractionManager.class) -public abstract class ClientPlayerInteractionManagerMixin { - @Unique - private long blockBreakingStartTicks; - @Unique - private BlockState stateBeingBroken; - - @Inject(method = "attackBlock", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;currentBreakingProgress:F", opcode = Opcodes.PUTFIELD)) - private void onBlockAttacked(BlockPos pos, Direction direction, CallbackInfoReturnable callbackInfo) { - World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world); - this.blockBreakingStartTicks = world.getTime(); - } - - @Inject(method = "cancelBlockBreaking", at = @At("HEAD")) - private void onBlockBreakingCanceled(CallbackInfo callbackInfo) { - this.blockBreakingStartTicks = -1L; - } - - @Inject(method = "breakBlock", at = @At("HEAD")) - private void onBreakBlockHead(BlockPos pos, CallbackInfoReturnable callbackInfo) { - World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world); - this.stateBeingBroken = world.getBlockState(pos); - } - - @Inject(method = "breakBlock", at = @At("RETURN")) - private void onBreakBlockReturn(BlockPos pos, CallbackInfoReturnable callbackInfo) { - World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world); - if (callbackInfo.getReturnValue()) { - Preconditions.checkNotNull(stateBeingBroken); - if (blockBreakingStartTicks != -1L) { - long totalTicksElapsed = world.getTime() - this.blockBreakingStartTicks; - long totalTimeElapsed = totalTicksElapsed * 50L; - System.out.printf("Breaking block %s took %dms%n", stateBeingBroken.getBlock(), totalTimeElapsed); - } else { - System.out.printf("Breaking block %s took 0ms [INSTANT BREAK]%n", stateBeingBroken.getBlock()); - } - } - this.blockBreakingStartTicks = -1L; - } -} diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index b0b039f7..759563e2 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.MinecraftVersion; import net.minecraft.server.dedicated.MinecraftDedicatedServer; @@ -10,18 +9,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.nio.file.Path; - @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = MinecraftVersion.GAME_VERSION.getName(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + MinecraftVersion.GAME_VERSION.getName(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java deleted file mode 100644 index 34b44bc5..00000000 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - - -import net.minecraft.sound.SoundEvent; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(SoundEvent.class) -public interface SoundAccessor { - @Accessor("id") - Identifier id(); -} diff --git a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index 5945fa02..3946c1fe 100644 --- a/1.17/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.17/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -1,57 +1,18 @@ 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.MinecraftClient; -import net.minecraft.client.resource.language.I18n; import net.minecraft.server.MinecraftServer; import net.minecraft.util.Language; import net.minecraft.world.World; public class DGU { - - private static final Language language = Language.getInstance(); - - @Environment(EnvType.CLIENT) - private static MinecraftServer getCurrentlyRunningServerClient() { - return MinecraftClient.getInstance().getServer(); - } - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return getCurrentlyRunningServerClient(); - } else if (environmentType == EnvType.SERVER) { - return getCurrentlyRunningServerDedicated(); - } - throw new UnsupportedOperationException(); - } - - @Environment(EnvType.CLIENT) - private static String translateTextClient(String translationKey) { - return I18n.translate(translationKey); - } - - private static String translateTextFallback(String translationKey) { - try { - return language.get(translationKey); - } catch (Exception ignored) { - } - throw new RuntimeException("Failed to translate: '" + translationKey + "'"); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } public static String translateText(String translationKey) { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return translateTextClient(translationKey); - } - return translateTextFallback(translationKey); + return Language.getInstance().get(translationKey); } public static World getWorld() { diff --git a/1.17/src/main/resources/fabric.mod.json b/1.17/src/main/resources/fabric.mod.json index 951064b8..ffac96b0 100644 --- a/1.17/src/main/resources/fabric.mod.json +++ b/1.17/src/main/resources/fabric.mod.json @@ -10,18 +10,11 @@ ], "contact": {}, "license": "MIT", - "environment": "server", - "entrypoints": { - "main": [ - "dev.u9g.minecraftdatagenerator.Main" - ] - }, "mixins": [ "minecraft-data-generator.mixins.json" ], "depends": { - "fabricloader": ">=0.13.3", - "fabric": "*", - "minecraft": "1.17" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/1.17/src/main/resources/minecraft-data-generator.mixins.json b/1.17/src/main/resources/minecraft-data-generator.mixins.json index d5bc0ee8..b8f9bb32 100644 --- a/1.17/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.17/src/main/resources/minecraft-data-generator.mixins.json @@ -4,10 +4,8 @@ "package": "dev.u9g.minecraftdatagenerator.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "ClientPlayerInteractionManagerMixin", "MiningToolItemAccessor", - "ReadyMixin", - "SoundAccessor" + "ReadyMixin" ], "client": [ ], diff --git a/1.18/build.gradle b/1.18/build.gradle index e85de392..ae4095d7 100644 --- a/1.18/build.gradle +++ b/1.18/build.gradle @@ -1,15 +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' } -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +unimined.minecraft { + version "1.18" + + mappings { + intermediary() + yarn(1) + + devFallbackNamespace "intermediary" + } + + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } + + customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() + } - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + defaultRemapJar = true +} + +dependencies { + implementation project(":common") } processResources { @@ -20,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.18/gradle.properties b/1.18/gradle.properties deleted file mode 100644 index a13d73ad..00000000 --- a/1.18/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.18 -yarn_mappings=1.18+build.1 -loader_version=0.14.4 -# Dependencies -# check this on https://modmuss50.me/fabric.html -fabric_version=0.44.0+1.18 diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index f8d17372..00000000 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.u9g.minecraftdatagenerator; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Main implements ModInitializer { - public static final Logger LOGGER = LoggerFactory.getLogger("mc-data-gen-serv"); - - @Override - public void onInitialize() { - - } -} diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 52c3181d..61e1b9e6 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,10 +12,7 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class BlockCollisionShapesDataGenerator implements IDataGenerator { @@ -40,8 +37,8 @@ public JsonObject generateDataJson() { } private static class BlockShapesCache { - public final Map uniqueBlockShapes = new HashMap<>(); - public final Map> blockCollisionShapes = new HashMap<>(); + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); private int lastCollisionShapeId = 0; public void processBlock(Block block) { @@ -70,7 +67,7 @@ public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { long distinctShapesCount = blockCollisions.stream().distinct().count(); JsonElement blockCollision; if (distinctShapesCount == 1L) { - blockCollision = new JsonPrimitive(blockCollisions.get(0)); + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); } else { blockCollision = new JsonArray(); for (int collisionId : blockCollisions) { diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 3c082458..077937eb 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -104,7 +104,7 @@ private static String findMatchingBlockMaterial(BlockState blockState, List 1) { - var firstMaterial = matchingMaterials.get(0); + var firstMaterial = matchingMaterials.getFirst(); var otherMaterials = matchingMaterials.subList(1, matchingMaterials.size()); if (!otherMaterials.stream().allMatch(firstMaterial::includesMaterial)) { @@ -114,25 +114,25 @@ private static String findMatchingBlockMaterial(BlockState blockState, List blockRegistry, List materials, Block block) { + public static JsonObject generateBlock(List materials, Block block) { JsonObject blockDesc = new JsonObject(); List blockStates = block.getStateManager().getStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = blockRegistry.getKey(block).orElseThrow().getValue(); + Identifier registryKey = Registry.BLOCK.getKey(block).orElseThrow().getValue(); String localizationKey = block.getTranslationKey(); List effectiveTools = getItemsEffectiveForBlock(defaultState); - blockDesc.addProperty("id", blockRegistry.getRawId(block)); + blockDesc.addProperty("id", Registry.BLOCK.getRawId(block)); blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); blockDesc.addProperty("name", registryKey.getPath()); blockDesc.addProperty("hardness", block.getHardness()); blockDesc.addProperty("resistance", block.getBlastResistance()); - blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.get(0))); - blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.get(blockStates.size() - 1))); + blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.getFirst())); + blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.getLast())); JsonArray stateProperties = new JsonArray(); for (Property property : block.getStateManager().getProperties()) { stateProperties.add(generateStateProperty(property)); @@ -140,7 +140,7 @@ public static JsonObject generateBlock(Registry blockRegistry, List actualBlockDrops = new ArrayList<>(); - // populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.get(0), actualBlockDrops); + // populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.getFirst(), actualBlockDrops); // for (ItemStack dropStack : actualBlockDrops) { // dropsArray.add(Item.getRawId(dropStack.getItem())); @@ -184,7 +184,7 @@ public JsonArray generateDataJson() { Registry blockRegistry = Registry.BLOCK; List availableMaterials = MaterialsDataGenerator.getGlobalMaterialInfo(); - blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, availableMaterials, block))); + blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(availableMaterials, block))); return resultBlocksArray; } } diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index 2abb6288..00000000 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -1,75 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; -import dev.u9g.minecraftdatagenerator.util.DGU; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -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.util.ArrayList; -import java.util.List; - -public class DataGenerators { - - private static final Logger logger = LoggerFactory.getLogger(DataGenerators.class); - private static final List GENERATORS = new ArrayList<>(); - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new MaterialsDataGenerator()); -// register(new RecipeDataGenerator()); - On hold until mcdata supports multiple materials for a recipe - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new SoundsDataGenerator()); - } - - public static void register(IDataGenerator generator) { - GENERATORS.add(generator); - } - - public static boolean runDataGenerators(Path outputDirectory) { - try { - Files.createDirectories(outputDirectory); - } catch (IOException exception) { - logger.error("Failed to create data generator output directory at {}", outputDirectory, exception); - return false; - } - - int generatorsFailed = 0; - logger.info("Running minecraft data generators, output at {}", outputDirectory); - - for (IDataGenerator dataGenerator : GENERATORS) { - logger.info("Running generator {}", 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)) { - DGU.JSON_ELEMENT.write(DGU.GSON.newJsonWriter(writer), outputElement); - } - logger.info("Generator: {} -> {}", dataGenerator.getDataName(), outputFileName); - - } catch (Throwable exception) { - logger.error("Failed to run data generator {}", dataGenerator.getDataName(), exception); - generatorsFailed++; - } - } - - logger.info("Finishing running data generators"); - return generatorsFailed == 0; - } -} diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 1c9849e6..9b4beb53 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -13,7 +13,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(statusEffect).orElseThrow().getValue(); diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java index e27fb68f..44449345 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.collect.ImmutableMap; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -11,29 +10,10 @@ import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; public class EnchantmentsDataGenerator implements IDataGenerator { - - private static final ImmutableMap ENCHANTMENT_TARGET_NAMES = ImmutableMap.builder() - .put(EnchantmentTarget.ARMOR, "armor") - .put(EnchantmentTarget.ARMOR_FEET, "armor_feet") - .put(EnchantmentTarget.ARMOR_LEGS, "armor_legs") - .put(EnchantmentTarget.ARMOR_CHEST, "armor_chest") - .put(EnchantmentTarget.ARMOR_HEAD, "armor_head") - .put(EnchantmentTarget.WEAPON, "weapon") - .put(EnchantmentTarget.DIGGER, "digger") - .put(EnchantmentTarget.FISHING_ROD, "fishing_rod") - .put(EnchantmentTarget.TRIDENT, "trident") - .put(EnchantmentTarget.BREAKABLE, "breakable") - .put(EnchantmentTarget.BOW, "bow") - .put(EnchantmentTarget.WEARABLE, "wearable") - .put(EnchantmentTarget.CROSSBOW, "crossbow") - .put(EnchantmentTarget.VANISHABLE, "vanishable") - .build(); - public static String getEnchantmentTargetName(EnchantmentTarget target) { - return ENCHANTMENT_TARGET_NAMES.getOrDefault(target, target.name().toLowerCase(Locale.ROOT)); + return 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 diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 8d94a6b7..29e7ee2b 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -18,7 +18,6 @@ import net.minecraft.util.registry.Registry; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getKey(entityType).orElseThrow().getValue(); diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index 45a0b35f..de659be9 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(Registry registry, Item foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = registry.getKey(foodItem).orElseThrow().getValue(); diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java index 3b96085d..5dcbb062 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.gson.JsonElement; @@ -41,7 +40,7 @@ private static String makeMaterialNameForTag(Tag tag) { } private static void createCompositeMaterialInfo(List allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); List mappedMaterials = combinedMaterials.stream() .map(otherName -> allMaterials.stream() @@ -53,16 +52,19 @@ private static void createCompositeMaterialInfo(List allMaterials, mappedMaterials.stream().allMatch(it -> it.getPredicate().test(blockState)); MaterialInfo materialInfo = new MaterialInfo(compositeMaterialName, compositePredicate).includes(mappedMaterials); - allMaterials.add(0, materialInfo); + allMaterials.addFirst(materialInfo); } private static void createCompositeMaterial(Map> allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); - Map resultingToolSpeeds = new HashMap<>(); + Map resultingToolSpeeds = new LinkedHashMap<>(); combinedMaterials.stream() .map(allMaterials::get) - .forEach(resultingToolSpeeds::putAll); + .forEach(v -> { + System.out.println(v); + resultingToolSpeeds.putAll(v); + }); allMaterials.put(compositeMaterialName, resultingToolSpeeds); } @@ -106,14 +108,14 @@ public String getDataName() { public JsonElement generateDataJson() { Registry itemRegistry = Registry.ITEM; - Map> materialMiningSpeeds = new HashMap<>(); + Map> materialMiningSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put("default", ImmutableMap.of()); //Special materials used for shears and swords special mining speed logic - Map leavesMaterialSpeeds = new HashMap<>(); - Map cowebMaterialSpeeds = new HashMap<>(); - Map plantMaterialSpeeds = new HashMap<>(); - Map gourdMaterialSpeeds = new HashMap<>(); + Map leavesMaterialSpeeds = new LinkedHashMap<>(); + Map cowebMaterialSpeeds = new LinkedHashMap<>(); + Map plantMaterialSpeeds = new LinkedHashMap<>(); + Map gourdMaterialSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put(makeMaterialNameForTag(BlockTags.LEAVES), leavesMaterialSpeeds); materialMiningSpeeds.put("coweb", cowebMaterialSpeeds); @@ -132,7 +134,7 @@ public JsonElement generateDataJson() { Tag effectiveBlocks = ((MiningToolItemAccessor) toolItem).getEffectiveBlocks(); String materialName = makeMaterialNameForTag(effectiveBlocks); - Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new HashMap<>()); + Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>()); float miningSpeed = ((MiningToolItemAccessor) toolItem).getMiningSpeed(); materialSpeeds.put(item, miningSpeed); } diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 5a6b1081..80cca516 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -7,7 +7,6 @@ import net.minecraft.util.registry.Registry; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(particleType).orElseThrow().getValue(); diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index 6fdecd68..585eb218 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -2,18 +2,15 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; import net.minecraft.sound.SoundEvent; import net.minecraft.util.registry.Registry; - public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(Registry registry, SoundEvent soundEvent) { + public static JsonObject generateSound(SoundEvent soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", registry.getRawId(soundEvent)); - soundDesc.addProperty("name", ((SoundAccessor)soundEvent).id().getPath()); + soundDesc.addProperty("id", Registry.SOUND_EVENT.getRawId(soundEvent)); + soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; } @@ -26,8 +23,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - Registry soundEventRegistry = Registry.SOUND_EVENT; - soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, sound))); + Registry.SOUND_EVENT.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 3ceef91b..5a287186 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -4,7 +4,6 @@ import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView; import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; import net.minecraft.block.Blocks; @@ -20,7 +19,6 @@ import java.util.*; public class TintsDataGenerator implements IDataGenerator { - public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { BiomeTintColors colors = new BiomeTintColors(); @@ -37,7 +35,7 @@ public static BiomeTintColors generateBiomeTintColors(Registry biomeRegis } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { int color = RedstoneWireBlock.getWireColor(redstoneLevel); @@ -46,26 +44,23 @@ public static Map generateRedstoneTintColors() { return resultColors; } - @Environment(EnvType.CLIENT) - private static int getBlockColor(Block block, BlockColors blockColors) { - return blockColors.getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); + private static int getBlockColor(Block block) { + return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); } - @Environment(EnvType.CLIENT) public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors)); - 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.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors)); + resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); return resultColors; } @@ -161,8 +156,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ClientPlayerInteractionManagerMixin.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ClientPlayerInteractionManagerMixin.java deleted file mode 100644 index 40e926af..00000000 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ClientPlayerInteractionManagerMixin.java +++ /dev/null @@ -1,57 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import com.google.common.base.Preconditions; -import net.minecraft.block.BlockState; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerInteractionManager; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ClientPlayerInteractionManager.class) -public abstract class ClientPlayerInteractionManagerMixin { - @Unique - private long blockBreakingStartTicks; - @Unique - private BlockState stateBeingBroken; - - @Inject(method = "attackBlock", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;currentBreakingProgress:F", opcode = Opcodes.PUTFIELD)) - private void onBlockAttacked(BlockPos pos, Direction direction, CallbackInfoReturnable callbackInfo) { - World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world); - this.blockBreakingStartTicks = world.getTime(); - } - - @Inject(method = "cancelBlockBreaking", at = @At("HEAD")) - private void onBlockBreakingCanceled(CallbackInfo callbackInfo) { - this.blockBreakingStartTicks = -1L; - } - - @Inject(method = "breakBlock", at = @At("HEAD")) - private void onBreakBlockHead(BlockPos pos, CallbackInfoReturnable callbackInfo) { - World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world); - this.stateBeingBroken = world.getBlockState(pos); - } - - @Inject(method = "breakBlock", at = @At("RETURN")) - private void onBreakBlockReturn(BlockPos pos, CallbackInfoReturnable callbackInfo) { - World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world); - if (callbackInfo.getReturnValue()) { - Preconditions.checkNotNull(stateBeingBroken); - if (blockBreakingStartTicks != -1L) { - long totalTicksElapsed = world.getTime() - this.blockBreakingStartTicks; - long totalTimeElapsed = totalTicksElapsed * 50L; - System.out.printf("Breaking block %s took %dms%n", stateBeingBroken.getBlock(), totalTimeElapsed); - } else { - System.out.printf("Breaking block %s took 0ms [INSTANT BREAK]%n", stateBeingBroken.getBlock()); - } - } - this.blockBreakingStartTicks = -1L; - } -} diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index ba3b26b4..c904c153 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.MinecraftVersion; import net.minecraft.server.dedicated.MinecraftDedicatedServer; @@ -10,18 +9,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.nio.file.Path; - @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = MinecraftVersion.CURRENT.getName(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + MinecraftVersion.CURRENT.getName(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java deleted file mode 100644 index 34b44bc5..00000000 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - - -import net.minecraft.sound.SoundEvent; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(SoundEvent.class) -public interface SoundAccessor { - @Accessor("id") - Identifier id(); -} diff --git a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index dfb640d5..3946c1fe 100644 --- a/1.18/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.18/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -1,143 +1,18 @@ package dev.u9g.minecraftdatagenerator.util; -import com.google.gson.*; -import com.google.gson.internal.LazilyParsedNumber; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.resource.language.I18n; import net.minecraft.server.MinecraftServer; import net.minecraft.util.Language; import net.minecraft.world.World; -import java.io.IOException; -import java.util.Map; - public class DGU { - - public static final TypeAdapter JSON_ELEMENT = new TypeAdapter<>() { - @Override - public JsonElement read(JsonReader in) throws IOException { - switch (in.peek()) { - case STRING: - return new JsonPrimitive(in.nextString()); - case NUMBER: - String number = in.nextString(); - return new JsonPrimitive(new LazilyParsedNumber(number)); - case BOOLEAN: - return new JsonPrimitive(in.nextBoolean()); - case NULL: - in.nextNull(); - return JsonNull.INSTANCE; - case BEGIN_ARRAY: - JsonArray array = new JsonArray(); - in.beginArray(); - while (in.hasNext()) { - array.add(read(in)); - } - in.endArray(); - return array; - case BEGIN_OBJECT: - JsonObject object = new JsonObject(); - in.beginObject(); - while (in.hasNext()) { - object.add(in.nextName(), read(in)); - } - in.endObject(); - return object; - case END_DOCUMENT: - case NAME: - case END_OBJECT: - case END_ARRAY: - default: - throw new IllegalArgumentException(); - } - } - - @Override - public void write(JsonWriter out, JsonElement value) throws IOException { - if (value == null || value.isJsonNull()) { - out.nullValue(); - } else if (value.isJsonPrimitive()) { - JsonPrimitive primitive = value.getAsJsonPrimitive(); - if (primitive.isNumber()) { - if (primitive.getAsDouble() == primitive.getAsLong()) { - out.value(primitive.getAsLong()); - } else { - out.value(primitive.getAsNumber()); - } - } else if (primitive.isBoolean()) { - out.value(primitive.getAsBoolean()); - } else { - out.value(primitive.getAsString()); - } - - } else if (value.isJsonArray()) { - out.beginArray(); - for (JsonElement e : value.getAsJsonArray()) { - write(out, e); - } - out.endArray(); - - } else if (value.isJsonObject()) { - out.beginObject(); - for (Map.Entry e : value.getAsJsonObject().entrySet()) { - out.name(e.getKey()); - write(out, e.getValue()); - } - out.endObject(); - - } else { - throw new IllegalArgumentException("Couldn't write " + value.getClass()); - } - } - }; - public static final Gson GSON = new GsonBuilder() - .registerTypeAdapter(JsonElement.class, JSON_ELEMENT).setPrettyPrinting().create(); - private static final Language language = Language.getInstance(); - - @Environment(EnvType.CLIENT) - private static MinecraftServer getCurrentlyRunningServerClient() { - return MinecraftClient.getInstance().getServer(); - } - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return getCurrentlyRunningServerClient(); - } else if (environmentType == EnvType.SERVER) { - return getCurrentlyRunningServerDedicated(); - } - throw new UnsupportedOperationException(); - } - - @Environment(EnvType.CLIENT) - private static String translateTextClient(String translationKey) { - return I18n.translate(translationKey); - } - - private static String translateTextFallback(String translationKey) { - try { - return language.get(translationKey); - } catch (Exception ignored) { - } - throw new RuntimeException("Failed to translate: '" + translationKey + "'"); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } public static String translateText(String translationKey) { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return translateTextClient(translationKey); - } - return translateTextFallback(translationKey); + return Language.getInstance().get(translationKey); } public static World getWorld() { diff --git a/1.18/src/main/resources/fabric.mod.json b/1.18/src/main/resources/fabric.mod.json index 4eeec5d2..ffac96b0 100644 --- a/1.18/src/main/resources/fabric.mod.json +++ b/1.18/src/main/resources/fabric.mod.json @@ -10,18 +10,11 @@ ], "contact": {}, "license": "MIT", - "environment": "server", - "entrypoints": { - "main": [ - "dev.u9g.minecraftdatagenerator.Main" - ] - }, "mixins": [ "minecraft-data-generator.mixins.json" ], "depends": { - "fabricloader": ">=0.14.4", - "fabric": "*", - "minecraft": "1.18" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/1.18/src/main/resources/minecraft-data-generator.mixins.json b/1.18/src/main/resources/minecraft-data-generator.mixins.json index 0867f2e4..d46bf65f 100644 --- a/1.18/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.18/src/main/resources/minecraft-data-generator.mixins.json @@ -4,11 +4,9 @@ "package": "dev.u9g.minecraftdatagenerator.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "ClientPlayerInteractionManagerMixin", "EULAMixin", "MiningToolItemAccessor", - "ReadyMixin", - "SoundAccessor" + "ReadyMixin" ], "client": [ ], diff --git a/1.19.2/build.gradle b/1.19.2/build.gradle index e85de392..6d565aef 100644 --- a/1.19.2/build.gradle +++ b/1.19.2/build.gradle @@ -1,15 +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' } -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +unimined.minecraft { + version "1.19.2" + + mappings { + intermediary() + yarn(9) + + devFallbackNamespace "intermediary" + } + + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } + + customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() + } - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + defaultRemapJar = true +} + +dependencies { + implementation project(":common") } processResources { @@ -20,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.19.2/gradle.properties b/1.19.2/gradle.properties deleted file mode 100644 index ff2fb68f..00000000 --- a/1.19.2/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.19.2 -yarn_mappings=1.19.2+build.28 -loader_version=0.14.10 -# Dependencies -# check this on https://modmuss50.me/fabric.html -fabric_version=0.67.0+1.19.2 diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index f8d17372..00000000 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.u9g.minecraftdatagenerator; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Main implements ModInitializer { - public static final Logger LOGGER = LoggerFactory.getLogger("mc-data-gen-serv"); - - @Override - public void onInitialize() { - - } -} diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 88200df7..e53f198b 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -2,35 +2,25 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.TheEndBiomeDataAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; -import net.fabricmc.fabric.api.biome.v1.NetherBiomes; +import net.minecraft.tag.BiomeTags; import net.minecraft.util.Identifier; +import net.minecraft.util.registry.BuiltinRegistries; import net.minecraft.util.registry.DynamicRegistryManager; import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.biome.Biome; -import java.util.HashSet; -import java.util.Set; - public class BiomesDataGenerator implements IDataGenerator { - private static final Set> END_BIOMES = new HashSet<>(); - - static { - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_BIOMES_MAP().keySet()); - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_BARRENS_MAP().keySet()); - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_MIDLANDS_MAP().keySet()); - } - - private static String guessBiomeDimensionFromCategory(Biome biome, String biomeName) { - var key = DynamicRegistryManager.BUILTIN.get().get(Registry.BIOME_KEY).getKey(biome).orElseThrow(); - if (NetherBiomes.canGenerateInNether(key)) { + private static String guessBiomeDimensionFromCategory(RegistryKey biome) { + var biomeRegistry = BuiltinRegistries.BIOME; + if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_NETHER)) { return "nether"; - } else if (END_BIOMES.contains(key) || biomeName.startsWith("end_")) { + } else if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_END)) { return "end"; + } else { + return "overworld"; } - return "overworld"; } private static String guessCategoryBasedOnName(String name, String dimension) { @@ -86,211 +76,22 @@ private static String guessCategoryBasedOnName(String name, String dimension) { } } - private static int getBiomeColorFor(String biomeName) { - switch (biomeName) { - case "the_void" -> { - return 0; - } - case "plains" -> { - return 9286496; - } - case "sunflower_plains" -> { - return 11918216; - } - case "snowy_plains" -> { - return 16777215; - } - case "ice_spikes" -> { - return 11853020; - } - case "desert" -> { - return 16421912; - } - case "swamp" -> { - return 522674; - } - case "forest" -> { - return 353825; - } - case "flower_forest" -> { - return 2985545; - } - case "birch_forest" -> { - return 3175492; - } - case "dark_forest" -> { - return 4215066; - } - case "old_growth_birch_forest" -> { - return 5807212; - } - case "old_growth_pine_taiga" -> { - return 5858897; - } - case "old_growth_spruce_taiga" -> { - return 8490617; - } - case "taiga" -> { - return 747097; - } - case "snowy_taiga" -> { - return 3233098; - } - case "savanna" -> { - return 12431967; - } - case "savanna_plateau" -> { - return 10984804; - } - case "windswept_hills" -> { - return 6316128; - } - case "windswept_gravelly_hills" -> { - return 8947848; - } - case "windswept_forest" -> { - return 2250012; - } - case "windswept_savanna" -> { - return 15063687; - } - case "jungle" -> { - return 5470985; - } - case "sparse_jungle" -> { - return 6458135; - } - case "bamboo_jungle" -> { - return 7769620; - } - case "badlands" -> { - return 14238997; - } - case "eroded_badlands" -> { - return 16739645; - } - case "wooded_badlands" -> { - return 11573093; - } - case "meadow" -> { - return 9217136; - } - case "grove" -> { - return 14675173; - } - case "snowy_slopes" -> { - return 14348785; - } - case "frozen_peaks" -> { - return 15399931; - } - case "jagged_peaks" -> { - return 14937325; - } - case "stony_peaks" -> { - return 13750737; - } - case "river" -> { - return 255; - } - case "frozen_river" -> { - return 10526975; - } - case "beach" -> { - return 16440917; - } - case "snowy_beach" -> { - return 16445632; - } - case "stony_shore" -> { - return 10658436; - } - case "warm_ocean" -> { - return 172; - } - case "lukewarm_ocean" -> { - return 144; - } - case "deep_lukewarm_ocean" -> { - return 64; - } - case "ocean" -> { - return 112; - } - case "deep_ocean" -> { - return 48; - } - case "cold_ocean" -> { - return 2105456; - } - case "deep_cold_ocean" -> { - return 2105400; - } - case "frozen_ocean" -> { - return 7368918; - } - case "deep_frozen_ocean" -> { - return 4210832; - } - case "mushroom_fields" -> { - return 16711935; - } - case "dripstone_caves" -> { - return 12690831; - } - case "lush_caves" -> { - return 14652980; - } - case "nether_wastes" -> { - return 12532539; - } - case "warped_forest" -> { - return 4821115; - } - case "crimson_forest" -> { - return 14485512; - } - case "soul_sand_valley" -> { - return 6174768; - } - case "basalt_deltas" -> { - return 4208182; - } - case "the_end" -> { - return 8421631; - } - case "end_highlands" -> { - return 12828041; - } - case "end_midlands" -> { - return 15464630; - } - case "small_end_islands" -> { - return 42; - } - case "end_barrens" -> { - return 9474162; - } - } - System.out.println("Don't know the color of biome: '" + biomeName + "'"); - return 0; - } - public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); - Identifier registryKey = registry.getKey(biome).orElseThrow().getValue(); - String localizationKey = String.format("biome.%s.%s", registryKey.getNamespace(), registryKey.getPath()); - String name = registryKey.getPath(); + RegistryKey registryKey = registry.getKey(biome).orElseThrow(); + Identifier identifier = registryKey.getValue(); + String localizationKey = String.format("biome.%s.%s", identifier.getNamespace(), identifier.getPath()); + String name = identifier.getPath(); biomeDesc.addProperty("id", registry.getRawId(biome)); biomeDesc.addProperty("name", name); - String dimension = guessBiomeDimensionFromCategory(biome, name); + String dimension = guessBiomeDimensionFromCategory(registryKey); biomeDesc.addProperty("category", guessCategoryBasedOnName(name, dimension)); biomeDesc.addProperty("temperature", biome.getTemperature()); biomeDesc.addProperty("precipitation", biome.getPrecipitation().getName()); //biomeDesc.addProperty("depth", biome.getDepth()); - Doesn't exist anymore in minecraft source biomeDesc.addProperty("dimension", dimension); biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); - biomeDesc.addProperty("color", getBiomeColorFor(registryKey.getPath())); + biomeDesc.addProperty("color", biome.getSkyColor()); biomeDesc.addProperty("rainfall", biome.getDownfall()); return biomeDesc; diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 52c3181d..61e1b9e6 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,10 +12,7 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class BlockCollisionShapesDataGenerator implements IDataGenerator { @@ -40,8 +37,8 @@ public JsonObject generateDataJson() { } private static class BlockShapesCache { - public final Map uniqueBlockShapes = new HashMap<>(); - public final Map> blockCollisionShapes = new HashMap<>(); + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); private int lastCollisionShapeId = 0; public void processBlock(Block block) { @@ -70,7 +67,7 @@ public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { long distinctShapesCount = blockCollisions.stream().distinct().count(); JsonElement blockCollision; if (distinctShapesCount == 1L) { - blockCollision = new JsonPrimitive(blockCollisions.get(0)); + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); } else { blockCollision = new JsonArray(); for (int collisionId : blockCollisions) { diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 51139655..cb407427 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -105,7 +105,7 @@ private static String findMatchingBlockMaterial(BlockState blockState, List 1) { - var firstMaterial = matchingMaterials.get(0); + var firstMaterial = matchingMaterials.getFirst(); var otherMaterials = matchingMaterials.subList(1, matchingMaterials.size()); if (!otherMaterials.stream().allMatch(firstMaterial::includesMaterial)) { @@ -115,19 +115,19 @@ private static String findMatchingBlockMaterial(BlockState blockState, List blockRegistry, List materials, Block block) { + public static JsonObject generateBlock(List materials, Block block) { JsonObject blockDesc = new JsonObject(); List blockStates = block.getStateManager().getStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = blockRegistry.getKey(block).orElseThrow().getValue(); + Identifier registryKey = Registry.BLOCK.getKey(block).orElseThrow().getValue(); String localizationKey = block.getTranslationKey(); List effectiveTools = getItemsEffectiveForBlock(defaultState); - blockDesc.addProperty("id", blockRegistry.getRawId(block)); + blockDesc.addProperty("id", Registry.BLOCK.getRawId(block)); blockDesc.addProperty("name", registryKey.getPath()); blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); @@ -148,8 +148,8 @@ public static JsonObject generateBlock(Registry blockRegistry, List property : block.getStateManager().getProperties()) { @@ -167,7 +167,7 @@ public static JsonObject generateBlock(Registry blockRegistry, List actualBlockDrops = new ArrayList<>(); - populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.get(0), actualBlockDrops); + populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.getFirst(), actualBlockDrops); JsonArray dropsArray = new JsonArray(); for (ItemStack dropStack : actualBlockDrops) { @@ -192,7 +192,7 @@ public JsonArray generateDataJson() { Registry blockRegistry = Registry.BLOCK; List availableMaterials = MaterialsDataGenerator.getGlobalMaterialInfo(); - blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, availableMaterials, block))); + blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(availableMaterials, block))); return resultBlocksArray; } } diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index ebf2ed5f..00000000 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -1,78 +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 org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -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.util.ArrayList; -import java.util.List; - -public class DataGenerators { - - private static final Logger logger = LoggerFactory.getLogger(DataGenerators.class); - private static final List GENERATORS = new ArrayList<>(); - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new MaterialsDataGenerator()); -// register(new RecipeDataGenerator()); - On hold until mcdata supports multiple materials for a recipe - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new SoundsDataGenerator()); - } - - public static void register(IDataGenerator generator) { - GENERATORS.add(generator); - } - - public static boolean runDataGenerators(Path outputDirectory) { - try { - Files.createDirectories(outputDirectory); - } catch (IOException exception) { - logger.error("Failed to create data generator output directory at {}", outputDirectory, exception); - return false; - } - - int generatorsFailed = 0; - logger.info("Running minecraft data generators, output at {}", outputDirectory); - - for (IDataGenerator dataGenerator : GENERATORS) { - logger.info("Running generator {}", 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("Generator: {} -> {}", dataGenerator.getDataName(), outputFileName); - - } catch (Throwable exception) { - logger.error("Failed to run data generator {}", dataGenerator.getDataName(), exception); - generatorsFailed++; - } - } - - logger.info("Finishing running data generators"); - return generatorsFailed == 0; - } -} diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 1c9849e6..9b4beb53 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -13,7 +13,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(statusEffect).orElseThrow().getValue(); diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java index e27fb68f..44449345 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.collect.ImmutableMap; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -11,29 +10,10 @@ import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; public class EnchantmentsDataGenerator implements IDataGenerator { - - private static final ImmutableMap ENCHANTMENT_TARGET_NAMES = ImmutableMap.builder() - .put(EnchantmentTarget.ARMOR, "armor") - .put(EnchantmentTarget.ARMOR_FEET, "armor_feet") - .put(EnchantmentTarget.ARMOR_LEGS, "armor_legs") - .put(EnchantmentTarget.ARMOR_CHEST, "armor_chest") - .put(EnchantmentTarget.ARMOR_HEAD, "armor_head") - .put(EnchantmentTarget.WEAPON, "weapon") - .put(EnchantmentTarget.DIGGER, "digger") - .put(EnchantmentTarget.FISHING_ROD, "fishing_rod") - .put(EnchantmentTarget.TRIDENT, "trident") - .put(EnchantmentTarget.BREAKABLE, "breakable") - .put(EnchantmentTarget.BOW, "bow") - .put(EnchantmentTarget.WEARABLE, "wearable") - .put(EnchantmentTarget.CROSSBOW, "crossbow") - .put(EnchantmentTarget.VANISHABLE, "vanishable") - .build(); - public static String getEnchantmentTargetName(EnchantmentTarget target) { - return ENCHANTMENT_TARGET_NAMES.getOrDefault(target, target.name().toLowerCase(Locale.ROOT)); + return 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 diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 4eacf202..703aeade 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -2,7 +2,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.EntityTypeAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -19,7 +18,6 @@ import net.minecraft.util.registry.Registry; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getKey(entityType).orElseThrow().getValue(); @@ -47,11 +45,8 @@ public static JsonObject generateEntity(Registry> entityRegistry, } private static String getCategoryFrom(EntityType entityType) { - if (entityType == EntityType.PLAYER) return "UNKNOWN"; // fail early for player entities - /*public T create(World world) { - return this.factory.create(this, world); - }*/ - Entity entity = ((EntityTypeAccessor) entityType).factory().create(entityType, DGU.getWorld()); + if (entityType == EntityType.PLAYER) return "UNKNOWN"; + Entity entity = entityType.create(DGU.getWorld()); if (entity == null) throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index 45a0b35f..de659be9 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(Registry registry, Item foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = registry.getKey(foodItem).orElseThrow().getValue(); diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java index 4253ae69..1739de21 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.gson.JsonElement; @@ -40,7 +39,7 @@ private static String makeMaterialNameForTag(TagKey tag) { } private static void createCompositeMaterialInfo(List allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); List mappedMaterials = combinedMaterials.stream() .map(otherName -> allMaterials.stream() @@ -52,13 +51,13 @@ private static void createCompositeMaterialInfo(List allMaterials, mappedMaterials.stream().allMatch(it -> it.getPredicate().test(blockState)); MaterialInfo materialInfo = new MaterialInfo(compositeMaterialName, compositePredicate).includes(mappedMaterials); - allMaterials.add(0, materialInfo); + allMaterials.addFirst(materialInfo); } private static void createCompositeMaterial(Map> allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); - Map resultingToolSpeeds = new HashMap<>(); + Map resultingToolSpeeds = new LinkedHashMap<>(); combinedMaterials.stream() .map(allMaterials::get) .forEach(resultingToolSpeeds::putAll); @@ -105,14 +104,14 @@ public String getDataName() { public JsonElement generateDataJson() { Registry itemRegistry = Registry.ITEM; - Map> materialMiningSpeeds = new HashMap<>(); + Map> materialMiningSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put("default", ImmutableMap.of()); //Special materials used for shears and swords special mining speed logic - Map leavesMaterialSpeeds = new HashMap<>(); - Map cowebMaterialSpeeds = new HashMap<>(); - Map plantMaterialSpeeds = new HashMap<>(); - Map gourdMaterialSpeeds = new HashMap<>(); + Map leavesMaterialSpeeds = new LinkedHashMap<>(); + Map cowebMaterialSpeeds = new LinkedHashMap<>(); + Map plantMaterialSpeeds = new LinkedHashMap<>(); + Map gourdMaterialSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put(makeMaterialNameForTag(BlockTags.LEAVES), leavesMaterialSpeeds); materialMiningSpeeds.put("coweb", cowebMaterialSpeeds); @@ -131,7 +130,7 @@ public JsonElement generateDataJson() { TagKey effectiveBlocks = ((MiningToolItemAccessor) toolItem).getEffectiveBlocks(); String materialName = makeMaterialNameForTag(effectiveBlocks); - Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new HashMap<>()); + Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>()); float miningSpeed = ((MiningToolItemAccessor) toolItem).getMiningSpeed(); materialSpeeds.put(item, miningSpeed); } diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 5a6b1081..80cca516 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -7,7 +7,6 @@ import net.minecraft.util.registry.Registry; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(particleType).orElseThrow().getValue(); diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index d063f71d..53afb138 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -5,13 +5,11 @@ import net.minecraft.sound.SoundEvent; import net.minecraft.util.registry.Registry; - public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(Registry registry, SoundEvent soundEvent) { + public static JsonObject generateSound(SoundEvent soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", registry.getRawId(soundEvent)+1); // the plus 1 is required for 1.19.2+ due to Mojang using 0 in the packet to say that you should read a string id instead. + soundDesc.addProperty("id", Registry.SOUND_EVENT.getRawId(soundEvent) + 1); // the plus 1 is required for 1.19.2+ due to Mojang using 0 in the packet to say that you should read a string id instead. soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; @@ -25,8 +23,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - Registry soundEventRegistry = Registry.SOUND_EVENT; - soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, sound))); + Registry.SOUND_EVENT.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index dda76c54..5cd4ad15 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -2,11 +2,11 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mojangannoyances.BlockColors; import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.RedstoneWireBlock; +import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.world.FoliageColors; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -14,13 +14,9 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class TintsDataGenerator implements IDataGenerator { - public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { BiomeTintColors colors = new BiomeTintColors(); @@ -37,7 +33,7 @@ public static BiomeTintColors generateBiomeTintColors(Registry biomeRegis } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { int color = RedstoneWireBlock.getWireColor(redstoneLevel); @@ -46,24 +42,23 @@ public static Map generateRedstoneTintColors() { return resultColors; } - private static int getBlockColor(Block block, BlockColors blockColors) { - return blockColors.getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); + private static int getBlockColor(Block block) { + return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); } public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors)); - 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.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors)); + resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); return resultColors; } @@ -154,8 +149,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java deleted file mode 100644 index 3e62bf59..00000000 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(EntityType.class) -public interface EntityTypeAccessor { - @Accessor("factory") - EntityType.EntityFactory factory(); -} diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index ba3b26b4..c904c153 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.MinecraftVersion; import net.minecraft.server.dedicated.MinecraftDedicatedServer; @@ -10,18 +9,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.nio.file.Path; - @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = MinecraftVersion.CURRENT.getName(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + MinecraftVersion.CURRENT.getName(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java deleted file mode 100644 index 2796b2a6..00000000 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java +++ /dev/null @@ -1,29 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.fabricmc.fabric.impl.biome.TheEndBiomeData; -import net.fabricmc.fabric.impl.biome.WeightedPicker; -import net.minecraft.util.registry.RegistryKey; -import net.minecraft.world.biome.Biome; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; - - -@Mixin(TheEndBiomeData.class) -public interface TheEndBiomeDataAccessor { - @Accessor(value = "END_BIOMES_MAP", remap = false) - static Map, WeightedPicker>> END_BIOMES_MAP() { - throw new IllegalStateException("Should never be called."); - } - - @Accessor(value = "END_MIDLANDS_MAP", remap = false) - static Map, WeightedPicker>> END_MIDLANDS_MAP() { - throw new IllegalStateException("Should never be called."); - } - - @Accessor(value = "END_BARRENS_MAP", remap = false) - static Map, WeightedPicker>> END_BARRENS_MAP() { - throw new IllegalStateException("Should never be called."); - } -} diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java deleted file mode 100644 index bb9ae83f..00000000 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.level.ColorResolver; - -@Environment(EnvType.CLIENT) -public class BiomeColors { - public static final ColorResolver GRASS_COLOR = Biome::getGrassColorAt; - public static final ColorResolver FOLIAGE_COLOR = (biome, x, z) -> biome.getFoliageColor(); - public static final ColorResolver WATER_COLOR = (biome, x, z) -> biome.getWaterColor(); - - public BiomeColors() { - } - - private static int getColor(BlockRenderView world, BlockPos pos, ColorResolver resolver) { - return world.getColor(pos, resolver); - } - - public static int getGrassColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, GRASS_COLOR); - } - - public static int getFoliageColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, FOLIAGE_COLOR); - } - - public static int getWaterColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, WATER_COLOR); - } -} - diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java deleted file mode 100644 index ac5dc572..00000000 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import org.jetbrains.annotations.Nullable; - -public interface BlockColorProvider { - int getColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex); -} - diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java deleted file mode 100644 index e8430ebe..00000000 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java +++ /dev/null @@ -1,93 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import net.minecraft.block.*; -import net.minecraft.block.enums.DoubleBlockHalf; -import net.minecraft.client.color.world.FoliageColors; -import net.minecraft.client.color.world.GrassColors; -import net.minecraft.state.property.Property; -import net.minecraft.util.collection.IdList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.BlockRenderView; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; -import java.util.Set; - -public class BlockColors { - private static final int NO_COLOR = -1; - private final IdList providers = new IdList<>(32); - private final Map>> properties = Maps.newHashMap(); - - public BlockColors() { - } - - public static BlockColors create() { - BlockColors blockColors = new BlockColors(); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, state.get(TallPlantBlock.HALF) == DoubleBlockHalf.UPPER ? pos.down() : pos) : -1, Blocks.LARGE_FERN, Blocks.TALL_GRASS); - blockColors.registerColorProperty(TallPlantBlock.HALF, Blocks.LARGE_FERN, Blocks.TALL_GRASS); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : GrassColors.getColor(0.5, 1.0), Blocks.GRASS_BLOCK, Blocks.FERN, Blocks.GRASS, Blocks.POTTED_FERN); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> FoliageColors.getSpruceColor(), Blocks.SPRUCE_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> FoliageColors.getBirchColor(), Blocks.BIRCH_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getFoliageColor(world, pos) : FoliageColors.getDefaultColor(), Blocks.OAK_LEAVES, Blocks.JUNGLE_LEAVES, Blocks.ACACIA_LEAVES, Blocks.DARK_OAK_LEAVES, Blocks.VINE, Blocks.MANGROVE_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getWaterColor(world, pos) : -1, Blocks.WATER, Blocks.BUBBLE_COLUMN, Blocks.WATER_CAULDRON); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> RedstoneWireBlock.getWireColor(state.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE); - blockColors.registerColorProperty(RedstoneWireBlock.POWER, Blocks.REDSTONE_WIRE); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : -1, Blocks.SUGAR_CANE); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> 14731036, Blocks.ATTACHED_MELON_STEM, Blocks.ATTACHED_PUMPKIN_STEM); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> { - int i = state.get(StemBlock.AGE); - int j = i * 32; - int k = 255 - i * 8; - int l = i * 4; - return j << 16 | k << 8 | l; - }, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.registerColorProperty(StemBlock.AGE, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? 2129968 : 7455580, Blocks.LILY_PAD); - return blockColors; - } - - public int getParticleColor(BlockState state, World world, BlockPos pos) { - BlockColorProvider blockColorProvider = this.providers.get(Registry.BLOCK.getRawId(state.getBlock())); - if (blockColorProvider != null) { - return blockColorProvider.getColor(state, null, null, 0); - } else { - MapColor mapColor = state.getMapColor(world, pos); - return mapColor != null ? mapColor.color : -1; - } - } - - public int getColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex) { - BlockColorProvider blockColorProvider = this.providers.get(Registry.BLOCK.getRawId(state.getBlock())); - return blockColorProvider == null ? -1 : blockColorProvider.getColor(state, world, pos, tintIndex); - } - - public void registerColorProvider(BlockColorProvider provider, Block... blocks) { - int var4 = blocks.length; - - for (Block block : blocks) { - this.providers.set(provider, Registry.BLOCK.getRawId(block)); - } - - } - - private void registerColorProperties(Set> properties, Block... blocks) { - int var4 = blocks.length; - - for (Block block : blocks) { - this.properties.put(block, properties); - } - - } - - private void registerColorProperty(Property property, Block... blocks) { - this.registerColorProperties(ImmutableSet.of(property), blocks); - } - - public Set> getProperties(Block block) { - return this.properties.getOrDefault(block, ImmutableSet.of()); - } -} diff --git a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index 32c2fb65..3946c1fe 100644 --- a/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.19.2/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -6,24 +6,13 @@ import net.minecraft.world.World; public class DGU { - - private static final Language language = Language.getInstance(); - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - return getCurrentlyRunningServerDedicated(); - } - - private static String translateTextFallback(String translationKey) { - return language.get(translationKey); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } public static String translateText(String translationKey) { - return translateTextFallback(translationKey); + return Language.getInstance().get(translationKey); } public static World getWorld() { diff --git a/1.19.2/src/main/resources/fabric.mod.json b/1.19.2/src/main/resources/fabric.mod.json index c999d2a8..ffac96b0 100644 --- a/1.19.2/src/main/resources/fabric.mod.json +++ b/1.19.2/src/main/resources/fabric.mod.json @@ -10,18 +10,11 @@ ], "contact": {}, "license": "MIT", - "environment": "server", - "entrypoints": { - "main": [ - "dev.u9g.minecraftdatagenerator.Main" - ] - }, "mixins": [ "minecraft-data-generator.mixins.json" ], "depends": { - "fabricloader": ">=0.14.4", - "fabric": "*", + "fabricloader": "*", "minecraft": "*" } } diff --git a/1.19.2/src/main/resources/minecraft-data-generator.mixins.json b/1.19.2/src/main/resources/minecraft-data-generator.mixins.json index f3afe061..d46bf65f 100644 --- a/1.19.2/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.19.2/src/main/resources/minecraft-data-generator.mixins.json @@ -4,11 +4,9 @@ "package": "dev.u9g.minecraftdatagenerator.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "EntityTypeAccessor", "EULAMixin", "MiningToolItemAccessor", - "ReadyMixin", - "TheEndBiomeDataAccessor" + "ReadyMixin" ], "client": [ ], diff --git a/1.19/build.gradle b/1.19/build.gradle index e85de392..054cda38 100644 --- a/1.19/build.gradle +++ b/1.19/build.gradle @@ -1,15 +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' } -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +unimined.minecraft { + version "1.19" + + mappings { + intermediary() + yarn(4) + + devFallbackNamespace "intermediary" + } + + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } + + customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() + } - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + defaultRemapJar = true +} + +dependencies { + implementation project(":common") } processResources { @@ -20,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.19/gradle.properties b/1.19/gradle.properties deleted file mode 100644 index b4a4ae23..00000000 --- a/1.19/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.19 -yarn_mappings=1.19+build.1 -loader_version=0.14.6 -# Dependencies -# check this on https://modmuss50.me/fabric.html -fabric_version=0.55.2+1.19 diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index f8d17372..00000000 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.u9g.minecraftdatagenerator; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Main implements ModInitializer { - public static final Logger LOGGER = LoggerFactory.getLogger("mc-data-gen-serv"); - - @Override - public void onInitialize() { - - } -} diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 88200df7..d80bf03e 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -2,35 +2,23 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.TheEndBiomeDataAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; -import net.fabricmc.fabric.api.biome.v1.NetherBiomes; +import net.minecraft.tag.BiomeTags; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.DynamicRegistryManager; -import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.BuiltinRegistries; import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.biome.Biome; -import java.util.HashSet; -import java.util.Set; - public class BiomesDataGenerator implements IDataGenerator { - private static final Set> END_BIOMES = new HashSet<>(); - - static { - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_BIOMES_MAP().keySet()); - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_BARRENS_MAP().keySet()); - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_MIDLANDS_MAP().keySet()); - } - - private static String guessBiomeDimensionFromCategory(Biome biome, String biomeName) { - var key = DynamicRegistryManager.BUILTIN.get().get(Registry.BIOME_KEY).getKey(biome).orElseThrow(); - if (NetherBiomes.canGenerateInNether(key)) { + private static String guessBiomeDimensionFromCategory(RegistryKey biome) { + var biomeRegistry = BuiltinRegistries.BIOME; + if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_NETHER)) { return "nether"; - } else if (END_BIOMES.contains(key) || biomeName.startsWith("end_")) { + } else if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_END)) { return "end"; + } else { + return "overworld"; } - return "overworld"; } private static String guessCategoryBasedOnName(String name, String dimension) { @@ -86,211 +74,22 @@ private static String guessCategoryBasedOnName(String name, String dimension) { } } - private static int getBiomeColorFor(String biomeName) { - switch (biomeName) { - case "the_void" -> { - return 0; - } - case "plains" -> { - return 9286496; - } - case "sunflower_plains" -> { - return 11918216; - } - case "snowy_plains" -> { - return 16777215; - } - case "ice_spikes" -> { - return 11853020; - } - case "desert" -> { - return 16421912; - } - case "swamp" -> { - return 522674; - } - case "forest" -> { - return 353825; - } - case "flower_forest" -> { - return 2985545; - } - case "birch_forest" -> { - return 3175492; - } - case "dark_forest" -> { - return 4215066; - } - case "old_growth_birch_forest" -> { - return 5807212; - } - case "old_growth_pine_taiga" -> { - return 5858897; - } - case "old_growth_spruce_taiga" -> { - return 8490617; - } - case "taiga" -> { - return 747097; - } - case "snowy_taiga" -> { - return 3233098; - } - case "savanna" -> { - return 12431967; - } - case "savanna_plateau" -> { - return 10984804; - } - case "windswept_hills" -> { - return 6316128; - } - case "windswept_gravelly_hills" -> { - return 8947848; - } - case "windswept_forest" -> { - return 2250012; - } - case "windswept_savanna" -> { - return 15063687; - } - case "jungle" -> { - return 5470985; - } - case "sparse_jungle" -> { - return 6458135; - } - case "bamboo_jungle" -> { - return 7769620; - } - case "badlands" -> { - return 14238997; - } - case "eroded_badlands" -> { - return 16739645; - } - case "wooded_badlands" -> { - return 11573093; - } - case "meadow" -> { - return 9217136; - } - case "grove" -> { - return 14675173; - } - case "snowy_slopes" -> { - return 14348785; - } - case "frozen_peaks" -> { - return 15399931; - } - case "jagged_peaks" -> { - return 14937325; - } - case "stony_peaks" -> { - return 13750737; - } - case "river" -> { - return 255; - } - case "frozen_river" -> { - return 10526975; - } - case "beach" -> { - return 16440917; - } - case "snowy_beach" -> { - return 16445632; - } - case "stony_shore" -> { - return 10658436; - } - case "warm_ocean" -> { - return 172; - } - case "lukewarm_ocean" -> { - return 144; - } - case "deep_lukewarm_ocean" -> { - return 64; - } - case "ocean" -> { - return 112; - } - case "deep_ocean" -> { - return 48; - } - case "cold_ocean" -> { - return 2105456; - } - case "deep_cold_ocean" -> { - return 2105400; - } - case "frozen_ocean" -> { - return 7368918; - } - case "deep_frozen_ocean" -> { - return 4210832; - } - case "mushroom_fields" -> { - return 16711935; - } - case "dripstone_caves" -> { - return 12690831; - } - case "lush_caves" -> { - return 14652980; - } - case "nether_wastes" -> { - return 12532539; - } - case "warped_forest" -> { - return 4821115; - } - case "crimson_forest" -> { - return 14485512; - } - case "soul_sand_valley" -> { - return 6174768; - } - case "basalt_deltas" -> { - return 4208182; - } - case "the_end" -> { - return 8421631; - } - case "end_highlands" -> { - return 12828041; - } - case "end_midlands" -> { - return 15464630; - } - case "small_end_islands" -> { - return 42; - } - case "end_barrens" -> { - return 9474162; - } - } - System.out.println("Don't know the color of biome: '" + biomeName + "'"); - return 0; - } - - public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { + public static JsonObject generateBiomeInfo(Biome biome) { JsonObject biomeDesc = new JsonObject(); - Identifier registryKey = registry.getKey(biome).orElseThrow().getValue(); - String localizationKey = String.format("biome.%s.%s", registryKey.getNamespace(), registryKey.getPath()); - String name = registryKey.getPath(); - biomeDesc.addProperty("id", registry.getRawId(biome)); + RegistryKey registryKey = BuiltinRegistries.BIOME.getKey(biome).orElseThrow(); + Identifier identifier = registryKey.getValue(); + String localizationKey = String.format("biome.%s.%s", identifier.getNamespace(), identifier.getPath()); + String name = identifier.getPath(); + biomeDesc.addProperty("id", BuiltinRegistries.BIOME.getRawId(biome)); biomeDesc.addProperty("name", name); - String dimension = guessBiomeDimensionFromCategory(biome, name); + String dimension = guessBiomeDimensionFromCategory(registryKey); biomeDesc.addProperty("category", guessCategoryBasedOnName(name, dimension)); biomeDesc.addProperty("temperature", biome.getTemperature()); biomeDesc.addProperty("precipitation", biome.getPrecipitation().getName()); //biomeDesc.addProperty("depth", biome.getDepth()); - Doesn't exist anymore in minecraft source biomeDesc.addProperty("dimension", dimension); biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); - biomeDesc.addProperty("color", getBiomeColorFor(registryKey.getPath())); + biomeDesc.addProperty("color", biome.getSkyColor()); biomeDesc.addProperty("rainfall", biome.getDownfall()); return biomeDesc; @@ -304,11 +103,8 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray biomesArray = new JsonArray(); - DynamicRegistryManager registryManager = DynamicRegistryManager.BUILTIN.get(); - Registry biomeRegistry = registryManager.get(Registry.BIOME_KEY); - - biomeRegistry.stream() - .map(biome -> generateBiomeInfo(biomeRegistry, biome)) + BuiltinRegistries.BIOME.stream() + .map(BiomesDataGenerator::generateBiomeInfo) .forEach(biomesArray::add); return biomesArray; } diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 52c3181d..61e1b9e6 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,10 +12,7 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class BlockCollisionShapesDataGenerator implements IDataGenerator { @@ -40,8 +37,8 @@ public JsonObject generateDataJson() { } private static class BlockShapesCache { - public final Map uniqueBlockShapes = new HashMap<>(); - public final Map> blockCollisionShapes = new HashMap<>(); + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); private int lastCollisionShapeId = 0; public void processBlock(Block block) { @@ -70,7 +67,7 @@ public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { long distinctShapesCount = blockCollisions.stream().distinct().count(); JsonElement blockCollision; if (distinctShapesCount == 1L) { - blockCollision = new JsonPrimitive(blockCollisions.get(0)); + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); } else { blockCollision = new JsonArray(); for (int collisionId : blockCollisions) { diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 51139655..cb407427 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -105,7 +105,7 @@ private static String findMatchingBlockMaterial(BlockState blockState, List 1) { - var firstMaterial = matchingMaterials.get(0); + var firstMaterial = matchingMaterials.getFirst(); var otherMaterials = matchingMaterials.subList(1, matchingMaterials.size()); if (!otherMaterials.stream().allMatch(firstMaterial::includesMaterial)) { @@ -115,19 +115,19 @@ private static String findMatchingBlockMaterial(BlockState blockState, List blockRegistry, List materials, Block block) { + public static JsonObject generateBlock(List materials, Block block) { JsonObject blockDesc = new JsonObject(); List blockStates = block.getStateManager().getStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = blockRegistry.getKey(block).orElseThrow().getValue(); + Identifier registryKey = Registry.BLOCK.getKey(block).orElseThrow().getValue(); String localizationKey = block.getTranslationKey(); List effectiveTools = getItemsEffectiveForBlock(defaultState); - blockDesc.addProperty("id", blockRegistry.getRawId(block)); + blockDesc.addProperty("id", Registry.BLOCK.getRawId(block)); blockDesc.addProperty("name", registryKey.getPath()); blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); @@ -148,8 +148,8 @@ public static JsonObject generateBlock(Registry blockRegistry, List property : block.getStateManager().getProperties()) { @@ -167,7 +167,7 @@ public static JsonObject generateBlock(Registry blockRegistry, List actualBlockDrops = new ArrayList<>(); - populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.get(0), actualBlockDrops); + populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.getFirst(), actualBlockDrops); JsonArray dropsArray = new JsonArray(); for (ItemStack dropStack : actualBlockDrops) { @@ -192,7 +192,7 @@ public JsonArray generateDataJson() { Registry blockRegistry = Registry.BLOCK; List availableMaterials = MaterialsDataGenerator.getGlobalMaterialInfo(); - blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, availableMaterials, block))); + blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(availableMaterials, block))); return resultBlocksArray; } } diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index ebf2ed5f..00000000 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -1,78 +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 org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -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.util.ArrayList; -import java.util.List; - -public class DataGenerators { - - private static final Logger logger = LoggerFactory.getLogger(DataGenerators.class); - private static final List GENERATORS = new ArrayList<>(); - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new MaterialsDataGenerator()); -// register(new RecipeDataGenerator()); - On hold until mcdata supports multiple materials for a recipe - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new SoundsDataGenerator()); - } - - public static void register(IDataGenerator generator) { - GENERATORS.add(generator); - } - - public static boolean runDataGenerators(Path outputDirectory) { - try { - Files.createDirectories(outputDirectory); - } catch (IOException exception) { - logger.error("Failed to create data generator output directory at {}", outputDirectory, exception); - return false; - } - - int generatorsFailed = 0; - logger.info("Running minecraft data generators, output at {}", outputDirectory); - - for (IDataGenerator dataGenerator : GENERATORS) { - logger.info("Running generator {}", 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("Generator: {} -> {}", dataGenerator.getDataName(), outputFileName); - - } catch (Throwable exception) { - logger.error("Failed to run data generator {}", dataGenerator.getDataName(), exception); - generatorsFailed++; - } - } - - logger.info("Finishing running data generators"); - return generatorsFailed == 0; - } -} diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 1c9849e6..9b4beb53 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -13,7 +13,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(statusEffect).orElseThrow().getValue(); diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java index e27fb68f..44449345 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.collect.ImmutableMap; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -11,29 +10,10 @@ import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; public class EnchantmentsDataGenerator implements IDataGenerator { - - private static final ImmutableMap ENCHANTMENT_TARGET_NAMES = ImmutableMap.builder() - .put(EnchantmentTarget.ARMOR, "armor") - .put(EnchantmentTarget.ARMOR_FEET, "armor_feet") - .put(EnchantmentTarget.ARMOR_LEGS, "armor_legs") - .put(EnchantmentTarget.ARMOR_CHEST, "armor_chest") - .put(EnchantmentTarget.ARMOR_HEAD, "armor_head") - .put(EnchantmentTarget.WEAPON, "weapon") - .put(EnchantmentTarget.DIGGER, "digger") - .put(EnchantmentTarget.FISHING_ROD, "fishing_rod") - .put(EnchantmentTarget.TRIDENT, "trident") - .put(EnchantmentTarget.BREAKABLE, "breakable") - .put(EnchantmentTarget.BOW, "bow") - .put(EnchantmentTarget.WEARABLE, "wearable") - .put(EnchantmentTarget.CROSSBOW, "crossbow") - .put(EnchantmentTarget.VANISHABLE, "vanishable") - .build(); - public static String getEnchantmentTargetName(EnchantmentTarget target) { - return ENCHANTMENT_TARGET_NAMES.getOrDefault(target, target.name().toLowerCase(Locale.ROOT)); + return 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 diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 4eacf202..703aeade 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -2,7 +2,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.EntityTypeAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -19,7 +18,6 @@ import net.minecraft.util.registry.Registry; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getKey(entityType).orElseThrow().getValue(); @@ -47,11 +45,8 @@ public static JsonObject generateEntity(Registry> entityRegistry, } private static String getCategoryFrom(EntityType entityType) { - if (entityType == EntityType.PLAYER) return "UNKNOWN"; // fail early for player entities - /*public T create(World world) { - return this.factory.create(this, world); - }*/ - Entity entity = ((EntityTypeAccessor) entityType).factory().create(entityType, DGU.getWorld()); + if (entityType == EntityType.PLAYER) return "UNKNOWN"; + Entity entity = entityType.create(DGU.getWorld()); if (entity == null) throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index 45a0b35f..de659be9 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(Registry registry, Item foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = registry.getKey(foodItem).orElseThrow().getValue(); diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java index 4253ae69..1739de21 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.gson.JsonElement; @@ -40,7 +39,7 @@ private static String makeMaterialNameForTag(TagKey tag) { } private static void createCompositeMaterialInfo(List allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); List mappedMaterials = combinedMaterials.stream() .map(otherName -> allMaterials.stream() @@ -52,13 +51,13 @@ private static void createCompositeMaterialInfo(List allMaterials, mappedMaterials.stream().allMatch(it -> it.getPredicate().test(blockState)); MaterialInfo materialInfo = new MaterialInfo(compositeMaterialName, compositePredicate).includes(mappedMaterials); - allMaterials.add(0, materialInfo); + allMaterials.addFirst(materialInfo); } private static void createCompositeMaterial(Map> allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); - Map resultingToolSpeeds = new HashMap<>(); + Map resultingToolSpeeds = new LinkedHashMap<>(); combinedMaterials.stream() .map(allMaterials::get) .forEach(resultingToolSpeeds::putAll); @@ -105,14 +104,14 @@ public String getDataName() { public JsonElement generateDataJson() { Registry itemRegistry = Registry.ITEM; - Map> materialMiningSpeeds = new HashMap<>(); + Map> materialMiningSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put("default", ImmutableMap.of()); //Special materials used for shears and swords special mining speed logic - Map leavesMaterialSpeeds = new HashMap<>(); - Map cowebMaterialSpeeds = new HashMap<>(); - Map plantMaterialSpeeds = new HashMap<>(); - Map gourdMaterialSpeeds = new HashMap<>(); + Map leavesMaterialSpeeds = new LinkedHashMap<>(); + Map cowebMaterialSpeeds = new LinkedHashMap<>(); + Map plantMaterialSpeeds = new LinkedHashMap<>(); + Map gourdMaterialSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put(makeMaterialNameForTag(BlockTags.LEAVES), leavesMaterialSpeeds); materialMiningSpeeds.put("coweb", cowebMaterialSpeeds); @@ -131,7 +130,7 @@ public JsonElement generateDataJson() { TagKey effectiveBlocks = ((MiningToolItemAccessor) toolItem).getEffectiveBlocks(); String materialName = makeMaterialNameForTag(effectiveBlocks); - Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new HashMap<>()); + Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>()); float miningSpeed = ((MiningToolItemAccessor) toolItem).getMiningSpeed(); materialSpeeds.put(item, miningSpeed); } diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 5a6b1081..80cca516 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -7,7 +7,6 @@ import net.minecraft.util.registry.Registry; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(particleType).orElseThrow().getValue(); diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index edbc9869..585eb218 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -5,13 +5,11 @@ import net.minecraft.sound.SoundEvent; import net.minecraft.util.registry.Registry; - public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(Registry registry, SoundEvent soundEvent) { + public static JsonObject generateSound(SoundEvent soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", registry.getRawId(soundEvent)); + soundDesc.addProperty("id", Registry.SOUND_EVENT.getRawId(soundEvent)); soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; @@ -25,8 +23,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - Registry soundEventRegistry = Registry.SOUND_EVENT; - soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, sound))); + Registry.SOUND_EVENT.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index dda76c54..5cd4ad15 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -2,11 +2,11 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mojangannoyances.BlockColors; import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.RedstoneWireBlock; +import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.world.FoliageColors; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -14,13 +14,9 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class TintsDataGenerator implements IDataGenerator { - public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { BiomeTintColors colors = new BiomeTintColors(); @@ -37,7 +33,7 @@ public static BiomeTintColors generateBiomeTintColors(Registry biomeRegis } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { int color = RedstoneWireBlock.getWireColor(redstoneLevel); @@ -46,24 +42,23 @@ public static Map generateRedstoneTintColors() { return resultColors; } - private static int getBlockColor(Block block, BlockColors blockColors) { - return blockColors.getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); + private static int getBlockColor(Block block) { + return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); } public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors)); - 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.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors)); + resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); return resultColors; } @@ -154,8 +149,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java deleted file mode 100644 index 3e62bf59..00000000 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(EntityType.class) -public interface EntityTypeAccessor { - @Accessor("factory") - EntityType.EntityFactory factory(); -} diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index ba3b26b4..c904c153 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.MinecraftVersion; import net.minecraft.server.dedicated.MinecraftDedicatedServer; @@ -10,18 +9,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.nio.file.Path; - @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = MinecraftVersion.CURRENT.getName(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + MinecraftVersion.CURRENT.getName(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java deleted file mode 100644 index b50d1a93..00000000 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java +++ /dev/null @@ -1,29 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.fabricmc.fabric.impl.biome.TheEndBiomeData; -import net.fabricmc.fabric.impl.biome.WeightedPicker; -import net.minecraft.util.registry.RegistryKey; -import net.minecraft.world.biome.Biome; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; - - -@Mixin(TheEndBiomeData.class) -public interface TheEndBiomeDataAccessor { - @Accessor("END_BIOMES_MAP") - static Map, WeightedPicker>> END_BIOMES_MAP() { - throw new IllegalStateException("Should never be called."); - } - - @Accessor("END_MIDLANDS_MAP") - static Map, WeightedPicker>> END_MIDLANDS_MAP() { - throw new IllegalStateException("Should never be called."); - } - - @Accessor("END_BARRENS_MAP") - static Map, WeightedPicker>> END_BARRENS_MAP() { - throw new IllegalStateException("Should never be called."); - } -} diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java deleted file mode 100644 index bb9ae83f..00000000 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.level.ColorResolver; - -@Environment(EnvType.CLIENT) -public class BiomeColors { - public static final ColorResolver GRASS_COLOR = Biome::getGrassColorAt; - public static final ColorResolver FOLIAGE_COLOR = (biome, x, z) -> biome.getFoliageColor(); - public static final ColorResolver WATER_COLOR = (biome, x, z) -> biome.getWaterColor(); - - public BiomeColors() { - } - - private static int getColor(BlockRenderView world, BlockPos pos, ColorResolver resolver) { - return world.getColor(pos, resolver); - } - - public static int getGrassColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, GRASS_COLOR); - } - - public static int getFoliageColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, FOLIAGE_COLOR); - } - - public static int getWaterColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, WATER_COLOR); - } -} - diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java deleted file mode 100644 index ac5dc572..00000000 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import org.jetbrains.annotations.Nullable; - -public interface BlockColorProvider { - int getColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex); -} - diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java deleted file mode 100644 index e8430ebe..00000000 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java +++ /dev/null @@ -1,93 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import net.minecraft.block.*; -import net.minecraft.block.enums.DoubleBlockHalf; -import net.minecraft.client.color.world.FoliageColors; -import net.minecraft.client.color.world.GrassColors; -import net.minecraft.state.property.Property; -import net.minecraft.util.collection.IdList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.BlockRenderView; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; -import java.util.Set; - -public class BlockColors { - private static final int NO_COLOR = -1; - private final IdList providers = new IdList<>(32); - private final Map>> properties = Maps.newHashMap(); - - public BlockColors() { - } - - public static BlockColors create() { - BlockColors blockColors = new BlockColors(); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, state.get(TallPlantBlock.HALF) == DoubleBlockHalf.UPPER ? pos.down() : pos) : -1, Blocks.LARGE_FERN, Blocks.TALL_GRASS); - blockColors.registerColorProperty(TallPlantBlock.HALF, Blocks.LARGE_FERN, Blocks.TALL_GRASS); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : GrassColors.getColor(0.5, 1.0), Blocks.GRASS_BLOCK, Blocks.FERN, Blocks.GRASS, Blocks.POTTED_FERN); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> FoliageColors.getSpruceColor(), Blocks.SPRUCE_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> FoliageColors.getBirchColor(), Blocks.BIRCH_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getFoliageColor(world, pos) : FoliageColors.getDefaultColor(), Blocks.OAK_LEAVES, Blocks.JUNGLE_LEAVES, Blocks.ACACIA_LEAVES, Blocks.DARK_OAK_LEAVES, Blocks.VINE, Blocks.MANGROVE_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getWaterColor(world, pos) : -1, Blocks.WATER, Blocks.BUBBLE_COLUMN, Blocks.WATER_CAULDRON); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> RedstoneWireBlock.getWireColor(state.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE); - blockColors.registerColorProperty(RedstoneWireBlock.POWER, Blocks.REDSTONE_WIRE); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : -1, Blocks.SUGAR_CANE); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> 14731036, Blocks.ATTACHED_MELON_STEM, Blocks.ATTACHED_PUMPKIN_STEM); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> { - int i = state.get(StemBlock.AGE); - int j = i * 32; - int k = 255 - i * 8; - int l = i * 4; - return j << 16 | k << 8 | l; - }, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.registerColorProperty(StemBlock.AGE, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? 2129968 : 7455580, Blocks.LILY_PAD); - return blockColors; - } - - public int getParticleColor(BlockState state, World world, BlockPos pos) { - BlockColorProvider blockColorProvider = this.providers.get(Registry.BLOCK.getRawId(state.getBlock())); - if (blockColorProvider != null) { - return blockColorProvider.getColor(state, null, null, 0); - } else { - MapColor mapColor = state.getMapColor(world, pos); - return mapColor != null ? mapColor.color : -1; - } - } - - public int getColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex) { - BlockColorProvider blockColorProvider = this.providers.get(Registry.BLOCK.getRawId(state.getBlock())); - return blockColorProvider == null ? -1 : blockColorProvider.getColor(state, world, pos, tintIndex); - } - - public void registerColorProvider(BlockColorProvider provider, Block... blocks) { - int var4 = blocks.length; - - for (Block block : blocks) { - this.providers.set(provider, Registry.BLOCK.getRawId(block)); - } - - } - - private void registerColorProperties(Set> properties, Block... blocks) { - int var4 = blocks.length; - - for (Block block : blocks) { - this.properties.put(block, properties); - } - - } - - private void registerColorProperty(Property property, Block... blocks) { - this.registerColorProperties(ImmutableSet.of(property), blocks); - } - - public Set> getProperties(Block block) { - return this.properties.getOrDefault(block, ImmutableSet.of()); - } -} diff --git a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index 32c2fb65..3946c1fe 100644 --- a/1.19/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.19/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -6,24 +6,13 @@ import net.minecraft.world.World; public class DGU { - - private static final Language language = Language.getInstance(); - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - return getCurrentlyRunningServerDedicated(); - } - - private static String translateTextFallback(String translationKey) { - return language.get(translationKey); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } public static String translateText(String translationKey) { - return translateTextFallback(translationKey); + return Language.getInstance().get(translationKey); } public static World getWorld() { diff --git a/1.19/src/main/resources/fabric.mod.json b/1.19/src/main/resources/fabric.mod.json index 1d6fbb58..74a506b1 100644 --- a/1.19/src/main/resources/fabric.mod.json +++ b/1.19/src/main/resources/fabric.mod.json @@ -10,18 +10,11 @@ ], "contact": {}, "license": "MIT", - "environment": "server", - "entrypoints": { - "main": [ - "dev.u9g.minecraftdatagenerator.Main" - ] - }, "mixins": [ "minecraft-data-generator.mixins.json" ], "depends": { - "fabricloader": ">=0.14.4", - "fabric": "*", + "fabricloader": "*", "minecraft": "1.19" } } diff --git a/1.19/src/main/resources/minecraft-data-generator.mixins.json b/1.19/src/main/resources/minecraft-data-generator.mixins.json index f3afe061..d46bf65f 100644 --- a/1.19/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.19/src/main/resources/minecraft-data-generator.mixins.json @@ -4,11 +4,9 @@ "package": "dev.u9g.minecraftdatagenerator.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "EntityTypeAccessor", "EULAMixin", "MiningToolItemAccessor", - "ReadyMixin", - "TheEndBiomeDataAccessor" + "ReadyMixin" ], "client": [ ], diff --git a/1.20.4/build.gradle b/1.20.4/build.gradle index e85de392..aecbdee9 100644 --- a/1.20.4/build.gradle +++ b/1.20.4/build.gradle @@ -1,15 +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' } -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +unimined.minecraft { + version "1.20.4" + + mappings { + intermediary() + yarn(3) + + devFallbackNamespace "intermediary" + } + + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } + + customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() + } - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + defaultRemapJar = true +} + +dependencies { + implementation project(":common") } processResources { @@ -20,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.20.4/gradle.properties b/1.20.4/gradle.properties deleted file mode 100644 index 7d228ec0..00000000 --- a/1.20.4/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.3 -loader_version=0.15.3 -# Dependencies -# check this on https://modmuss50.me/fabric.html -fabric_version=0.92.0+1.20.4 diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index f8d17372..00000000 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.u9g.minecraftdatagenerator; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Main implements ModInitializer { - public static final Logger LOGGER = LoggerFactory.getLogger("mc-data-gen-serv"); - - @Override - public void onInitialize() { - - } -} diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index bda5f967..a1b3b732 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -2,36 +2,24 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.TheEndBiomeDataAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; -import net.fabricmc.fabric.api.biome.v1.NetherBiomes; import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.Registry; -import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.BiomeTags; import net.minecraft.util.Identifier; import net.minecraft.world.biome.Biome; -import java.util.HashSet; -import java.util.Set; - public class BiomesDataGenerator implements IDataGenerator { - private static final Set> END_BIOMES = new HashSet<>(); - - static { - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_BIOMES_MAP().keySet()); - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_BARRENS_MAP().keySet()); - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_MIDLANDS_MAP().keySet()); - } - - private static String guessBiomeDimensionFromCategory(Biome biome, String biomeName) { - var key = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME).getKey(biome).orElseThrow(); - if (NetherBiomes.canGenerateInNether(key)) { + private static String guessBiomeDimensionFromCategory(Biome biome) { + var biomeRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME); + if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_NETHER)) { return "nether"; - } else if (END_BIOMES.contains(key) || biomeName.startsWith("end_")) { + } else if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_END)) { return "end"; + } else { + return "overworld"; } - return "overworld"; } private static String guessCategoryBasedOnName(String name, String dimension) { @@ -87,196 +75,6 @@ private static String guessCategoryBasedOnName(String name, String dimension) { } } - private static int getBiomeColorFor(String biomeName) { - switch (biomeName) { - case "the_void" -> { - return 0; - } - case "plains" -> { - return 9286496; - } - case "sunflower_plains" -> { - return 11918216; - } - case "snowy_plains" -> { - return 16777215; - } - case "ice_spikes" -> { - return 11853020; - } - case "desert" -> { - return 16421912; - } - case "swamp" -> { - return 522674; - } - case "forest" -> { - return 353825; - } - case "flower_forest" -> { - return 2985545; - } - case "birch_forest" -> { - return 3175492; - } - case "dark_forest" -> { - return 4215066; - } - case "old_growth_birch_forest" -> { - return 5807212; - } - case "old_growth_pine_taiga" -> { - return 5858897; - } - case "old_growth_spruce_taiga" -> { - return 8490617; - } - case "taiga" -> { - return 747097; - } - case "snowy_taiga" -> { - return 3233098; - } - case "savanna" -> { - return 12431967; - } - case "savanna_plateau" -> { - return 10984804; - } - case "windswept_hills" -> { - return 6316128; - } - case "windswept_gravelly_hills" -> { - return 8947848; - } - case "windswept_forest" -> { - return 2250012; - } - case "windswept_savanna" -> { - return 15063687; - } - case "jungle" -> { - return 5470985; - } - case "sparse_jungle" -> { - return 6458135; - } - case "bamboo_jungle" -> { - return 7769620; - } - case "badlands" -> { - return 14238997; - } - case "eroded_badlands" -> { - return 16739645; - } - case "wooded_badlands" -> { - return 11573093; - } - case "meadow" -> { - return 9217136; - } - case "grove" -> { - return 14675173; - } - case "snowy_slopes" -> { - return 14348785; - } - case "frozen_peaks" -> { - return 15399931; - } - case "jagged_peaks" -> { - return 14937325; - } - case "stony_peaks" -> { - return 13750737; - } - case "river" -> { - return 255; - } - case "frozen_river" -> { - return 10526975; - } - case "beach" -> { - return 16440917; - } - case "snowy_beach" -> { - return 16445632; - } - case "stony_shore" -> { - return 10658436; - } - case "warm_ocean" -> { - return 172; - } - case "lukewarm_ocean" -> { - return 144; - } - case "deep_lukewarm_ocean" -> { - return 64; - } - case "ocean" -> { - return 112; - } - case "deep_ocean" -> { - return 48; - } - case "cold_ocean" -> { - return 2105456; - } - case "deep_cold_ocean" -> { - return 2105400; - } - case "frozen_ocean" -> { - return 7368918; - } - case "deep_frozen_ocean" -> { - return 4210832; - } - case "mushroom_fields" -> { - return 16711935; - } - case "dripstone_caves" -> { - return 12690831; - } - case "lush_caves" -> { - return 14652980; - } - case "nether_wastes" -> { - return 12532539; - } - case "warped_forest" -> { - return 4821115; - } - case "crimson_forest" -> { - return 14485512; - } - case "soul_sand_valley" -> { - return 6174768; - } - case "basalt_deltas" -> { - return 4208182; - } - case "the_end" -> { - return 8421631; - } - case "end_highlands" -> { - return 12828041; - } - case "end_midlands" -> { - return 15464630; - } - case "small_end_islands" -> { - return 42; - } - case "end_barrens" -> { - return 9474162; - } - } - System.out.println("Don't know the color of biome: '" + biomeName + "'"); - return 0; - } - public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); Identifier registryKey = registry.getKey(biome).orElseThrow().getValue(); @@ -284,7 +82,7 @@ public static JsonObject generateBiomeInfo(Registry registry, Biome biome String name = registryKey.getPath(); biomeDesc.addProperty("id", registry.getRawId(biome)); biomeDesc.addProperty("name", name); - String dimension = guessBiomeDimensionFromCategory(biome, name); + String dimension = guessBiomeDimensionFromCategory(biome); biomeDesc.addProperty("category", guessCategoryBasedOnName(name, dimension)); biomeDesc.addProperty("temperature", biome.getTemperature()); //biomeDesc.addProperty("precipitation", biome.getPrecipitation().getName());// - removed in 1.19.4 @@ -292,7 +90,7 @@ public static JsonObject generateBiomeInfo(Registry registry, Biome biome //biomeDesc.addProperty("depth", biome.getDepth()); - Doesn't exist anymore in minecraft source biomeDesc.addProperty("dimension", dimension); biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); - biomeDesc.addProperty("color", getBiomeColorFor(registryKey.getPath())); + biomeDesc.addProperty("color", biome.getSkyColor()); //biomeDesc.addProperty("rainfall", biome.getDownfall());// - removed in 1.19.4 return biomeDesc; diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 8b9d0e06..68a169cd 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -14,10 +14,7 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class BlockCollisionShapesDataGenerator implements IDataGenerator { @@ -42,8 +39,8 @@ public JsonObject generateDataJson() { } private static class BlockShapesCache { - public final Map uniqueBlockShapes = new HashMap<>(); - public final Map> blockCollisionShapes = new HashMap<>(); + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); private int lastCollisionShapeId = 0; public void processBlock(Block block) { @@ -72,7 +69,7 @@ public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { long distinctShapesCount = blockCollisions.stream().distinct().count(); JsonElement blockCollision; if (distinctShapesCount == 1L) { - blockCollision = new JsonPrimitive(blockCollisions.get(0)); + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); } else { blockCollision = new JsonArray(); for (int collisionId : blockCollisions) { diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 44e8e29c..324b4d90 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -12,7 +12,7 @@ import net.minecraft.item.Items; import net.minecraft.loot.context.LootContextParameterSet; import net.minecraft.loot.context.LootContextParameters; -import net.minecraft.registry.Registry; +import net.minecraft.registry.Registries; import net.minecraft.registry.RegistryKeys; import net.minecraft.server.MinecraftServer; import net.minecraft.server.world.ServerWorld; @@ -105,7 +105,7 @@ private static String findMatchingBlockMaterial(BlockState blockState, List 1) { - var firstMaterial = matchingMaterials.get(0); + var firstMaterial = matchingMaterials.getFirst(); var otherMaterials = matchingMaterials.subList(1, matchingMaterials.size()); if (!otherMaterials.stream().allMatch(firstMaterial::includesMaterial)) { @@ -115,19 +115,19 @@ private static String findMatchingBlockMaterial(BlockState blockState, List blockRegistry, List materials, Block block) { + public static JsonObject generateBlock(List materials, Block block) { JsonObject blockDesc = new JsonObject(); List blockStates = block.getStateManager().getStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = blockRegistry.getKey(block).orElseThrow().getValue(); + Identifier registryKey = Registries.BLOCK.getKey(block).orElseThrow().getValue(); String localizationKey = block.getTranslationKey(); List effectiveTools = getItemsEffectiveForBlock(defaultState); - blockDesc.addProperty("id", blockRegistry.getRawId(block)); + blockDesc.addProperty("id", Registries.BLOCK.getRawId(block)); blockDesc.addProperty("name", registryKey.getPath()); blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); @@ -148,8 +148,8 @@ public static JsonObject generateBlock(Registry blockRegistry, List property : block.getStateManager().getProperties()) { @@ -167,7 +167,7 @@ public static JsonObject generateBlock(Registry blockRegistry, List actualBlockDrops = new ArrayList<>(); - populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.get(0), actualBlockDrops); + populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.getFirst(), actualBlockDrops); JsonArray dropsArray = new JsonArray(); for (ItemStack dropStack : actualBlockDrops) { @@ -189,10 +189,9 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultBlocksArray = new JsonArray(); - Registry blockRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BLOCK); List availableMaterials = MaterialsDataGenerator.getGlobalMaterialInfo(); - blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, availableMaterials, block))); + Registries.BLOCK.forEach(block -> resultBlocksArray.add(generateBlock(availableMaterials, block))); return resultBlocksArray; } } diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index c47684ab..00000000 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -1,77 +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 org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -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.util.ArrayList; -import java.util.List; - -public class DataGenerators { - - private static final Logger logger = LoggerFactory.getLogger(DataGenerators.class); - private static final List GENERATORS = new ArrayList<>(); - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new MaterialsDataGenerator()); -// register(new RecipeDataGenerator()); - On hold until mcdata supports multiple materials for a recipe - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - } - - public static void register(IDataGenerator generator) { - GENERATORS.add(generator); - } - - public static boolean runDataGenerators(Path outputDirectory) { - try { - Files.createDirectories(outputDirectory); - } catch (IOException exception) { - logger.error("Failed to create data generator output directory at {}", outputDirectory, exception); - return false; - } - - int generatorsFailed = 0; - logger.info("Running minecraft data generators, output at {}", outputDirectory); - - for (IDataGenerator dataGenerator : GENERATORS) { - logger.info("Running generator {}", 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("Generator: {} -> {}", dataGenerator.getDataName(), outputFileName); - - } catch (Throwable exception) { - logger.error("Failed to run data generator {}", dataGenerator.getDataName(), exception); - generatorsFailed++; - } - } - - logger.info("Finishing running data generators"); - return generatorsFailed == 0; - } -} diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 3c619c36..dd6dc019 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -14,7 +14,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(statusEffect).orElseThrow().getValue(); diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java index 6bd50d74..38d68ac4 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.collect.ImmutableMap; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -12,29 +11,11 @@ import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; public class EnchantmentsDataGenerator implements IDataGenerator { - private static final ImmutableMap ENCHANTMENT_TARGET_NAMES = ImmutableMap.builder() - .put(EnchantmentTarget.ARMOR, "armor") - .put(EnchantmentTarget.ARMOR_FEET, "armor_feet") - .put(EnchantmentTarget.ARMOR_LEGS, "armor_legs") - .put(EnchantmentTarget.ARMOR_CHEST, "armor_chest") - .put(EnchantmentTarget.ARMOR_HEAD, "armor_head") - .put(EnchantmentTarget.WEAPON, "weapon") - .put(EnchantmentTarget.DIGGER, "digger") - .put(EnchantmentTarget.FISHING_ROD, "fishing_rod") - .put(EnchantmentTarget.TRIDENT, "trident") - .put(EnchantmentTarget.BREAKABLE, "breakable") - .put(EnchantmentTarget.BOW, "bow") - .put(EnchantmentTarget.WEARABLE, "wearable") - .put(EnchantmentTarget.CROSSBOW, "crossbow") - .put(EnchantmentTarget.VANISHABLE, "vanishable") - .build(); - public static String getEnchantmentTargetName(EnchantmentTarget target) { - return ENCHANTMENT_TARGET_NAMES.getOrDefault(target, target.name().toLowerCase(Locale.ROOT)); + return 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 diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 50e3516d..71c5ca7e 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -2,12 +2,10 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.EntityTypeAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.SpawnReason; import net.minecraft.entity.mob.AmbientEntity; import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.mob.MobEntity; @@ -17,12 +15,10 @@ import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKeys; -import net.minecraft.registry.tag.TagKey; import net.minecraft.server.MinecraftServer; import net.minecraft.util.Identifier; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getKey(entityType).orElseThrow().getValue(); @@ -40,10 +36,10 @@ public static JsonObject generateEntity(Registry> entityRegistry, MinecraftServer minecraftServer = DGU.getCurrentlyRunningServer(); if (minecraftServer != null) { - Entity entityObject = ((EntityTypeAccessor) entityType).factory().create(entityType, minecraftServer.getOverworld()); + Entity entityObject = entityType.create(minecraftServer.getOverworld()); entityTypeString = entityObject != null ? getEntityTypeForClass(entityObject.getClass()) : "unknown"; } - if(entityType == EntityType.PLAYER){ + if (entityType == EntityType.PLAYER) { entityTypeString = "player"; } @@ -54,11 +50,8 @@ public static JsonObject generateEntity(Registry> entityRegistry, } private static String getCategoryFrom(EntityType entityType) { - if (entityType == EntityType.PLAYER) return "UNKNOWN"; // fail early for player entities - /*public T create(World world) { - return this.factory.create(this, world); - }*/ - Entity entity = ((EntityTypeAccessor) entityType).factory().create(entityType, DGU.getWorld()); + if (entityType == EntityType.PLAYER) return "UNKNOWN"; + Entity entity = entityType.create(DGU.getWorld()); if (entity == null) throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index a5b164f1..97a73639 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -12,7 +12,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(Registry registry, Item foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = registry.getKey(foodItem).orElseThrow().getValue(); diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java index 9a5fac15..674dd22a 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.gson.JsonElement; @@ -41,7 +40,7 @@ private static String makeMaterialNameForTag(TagKey tag) { } private static void createCompositeMaterialInfo(List allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); List mappedMaterials = combinedMaterials.stream() .map(otherName -> allMaterials.stream() @@ -53,13 +52,13 @@ private static void createCompositeMaterialInfo(List allMaterials, mappedMaterials.stream().allMatch(it -> it.getPredicate().test(blockState)); MaterialInfo materialInfo = new MaterialInfo(compositeMaterialName, compositePredicate).includes(mappedMaterials); - allMaterials.add(0, materialInfo); + allMaterials.addFirst(materialInfo); } private static void createCompositeMaterial(Map> allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); - Map resultingToolSpeeds = new HashMap<>(); + Map resultingToolSpeeds = new LinkedHashMap<>(); combinedMaterials.stream() .map(allMaterials::get) .forEach(resultingToolSpeeds::putAll); @@ -108,14 +107,14 @@ public String getDataName() { public JsonElement generateDataJson() { Registry itemRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.ITEM); - Map> materialMiningSpeeds = new HashMap<>(); + Map> materialMiningSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put("default", ImmutableMap.of()); //Special materials used for shears and swords special mining speed logic - Map leavesMaterialSpeeds = new HashMap<>(); - Map cowebMaterialSpeeds = new HashMap<>(); - Map plantMaterialSpeeds = new HashMap<>(); - Map gourdMaterialSpeeds = new HashMap<>(); + Map leavesMaterialSpeeds = new LinkedHashMap<>(); + Map cowebMaterialSpeeds = new LinkedHashMap<>(); + Map plantMaterialSpeeds = new LinkedHashMap<>(); + Map gourdMaterialSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put(makeMaterialNameForTag(BlockTags.LEAVES), leavesMaterialSpeeds); materialMiningSpeeds.put("coweb", cowebMaterialSpeeds); @@ -134,7 +133,7 @@ public JsonElement generateDataJson() { TagKey effectiveBlocks = ((MiningToolItemAccessor) toolItem).getEffectiveBlocks(); String materialName = makeMaterialNameForTag(effectiveBlocks); - Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new HashMap<>()); + Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>()); float miningSpeed = ((MiningToolItemAccessor) toolItem).getMiningSpeed(); materialSpeeds.put(item, miningSpeed); } diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index e446a50b..bc5a9acc 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -9,7 +9,6 @@ import net.minecraft.util.Identifier; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(particleType).orElseThrow().getValue(); diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 1f4f96b0..5c21246b 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -2,12 +2,12 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mojangannoyances.BlockColors; import dev.u9g.minecraftdatagenerator.util.DGU; import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.RedstoneWireBlock; +import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.world.FoliageColors; import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.Registry; @@ -16,13 +16,9 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.biome.Biome; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class TintsDataGenerator implements IDataGenerator { - public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { BiomeTintColors colors = new BiomeTintColors(); @@ -39,7 +35,7 @@ public static BiomeTintColors generateBiomeTintColors(Registry biomeRegis } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { int color = RedstoneWireBlock.getWireColor(redstoneLevel); @@ -48,24 +44,23 @@ public static Map generateRedstoneTintColors() { return resultColors; } - private static int getBlockColor(Block block, BlockColors blockColors) { - return blockColors.getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); + private static int getBlockColor(Block block) { + return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); } public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors)); - 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.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors)); + resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); return resultColors; } @@ -156,8 +151,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java deleted file mode 100644 index 3e62bf59..00000000 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(EntityType.class) -public interface EntityTypeAccessor { - @Accessor("factory") - EntityType.EntityFactory factory(); -} diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index 9cec9cd1..cf8d9ffc 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.MinecraftVersion; import net.minecraft.server.dedicated.MinecraftDedicatedServer; @@ -10,19 +9,14 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.nio.file.Path; - @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = MinecraftVersion.CURRENT.getName(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + MinecraftVersion.CURRENT.getName(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java deleted file mode 100644 index dc35e0b3..00000000 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java +++ /dev/null @@ -1,29 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.fabricmc.fabric.impl.biome.TheEndBiomeData; -import net.fabricmc.fabric.impl.biome.WeightedPicker; -import net.minecraft.registry.RegistryKey; -import net.minecraft.world.biome.Biome; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; - - -@Mixin(TheEndBiomeData.class) -public interface TheEndBiomeDataAccessor { - @Accessor(value = "END_BIOMES_MAP", remap = false) - static Map, WeightedPicker>> END_BIOMES_MAP() { - throw new IllegalStateException("Should never be called."); - } - - @Accessor(value = "END_MIDLANDS_MAP", remap = false) - static Map, WeightedPicker>> END_MIDLANDS_MAP() { - throw new IllegalStateException("Should never be called."); - } - - @Accessor(value = "END_BARRENS_MAP", remap = false) - static Map, WeightedPicker>> END_BARRENS_MAP() { - throw new IllegalStateException("Should never be called."); - } -} diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java deleted file mode 100644 index d374b11a..00000000 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.ColorResolver; - -@Environment(EnvType.CLIENT) -public class BiomeColors { - public static final ColorResolver GRASS_COLOR = Biome::getGrassColorAt; - public static final ColorResolver FOLIAGE_COLOR = (biome, x, z) -> biome.getFoliageColor(); - public static final ColorResolver WATER_COLOR = (biome, x, z) -> biome.getWaterColor(); - - public BiomeColors() { - } - - private static int getColor(BlockRenderView world, BlockPos pos, ColorResolver resolver) { - return world.getColor(pos, resolver); - } - - public static int getGrassColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, GRASS_COLOR); - } - - public static int getFoliageColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, FOLIAGE_COLOR); - } - - public static int getWaterColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, WATER_COLOR); - } -} - diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java deleted file mode 100644 index ac5dc572..00000000 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import org.jetbrains.annotations.Nullable; - -public interface BlockColorProvider { - int getColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex); -} - diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java deleted file mode 100644 index e48e98a8..00000000 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java +++ /dev/null @@ -1,94 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import dev.u9g.minecraftdatagenerator.util.DGU; -import net.minecraft.block.*; -import net.minecraft.block.enums.DoubleBlockHalf; -import net.minecraft.client.color.world.FoliageColors; -import net.minecraft.client.color.world.GrassColors; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.state.property.Property; -import net.minecraft.util.collection.IdList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; -import java.util.Set; - -public class BlockColors { - private static final int NO_COLOR = -1; - private final IdList providers = new IdList<>(32); - private final Map>> properties = Maps.newHashMap(); - - public BlockColors() { - } - - public static BlockColors create() { - BlockColors blockColors = new BlockColors(); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, state.get(TallPlantBlock.HALF) == DoubleBlockHalf.UPPER ? pos.down() : pos) : -1, Blocks.LARGE_FERN, Blocks.TALL_GRASS); - blockColors.registerColorProperty(TallPlantBlock.HALF, Blocks.LARGE_FERN, Blocks.TALL_GRASS); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : GrassColors.getColor(0.5, 1.0), Blocks.GRASS_BLOCK, Blocks.FERN, Blocks.SHORT_GRASS, Blocks.POTTED_FERN); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> FoliageColors.getSpruceColor(), Blocks.SPRUCE_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> FoliageColors.getBirchColor(), Blocks.BIRCH_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getFoliageColor(world, pos) : FoliageColors.getDefaultColor(), Blocks.OAK_LEAVES, Blocks.JUNGLE_LEAVES, Blocks.ACACIA_LEAVES, Blocks.DARK_OAK_LEAVES, Blocks.VINE, Blocks.MANGROVE_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getWaterColor(world, pos) : -1, Blocks.WATER, Blocks.BUBBLE_COLUMN, Blocks.WATER_CAULDRON); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> RedstoneWireBlock.getWireColor(state.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE); - blockColors.registerColorProperty(RedstoneWireBlock.POWER, Blocks.REDSTONE_WIRE); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : -1, Blocks.SUGAR_CANE); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> 14731036, Blocks.ATTACHED_MELON_STEM, Blocks.ATTACHED_PUMPKIN_STEM); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> { - int i = state.get(StemBlock.AGE); - int j = i * 32; - int k = 255 - i * 8; - int l = i * 4; - return j << 16 | k << 8 | l; - }, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.registerColorProperty(StemBlock.AGE, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? 2129968 : 7455580, Blocks.LILY_PAD); - return blockColors; - } - - public int getParticleColor(BlockState state, World world, BlockPos pos) { - BlockColorProvider blockColorProvider = this.providers.get(DGU.getWorld().getRegistryManager().get(RegistryKeys.BLOCK).getRawId(state.getBlock())); - if (blockColorProvider != null) { - return blockColorProvider.getColor(state, null, null, 0); - } else { - MapColor mapColor = state.getMapColor(world, pos); - return mapColor != null ? mapColor.color : -1; - } - } - - public int getColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex) { - BlockColorProvider blockColorProvider = this.providers.get(DGU.getWorld().getRegistryManager().get(RegistryKeys.BLOCK).getRawId(state.getBlock())); - return blockColorProvider == null ? -1 : blockColorProvider.getColor(state, world, pos, tintIndex); - } - - public void registerColorProvider(BlockColorProvider provider, Block... blocks) { - int var4 = blocks.length; - - for (Block block : blocks) { - this.providers.set(provider, DGU.getWorld().getRegistryManager().get(RegistryKeys.BLOCK).getRawId(block)); - } - - } - - private void registerColorProperties(Set> properties, Block... blocks) { - int var4 = blocks.length; - - for (Block block : blocks) { - this.properties.put(block, properties); - } - - } - - private void registerColorProperty(Property property, Block... blocks) { - this.registerColorProperties(ImmutableSet.of(property), blocks); - } - - public Set> getProperties(Block block) { - return this.properties.getOrDefault(block, ImmutableSet.of()); - } -} diff --git a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index 32c2fb65..3946c1fe 100644 --- a/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.20.4/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -6,24 +6,13 @@ import net.minecraft.world.World; public class DGU { - - private static final Language language = Language.getInstance(); - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - return getCurrentlyRunningServerDedicated(); - } - - private static String translateTextFallback(String translationKey) { - return language.get(translationKey); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } public static String translateText(String translationKey) { - return translateTextFallback(translationKey); + return Language.getInstance().get(translationKey); } public static World getWorld() { diff --git a/1.20.4/src/main/resources/fabric.mod.json b/1.20.4/src/main/resources/fabric.mod.json index c999d2a8..ffac96b0 100644 --- a/1.20.4/src/main/resources/fabric.mod.json +++ b/1.20.4/src/main/resources/fabric.mod.json @@ -10,18 +10,11 @@ ], "contact": {}, "license": "MIT", - "environment": "server", - "entrypoints": { - "main": [ - "dev.u9g.minecraftdatagenerator.Main" - ] - }, "mixins": [ "minecraft-data-generator.mixins.json" ], "depends": { - "fabricloader": ">=0.14.4", - "fabric": "*", + "fabricloader": "*", "minecraft": "*" } } diff --git a/1.20.4/src/main/resources/minecraft-data-generator.mixins.json b/1.20.4/src/main/resources/minecraft-data-generator.mixins.json index f3afe061..d46bf65f 100644 --- a/1.20.4/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.20.4/src/main/resources/minecraft-data-generator.mixins.json @@ -4,11 +4,9 @@ "package": "dev.u9g.minecraftdatagenerator.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "EntityTypeAccessor", "EULAMixin", "MiningToolItemAccessor", - "ReadyMixin", - "TheEndBiomeDataAccessor" + "ReadyMixin" ], "client": [ ], diff --git a/1.20.5/build.gradle b/1.20.5/build.gradle new file mode 100644 index 00000000..b062e214 --- /dev/null +++ b/1.20.5/build.gradle @@ -0,0 +1,47 @@ +import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider + +plugins { + id 'xyz.wagyourtail.unimined' +} + +unimined.minecraft { + version "1.20.5" + + mappings { + intermediary() + yarn(1) + + devFallbackNamespace "intermediary" + } + + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } + + customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() + } + + defaultRemapJar = true +} + +dependencies { + implementation project(":common") +} + +processResources { + filteringCharset "UTF-8" + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} +} + +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java new file mode 100644 index 00000000..a1b3b732 --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -0,0 +1,115 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import dev.u9g.minecraftdatagenerator.util.DGU; +import net.minecraft.registry.DynamicRegistryManager; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.BiomeTags; +import net.minecraft.util.Identifier; +import net.minecraft.world.biome.Biome; + +public class BiomesDataGenerator implements IDataGenerator { + private static String guessBiomeDimensionFromCategory(Biome biome) { + var biomeRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME); + if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_NETHER)) { + return "nether"; + } else if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_END)) { + return "end"; + } else { + return "overworld"; + } + } + + private static String guessCategoryBasedOnName(String name, String dimension) { + if (dimension.equals("nether")) { + return "nether"; + } else if (dimension.equals("end")) { + return "the_end"; + } + + if (name.contains("end")) { + System.out.println(); + } + + if (name.contains("hills")) { + return "extreme_hills"; + } else if (name.contains("ocean")) { + return "ocean"; + } else if (name.contains("plains")) { + return "plains"; + } else if (name.contains("ice") || name.contains("frozen")) { + return "ice"; + } else if (name.contains("jungle")) { + return "jungle"; + } else if (name.contains("desert")) { + return "desert"; + } else if (name.contains("forest") || name.contains("grove")) { + return "forest"; + } else if (name.contains("taiga")) { + return "taiga"; + } else if (name.contains("swamp")) { + return "swamp"; + } else if (name.contains("river")) { + return "river"; + } else if (name.equals("the_end")) { + return "the_end"; + } else if (name.contains("mushroom")) { + return "mushroom"; + } else if (name.contains("beach") || name.equals("stony_shore")) { + return "beach"; + } else if (name.contains("savanna")) { + return "savanna"; + } else if (name.contains("badlands")) { + return "mesa"; + } else if (name.contains("peaks") || name.equals("snowy_slopes") || name.equals("meadow")) { + return "mountain"; + } else if (name.equals("the_void")) { + return "none"; + } else if (name.contains("cave") || name.equals("deep_dark")) { + return "underground"; + } else { + System.out.println("Unable to find biome category for biome with name: '" + name + "'"); + return "none"; + } + } + + public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { + JsonObject biomeDesc = new JsonObject(); + Identifier registryKey = registry.getKey(biome).orElseThrow().getValue(); + String localizationKey = String.format("biome.%s.%s", registryKey.getNamespace(), registryKey.getPath()); + String name = registryKey.getPath(); + biomeDesc.addProperty("id", registry.getRawId(biome)); + biomeDesc.addProperty("name", name); + String dimension = guessBiomeDimensionFromCategory(biome); + biomeDesc.addProperty("category", guessCategoryBasedOnName(name, dimension)); + biomeDesc.addProperty("temperature", biome.getTemperature()); + //biomeDesc.addProperty("precipitation", biome.getPrecipitation().getName());// - removed in 1.19.4 + biomeDesc.addProperty("has_precipitation", biome.hasPrecipitation()); + //biomeDesc.addProperty("depth", biome.getDepth()); - Doesn't exist anymore in minecraft source + biomeDesc.addProperty("dimension", dimension); + biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); + biomeDesc.addProperty("color", biome.getSkyColor()); + //biomeDesc.addProperty("rainfall", biome.getDownfall());// - removed in 1.19.4 + + return biomeDesc; + } + + @Override + public String getDataName() { + return "biomes"; + } + + @Override + public JsonArray generateDataJson() { + JsonArray biomesArray = new JsonArray(); + DynamicRegistryManager registryManager = DGU.getWorld().getRegistryManager(); + Registry biomeRegistry = registryManager.get(RegistryKeys.BIOME); + + biomeRegistry.stream() + .map(biome -> generateBiomeInfo(biomeRegistry, biome)) + .forEach(biomesArray::add); + return biomesArray; + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java new file mode 100644 index 00000000..68a169cd --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -0,0 +1,110 @@ +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.DGU; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.EmptyBlockView; + +import java.util.*; + +public class BlockCollisionShapesDataGenerator implements IDataGenerator { + + @Override + public String getDataName() { + return "blockCollisionShapes"; + } + + @Override + public JsonObject generateDataJson() { + Registry blockRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BLOCK); + BlockShapesCache blockShapesCache = new BlockShapesCache(); + + blockRegistry.forEach(blockShapesCache::processBlock); + + JsonObject resultObject = new JsonObject(); + + resultObject.add("blocks", blockShapesCache.dumpBlockShapeIndices(blockRegistry)); + resultObject.add("shapes", blockShapesCache.dumpShapesObject()); + + return resultObject; + } + + private static class BlockShapesCache { + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); + private int lastCollisionShapeId = 0; + + public void processBlock(Block block) { + List blockStates = block.getStateManager().getStates(); + List blockCollisionShapes = new ArrayList<>(); + + for (BlockState blockState : blockStates) { + VoxelShape blockShape = blockState.getCollisionShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN); + Integer blockShapeIndex = uniqueBlockShapes.get(blockShape); + + if (blockShapeIndex == null) { + blockShapeIndex = lastCollisionShapeId++; + uniqueBlockShapes.put(blockShape, blockShapeIndex); + } + blockCollisionShapes.add(blockShapeIndex); + } + + this.blockCollisionShapes.put(block, blockCollisionShapes); + } + + public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { + JsonObject resultObject = new JsonObject(); + + for (var entry : blockCollisionShapes.entrySet()) { + List blockCollisions = entry.getValue(); + long distinctShapesCount = blockCollisions.stream().distinct().count(); + JsonElement blockCollision; + if (distinctShapesCount == 1L) { + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); + } else { + blockCollision = new JsonArray(); + for (int collisionId : blockCollisions) { + ((JsonArray) blockCollision).add(collisionId); + } + } + + Identifier registryKey = blockRegistry.getKey(entry.getKey()).orElseThrow().getValue(); + resultObject.add(registryKey.getPath(), blockCollision); + } + + return resultObject; + } + + public JsonObject dumpShapesObject() { + JsonObject shapesObject = new JsonObject(); + + for (var entry : uniqueBlockShapes.entrySet()) { + JsonArray boxesArray = new JsonArray(); + entry.getKey().forEachBox((x1, y1, z1, x2, y2, z2) -> { + JsonArray oneBoxJsonArray = new JsonArray(); + + oneBoxJsonArray.add(x1); + oneBoxJsonArray.add(y1); + oneBoxJsonArray.add(z1); + + oneBoxJsonArray.add(x2); + oneBoxJsonArray.add(y2); + oneBoxJsonArray.add(z2); + + boxesArray.add(oneBoxJsonArray); + }); + shapesObject.add(Integer.toString(entry.getValue()), boxesArray); + } + return shapesObject; + } + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java new file mode 100644 index 00000000..324b4d90 --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -0,0 +1,197 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.common.base.CaseFormat; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import dev.u9g.minecraftdatagenerator.util.DGU; +import net.minecraft.block.AirBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.loot.context.LootContextParameterSet; +import net.minecraft.loot.context.LootContextParameters; +import net.minecraft.registry.Registries; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.state.property.BooleanProperty; +import net.minecraft.state.property.EnumProperty; +import net.minecraft.state.property.IntProperty; +import net.minecraft.state.property.Property; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.EmptyBlockView; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +public class BlocksDataGenerator implements IDataGenerator { + + private static final Logger logger = LoggerFactory.getLogger(BlocksDataGenerator.class); + + private static List getItemsEffectiveForBlock(BlockState blockState) { + return DGU.getWorld().getRegistryManager().get(RegistryKeys.ITEM).stream() + .filter(item -> item.getDefaultStack().isSuitableFor(blockState)) + .collect(Collectors.toList()); + } + + private static void populateDropsIfPossible(BlockState blockState, Item firstToolItem, List outDrops) { + MinecraftServer minecraftServer = DGU.getCurrentlyRunningServer(); + if (minecraftServer != null) { + //If we have local world context, we can actually evaluate loot tables and determine actual data + ServerWorld serverWorld = minecraftServer.getOverworld(); + LootContextParameterSet.Builder lootContextParameterSet = new LootContextParameterSet.Builder(serverWorld) + .add(LootContextParameters.BLOCK_STATE, blockState) + .add(LootContextParameters.ORIGIN, Vec3d.ZERO) + .add(LootContextParameters.TOOL, firstToolItem.getDefaultStack()); + outDrops.addAll(blockState.getDroppedStacks(lootContextParameterSet)); + } else { + //If we're lacking world context to correctly determine drops, assume that default drop is ItemBlock stack in quantity of 1 + Item itemBlock = blockState.getBlock().asItem(); + if (itemBlock != Items.AIR) { + outDrops.add(itemBlock.getDefaultStack()); + } + } + } + + private static String getPropertyTypeName(Property property) { + //Explicitly handle default minecraft properties + if (property instanceof BooleanProperty) { + return "bool"; + } + if (property instanceof IntProperty) { + return "int"; + } + if (property instanceof EnumProperty) { + return "enum"; + } + + //Use simple class name as fallback, this code will give something like + //example_type for ExampleTypeProperty class name + String rawPropertyName = property.getClass().getSimpleName().replace("Property", ""); + return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, rawPropertyName); + } + + private static > JsonObject generateStateProperty(Property property) { + JsonObject propertyObject = new JsonObject(); + Collection propertyValues = property.getValues(); + + propertyObject.addProperty("name", property.getName()); + propertyObject.addProperty("type", getPropertyTypeName(property)); + propertyObject.addProperty("num_values", propertyValues.size()); + + //Do not add values for vanilla boolean properties, they are known by default + if (!(property instanceof BooleanProperty)) { + JsonArray propertyValuesArray = new JsonArray(); + for (T propertyValue : propertyValues) { + propertyValuesArray.add(property.name(propertyValue)); + } + propertyObject.add("values", propertyValuesArray); + } + return propertyObject; + } + + private static String findMatchingBlockMaterial(BlockState blockState, List materials) { + List matchingMaterials = materials.stream() + .filter(material -> material.getPredicate().test(blockState)) + .collect(Collectors.toList()); + + if (matchingMaterials.size() > 1) { + var firstMaterial = matchingMaterials.getFirst(); + var otherMaterials = matchingMaterials.subList(1, matchingMaterials.size()); + + if (!otherMaterials.stream().allMatch(firstMaterial::includesMaterial)) { + logger.error("Block {} matches multiple materials: {}", blockState.getBlock(), matchingMaterials); + } + } + if (matchingMaterials.isEmpty()) { + return "default"; + } + return matchingMaterials.getFirst().getMaterialName(); + } + + public static JsonObject generateBlock(List materials, Block block) { + JsonObject blockDesc = new JsonObject(); + + List blockStates = block.getStateManager().getStates(); + BlockState defaultState = block.getDefaultState(); + Identifier registryKey = Registries.BLOCK.getKey(block).orElseThrow().getValue(); + String localizationKey = block.getTranslationKey(); + List effectiveTools = getItemsEffectiveForBlock(defaultState); + + blockDesc.addProperty("id", Registries.BLOCK.getRawId(block)); + blockDesc.addProperty("name", registryKey.getPath()); + blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); + + blockDesc.addProperty("hardness", block.getHardness()); + blockDesc.addProperty("resistance", block.getBlastResistance()); + blockDesc.addProperty("stackSize", block.asItem().getMaxCount()); + blockDesc.addProperty("diggable", block.getHardness() != -1.0f && !(block instanceof AirBlock)); +// JsonObject effTools = new JsonObject(); +// effectiveTools.forEach(item -> effTools.addProperty( +// String.valueOf(Registry.ITEM.getRawId(item)), // key +// item.getMiningSpeedMultiplier(item.getDefaultStack(), defaultState) // value +// )); +// blockDesc.add("effectiveTools", effTools); + blockDesc.addProperty("material", findMatchingBlockMaterial(defaultState, materials)); + + blockDesc.addProperty("transparent", !defaultState.isOpaque()); + blockDesc.addProperty("emitLight", defaultState.getLuminance()); + blockDesc.addProperty("filterLight", defaultState.getOpacity(EmptyBlockView.INSTANCE, BlockPos.ORIGIN)); + + blockDesc.addProperty("defaultState", Block.getRawIdFromState(defaultState)); + blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.getFirst())); + blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.getLast())); + + JsonArray stateProperties = new JsonArray(); + for (Property property : block.getStateManager().getProperties()) { + stateProperties.add(generateStateProperty(property)); + } + blockDesc.add("states", stateProperties); + + //Only add harvest tools if tool is required for harvesting this block + if (defaultState.isToolRequired()) { + JsonObject effectiveToolsObject = new JsonObject(); + for (Item effectiveItem : effectiveTools) { + effectiveToolsObject.addProperty(Integer.toString(Item.getRawId(effectiveItem)), true); + } + blockDesc.add("harvestTools", effectiveToolsObject); + } + + List actualBlockDrops = new ArrayList<>(); + populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.getFirst(), actualBlockDrops); + + JsonArray dropsArray = new JsonArray(); + for (ItemStack dropStack : actualBlockDrops) { + dropsArray.add(Item.getRawId(dropStack.getItem())); + } + blockDesc.add("drops", dropsArray); + + VoxelShape blockCollisionShape = defaultState.getCollisionShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN); + blockDesc.addProperty("boundingBox", blockCollisionShape.isEmpty() ? "empty" : "block"); + + return blockDesc; + } + + @Override + public String getDataName() { + return "blocks"; + } + + @Override + public JsonArray generateDataJson() { + JsonArray resultBlocksArray = new JsonArray(); + List availableMaterials = MaterialsDataGenerator.getGlobalMaterialInfo(); + + Registries.BLOCK.forEach(block -> resultBlocksArray.add(generateBlock(availableMaterials, block))); + return resultBlocksArray; + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java new file mode 100644 index 00000000..dd6dc019 --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -0,0 +1,46 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import dev.u9g.minecraftdatagenerator.util.DGU; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; +import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.stream.Collectors; + +public class EffectsDataGenerator implements IDataGenerator { + public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { + JsonObject effectDesc = new JsonObject(); + Identifier registryKey = registry.getKey(statusEffect).orElseThrow().getValue(); + + effectDesc.addProperty("id", registry.getRawId(statusEffect)); + if (statusEffect == StatusEffects.UNLUCK) { + effectDesc.addProperty("name", "BadLuck"); + effectDesc.addProperty("displayName", "Bad Luck"); + } else { + effectDesc.addProperty("name", Arrays.stream(registryKey.getPath().split("_")).map(StringUtils::capitalize).collect(Collectors.joining())); + effectDesc.addProperty("displayName", DGU.translateText(statusEffect.getTranslationKey())); + } + + effectDesc.addProperty("type", statusEffect.isBeneficial() ? "good" : "bad"); + return effectDesc; + } + + @Override + public String getDataName() { + return "effects"; + } + + @Override + public JsonArray generateDataJson() { + JsonArray resultsArray = new JsonArray(); + Registry statusEffectRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.STATUS_EFFECT); + statusEffectRegistry.forEach(effect -> resultsArray.add(generateEffect(statusEffectRegistry, effect))); + return resultsArray; + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java new file mode 100644 index 00000000..5d2ebb96 --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -0,0 +1,89 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import dev.u9g.minecraftdatagenerator.util.DGU; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.Item; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.Identifier; + +import java.util.List; + +public class EnchantmentsDataGenerator implements IDataGenerator { + public static String getEnchantmentTargetName(TagKey target) { + return target.id().getPath().split("/")[1]; + } + + //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.getMinPower(0); + int a = enchantment.getMinPower(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.getMaxPower(0); + int a = enchantment.getMaxPower(1) - b; + + JsonObject resultObject = new JsonObject(); + resultObject.addProperty("a", a); + resultObject.addProperty("b", b); + return resultObject; + } + + public static JsonObject generateEnchantment(Registry registry, Enchantment enchantment) { + JsonObject enchantmentDesc = new JsonObject(); + Identifier registryKey = registry.getKey(enchantment).orElseThrow().getValue(); + + enchantmentDesc.addProperty("id", registry.getRawId(enchantment)); + enchantmentDesc.addProperty("name", registryKey.getPath()); + enchantmentDesc.addProperty("displayName", DGU.translateText(enchantment.getTranslationKey())); + + enchantmentDesc.addProperty("maxLevel", enchantment.getMaxLevel()); + enchantmentDesc.add("minCost", generateEnchantmentMinPowerCoefficients(enchantment)); + enchantmentDesc.add("maxCost", generateEnchantmentMaxPowerCoefficients(enchantment)); + + enchantmentDesc.addProperty("treasureOnly", enchantment.isTreasure()); + enchantmentDesc.addProperty("curse", enchantment.isCursed()); + + List incompatibleEnchantments = registry.stream() + .filter(other -> !enchantment.canCombine(other)) + .filter(other -> other != enchantment) + .toList(); + + JsonArray excludes = new JsonArray(); + for (Enchantment excludedEnchantment : incompatibleEnchantments) { + Identifier otherKey = registry.getKey(excludedEnchantment).orElseThrow().getValue(); + excludes.add(otherKey.getPath()); + } + enchantmentDesc.add("exclude", excludes); + + enchantmentDesc.addProperty("category", getEnchantmentTargetName(enchantment.getApplicableItems())); + enchantmentDesc.addProperty("weight", enchantment.getWeight()); + enchantmentDesc.addProperty("tradeable", enchantment.isAvailableForEnchantedBookOffer()); + enchantmentDesc.addProperty("discoverable", enchantment.isAvailableForRandomSelection()); + + return enchantmentDesc; + } + + @Override + public String getDataName() { + return "enchantments"; + } + + @Override + public JsonArray generateDataJson() { + JsonArray resultsArray = new JsonArray(); + Registry enchantmentRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.ENCHANTMENT); + enchantmentRegistry.stream() + .forEach(enchantment -> resultsArray.add(generateEnchantment(enchantmentRegistry, enchantment))); + return resultsArray; + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java new file mode 100644 index 00000000..70a88040 --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -0,0 +1,119 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import dev.u9g.minecraftdatagenerator.util.DGU; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +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.passive.PassiveEntity; +import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.Identifier; + +public class EntitiesDataGenerator implements IDataGenerator { + public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { + JsonObject entityDesc = new JsonObject(); + Identifier registryKey = entityRegistry.getKey(entityType).orElseThrow().getValue(); + int entityRawId = entityRegistry.getRawId(entityType); + + entityDesc.addProperty("id", entityRawId); + entityDesc.addProperty("internalId", entityRawId); + entityDesc.addProperty("name", registryKey.getPath()); + + entityDesc.addProperty("displayName", DGU.translateText(entityType.getTranslationKey())); + entityDesc.addProperty("width", entityType.getDimensions().width()); + entityDesc.addProperty("height", entityType.getDimensions().height()); + + String entityTypeString = "UNKNOWN"; + MinecraftServer minecraftServer = DGU.getCurrentlyRunningServer(); + + if (minecraftServer != null) { + Entity entityObject = entityType.create(minecraftServer.getOverworld()); + entityTypeString = entityObject != null ? getEntityTypeForClass(entityObject.getClass()) : "unknown"; + } + if (entityType == EntityType.PLAYER) { + entityTypeString = "player"; + } + + entityDesc.addProperty("type", entityTypeString); + entityDesc.addProperty("category", getCategoryFrom(entityType)); + + return entityDesc; + } + + private static String getCategoryFrom(EntityType entityType) { + if (entityType == EntityType.PLAYER) return "UNKNOWN"; + Entity entity = entityType.create(DGU.getWorld()); + if (entity == null) + throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + entity.discard(); + return switch (entity.getClass().getPackageName()) { + 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.projectile.thrown" -> "Projectiles"; + case "net.minecraft.entity.passive" -> "Passive mobs"; + case "net.minecraft.entity.vehicle" -> "Vehicles"; + case "net.minecraft.entity" -> "UNKNOWN"; + default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); + }; + } + + //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 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 (PassiveEntity.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 (ProjectileEntity.class.isAssignableFrom(entityClass)) { + return "projectile"; + } + return "other"; + } + + @Override + public String getDataName() { + return "entities"; + } + + @Override + public JsonArray generateDataJson() { + JsonArray resultArray = new JsonArray(); + Registry> entityTypeRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.ENTITY_TYPE); + entityTypeRegistry.forEach(entity -> resultArray.add(generateEntity(entityTypeRegistry, entity))); + return resultArray; + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java new file mode 100644 index 00000000..ddb61fe9 --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -0,0 +1,52 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import dev.u9g.minecraftdatagenerator.util.DGU; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.FoodComponent; +import net.minecraft.item.Item; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; + +import java.util.Objects; + +public class FoodsDataGenerator implements IDataGenerator { + public static JsonObject generateFoodDescriptor(Registry registry, Item foodItem) { + JsonObject foodDesc = new JsonObject(); + Identifier registryKey = registry.getKey(foodItem).orElseThrow().getValue(); + + foodDesc.addProperty("id", registry.getRawId(foodItem)); + foodDesc.addProperty("name", registryKey.getPath()); + + foodDesc.addProperty("stackSize", foodItem.getMaxCount()); + foodDesc.addProperty("displayName", DGU.translateText(foodItem.getTranslationKey())); + + FoodComponent foodComponent = Objects.requireNonNull(foodItem.getComponents().get(DataComponentTypes.FOOD)); + float foodPoints = foodComponent.nutrition(); + float saturationRatio = foodComponent.saturation() * 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(); + Registry itemRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.ITEM); + itemRegistry.stream() + .filter(i -> i.getComponents().contains(DataComponentTypes.FOOD)) + .forEach(food -> resultsArray.add(generateFoodDescriptor(itemRegistry, food))); + return resultsArray; + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java new file mode 100644 index 00000000..e7b9b54f --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java @@ -0,0 +1,25 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.minecraft.block.enums.Instrument; + +public class InstrumentsDataGenerator implements IDataGenerator { + @Override + public String getDataName() { + return "instruments"; + } + + @Override + public JsonElement generateDataJson() { + JsonArray array = new JsonArray(); + for (Instrument instrument : Instrument.values()) { + JsonObject object = new JsonObject(); + object.addProperty("id", instrument.ordinal()); + object.addProperty("name", instrument.asString()); + array.add(object); + } + return array; + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/ItemsDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/ItemsDataGenerator.java new file mode 100644 index 00000000..836cf5a9 --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/ItemsDataGenerator.java @@ -0,0 +1,88 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import dev.u9g.minecraftdatagenerator.util.DGU; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.Identifier; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public class ItemsDataGenerator implements IDataGenerator { + + private static List calculateItemsToRepairWith(Registry itemRegistry, Item sourceItem) { + ItemStack sourceItemStack = sourceItem.getDefaultStack(); + return itemRegistry.stream() + .filter(otherItem -> sourceItem.canRepair(sourceItemStack, otherItem.getDefaultStack())) + .collect(Collectors.toList()); + } + + private static List> getApplicableEnchantmentTargets(Item sourceItem) { + return sourceItem.getComponents().get(DataComponentTypes.ENCHANTMENTS) + .getEnchantments() + .stream() + .map(RegistryEntry::value) + .map(Enchantment::getApplicableItems) + .toList(); + } + + public static JsonObject generateItem(Registry itemRegistry, Item item) { + JsonObject itemDesc = new JsonObject(); + Identifier registryKey = itemRegistry.getKey(item).orElseThrow().getValue(); + + itemDesc.addProperty("id", itemRegistry.getRawId(item)); + itemDesc.addProperty("name", registryKey.getPath()); + + itemDesc.addProperty("displayName", DGU.translateText(item.getTranslationKey())); + itemDesc.addProperty("stackSize", item.getMaxCount()); + + List> enchantmentTargets = getApplicableEnchantmentTargets(item); + + JsonArray enchantCategoriesArray = new JsonArray(); + for (TagKey target : enchantmentTargets) { + enchantCategoriesArray.add(EnchantmentsDataGenerator.getEnchantmentTargetName(target)); + } + if (enchantCategoriesArray.size() > 0) { + itemDesc.add("enchantCategories", enchantCategoriesArray); + } + + if (item.getComponents().contains(DataComponentTypes.DAMAGE)) { + List repairWithItems = calculateItemsToRepairWith(itemRegistry, item); + + JsonArray fixedWithArray = new JsonArray(); + for (Item repairWithItem : repairWithItems) { + Identifier repairWithName = itemRegistry.getKey(repairWithItem).orElseThrow().getValue(); + fixedWithArray.add(repairWithName.getPath()); + } + if (fixedWithArray.size() > 0) { + itemDesc.add("repairWith", fixedWithArray); + } + + int maxDurability = Objects.requireNonNull(item.getComponents().get(DataComponentTypes.MAX_DAMAGE)); + itemDesc.addProperty("maxDurability", maxDurability); + } + return itemDesc; + } + + @Override + public String getDataName() { + return "items"; + } + + @Override + public JsonArray generateDataJson() { + JsonArray resultArray = new JsonArray(); + Registry itemRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.ITEM); + itemRegistry.stream().forEach(item -> resultArray.add(generateItem(itemRegistry, item))); + return resultArray; + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java new file mode 100644 index 00000000..7a3c6ced --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/LanguageDataGenerator.java @@ -0,0 +1,27 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.Objects; + +public class LanguageDataGenerator implements IDataGenerator { + @Override + public String getDataName() { + return "language"; + } + + @Override + public JsonElement generateDataJson() { + try { + InputStream inputStream = Objects.requireNonNull(this.getClass().getResourceAsStream("/assets/minecraft/lang/en_us.json")); + return new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); + } catch (Exception ignored) { + } + throw new RuntimeException("Failed to generate language file"); + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java new file mode 100644 index 00000000..46e42b47 --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java @@ -0,0 +1,211 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import dev.u9g.minecraftdatagenerator.util.DGU; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.item.Item; +import net.minecraft.item.Items; +import net.minecraft.item.MiningToolItem; +import net.minecraft.item.SwordItem; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.BlockTags; +import net.minecraft.registry.tag.TagKey; + +import java.util.*; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +//TODO entire idea of linking materials to tool speeds is obsolete and just wrong now, +//TODO but we kinda have to support it to let old code work for computing digging times, +//TODO so for now we will handle materials as "virtual" ones based on which tools can break blocks +public class MaterialsDataGenerator implements IDataGenerator { + + private static final List> COMPOSITE_MATERIALS = ImmutableList.>builder() + .add(ImmutableList.of("plant", makeMaterialNameForTag(BlockTags.AXE_MINEABLE))) + .add(ImmutableList.of("gourd", makeMaterialNameForTag(BlockTags.AXE_MINEABLE))) + .add(ImmutableList.of(makeMaterialNameForTag(BlockTags.LEAVES), makeMaterialNameForTag(BlockTags.HOE_MINEABLE))) + .add(ImmutableList.of(makeMaterialNameForTag(BlockTags.LEAVES), makeMaterialNameForTag(BlockTags.AXE_MINEABLE), makeMaterialNameForTag(BlockTags.HOE_MINEABLE))) + .add(ImmutableList.of("vine_or_glow_lichen", "plant", makeMaterialNameForTag(BlockTags.AXE_MINEABLE) + )).build(); + + private static String makeMaterialNameForTag(TagKey tag) { + return tag.id().getPath(); + } + + private static void createCompositeMaterialInfo(List allMaterials, List combinedMaterials) { + String compositeMaterialName = String.join(";", combinedMaterials); + + List mappedMaterials = combinedMaterials.stream() + .map(otherName -> allMaterials.stream() + .filter(other -> other.getMaterialName().equals(otherName)) + .findFirst().orElseThrow(() -> new RuntimeException("Material not found with name " + otherName))) + .collect(Collectors.toList()); + + Predicate compositePredicate = blockState -> + mappedMaterials.stream().allMatch(it -> it.getPredicate().test(blockState)); + + MaterialInfo materialInfo = new MaterialInfo(compositeMaterialName, compositePredicate).includes(mappedMaterials); + allMaterials.addFirst(materialInfo); + } + + private static void createCompositeMaterial(Map> allMaterials, List combinedMaterials) { + String compositeMaterialName = String.join(";", combinedMaterials); + + Map resultingToolSpeeds = new LinkedHashMap<>(); + combinedMaterials.stream() + .map(allMaterials::get) + .forEach(resultingToolSpeeds::putAll); + allMaterials.put(compositeMaterialName, resultingToolSpeeds); + } + + public static List getGlobalMaterialInfo() { + ArrayList resultList = new ArrayList<>(); + + resultList.add(new MaterialInfo("vine_or_glow_lichen", blockState -> blockState.isOf(Blocks.VINE) || blockState.isOf(Blocks.GLOW_LICHEN))); + resultList.add(new MaterialInfo("coweb", blockState -> blockState.isOf(Blocks.COBWEB))); + + resultList.add(new MaterialInfo("leaves", blockState -> blockState.isIn(BlockTags.LEAVES))); + resultList.add(new MaterialInfo("wool", blockState -> blockState.isIn(BlockTags.WOOL))); + + // Block Materials were removed in 1.20 in favor of block tags + resultList.add(new MaterialInfo("gourd", blockState -> blockState.isOf(Blocks.MELON) || blockState.isOf(Blocks.PUMPKIN) || blockState.isOf(Blocks.JACK_O_LANTERN))); + // 'sword_efficient' tag is for all plants, and includes everything from the old PLANT and REPLACEABLE_PLANT materials (see https://minecraft.fandom.com/wiki/Tag#Blocks) + resultList.add(new MaterialInfo("plant", blockState -> blockState.isIn(BlockTags.SWORD_EFFICIENT))); + + HashSet uniqueMaterialNames = new HashSet<>(); + + Registry itemRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.ITEM); + itemRegistry.forEach(item -> { + if (item instanceof MiningToolItem toolItem) { + item.getComponents().get(DataComponentTypes.TOOL).rules() + .stream().map(rule -> rule.blocks()) + .forEach(blocks -> { + Optional> tagKey = blocks.getTagKey(); + if (tagKey.isPresent()) { + String materialName = makeMaterialNameForTag((tagKey.get())); + + if (!uniqueMaterialNames.contains(materialName)) { + uniqueMaterialNames.add(materialName); + resultList.add(new MaterialInfo(materialName, blockState -> blockState.isIn(blocks))); + } + } + }); + } + }); + + COMPOSITE_MATERIALS.forEach(values -> createCompositeMaterialInfo(resultList, values)); + return resultList; + } + + @Override + public String getDataName() { + return "materials"; + } + + @Override + public JsonElement generateDataJson() { + Registry itemRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.ITEM); + + Map> materialMiningSpeeds = new LinkedHashMap<>(); + materialMiningSpeeds.put("default", ImmutableMap.of()); + + //Special materials used for shears and swords special mining speed logic + Map leavesMaterialSpeeds = new LinkedHashMap<>(); + Map cowebMaterialSpeeds = new LinkedHashMap<>(); + Map plantMaterialSpeeds = new LinkedHashMap<>(); + Map gourdMaterialSpeeds = new LinkedHashMap<>(); + + materialMiningSpeeds.put(makeMaterialNameForTag(BlockTags.LEAVES), leavesMaterialSpeeds); + materialMiningSpeeds.put("coweb", cowebMaterialSpeeds); + materialMiningSpeeds.put("plant", plantMaterialSpeeds); + materialMiningSpeeds.put("gourd", gourdMaterialSpeeds); + + //Shears need special handling because they do not follow normal rules like tools + leavesMaterialSpeeds.put(Items.SHEARS, 15.0f); + cowebMaterialSpeeds.put(Items.SHEARS, 15.0f); + materialMiningSpeeds.put("vine_or_glow_lichen", ImmutableMap.of(Items.SHEARS, 2.0f)); + materialMiningSpeeds.put("wool", ImmutableMap.of(Items.SHEARS, 5.0f)); + + itemRegistry.forEach(item -> { + //Tools are handled rather easily and do not require anything else + if (item instanceof MiningToolItem toolItem) { + item.getComponents().get(DataComponentTypes.TOOL).rules() + .stream().map(rule -> rule.blocks()) + .forEach(blocks -> { + Optional> tagKey = blocks.getTagKey(); + if (tagKey.isPresent()) { + String materialName = makeMaterialNameForTag(tagKey.get()); + + Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>()); + float miningSpeed = item.getComponents().get(DataComponentTypes.TOOL).defaultMiningSpeed(); + materialSpeeds.put(item, miningSpeed); + } + } + ); + + //Swords require special treatment + if (item instanceof SwordItem) { + cowebMaterialSpeeds.put(item, 15.0f); + plantMaterialSpeeds.put(item, 1.5f); + leavesMaterialSpeeds.put(item, 1.5f); + gourdMaterialSpeeds.put(item, 1.5f); + } + }}); + + COMPOSITE_MATERIALS.forEach(values -> createCompositeMaterial(materialMiningSpeeds, values)); + + JsonObject resultObject = new JsonObject(); + + for (var entry : materialMiningSpeeds.entrySet()) { + JsonObject toolSpeedsObject = new JsonObject(); + + for (var toolEntry : entry.getValue().entrySet()) { + int rawItemId = itemRegistry.getRawId(toolEntry.getKey()); + toolSpeedsObject.addProperty(Integer.toString(rawItemId), toolEntry.getValue()); + } + resultObject.add(entry.getKey(), toolSpeedsObject); + } + + return resultObject; + } + + public static class MaterialInfo { + private final String materialName; + private final Predicate predicate; + private final List includedMaterials = new ArrayList<>(); + + public MaterialInfo(String materialName, Predicate predicate) { + this.materialName = materialName; + this.predicate = predicate; + } + + protected MaterialInfo includes(List otherMaterials) { + this.includedMaterials.addAll(otherMaterials); + return this; + } + + public String getMaterialName() { + return materialName; + } + + public Predicate getPredicate() { + return predicate; + } + + public boolean includesMaterial(MaterialInfo materialInfo) { + return includedMaterials.contains(materialInfo); + } + + @Override + public String toString() { + return materialName; + } + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java new file mode 100644 index 00000000..bc5a9acc --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -0,0 +1,33 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import dev.u9g.minecraftdatagenerator.util.DGU; +import net.minecraft.particle.ParticleType; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; + +public class ParticlesDataGenerator implements IDataGenerator { + public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { + JsonObject effectDesc = new JsonObject(); + Identifier registryKey = registry.getKey(particleType).orElseThrow().getValue(); + + effectDesc.addProperty("id", registry.getRawId(particleType)); + effectDesc.addProperty("name", registryKey.getPath()); + return effectDesc; + } + + @Override + public String getDataName() { + return "particles"; + } + + @Override + public JsonArray generateDataJson() { + JsonArray resultsArray = new JsonArray(); + Registry> particleTypeRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.PARTICLE_TYPE); + particleTypeRegistry.forEach(particleType -> resultsArray.add(generateParticleType(particleTypeRegistry, particleType))); + return resultsArray; + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java new file mode 100644 index 00000000..ea489d11 --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -0,0 +1,128 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import dev.u9g.minecraftdatagenerator.util.DGU; +import net.minecraft.item.Item; +import net.minecraft.recipe.*; +import net.minecraft.registry.DynamicRegistryManager; +import net.minecraft.registry.RegistryKeys; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class RecipeDataGenerator implements IDataGenerator { + + private static int getRawIdFor(Item item) { + return DGU.getWorld().getRegistryManager().get(RegistryKeys.ITEM).getRawId(item); + } + + @Override + public String getDataName() { + return "recipes"; + } + + @Override + public JsonElement generateDataJson() { + DynamicRegistryManager registryManager = DGU.getWorld().getRegistryManager(); + JsonObject finalObj = new JsonObject(); + Multimap recipes = ArrayListMultimap.create(); + for (RecipeEntry recipeE : Objects.requireNonNull(DGU.getWorld()).getRecipeManager().values()) { + Recipe recipe = recipeE.value(); + if (recipe instanceof ShapedRecipe sr) { + var ingredients = sr.getIngredients(); + List 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 < sr.getHeight(); y++) { + var jsonRow = new JsonArray(); + for (int z = 0; z < sr.getWidth(); z++) { + jsonRow.add(iter.next()); + } + inShape.add(jsonRow); + } + + JsonObject finalRecipe = new JsonObject(); + finalRecipe.add("inShape", inShape); + + var resultObject = new JsonObject(); + resultObject.addProperty("id", getRawIdFor(sr.getResult(registryManager).getItem())); + resultObject.addProperty("count", sr.getResult(registryManager).getCount()); + finalRecipe.add("result", resultObject); + + String id = ((Integer) getRawIdFor(sr.getResult(registryManager).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.getResult(registryManager).getItem())); + resultObject.addProperty("count", sl.getResult(registryManager).getCount()); + rootRecipeObject.add("result", resultObject); + recipes.put(getRawIdFor(sl.getResult(registryManager).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; + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java new file mode 100644 index 00000000..5c21246b --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -0,0 +1,158 @@ +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.EmptyRenderBlockView; +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.block.RedstoneWireBlock; +import net.minecraft.client.color.block.BlockColors; +import net.minecraft.client.color.world.FoliageColors; +import net.minecraft.registry.DynamicRegistryManager; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.biome.Biome; + +import java.util.*; + +public class TintsDataGenerator implements IDataGenerator { + public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { + BiomeTintColors colors = new BiomeTintColors(); + + biomeRegistry.forEach(biome -> { + int biomeGrassColor = biome.getGrassColorAt(0.0, 0.0); + int biomeFoliageColor = biome.getFoliageColor(); + int biomeWaterColor = biome.getWaterColor(); + + 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; + } + + public static Map generateRedstoneTintColors() { + Map resultColors = new LinkedHashMap<>(); + + for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { + int color = RedstoneWireBlock.getWireColor(redstoneLevel); + resultColors.put(redstoneLevel, color); + } + return resultColors; + } + + private static int getBlockColor(Block block) { + return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); + } + + public static Map generateConstantTintColors() { + Map resultColors = new LinkedHashMap<>(); + + resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); + resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); + + resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); + + return resultColors; + } + + private static JsonObject encodeBiomeColorMap(Registry biomeRegistry, Map> colorsMap) { + JsonArray resultColorsArray = new JsonArray(); + for (var entry : colorsMap.entrySet()) { + JsonObject entryObject = new JsonObject(); + + JsonArray keysArray = new JsonArray(); + for (Biome biome : entry.getValue()) { + Identifier registryKey = biomeRegistry.getKey(biome).orElseThrow().getValue(); + keysArray.add(registryKey.getPath()); + } + + 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 colorsMap) { + JsonArray resultColorsArray = new JsonArray(); + for (var entry : colorsMap.entrySet()) { + JsonObject entryObject = new JsonObject(); + + JsonArray keysArray = new JsonArray(); + keysArray.add(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(Registry blockRegistry, Map colorsMap) { + JsonArray resultColorsArray = new JsonArray(); + for (var entry : colorsMap.entrySet()) { + JsonObject entryObject = new JsonObject(); + + JsonArray keysArray = new JsonArray(); + Identifier registryKey = blockRegistry.getKey(entry.getKey()).orElseThrow().getValue(); + keysArray.add(registryKey.getPath()); + + 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() { + DynamicRegistryManager registryManager = DGU.getWorld().getRegistryManager(); + Registry biomeRegistry = registryManager.get(RegistryKeys.BIOME); + Registry blockRegistry = registryManager.get(RegistryKeys.BLOCK); + + BiomeTintColors biomeTintColors = generateBiomeTintColors(biomeRegistry); + Map redstoneColors = generateRedstoneTintColors(); + Map constantTintColors = generateConstantTintColors(); + + JsonObject resultObject = new JsonObject(); + + resultObject.add("grass", encodeBiomeColorMap(biomeRegistry, biomeTintColors.grassColoursMap)); + resultObject.add("foliage", encodeBiomeColorMap(biomeRegistry, biomeTintColors.foliageColoursMap)); + resultObject.add("water", encodeBiomeColorMap(biomeRegistry, biomeTintColors.waterColourMap)); + + resultObject.add("redstone", encodeRedstoneColorMap(redstoneColors)); + resultObject.add("constant", encodeBlocksColorMap(blockRegistry, constantTintColors)); + + return resultObject; + } + + public static class BiomeTintColors { + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EULAMixin.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EULAMixin.java new file mode 100644 index 00000000..0d297e7a --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EULAMixin.java @@ -0,0 +1,15 @@ +package dev.u9g.minecraftdatagenerator.mixin; + +import net.minecraft.server.dedicated.EulaReader; +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; + +@Mixin(EulaReader.class) +public class EULAMixin { + @Inject(method = "isEulaAgreedTo()Z", at = @At("TAIL"), cancellable = true) + public void init(CallbackInfoReturnable cir) { + cir.setReturnValue(true); + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java new file mode 100644 index 00000000..cf8d9ffc --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -0,0 +1,22 @@ +package dev.u9g.minecraftdatagenerator.mixin; + +import dev.u9g.minecraftdatagenerator.MinecraftDataGenerator; +import dev.u9g.minecraftdatagenerator.util.DGU; +import net.minecraft.MinecraftVersion; +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; + +@Mixin(MinecraftDedicatedServer.class) +public class ReadyMixin { + + @Inject(method = "setupServer()Z", at = @At("TAIL")) + private void init(CallbackInfoReturnable cir) { + MinecraftDataGenerator.start( + MinecraftVersion.CURRENT.getName(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java new file mode 100644 index 00000000..3946c1fe --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -0,0 +1,21 @@ +package dev.u9g.minecraftdatagenerator.util; + +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.Language; +import net.minecraft.world.World; + +public class DGU { + @SuppressWarnings("deprecation") + public static MinecraftServer getCurrentlyRunningServer() { + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); + } + + public static String translateText(String translationKey) { + return Language.getInstance().get(translationKey); + } + + public static World getWorld() { + return getCurrentlyRunningServer().getOverworld(); + } +} diff --git a/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyRenderBlockView.java b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyRenderBlockView.java new file mode 100644 index 00000000..460efd82 --- /dev/null +++ b/1.20.5/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyRenderBlockView.java @@ -0,0 +1,72 @@ +package dev.u9g.minecraftdatagenerator.util; + +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.BlockRenderView; +import net.minecraft.world.LightType; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeKeys; +import net.minecraft.world.biome.ColorResolver; +import net.minecraft.world.chunk.light.LightingProvider; +import org.jetbrains.annotations.Nullable; + +public enum EmptyRenderBlockView implements BlockRenderView { + INSTANCE; + + @Nullable + public BlockEntity getBlockEntity(BlockPos pos) { + return null; + } + + public BlockState getBlockState(BlockPos pos) { + return Blocks.AIR.getDefaultState(); + } + + public FluidState getFluidState(BlockPos pos) { + return Fluids.EMPTY.getDefaultState(); + } + + public int getBottomY() { + return 0; + } + + public int getHeight() { + return 0; + } + + + @Override + public float getBrightness(Direction direction, boolean shaded) { + return 0.0f; + } + + @Override + public LightingProvider getLightingProvider() { + return null; + } + + @Override + public int getColor(BlockPos pos, ColorResolver colorResolver) { + Registry biomeRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME); + Biome plainsBiome = biomeRegistry.get(BiomeKeys.PLAINS); + + return colorResolver.getColor(plainsBiome, pos.getX(), pos.getY()); + } + + @Override + public int getLightLevel(LightType type, BlockPos pos) { + return type == LightType.SKY ? getMaxLightLevel() : 0; + } + + @Override + public int getBaseLightLevel(BlockPos pos, int ambientDarkness) { + return ambientDarkness; + } +} diff --git a/1.20.5/src/main/resources/fabric.mod.json b/1.20.5/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..ffac96b0 --- /dev/null +++ b/1.20.5/src/main/resources/fabric.mod.json @@ -0,0 +1,20 @@ +{ + "schemaVersion": 1, + "id": "minecraft-data-generator", + "version": "${version}", + "name": "Minecraft Data Generator", + "description": "", + "authors": [ + "Archengius", + "U9G" + ], + "contact": {}, + "license": "MIT", + "mixins": [ + "minecraft-data-generator.mixins.json" + ], + "depends": { + "fabricloader": "*", + "minecraft": "*" + } +} diff --git a/1.20.5/src/main/resources/minecraft-data-generator.mixins.json b/1.20.5/src/main/resources/minecraft-data-generator.mixins.json new file mode 100644 index 00000000..82185961 --- /dev/null +++ b/1.20.5/src/main/resources/minecraft-data-generator.mixins.json @@ -0,0 +1,15 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "dev.u9g.minecraftdatagenerator.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "EULAMixin", + "ReadyMixin" + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/1.20/build.gradle b/1.20/build.gradle index e85de392..90cfd957 100644 --- a/1.20/build.gradle +++ b/1.20/build.gradle @@ -1,15 +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' } -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +unimined.minecraft { + version "1.20" + + mappings { + intermediary() + yarn(1) + + devFallbackNamespace "intermediary" + } + + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } + + customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() + } - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + defaultRemapJar = true +} + +dependencies { + implementation project(":common") } processResources { @@ -20,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.20/gradle.properties b/1.20/gradle.properties deleted file mode 100644 index 1818770d..00000000 --- a/1.20/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.20.2 -yarn_mappings=1.20.2+build.4 -loader_version=0.14.24 -# Dependencies -# check this on https://modmuss50.me/fabric.html -fabric_version=0.90.4+1.20.2 diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index f8d17372..00000000 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.u9g.minecraftdatagenerator; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Main implements ModInitializer { - public static final Logger LOGGER = LoggerFactory.getLogger("mc-data-gen-serv"); - - @Override - public void onInitialize() { - - } -} diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index bda5f967..a1b3b732 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -2,36 +2,24 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.TheEndBiomeDataAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; -import net.fabricmc.fabric.api.biome.v1.NetherBiomes; import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.Registry; -import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.BiomeTags; import net.minecraft.util.Identifier; import net.minecraft.world.biome.Biome; -import java.util.HashSet; -import java.util.Set; - public class BiomesDataGenerator implements IDataGenerator { - private static final Set> END_BIOMES = new HashSet<>(); - - static { - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_BIOMES_MAP().keySet()); - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_BARRENS_MAP().keySet()); - END_BIOMES.addAll(TheEndBiomeDataAccessor.END_MIDLANDS_MAP().keySet()); - } - - private static String guessBiomeDimensionFromCategory(Biome biome, String biomeName) { - var key = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME).getKey(biome).orElseThrow(); - if (NetherBiomes.canGenerateInNether(key)) { + private static String guessBiomeDimensionFromCategory(Biome biome) { + var biomeRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME); + if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_NETHER)) { return "nether"; - } else if (END_BIOMES.contains(key) || biomeName.startsWith("end_")) { + } else if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_END)) { return "end"; + } else { + return "overworld"; } - return "overworld"; } private static String guessCategoryBasedOnName(String name, String dimension) { @@ -87,196 +75,6 @@ private static String guessCategoryBasedOnName(String name, String dimension) { } } - private static int getBiomeColorFor(String biomeName) { - switch (biomeName) { - case "the_void" -> { - return 0; - } - case "plains" -> { - return 9286496; - } - case "sunflower_plains" -> { - return 11918216; - } - case "snowy_plains" -> { - return 16777215; - } - case "ice_spikes" -> { - return 11853020; - } - case "desert" -> { - return 16421912; - } - case "swamp" -> { - return 522674; - } - case "forest" -> { - return 353825; - } - case "flower_forest" -> { - return 2985545; - } - case "birch_forest" -> { - return 3175492; - } - case "dark_forest" -> { - return 4215066; - } - case "old_growth_birch_forest" -> { - return 5807212; - } - case "old_growth_pine_taiga" -> { - return 5858897; - } - case "old_growth_spruce_taiga" -> { - return 8490617; - } - case "taiga" -> { - return 747097; - } - case "snowy_taiga" -> { - return 3233098; - } - case "savanna" -> { - return 12431967; - } - case "savanna_plateau" -> { - return 10984804; - } - case "windswept_hills" -> { - return 6316128; - } - case "windswept_gravelly_hills" -> { - return 8947848; - } - case "windswept_forest" -> { - return 2250012; - } - case "windswept_savanna" -> { - return 15063687; - } - case "jungle" -> { - return 5470985; - } - case "sparse_jungle" -> { - return 6458135; - } - case "bamboo_jungle" -> { - return 7769620; - } - case "badlands" -> { - return 14238997; - } - case "eroded_badlands" -> { - return 16739645; - } - case "wooded_badlands" -> { - return 11573093; - } - case "meadow" -> { - return 9217136; - } - case "grove" -> { - return 14675173; - } - case "snowy_slopes" -> { - return 14348785; - } - case "frozen_peaks" -> { - return 15399931; - } - case "jagged_peaks" -> { - return 14937325; - } - case "stony_peaks" -> { - return 13750737; - } - case "river" -> { - return 255; - } - case "frozen_river" -> { - return 10526975; - } - case "beach" -> { - return 16440917; - } - case "snowy_beach" -> { - return 16445632; - } - case "stony_shore" -> { - return 10658436; - } - case "warm_ocean" -> { - return 172; - } - case "lukewarm_ocean" -> { - return 144; - } - case "deep_lukewarm_ocean" -> { - return 64; - } - case "ocean" -> { - return 112; - } - case "deep_ocean" -> { - return 48; - } - case "cold_ocean" -> { - return 2105456; - } - case "deep_cold_ocean" -> { - return 2105400; - } - case "frozen_ocean" -> { - return 7368918; - } - case "deep_frozen_ocean" -> { - return 4210832; - } - case "mushroom_fields" -> { - return 16711935; - } - case "dripstone_caves" -> { - return 12690831; - } - case "lush_caves" -> { - return 14652980; - } - case "nether_wastes" -> { - return 12532539; - } - case "warped_forest" -> { - return 4821115; - } - case "crimson_forest" -> { - return 14485512; - } - case "soul_sand_valley" -> { - return 6174768; - } - case "basalt_deltas" -> { - return 4208182; - } - case "the_end" -> { - return 8421631; - } - case "end_highlands" -> { - return 12828041; - } - case "end_midlands" -> { - return 15464630; - } - case "small_end_islands" -> { - return 42; - } - case "end_barrens" -> { - return 9474162; - } - } - System.out.println("Don't know the color of biome: '" + biomeName + "'"); - return 0; - } - public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); Identifier registryKey = registry.getKey(biome).orElseThrow().getValue(); @@ -284,7 +82,7 @@ public static JsonObject generateBiomeInfo(Registry registry, Biome biome String name = registryKey.getPath(); biomeDesc.addProperty("id", registry.getRawId(biome)); biomeDesc.addProperty("name", name); - String dimension = guessBiomeDimensionFromCategory(biome, name); + String dimension = guessBiomeDimensionFromCategory(biome); biomeDesc.addProperty("category", guessCategoryBasedOnName(name, dimension)); biomeDesc.addProperty("temperature", biome.getTemperature()); //biomeDesc.addProperty("precipitation", biome.getPrecipitation().getName());// - removed in 1.19.4 @@ -292,7 +90,7 @@ public static JsonObject generateBiomeInfo(Registry registry, Biome biome //biomeDesc.addProperty("depth", biome.getDepth()); - Doesn't exist anymore in minecraft source biomeDesc.addProperty("dimension", dimension); biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); - biomeDesc.addProperty("color", getBiomeColorFor(registryKey.getPath())); + biomeDesc.addProperty("color", biome.getSkyColor()); //biomeDesc.addProperty("rainfall", biome.getDownfall());// - removed in 1.19.4 return biomeDesc; diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 8b9d0e06..68a169cd 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -14,10 +14,7 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class BlockCollisionShapesDataGenerator implements IDataGenerator { @@ -42,8 +39,8 @@ public JsonObject generateDataJson() { } private static class BlockShapesCache { - public final Map uniqueBlockShapes = new HashMap<>(); - public final Map> blockCollisionShapes = new HashMap<>(); + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); private int lastCollisionShapeId = 0; public void processBlock(Block block) { @@ -72,7 +69,7 @@ public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { long distinctShapesCount = blockCollisions.stream().distinct().count(); JsonElement blockCollision; if (distinctShapesCount == 1L) { - blockCollision = new JsonPrimitive(blockCollisions.get(0)); + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); } else { blockCollision = new JsonArray(); for (int collisionId : blockCollisions) { diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 44e8e29c..324b4d90 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -12,7 +12,7 @@ import net.minecraft.item.Items; import net.minecraft.loot.context.LootContextParameterSet; import net.minecraft.loot.context.LootContextParameters; -import net.minecraft.registry.Registry; +import net.minecraft.registry.Registries; import net.minecraft.registry.RegistryKeys; import net.minecraft.server.MinecraftServer; import net.minecraft.server.world.ServerWorld; @@ -105,7 +105,7 @@ private static String findMatchingBlockMaterial(BlockState blockState, List 1) { - var firstMaterial = matchingMaterials.get(0); + var firstMaterial = matchingMaterials.getFirst(); var otherMaterials = matchingMaterials.subList(1, matchingMaterials.size()); if (!otherMaterials.stream().allMatch(firstMaterial::includesMaterial)) { @@ -115,19 +115,19 @@ private static String findMatchingBlockMaterial(BlockState blockState, List blockRegistry, List materials, Block block) { + public static JsonObject generateBlock(List materials, Block block) { JsonObject blockDesc = new JsonObject(); List blockStates = block.getStateManager().getStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = blockRegistry.getKey(block).orElseThrow().getValue(); + Identifier registryKey = Registries.BLOCK.getKey(block).orElseThrow().getValue(); String localizationKey = block.getTranslationKey(); List effectiveTools = getItemsEffectiveForBlock(defaultState); - blockDesc.addProperty("id", blockRegistry.getRawId(block)); + blockDesc.addProperty("id", Registries.BLOCK.getRawId(block)); blockDesc.addProperty("name", registryKey.getPath()); blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); @@ -148,8 +148,8 @@ public static JsonObject generateBlock(Registry blockRegistry, List property : block.getStateManager().getProperties()) { @@ -167,7 +167,7 @@ public static JsonObject generateBlock(Registry blockRegistry, List actualBlockDrops = new ArrayList<>(); - populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.get(0), actualBlockDrops); + populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.getFirst(), actualBlockDrops); JsonArray dropsArray = new JsonArray(); for (ItemStack dropStack : actualBlockDrops) { @@ -189,10 +189,9 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultBlocksArray = new JsonArray(); - Registry blockRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BLOCK); List availableMaterials = MaterialsDataGenerator.getGlobalMaterialInfo(); - blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, availableMaterials, block))); + Registries.BLOCK.forEach(block -> resultBlocksArray.add(generateBlock(availableMaterials, block))); return resultBlocksArray; } } diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index ebf2ed5f..00000000 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -1,78 +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 org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -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.util.ArrayList; -import java.util.List; - -public class DataGenerators { - - private static final Logger logger = LoggerFactory.getLogger(DataGenerators.class); - private static final List GENERATORS = new ArrayList<>(); - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new MaterialsDataGenerator()); -// register(new RecipeDataGenerator()); - On hold until mcdata supports multiple materials for a recipe - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new SoundsDataGenerator()); - } - - public static void register(IDataGenerator generator) { - GENERATORS.add(generator); - } - - public static boolean runDataGenerators(Path outputDirectory) { - try { - Files.createDirectories(outputDirectory); - } catch (IOException exception) { - logger.error("Failed to create data generator output directory at {}", outputDirectory, exception); - return false; - } - - int generatorsFailed = 0; - logger.info("Running minecraft data generators, output at {}", outputDirectory); - - for (IDataGenerator dataGenerator : GENERATORS) { - logger.info("Running generator {}", 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("Generator: {} -> {}", dataGenerator.getDataName(), outputFileName); - - } catch (Throwable exception) { - logger.error("Failed to run data generator {}", dataGenerator.getDataName(), exception); - generatorsFailed++; - } - } - - logger.info("Finishing running data generators"); - return generatorsFailed == 0; - } -} diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 3c619c36..dd6dc019 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -14,7 +14,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(statusEffect).orElseThrow().getValue(); diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java index 6bd50d74..d00d886d 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.collect.ImmutableMap; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -12,29 +11,10 @@ import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; public class EnchantmentsDataGenerator implements IDataGenerator { - - private static final ImmutableMap ENCHANTMENT_TARGET_NAMES = ImmutableMap.builder() - .put(EnchantmentTarget.ARMOR, "armor") - .put(EnchantmentTarget.ARMOR_FEET, "armor_feet") - .put(EnchantmentTarget.ARMOR_LEGS, "armor_legs") - .put(EnchantmentTarget.ARMOR_CHEST, "armor_chest") - .put(EnchantmentTarget.ARMOR_HEAD, "armor_head") - .put(EnchantmentTarget.WEAPON, "weapon") - .put(EnchantmentTarget.DIGGER, "digger") - .put(EnchantmentTarget.FISHING_ROD, "fishing_rod") - .put(EnchantmentTarget.TRIDENT, "trident") - .put(EnchantmentTarget.BREAKABLE, "breakable") - .put(EnchantmentTarget.BOW, "bow") - .put(EnchantmentTarget.WEARABLE, "wearable") - .put(EnchantmentTarget.CROSSBOW, "crossbow") - .put(EnchantmentTarget.VANISHABLE, "vanishable") - .build(); - public static String getEnchantmentTargetName(EnchantmentTarget target) { - return ENCHANTMENT_TARGET_NAMES.getOrDefault(target, target.name().toLowerCase(Locale.ROOT)); + return 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 diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index 37d4fb1b..94a0ca61 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -2,7 +2,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.EntityTypeAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -20,7 +19,6 @@ import net.minecraft.util.Identifier; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getKey(entityType).orElseThrow().getValue(); @@ -48,11 +46,8 @@ public static JsonObject generateEntity(Registry> entityRegistry, } private static String getCategoryFrom(EntityType entityType) { - if (entityType == EntityType.PLAYER) return "UNKNOWN"; // fail early for player entities - /*public T create(World world) { - return this.factory.create(this, world); - }*/ - Entity entity = ((EntityTypeAccessor) entityType).factory().create(entityType, DGU.getWorld()); + if (entityType == EntityType.PLAYER) return "UNKNOWN"; + Entity entity = entityType.create(DGU.getWorld()); if (entity == null) throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); entity.discard(); diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index a5b164f1..97a73639 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -12,7 +12,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(Registry registry, Item foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = registry.getKey(foodItem).orElseThrow().getValue(); diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java index 9a5fac15..674dd22a 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.gson.JsonElement; @@ -41,7 +40,7 @@ private static String makeMaterialNameForTag(TagKey tag) { } private static void createCompositeMaterialInfo(List allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); List mappedMaterials = combinedMaterials.stream() .map(otherName -> allMaterials.stream() @@ -53,13 +52,13 @@ private static void createCompositeMaterialInfo(List allMaterials, mappedMaterials.stream().allMatch(it -> it.getPredicate().test(blockState)); MaterialInfo materialInfo = new MaterialInfo(compositeMaterialName, compositePredicate).includes(mappedMaterials); - allMaterials.add(0, materialInfo); + allMaterials.addFirst(materialInfo); } private static void createCompositeMaterial(Map> allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); - Map resultingToolSpeeds = new HashMap<>(); + Map resultingToolSpeeds = new LinkedHashMap<>(); combinedMaterials.stream() .map(allMaterials::get) .forEach(resultingToolSpeeds::putAll); @@ -108,14 +107,14 @@ public String getDataName() { public JsonElement generateDataJson() { Registry itemRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.ITEM); - Map> materialMiningSpeeds = new HashMap<>(); + Map> materialMiningSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put("default", ImmutableMap.of()); //Special materials used for shears and swords special mining speed logic - Map leavesMaterialSpeeds = new HashMap<>(); - Map cowebMaterialSpeeds = new HashMap<>(); - Map plantMaterialSpeeds = new HashMap<>(); - Map gourdMaterialSpeeds = new HashMap<>(); + Map leavesMaterialSpeeds = new LinkedHashMap<>(); + Map cowebMaterialSpeeds = new LinkedHashMap<>(); + Map plantMaterialSpeeds = new LinkedHashMap<>(); + Map gourdMaterialSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put(makeMaterialNameForTag(BlockTags.LEAVES), leavesMaterialSpeeds); materialMiningSpeeds.put("coweb", cowebMaterialSpeeds); @@ -134,7 +133,7 @@ public JsonElement generateDataJson() { TagKey effectiveBlocks = ((MiningToolItemAccessor) toolItem).getEffectiveBlocks(); String materialName = makeMaterialNameForTag(effectiveBlocks); - Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new HashMap<>()); + Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>()); float miningSpeed = ((MiningToolItemAccessor) toolItem).getMiningSpeed(); materialSpeeds.put(item, miningSpeed); } diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index e446a50b..bc5a9acc 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -9,7 +9,6 @@ import net.minecraft.util.Identifier; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(particleType).orElseThrow().getValue(); diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java index ea489d11..6133772d 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -7,7 +7,10 @@ import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.item.Item; -import net.minecraft.recipe.*; +import net.minecraft.recipe.Ingredient; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.ShapedRecipe; +import net.minecraft.recipe.ShapelessRecipe; import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.RegistryKeys; @@ -31,8 +34,7 @@ public JsonElement generateDataJson() { DynamicRegistryManager registryManager = DGU.getWorld().getRegistryManager(); JsonObject finalObj = new JsonObject(); Multimap recipes = ArrayListMultimap.create(); - for (RecipeEntry recipeE : Objects.requireNonNull(DGU.getWorld()).getRecipeManager().values()) { - Recipe recipe = recipeE.value(); + for (Recipe recipe : Objects.requireNonNull(DGU.getWorld()).getRecipeManager().values()) { if (recipe instanceof ShapedRecipe sr) { var ingredients = sr.getIngredients(); List ingr = new ArrayList<>(); @@ -67,11 +69,11 @@ public JsonElement generateDataJson() { finalRecipe.add("inShape", inShape); var resultObject = new JsonObject(); - resultObject.addProperty("id", getRawIdFor(sr.getResult(registryManager).getItem())); - resultObject.addProperty("count", sr.getResult(registryManager).getCount()); + resultObject.addProperty("id", getRawIdFor(sr.getOutput(registryManager).getItem())); + resultObject.addProperty("count", sr.getOutput(registryManager).getCount()); finalRecipe.add("result", resultObject); - String id = ((Integer) getRawIdFor(sr.getResult(registryManager).getItem())).toString(); + String id = ((Integer) getRawIdFor(sr.getOutput(registryManager).getItem())).toString(); if (!finalObj.has(id)) { finalObj.add(id, new JsonArray()); @@ -111,10 +113,10 @@ public JsonElement generateDataJson() { var rootRecipeObject = new JsonObject(); rootRecipeObject.add("ingredients", ingredients); var resultObject = new JsonObject(); - resultObject.addProperty("id", getRawIdFor(sl.getResult(registryManager).getItem())); - resultObject.addProperty("count", sl.getResult(registryManager).getCount()); + resultObject.addProperty("id", getRawIdFor(sl.getOutput(registryManager).getItem())); + resultObject.addProperty("count", sl.getOutput(registryManager).getCount()); rootRecipeObject.add("result", resultObject); - recipes.put(getRawIdFor(sl.getResult(registryManager).getItem()), rootRecipeObject); + recipes.put(getRawIdFor(sl.getOutput(registryManager).getItem()), rootRecipeObject); } } recipes.forEach((a, b) -> { diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index 77e54d45..e3906559 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -2,17 +2,14 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.util.DGU; -import net.minecraft.registry.Registry; -import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.Registries; import net.minecraft.sound.SoundEvent; public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(Registry registry, SoundEvent soundEvent) { + public static JsonObject generateSound(SoundEvent soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", registry.getRawId(soundEvent)+1); // the plus 1 is required for 1.19.2+ due to Mojang using 0 in the packet to say that you should read a string id instead. + soundDesc.addProperty("id", Registries.SOUND_EVENT.getRawId(soundEvent) + 1); // the plus 1 is required for 1.19.2+ due to Mojang using 0 in the packet to say that you should read a string id instead. soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; @@ -26,8 +23,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - Registry soundEventRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.SOUND_EVENT); - soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, sound))); + Registries.SOUND_EVENT.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 1f4f96b0..5c21246b 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -2,12 +2,12 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mojangannoyances.BlockColors; import dev.u9g.minecraftdatagenerator.util.DGU; import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.RedstoneWireBlock; +import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.world.FoliageColors; import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.Registry; @@ -16,13 +16,9 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.biome.Biome; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class TintsDataGenerator implements IDataGenerator { - public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { BiomeTintColors colors = new BiomeTintColors(); @@ -39,7 +35,7 @@ public static BiomeTintColors generateBiomeTintColors(Registry biomeRegis } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { int color = RedstoneWireBlock.getWireColor(redstoneLevel); @@ -48,24 +44,23 @@ public static Map generateRedstoneTintColors() { return resultColors; } - private static int getBlockColor(Block block, BlockColors blockColors) { - return blockColors.getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); + private static int getBlockColor(Block block) { + return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); } public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors)); - 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.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors)); + resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); return resultColors; } @@ -156,8 +151,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java deleted file mode 100644 index 3e62bf59..00000000 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/EntityTypeAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(EntityType.class) -public interface EntityTypeAccessor { - @Accessor("factory") - EntityType.EntityFactory factory(); -} diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index ba3b26b4..c904c153 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.MinecraftVersion; import net.minecraft.server.dedicated.MinecraftDedicatedServer; @@ -10,18 +9,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.nio.file.Path; - @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = MinecraftVersion.CURRENT.getName(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + MinecraftVersion.CURRENT.getName(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java deleted file mode 100644 index dc35e0b3..00000000 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java +++ /dev/null @@ -1,29 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.fabricmc.fabric.impl.biome.TheEndBiomeData; -import net.fabricmc.fabric.impl.biome.WeightedPicker; -import net.minecraft.registry.RegistryKey; -import net.minecraft.world.biome.Biome; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; - - -@Mixin(TheEndBiomeData.class) -public interface TheEndBiomeDataAccessor { - @Accessor(value = "END_BIOMES_MAP", remap = false) - static Map, WeightedPicker>> END_BIOMES_MAP() { - throw new IllegalStateException("Should never be called."); - } - - @Accessor(value = "END_MIDLANDS_MAP", remap = false) - static Map, WeightedPicker>> END_MIDLANDS_MAP() { - throw new IllegalStateException("Should never be called."); - } - - @Accessor(value = "END_BARRENS_MAP", remap = false) - static Map, WeightedPicker>> END_BARRENS_MAP() { - throw new IllegalStateException("Should never be called."); - } -} diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java deleted file mode 100644 index d374b11a..00000000 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BiomeColors.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.ColorResolver; - -@Environment(EnvType.CLIENT) -public class BiomeColors { - public static final ColorResolver GRASS_COLOR = Biome::getGrassColorAt; - public static final ColorResolver FOLIAGE_COLOR = (biome, x, z) -> biome.getFoliageColor(); - public static final ColorResolver WATER_COLOR = (biome, x, z) -> biome.getWaterColor(); - - public BiomeColors() { - } - - private static int getColor(BlockRenderView world, BlockPos pos, ColorResolver resolver) { - return world.getColor(pos, resolver); - } - - public static int getGrassColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, GRASS_COLOR); - } - - public static int getFoliageColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, FOLIAGE_COLOR); - } - - public static int getWaterColor(BlockRenderView world, BlockPos pos) { - return getColor(world, pos, WATER_COLOR); - } -} - diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java deleted file mode 100644 index ac5dc572..00000000 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColorProvider.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import org.jetbrains.annotations.Nullable; - -public interface BlockColorProvider { - int getColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex); -} - diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java deleted file mode 100644 index a0a3bdf8..00000000 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/mojangannoyances/BlockColors.java +++ /dev/null @@ -1,94 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mojangannoyances; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import dev.u9g.minecraftdatagenerator.util.DGU; -import net.minecraft.block.*; -import net.minecraft.block.enums.DoubleBlockHalf; -import net.minecraft.client.color.world.FoliageColors; -import net.minecraft.client.color.world.GrassColors; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.state.property.Property; -import net.minecraft.util.collection.IdList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; -import java.util.Set; - -public class BlockColors { - private static final int NO_COLOR = -1; - private final IdList providers = new IdList<>(32); - private final Map>> properties = Maps.newHashMap(); - - public BlockColors() { - } - - public static BlockColors create() { - BlockColors blockColors = new BlockColors(); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, state.get(TallPlantBlock.HALF) == DoubleBlockHalf.UPPER ? pos.down() : pos) : -1, Blocks.LARGE_FERN, Blocks.TALL_GRASS); - blockColors.registerColorProperty(TallPlantBlock.HALF, Blocks.LARGE_FERN, Blocks.TALL_GRASS); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : GrassColors.getColor(0.5, 1.0), Blocks.GRASS_BLOCK, Blocks.FERN, Blocks.GRASS, Blocks.POTTED_FERN); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> FoliageColors.getSpruceColor(), Blocks.SPRUCE_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> FoliageColors.getBirchColor(), Blocks.BIRCH_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getFoliageColor(world, pos) : FoliageColors.getDefaultColor(), Blocks.OAK_LEAVES, Blocks.JUNGLE_LEAVES, Blocks.ACACIA_LEAVES, Blocks.DARK_OAK_LEAVES, Blocks.VINE, Blocks.MANGROVE_LEAVES); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getWaterColor(world, pos) : -1, Blocks.WATER, Blocks.BUBBLE_COLUMN, Blocks.WATER_CAULDRON); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> RedstoneWireBlock.getWireColor(state.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE); - blockColors.registerColorProperty(RedstoneWireBlock.POWER, Blocks.REDSTONE_WIRE); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : -1, Blocks.SUGAR_CANE); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> 14731036, Blocks.ATTACHED_MELON_STEM, Blocks.ATTACHED_PUMPKIN_STEM); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> { - int i = state.get(StemBlock.AGE); - int j = i * 32; - int k = 255 - i * 8; - int l = i * 4; - return j << 16 | k << 8 | l; - }, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.registerColorProperty(StemBlock.AGE, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? 2129968 : 7455580, Blocks.LILY_PAD); - return blockColors; - } - - public int getParticleColor(BlockState state, World world, BlockPos pos) { - BlockColorProvider blockColorProvider = this.providers.get(DGU.getWorld().getRegistryManager().get(RegistryKeys.BLOCK).getRawId(state.getBlock())); - if (blockColorProvider != null) { - return blockColorProvider.getColor(state, null, null, 0); - } else { - MapColor mapColor = state.getMapColor(world, pos); - return mapColor != null ? mapColor.color : -1; - } - } - - public int getColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex) { - BlockColorProvider blockColorProvider = this.providers.get(DGU.getWorld().getRegistryManager().get(RegistryKeys.BLOCK).getRawId(state.getBlock())); - return blockColorProvider == null ? -1 : blockColorProvider.getColor(state, world, pos, tintIndex); - } - - public void registerColorProvider(BlockColorProvider provider, Block... blocks) { - int var4 = blocks.length; - - for (Block block : blocks) { - this.providers.set(provider, DGU.getWorld().getRegistryManager().get(RegistryKeys.BLOCK).getRawId(block)); - } - - } - - private void registerColorProperties(Set> properties, Block... blocks) { - int var4 = blocks.length; - - for (Block block : blocks) { - this.properties.put(block, properties); - } - - } - - private void registerColorProperty(Property property, Block... blocks) { - this.registerColorProperties(ImmutableSet.of(property), blocks); - } - - public Set> getProperties(Block block) { - return this.properties.getOrDefault(block, ImmutableSet.of()); - } -} diff --git a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index 32c2fb65..3946c1fe 100644 --- a/1.20/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.20/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -6,24 +6,13 @@ import net.minecraft.world.World; public class DGU { - - private static final Language language = Language.getInstance(); - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - return getCurrentlyRunningServerDedicated(); - } - - private static String translateTextFallback(String translationKey) { - return language.get(translationKey); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } public static String translateText(String translationKey) { - return translateTextFallback(translationKey); + return Language.getInstance().get(translationKey); } public static World getWorld() { diff --git a/1.20/src/main/resources/fabric.mod.json b/1.20/src/main/resources/fabric.mod.json index c999d2a8..ffac96b0 100644 --- a/1.20/src/main/resources/fabric.mod.json +++ b/1.20/src/main/resources/fabric.mod.json @@ -10,18 +10,11 @@ ], "contact": {}, "license": "MIT", - "environment": "server", - "entrypoints": { - "main": [ - "dev.u9g.minecraftdatagenerator.Main" - ] - }, "mixins": [ "minecraft-data-generator.mixins.json" ], "depends": { - "fabricloader": ">=0.14.4", - "fabric": "*", + "fabricloader": "*", "minecraft": "*" } } diff --git a/1.20/src/main/resources/minecraft-data-generator.mixins.json b/1.20/src/main/resources/minecraft-data-generator.mixins.json index f3afe061..d46bf65f 100644 --- a/1.20/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.20/src/main/resources/minecraft-data-generator.mixins.json @@ -4,11 +4,9 @@ "package": "dev.u9g.minecraftdatagenerator.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "EntityTypeAccessor", "EULAMixin", "MiningToolItemAccessor", - "ReadyMixin", - "TheEndBiomeDataAccessor" + "ReadyMixin" ], "client": [ ], diff --git a/1.7/build.gradle b/1.7/build.gradle index 224e88a1..1fe04909 100644 --- a/1.7/build.gradle +++ b/1.7/build.gradle @@ -1,54 +1,33 @@ -plugins { - id 'fabric-loom' -} +import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider -repositories { - maven { - name = "u9g" - url = "https://maven.u9g.dev" - } +plugins { + id 'xyz.wagyourtail.unimined' } -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}") +unimined.minecraft { + version "1.7" - // Required by 1.7.x - runs { - client { - programArgs "--userProperties", "{}" - } - } -} + mappings { + legacyIntermediary() + legacyYarn(514) -dependencies { - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + devFallbackNamespace "intermediary" + } - // 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" -// } + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } - 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' + customPatcher(new CustomLegacyFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() } + + defaultRemapJar = true } -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' - } - } +dependencies { + implementation project(":common") } processResources { @@ -59,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.7/gradle.properties b/1.7/gradle.properties deleted file mode 100644 index 8212c17c..00000000 --- a/1.7/gradle.properties +++ /dev/null @@ -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/ diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index d23c5ba2..00000000 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -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() { - } -} diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeBlockColors.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeBlockColors.java deleted file mode 100644 index c032c331..00000000 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeBlockColors.java +++ /dev/null @@ -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; - } -} diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java deleted file mode 100644 index b5538a62..00000000 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java +++ /dev/null @@ -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); - } -} - diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java deleted file mode 100644 index 0ca9862a..00000000 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java +++ /dev/null @@ -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); - } -} - - - diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java deleted file mode 100644 index 75c9f89c..00000000 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java +++ /dev/null @@ -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; - } -} diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index b2d77af7..5ba2fbd2 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -93,7 +93,7 @@ public Object addShapesFrom(Block block) { // } // } // 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 JsonObject toJSON() { private record Shapes(List 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); + } } } diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index feaed25b..c42ab27c 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -2,7 +2,6 @@ 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 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 getItemsEffectiveForBlock(Block block) { List items = new ArrayList<>(); for (Item item : Registries.ITEMS) { @@ -49,7 +44,7 @@ public static JsonObject generateBlock(Block block) { 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 static JsonObject generateBlock(Block block) { } 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"; diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index c2ac739c..00000000 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -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 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; - } -} diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 66f54d2f..cc622676 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -11,7 +11,6 @@ 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)); diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index ebfcf936..166b12f1 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -20,7 +20,6 @@ import java.util.Objects; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Class entityClass) { JsonObject entityDesc = new JsonObject(); String registryKey = Registries.ENTITY_TYPES.getId(entityClass); @@ -31,7 +30,7 @@ public static JsonObject generateEntity(Class entityClass) { 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); } diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index b93cec8f..695238b7 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -10,7 +10,6 @@ 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); diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java index 1054ac87..e028b7b9 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java @@ -4,7 +4,7 @@ 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; diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java index 32498dfa..f80891e9 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -112,6 +112,12 @@ public JsonElement generateDataJson() { // 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); diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 414749bb..fc1385c9 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -3,32 +3,27 @@ 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 Biome getBiome(int x, int z) { return colors; } - private static int getBlockColor(Block block) { - return BiomeBlockColors.getBlockColor(block, EmptyBlockView.INSTANCE.getBiome(0, 0), 0); - } - public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); + Map 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 JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/BlocksMixin.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/BlocksMixin.java deleted file mode 100644 index 5a032e42..00000000 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/BlocksMixin.java +++ /dev/null @@ -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 = "", at = @At("HEAD")) - private static void doBlocksStaticCtor(CallbackInfo ci) { -// Block.setup(); - } -} diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index 7ea7dcbf..d70a0299 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -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.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 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() + ); } } diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/ItemEntityOverwrite.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/ItemEntityOverwrite.java index 4aa5ec67..e2f9a197 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/ItemEntityOverwrite.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/ItemEntityOverwrite.java @@ -18,7 +18,7 @@ public ItemEntityOverwrite(World world) { * @reason a */ @Overwrite - public String getTranslatedName() { - return super.getTranslatedName(); + public String getTranslationKey() { + return super.getTranslationKey(); } } diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index 9f1bf0b7..eff78862 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -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 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); + return Registries.LANGUAGE.translate(translationKey); } @NotNull diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyBlockView.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyBlockView.java deleted file mode 100644 index 6439917b..00000000 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/EmptyBlockView.java +++ /dev/null @@ -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; - } -} diff --git a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java index d345d91e..976e8d11 100644 --- a/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java +++ b/1.7/src/main/java/dev/u9g/minecraftdatagenerator/util/Registries.java @@ -20,13 +20,23 @@ import java.util.Map; public class Registries { - public static Language LANGUAGE; - public static RegistryView BIOMES; - public static RegistryView BLOCKS; - public static RegistryView ITEMS; - public static RegistryView STATUS_EFFECTS; - public static RegistryView ENCHANTMENTS; - public static RegistryView> ENTITY_TYPES; + public static final Language LANGUAGE; + public static final RegistryView BIOMES; + public static final RegistryView BLOCKS; + public static final RegistryView ITEMS; + public static final RegistryView STATUS_EFFECTS; + public static final RegistryView ENCHANTMENTS; + public static final RegistryView> ENTITY_TYPES; + + static { + LANGUAGE = new Language(); + BIOMES = setupBiomeRegistry(); + BLOCKS = new RegistryBackedRegistryView<>(Block.REGISTRY); + ITEMS = new RegistryBackedRegistryView<>(Item.REGISTRY); + STATUS_EFFECTS = setupStatusEffectRegistry(); + ENCHANTMENTS = setupEnchantmentRegistry(); + ENTITY_TYPES = setupEntityTypesRegistry(); + } private static RegistryView> setupEntityTypesRegistry() { TableBackedRegistryView.Builder> registry = new TableBackedRegistryView.Builder<>(); @@ -68,14 +78,4 @@ private static RegistryView setupStatusEffectRegistry() { } 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(); - } } diff --git a/1.7/src/main/resources/fabric.mod.json b/1.7/src/main/resources/fabric.mod.json index 2e49539c..ffac96b0 100644 --- a/1.7/src/main/resources/fabric.mod.json +++ b/1.7/src/main/resources/fabric.mod.json @@ -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": "*" } } diff --git a/1.7/src/main/resources/minecraft-data-generator.mixins.json b/1.7/src/main/resources/minecraft-data-generator.mixins.json index 804329be..f4b1236d 100644 --- a/1.7/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.7/src/main/resources/minecraft-data-generator.mixins.json @@ -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 } diff --git a/1.8.9/build.gradle b/1.8.9/build.gradle index 057916c6..5b8c0832 100644 --- a/1.8.9/build.gradle +++ b/1.8.9/build.gradle @@ -1,47 +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 = "legacy-fabric" - url = "https://maven.legacyfabric.net" +unimined.minecraft { + version "1.8.9" + + mappings { + legacyIntermediary() + legacyYarn(541) + + devFallbackNamespace "intermediary" } -} -loom { - setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar'); - customMinecraftManifest.set("https://meta.legacyfabric.net/v2/manifest/${minecraft_version}") -} + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } -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' + customPatcher(new CustomLegacyFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() } + + defaultRemapJar = true } -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' - } - } +dependencies { + implementation project(":common") } processResources { @@ -52,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.8.9/gradle.properties b/1.8.9/gradle.properties deleted file mode 100644 index 7cbf4cd4..00000000 --- a/1.8.9/gradle.properties +++ /dev/null @@ -1,7 +0,0 @@ -# Fabric Properties -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ -minecraft_version=1.8.9 -yarn_mappings=1.8.9+build.202206020145 -loader_version=0.14.3 -# Dependencies -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index d23c5ba2..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -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() { - } -} diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeBlockColors.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeBlockColors.java deleted file mode 100644 index ee0d2201..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeBlockColors.java +++ /dev/null @@ -1,81 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; -import net.minecraft.block.*; -import net.minecraft.client.color.world.BiomeColors; -import net.minecraft.client.color.world.FoliageColors; -import net.minecraft.util.math.BlockPos; - -import static net.minecraft.block.RedstoneWireBlock.POWER; - -public class BiomeBlockColors { - // generated manually from each Biome's Biome#getBlockColor - public static int getBlockColor(Block block, BlockState state) { - if (block instanceof AbstractFluidBlock) { - return BiomeColors.getWaterColor(EmptyBlockView.INSTANCE, BlockPos.ORIGIN); - } else if (block instanceof AttachedStemBlock) { - return getAttachedStemColor(state, block); - } else if (block instanceof DoublePlantBlock) { - EmptyBlockView bv = new EmptyBlockView() { - @Override - public BlockState getBlockState(BlockPos pos) { - return state; - } - }; - DoublePlantBlock.DoublePlantType doublePlantType = ((DoublePlantBlock) block).getVariant(bv, BlockPos.ORIGIN); - if (doublePlantType == DoublePlantBlock.DoublePlantType.GRASS || doublePlantType == DoublePlantBlock.DoublePlantType.FERN) { - return BiomeColors.getGrassColor(bv, BlockPos.ORIGIN); - } - } else if (block instanceof FlowerPotBlock) { - // FIXME: Yeah, flower pot block's color depends on the block inside of it, since we dont compute that, let's just not do anything -// Item item; -// BlockEntity blockEntity = view.getBlockEntity(pos); -// if (blockEntity instanceof FlowerPotBlockEntity && (item = ((FlowerPotBlockEntity)blockEntity).getItem()) instanceof BlockItem) { -// return Block.getBlockFromItem(item).getBlockColor(view, pos, id); -// } - } else if (block instanceof GrassBlock) { - return BiomeColors.getGrassColor(EmptyBlockView.INSTANCE, BlockPos.ORIGIN); - } else if (block instanceof Leaves1Block) { - return getLeaves1Color(state, block); - } else if (block instanceof LeavesBlock) { - return getLeavesColor(); - } else if (block instanceof RedstoneWireBlock) { - if (state.getBlock() == block) { - return ServerSideRedstoneWireBlock.getWireColor(state.get(POWER)); - } - } else if (block instanceof SugarCaneBlock || block instanceof TallPlantBlock) { - return GrassColors.getGrassColor(EmptyBlockView.INSTANCE.getBiome(BlockPos.ORIGIN)); - } else if (block instanceof VineBlock) { - return dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors.getFoliageColor(EmptyBlockView.INSTANCE.getBiome(BlockPos.ORIGIN)); - } - return 0xFFFFFF; - } - - private static int getLeaves1Color(BlockState blockState, Block block) { - if (blockState.getBlock() == block) { - PlanksBlock.WoodType woodType = blockState.get(Leaves1Block.VARIANT); - if (woodType == PlanksBlock.WoodType.SPRUCE) { - return net.minecraft.client.color.world.FoliageColors.getSpruceColor(); - } - if (woodType == PlanksBlock.WoodType.BIRCH) { - return FoliageColors.getBirchColor(); - } - } - return getLeavesColor(); - } - - private static int getLeavesColor() { - return FoliageColors.getColor(0.5, 1.0); - } - - private static int getAttachedStemColor(BlockState state, Block block) { - if (state.getBlock() != block) { - return 0xFFFFFF; - } - int i = state.get(AttachedStemBlock.AGE); - int j = i * 32; - int k = 255 - i * 8; - int l = i * 4; - return j << 16 | k << 8 | l; - } -} diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java deleted file mode 100644 index fca5440a..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java +++ /dev/null @@ -1,46 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import net.minecraft.world.biome.Biome; - -import java.util.Iterator; - -public class BiomeColors { - private static final ColorProvider GRASS_COLOR = Biome::getGrassColor; - private static final ColorProvider FOLIAGE_COLOR = Biome::getFoliageColor; - private static final ColorProvider WATER_COLOR = (biome, pos) -> biome.waterColor; - - private static int getColor(BlockView view, BlockPos pos, ColorProvider provider) { - int i = 0; - int j = 0; - int k = 0; - - int l; - for (Iterator iterator = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); iterator.hasNext(); k += l & 255) { - BlockPos.Mutable mutable = (BlockPos.Mutable) iterator.next(); - l = provider.getColorAtPos(view.getBiome(mutable), mutable); - i += (l & 16711680) >> 16; - j += (l & '\uff00') >> 8; - } - - return (i / 9 & 255) << 16 | (j / 9 & 255) << 8 | k / 9 & 255; - } - - public static int getGrassColor(BlockView view, BlockPos pos) { - return getColor(view, pos, GRASS_COLOR); - } - - public static int getFoliageColor(BlockView view, BlockPos pos) { - return getColor(view, pos, FOLIAGE_COLOR); - } - - public static int getWaterColor(BlockView view, BlockPos pos) { - return getColor(view, pos, WATER_COLOR); - } - - interface ColorProvider { - int getColorAtPos(Biome biome, BlockPos pos); - } -} - diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java deleted file mode 100644 index 1a55df05..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java +++ /dev/null @@ -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 getFoliageColor(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); - } -} - diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java deleted file mode 100644 index ff015f9a..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java +++ /dev/null @@ -1,29 +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) { - humidity *= temperature; - int i = (int) ((1.0D - temperature) * 255.0D); - int j = (int) ((1.0D - humidity) * 255.0D); - int k = j << 8 | i; - return k > colorMap.length ? -65281 : colorMap[k]; - } - - 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); - } -} - - - diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java deleted file mode 100644 index 75c9f89c..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java +++ /dev/null @@ -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; - } -} diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 675e449f..24ce0d6f 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -5,7 +5,6 @@ import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor; import dev.u9g.minecraftdatagenerator.util.Registries; import net.minecraft.world.biome.*; -import org.apache.commons.lang3.StringUtils; import java.util.Locale; @@ -20,91 +19,6 @@ private static String guessBiomeDimensionFromCategory(Biome biome) { return "overworld"; } - private static int getBiomeColorFor(String biomeDisplayNamed) { - if (biomeDisplayNamed.equals("Redwood Taiga Hills M")) { - biomeDisplayNamed = "MegaTaigaHills"; - } - String biomeDisplayName = StringUtils.join(biomeDisplayNamed.split(" "), ""); - return switch (biomeDisplayName) { - case "Ocean" -> 112; - case "Plains" -> 9286496; - case "Desert" -> 16421912; - case "ExtremeHills", "Extreme Hills" -> 6316128; - case "Forest" -> 353825; - case "Taiga" -> 747097; - case "Swampland" -> 522674; - case "River" -> 255; - case "Hell" -> 16711680; - case "TheEnd", "The End" -> 8421631; - case "FrozenOcean", "Frozen Ocean" -> 7368918; - case "FrozenRiver", "Frozen River" -> 10526975; - case "IcePlains", "Ice Plains" -> 16777215; - case "IceMountains", "Ice Mountains" -> 10526880; - case "MushroomIsland", "Mushroom Island" -> 16711935; - case "MushroomIslandShore", "Mushroom Island Shore" -> 10486015; - case "Beach" -> 16440917; - case "DesertHills", "Desert Hills" -> 13786898; - case "ForestHills", "Forest Hills" -> 2250012; - case "TaigaHills", "Taiga Hills" -> 1456435; - case "ExtremeHillsEdge", "Extreme Hills Edge" -> 7501978; - case "Jungle" -> 5470985; - case "JungleHills", "Jungle Hills" -> 2900485; - case "JungleEdge", "Jungle Edge" -> 6458135; - case "DeepOcean", "Deep Ocean" -> 48; - case "StoneBeach", "Stone Beach" -> 10658436; - case "ColdBeach", "Cold Beach" -> 16445632; - case "BirchForest", "Birch Forest" -> 3175492; - case "BirchForestHills", "Birch Forest Hills" -> 2055986; - case "RoofedForest", "Roofed Forest" -> 4215066; - case "ColdTaiga", "Cold Taiga" -> 3233098; - case "ColdTaigaHills", "Cold Taiga Hills" -> 2375478; - case "MegaTaiga", "Mega Taiga" -> 5858897; - case "MegaTaigaHills", "Mega Taiga Hills" -> 4542270; - case "ExtremeHills+", "Extreme Hills+" -> 5271632; - case "Savanna" -> 12431967; - case "SavannaPlateau", "Savanna Plateau" -> 10984804; - case "Mesa" -> 14238997; - case "MesaPlateauF", "Mesa Plateau F" -> 11573093; - case "MesaPlateau", "Mesa Plateau" -> 13274213; - case "TheEnd-Floatingislands", "The End - Floating islands" -> 8421631; - case "TheEnd-Mediumisland", "The End - Medium island" -> 8421631; - case "TheEnd-Highisland", "The End - High island" -> 8421631; - case "TheEnd-Barrenisland", "The End - Barren island" -> 8421631; - case "WarmOcean", "Warm Ocean" -> 172; - case "LukewarmOcean", "Lukewarm Ocean" -> 144; - case "ColdOcean", "Cold Ocean" -> 2105456; - case "WarmDeepOcean", "Warm Deep Ocean" -> 80; - case "LukewarmDeepOcean", "Lukewarm Deep Ocean" -> 64; - case "ColdDeepOcean", "Cold Deep Ocean" -> 2105400; - case "FrozenDeepOcean", "Frozen Deep Ocean" -> 4210832; - case "TheVoid", "The Void" -> 0; - case "SunflowerPlains", "Sunflower Plains" -> 11918216; - case "DesertM", "Desert M" -> 16759872; - case "ExtremeHillsM", "Extreme Hills M" -> 8947848; - case "FlowerForest", "Flower Forest" -> 2985545; - case "TaigaM", "Taiga M" -> 3378817; - case "SwamplandM", "Swampland M" -> 3145690; - case "IcePlainsSpikes", "Ice Plains Spikes" -> 11853020; - case "JungleM", "Jungle M" -> 8102705; - case "JungleEdgeM", "Jungle Edge M" -> 9089855; - case "BirchForestM", "Birch Forest M" -> 5807212; - case "BirchForestHillsM", "Birch Forest Hills M" -> 4687706; - case "RoofedForestM", "Roofed Forest M" -> 6846786; - case "ColdTaigaM", "Cold Taiga M" -> 5864818; - case "MegaSpruceTaiga", "Mega Spruce Taiga" -> 8490617; - case "MegaSpruceTaiga(Hills)", "Mega Spruce Taiga (Hills)" -> 7173990; - case "ExtremeHills+M", "Extreme Hills+ M" -> 7903352; - case "SavannaM", "Savanna M" -> 15063687; - case "SavannaPlateauM", "Savanna Plateau M" -> 13616524; - case "Mesa(Bryce)", "Mesa (Bryce)" -> 16739645; - case "MesaPlateauFM", "Mesa Plateau F M" -> 14204813; - case "MesaPlateauM", "Mesa Plateau M" -> 15905933; - case "BambooJungle", "Bamboo Jungle" -> 7769620; - case "BambooJungleHills", "Bamboo Jungle Hills" -> 3884810; - default -> throw new Error("Unexpected biome, with name: '" + biomeDisplayName + "'"); - }; - } - public static JsonObject generateBiomeInfo(Biome biome) { JsonObject biomeDesc = new JsonObject(); // Identifier registryKey = registry.getIdentifier(biome); @@ -117,7 +31,7 @@ public static JsonObject generateBiomeInfo(Biome biome) { biomeDesc.addProperty("depth", biome.depth); biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); biomeDesc.addProperty("displayName", ((BiomeAccessor) biome).name()); - biomeDesc.addProperty("color", getBiomeColorFor(((BiomeAccessor) biome).name())); + biomeDesc.addProperty("color", biome.getSkyColor(biome.temperature)); biomeDesc.addProperty("rainfall", biome.downfall); return biomeDesc; diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 38ec86b6..411a4666 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -79,7 +79,7 @@ public Object addShapesFrom(Block block) { } } 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))); @@ -99,18 +99,18 @@ public JsonObject toJSON() { private record Shapes(List 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); + } } } diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 5431a483..1262f5f5 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -4,7 +4,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import dev.u9g.minecraftdatagenerator.Main; import dev.u9g.minecraftdatagenerator.mixin.BlockAccessor; import dev.u9g.minecraftdatagenerator.mixin.MiningToolItemAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -27,12 +26,8 @@ import java.util.Collection; 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 getItemsEffectiveForBlock(Block block) { List items = new ArrayList<>(); for (Item item : Registries.ITEMS) { diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index 249c6308..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -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 GENERATORS = new ArrayList<>(); - private static final Logger logger = Main.LOGGER; - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - 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; - } -} diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 08524dc0..3dc768f7 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -15,7 +15,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); @NotNull Identifier registryKey = Objects.requireNonNull(Registries.STATUS_EFFECTS.getIdentifier(statusEffect)); diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index e0e9e745..a14483d7 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -21,7 +21,6 @@ import java.util.Objects; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Class entityClass) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass); diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index fd68583a..f2ad50b6 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(FoodItem foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = Registries.ITEMS.getIdentifier(foodItem); diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 2b1a5085..36025a4d 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -5,7 +5,6 @@ import net.minecraft.client.particle.ParticleType; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(int id, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java index 32498dfa..553fbdf6 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -112,6 +112,11 @@ public JsonElement generateDataJson() { // 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); diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 4412712d..cddf868a 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -3,36 +3,30 @@ 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.clientsideannoyances.ServerSideRedstoneWireBlock; import dev.u9g.minecraftdatagenerator.mixin.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.block.RedstoneWireBlock; +import net.minecraft.client.color.world.FoliageColors; +import net.minecraft.client.color.world.GrassColors; import net.minecraft.util.Identifier; -import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.biome.Biome; +import java.lang.reflect.Method; 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(BlockPos pos) { - return biome; - } - }; - int biomeGrassColor = GrassColors.getGrassColor(bv.getBiome(BlockPos.ORIGIN)); - int biomeFoliageColor = FoliageColors.getFoliageColor(bv.getBiome(BlockPos.ORIGIN)); + 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); @@ -43,33 +37,37 @@ public Biome getBiome(BlockPos pos) { } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); - - for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { - int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel); - resultColors.put(redstoneLevel, color); + Map resultColors = new LinkedHashMap<>(); + + RedstoneWireBlock redstoneWireBlock = new RedstoneWireBlock(); + try { + Method colorIntensity = RedstoneWireBlock.class.getDeclaredMethod("getColorIntensity", int.class); + colorIntensity.setAccessible(true); + for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { + int color = (int) colorIntensity.invoke(redstoneWireBlock, redstoneLevel); + resultColors.put(redstoneLevel, color); + } + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); } - return resultColors; - } - private static int getBlockColor(Block block) { - return BiomeBlockColors.getBlockColor(block, block.getDefaultState()); + return resultColors; } public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); // FIXME: ? // resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); // resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + resultColors.put(Blocks.LILY_PAD, 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); + resultColors.put(Blocks.MELON_STEM, Blocks.MELON_STEM.getColor()); + resultColors.put(Blocks.PUMPKIN_STEM, Blocks.PUMPKIN_STEM.getColor()); return resultColors; } @@ -154,8 +152,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index f5608f0a..c1d96581 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.server.dedicated.MinecraftDedicatedServer; import org.spongepowered.asm.mixin.Mixin; @@ -9,19 +8,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -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 cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = DGU.getCurrentlyRunningServer().getVersion(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + DGU.getCurrentlyRunningServer().getVersion(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/CocoaBlockOverwrite.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/CocoaBlockOverwrite.java deleted file mode 100644 index 5158ecd6..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/CocoaBlockOverwrite.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin.overwrite; - -import net.minecraft.block.BlockState; -import net.minecraft.block.CocoaBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Unique; - -@Mixin(CocoaBlock.class) -public class CocoaBlockOverwrite { - @Unique - private static Box collisionBox(BlockState state) { - Direction direction = state.get(CocoaBlock.FACING); - int i = state.get(CocoaBlock.AGE); - int j = 4 + i * 2; - int k = 5 + i * 2; - float f = (float) j / 2.0f; - return switch (direction) { - case SOUTH -> - new Box((8.0f - f) / 16.0f, (12.0f - (float) k) / 16.0f, (15.0f - (float) j) / 16.0f, (8.0f + f) / 16.0f, 0.75f, 0.9375f); - case NORTH -> - new Box((8.0f - f) / 16.0f, (12.0f - (float) k) / 16.0f, 0.0625f, (8.0f + f) / 16.0f, 0.75f, (1.0f + (float) j) / 16.0f); - case WEST -> - new Box(0.0625f, (12.0f - (float) k) / 16.0f, (8.0f - f) / 16.0f, (1.0f + (float) j) / 16.0f, 0.75f, (8.0f + f) / 16.0f); - case EAST -> - new Box((15.0f - (float) j) / 16.0f, (12.0f - (float) k) / 16.0f, (8.0f - f) / 16.0f, 0.9375f, 0.75f, (8.0f + f) / 16.0f); - default -> throw new Error("Should never hit here"); - }; - } - - /** - * @author a - * @reason a - */ - @Overwrite - public Box getCollisionBox(World world, BlockPos pos, BlockState state) { - return collisionBox(state); - } -} diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/EndPortalFrameBlockOverwrite.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/EndPortalFrameBlockOverwrite.java deleted file mode 100644 index f4ac01bf..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/EndPortalFrameBlockOverwrite.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin.overwrite; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.EndPortalFrameBlock; -import net.minecraft.block.Material; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; - -import java.util.List; - -@Mixin(EndPortalFrameBlock.class) -public class EndPortalFrameBlockOverwrite extends Block { - protected EndPortalFrameBlockOverwrite(Material material) { - super(material); - } - - /** - * @author a - * @reason a - */ - @Overwrite() - public void appendCollisionBoxes(World world, BlockPos pos, BlockState state, Box box, List list, Entity entity) { - this.setBoundingBox(0.0F, 0.0F, 0.0F, 1.0F, 0.8125F, 1.0F); - super.appendCollisionBoxes(world, pos, state, box, list, entity); - this.setBoundingBox(0.3125F, 0.8125F, 0.3125F, 0.6875F, 1.0F, 0.6875F); - super.appendCollisionBoxes(world, pos, state, box, list, entity); - this.setBlockItemBounds(); - } -} diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/ItemEntityOverwrite.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/ItemEntityOverwrite.java deleted file mode 100644 index e2f9a197..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/ItemEntityOverwrite.java +++ /dev/null @@ -1,24 +0,0 @@ -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 getTranslationKey() { - return super.getTranslationKey(); - } -} diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/SkeletonSkullBlockOverwrite.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/SkeletonSkullBlockOverwrite.java deleted file mode 100644 index c0e76338..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/SkeletonSkullBlockOverwrite.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin.overwrite; - -import net.minecraft.block.BlockState; -import net.minecraft.block.SkeletonSkullBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -@Mixin(SkeletonSkullBlock.class) -public class SkeletonSkullBlockOverwrite { - @Unique - private static Box boundingBox(BlockState state) { - return switch (state.get(SkeletonSkullBlock.FACING)) { - default -> new Box(0.25f, 0.0f, 0.25f, 0.75f, 0.5f, 0.75f); - case NORTH -> new Box(0.25f, 0.25f, 0.5f, 0.75f, 0.75f, 1.0f); - case SOUTH -> new Box(0.25f, 0.25f, 0.0f, 0.75f, 0.75f, 0.5f); - case WEST -> new Box(0.5f, 0.25f, 0.25f, 1.0f, 0.75f, 0.75f); - case EAST -> new Box(0.0f, 0.25f, 0.25f, 0.5f, 0.75f, 0.75f); - }; - } - - @Unique - public Box getCollisionBox(World world, BlockPos pos, BlockState state) { - return boundingBox(state); - } -} diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/StairBlockOverwrite.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/StairBlockOverwrite.java deleted file mode 100644 index 2da77868..00000000 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/mixin/overwrite/StairBlockOverwrite.java +++ /dev/null @@ -1,153 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin.overwrite; - -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Material; -import net.minecraft.block.StairsBlock; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; -import net.minecraft.util.math.Direction; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; - -import java.util.List; - -import static net.minecraft.block.StairsBlock.HALF; - -@Mixin(StairsBlock.class) -public abstract class StairBlockOverwrite extends Block { - protected StairBlockOverwrite(Material material) { - super(material); - } - - @Shadow - public abstract void setBoundingBox(BlockView view, BlockPos pos); - - @Shadow - public abstract boolean method_8911(BlockView blockView, BlockPos blockPos); - - /** - * @author a - * @reason a - */ - @Overwrite - public void appendCollisionBoxes(World world, BlockPos pos, BlockState state, Box box, List list, Entity entity) { - list.add(someFuncThatIRemade(state)); - super.appendCollisionBoxes(world, pos, state, box, list, entity); - EmptyBlockView bv = new EmptyBlockView() { - @Override - public BlockState getBlockState(BlockPos pos) { - return state; - } - }; - boolean bl = this.method_8911(bv, pos); - list.add(this.getCollisionBox(world, pos, state)); - if (bl && calculateWhichTypeOfStairThisIsButDoesntWorkBecauseWeDontHaveAdjBlocks(state)) { - list.add(this.getCollisionBox(world, pos, state)); - } - this.setBoundingBox(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); - } - - @Unique - public Box someFuncThatIRemade(BlockState state) { - if (state.get(HALF) == StairsBlock.Half.TOP) { - return new Box(0.0f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f); - } else { - return new Box(0.0f, 0.0f, 0.0f, 1.0f, 0.5f, 1.0f); - } - } - - @Unique - public boolean calculateWhichTypeOfStairThisIsButDoesntWorkBecauseWeDontHaveAdjBlocks(BlockState state) { - EmptyBlockView blockView = new EmptyBlockView() { - @Override - public BlockState getBlockState(BlockPos pos) { - return state; - } - }; - BlockState blockState2; - Block block; - BlockState blockState = blockView.getBlockState(BlockPos.ORIGIN); - Direction direction = blockState.get(StairsBlock.FACING); - StairsBlock.Half half = blockState.get(HALF); - boolean bl = half == StairsBlock.Half.TOP; - float f = 0.5f; - float g = 1.0f; - if (bl) { - f = 0.0f; - g = 0.5f; - } - float h = 0.0f; - float i = 0.5f; - float j = 0.5f; - float k = 1.0f; - boolean bl2 = false; - if (direction == Direction.EAST) { - BlockState blockState22 = blockView.getBlockState(BlockPos.ORIGIN); - Block block2 = blockState22.getBlock(); - if (StairsBlock.method_6513(block2) && half == blockState22.get(HALF)) { - Direction direction2 = blockState22.get(StairsBlock.FACING); - if (direction2 == Direction.NORTH && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) { - j = 0.0f; - k = 0.5f; - bl2 = true; - } else if (direction2 == Direction.SOUTH && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) { - j = 0.5f; - k = 1.0f; - bl2 = true; - } - } - } else if (direction == Direction.WEST) { - BlockState blockState23 = blockView.getBlockState(BlockPos.ORIGIN); - Block block3 = blockState23.getBlock(); - if (StairsBlock.method_6513(block3) && half == blockState23.get(HALF)) { - h = 0.5f; - i = 1.0f; - Direction direction2 = blockState23.get(StairsBlock.FACING); - if (direction2 == Direction.NORTH && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) { - j = 0.0f; - k = 0.5f; - bl2 = true; - } else if (direction2 == Direction.SOUTH && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) { - j = 0.5f; - k = 1.0f; - bl2 = true; - } - } - } else if (direction == Direction.SOUTH) { - BlockState blockState24 = blockView.getBlockState(BlockPos.ORIGIN); - Block block4 = blockState24.getBlock(); - if (StairsBlock.method_6513(block4) && half == blockState24.get(HALF)) { - j = 0.0f; - k = 0.5f; - Direction direction2 = blockState24.get(StairsBlock.FACING); - if (direction2 == Direction.WEST && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) { - bl2 = true; - } else if (direction2 == Direction.EAST && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) { - h = 0.5f; - i = 1.0f; - bl2 = true; - } - } - } else if (direction == Direction.NORTH && StairsBlock.method_6513(block = (blockState2 = blockView.getBlockState(BlockPos.ORIGIN)).getBlock()) && half == blockState2.get(HALF)) { - Direction direction2 = blockState2.get(StairsBlock.FACING); - if (direction2 == Direction.WEST && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) { - bl2 = true; - } else if (direction2 == Direction.EAST && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) { - h = 0.5f; - i = 1.0f; - bl2 = true; - } - } - if (bl2) { - this.setBoundingBox(h, f, j, i, g, k); - } - return bl2; - } -} diff --git a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index 5f77e529..eff78862 100644 --- a/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.8.9/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -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; @@ -12,28 +8,11 @@ public class DGU { public static MinecraftServer getCurrentlyRunningServer() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - - @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 ignored) { - } - throw new RuntimeException("Failed to translate: '" + translationKey + "'"); + return MinecraftServer.getServer(); } 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 diff --git a/1.8.9/src/main/resources/fabric.mod.json b/1.8.9/src/main/resources/fabric.mod.json index 96b7e403..ffac96b0 100644 --- a/1.8.9/src/main/resources/fabric.mod.json +++ b/1.8.9/src/main/resources/fabric.mod.json @@ -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.8.9" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/1.8.9/src/main/resources/minecraft-data-generator.mixins.json b/1.8.9/src/main/resources/minecraft-data-generator.mixins.json index 90389267..7bb04498 100644 --- a/1.8.9/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.8.9/src/main/resources/minecraft-data-generator.mixins.json @@ -12,14 +12,7 @@ "MiningToolItemAccessor", "NoteBlockAccessor", "ReadyMixin", - "StatusEffectAccessor", - "overwrite.CocoaBlockOverwrite", - "overwrite.EndPortalFrameBlockOverwrite", - "overwrite.ItemEntityOverwrite", - "overwrite.SkeletonSkullBlockOverwrite", - "overwrite.StairBlockOverwrite" - ], - "client": [ + "StatusEffectAccessor" ], "injectors": { "defaultRequire": 1 diff --git a/1.9.4/build.gradle b/1.9.4/build.gradle index 057916c6..7846c5eb 100644 --- a/1.9.4/build.gradle +++ b/1.9.4/build.gradle @@ -1,47 +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 = "legacy-fabric" - url = "https://maven.legacyfabric.net" +unimined.minecraft { + version "1.9.4" + + mappings { + legacyIntermediary() + legacyYarn(541) + + devFallbackNamespace "intermediary" } -} -loom { - setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar'); - customMinecraftManifest.set("https://meta.legacyfabric.net/v2/manifest/${minecraft_version}") -} + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } -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' + customPatcher(new CustomLegacyFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() } + + defaultRemapJar = true } -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' - } - } +dependencies { + implementation project(":common") } processResources { @@ -52,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/1.9.4/gradle.properties b/1.9.4/gradle.properties deleted file mode 100644 index fc6b90df..00000000 --- a/1.9.4/gradle.properties +++ /dev/null @@ -1,7 +0,0 @@ -# Fabric Properties -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ -minecraft_version=1.9.4 -yarn_mappings=1.9.4+build.202206020145 -loader_version=0.14.3 -# Dependencies -# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/ diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index d23c5ba2..00000000 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -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() { - } -} diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java deleted file mode 100644 index f42641fb..00000000 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BiomeColors.java +++ /dev/null @@ -1,47 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.biome.Biome; - -import java.util.Iterator; - -public class BiomeColors { - private static final ColorProvider GRASS_COLOR = Biome::getGrassColor; - private static final ColorProvider FOLIAGE_COLOR = Biome::getFoliageColor; - private static final ColorProvider WATER_COLOR = (biome, pos) -> biome.getWaterColor(); - - private static int getColor(EmptyBlockView view, BlockPos pos, ColorProvider provider) { - int i = 0; - int j = 0; - int k = 0; - - int l; - for (Iterator iterator = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); iterator.hasNext(); k += l & 255) { - BlockPos.Mutable mutable = (BlockPos.Mutable) iterator.next(); - l = provider.getColorAtPos(view.getBiome(mutable), mutable); - i += (l & 16711680) >> 16; - j += (l & '\uff00') >> 8; - } - - return (i / 9 & 255) << 16 | (j / 9 & 255) << 8 | k / 9 & 255; - } - - public static int getGrassColor(EmptyBlockView view, BlockPos pos) { - return getColor(view, pos, GRASS_COLOR); - } - - public static int getFoliageColor(EmptyBlockView view, BlockPos pos) { - return getColor(view, pos, FOLIAGE_COLOR); - } - - public static int getWaterColor(EmptyBlockView view, BlockPos pos) { - return getColor(view, pos, WATER_COLOR); - } - - interface ColorProvider { - int getColorAtPos(Biome biome, BlockPos pos); - } -} - - diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java deleted file mode 100644 index b6819227..00000000 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColorable.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.Nullable; - -public interface BlockColorable { - int method_12155(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i); -} diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java deleted file mode 100644 index 2bd090ca..00000000 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/BlockColors.java +++ /dev/null @@ -1,96 +0,0 @@ -package dev.u9g.minecraftdatagenerator.clientsideannoyances; - -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; -import net.minecraft.block.*; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.FlowerPotBlockEntity; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.util.collection.IdList; -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.Nullable; - -public class BlockColors { - private final IdList BlockColor2Id = new IdList<>(32); - - public BlockColors() { - } - - public static BlockColors create() { - final BlockColors blockColors = new BlockColors(); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - DoublePlantBlock.DoublePlantType doublePlantType = blockState.get(DoublePlantBlock.VARIANT); - return blockView == null || blockPos == null || doublePlantType != DoublePlantBlock.DoublePlantType.GRASS && doublePlantType != DoublePlantBlock.DoublePlantType.FERN ? -1 : BiomeColors.getGrassColor(blockView, blockPos); - }, Blocks.DOUBLE_PLANT); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - if (blockView != null && blockPos != null) { - BlockEntity blockEntity = blockView.getBlockEntity(blockPos); - if (blockEntity instanceof FlowerPotBlockEntity) { - Item item = ((FlowerPotBlockEntity) blockEntity).getItem(); - if (item instanceof BlockItem) { - BlockState blockState2 = Block.getBlockFromItem(item).getDefaultState(); - return blockColors.method_12157(blockState2, blockView, blockPos, i); - } - } - } - - return -1; - }, Blocks.FLOWER_POT); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : GrassColors.getColor(0.5D, 1.0D), Blocks.GRASS); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - PlanksBlock.WoodType woodType = blockState.get(Leaves1Block.VARIANT); - if (woodType == PlanksBlock.WoodType.SPRUCE) { - return FoliageColors.getSpruceColor(); - } else if (woodType == PlanksBlock.WoodType.BIRCH) { - return FoliageColors.getBirchColor(); - } else { - return blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(); - } - }, Blocks.LEAVES); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.LEAVES2); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getWaterColor(blockView, blockPos) : -1, Blocks.WATER, Blocks.FLOWING_WATER); - blockColors.method_12158((blockState, blockView, blockPos, i) -> RedstoneWireBlock.method_8877(blockState.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : -1, Blocks.SUGARCANE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - int j = blockState.get(AttachedStemBlock.AGE); - int k = j * 32; - int l = 255 - j * 8; - int m = j * 4; - return k << 16 | l << 8 | m; - }, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM); - blockColors.method_12158((blockState, blockView, blockPos, i) -> { - if (blockView != null && blockPos != null) { - return BiomeColors.getGrassColor(blockView, blockPos); - } else { - return blockState.get(TallPlantBlock.TYPE) == TallPlantBlock.GrassType.DEAD_BUSH ? 16777215 : GrassColors.getColor(0.5D, 1.0D); - } - }, Blocks.TALLGRASS); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.VINE); - blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? 2129968 : 7455580, Blocks.LILY_PAD); - return blockColors; - } - - public int method_13410(BlockState blockState) { - BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock())); - if (blockColorable != null) { - return blockColorable.method_12155(blockState, null, null, 0); - } else { - MaterialColor materialColor = blockState.getMaterialColor(); - return materialColor != null ? materialColor.color : -1; - } - } - - public int method_12157(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i) { - BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock())); - return blockColorable == null ? -1 : blockColorable.method_12155(blockState, blockView, blockPos, i); - } - - public void method_12158(BlockColorable blockColorable, Block... blocks) { - int i = blocks.length; - - for (Block block : blocks) { - this.BlockColor2Id.set(blockColorable, Block.getIdByBlock(block)); - } - - } -} diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java deleted file mode 100644 index b63e543b..00000000 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/FoliageColors.java +++ /dev/null @@ -1,37 +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 getFoliageColor(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0F, 1.0F); - double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F); - return FoliageColors.getColor(d, e); - } -} diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java deleted file mode 100644 index afee2b70..00000000 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/GrassColors.java +++ /dev/null @@ -1,29 +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) { - humidity *= temperature; - int i = (int) ((1.0D - temperature) * 255.0D); - int j = (int) ((1.0D - humidity) * 255.0D); - int k = j << 8 | i; - return k > colorMap.length ? -65281 : colorMap[k]; - } - - public static int getGrassColor(Biome biome) { - double d = MathHelper.clamp(biome.getTemperature(), 0.0F, 1.0F); - double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F); - return GrassColors.getColor(d, e); - } -} - - - diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java deleted file mode 100644 index 75c9f89c..00000000 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/clientsideannoyances/ServerSideRedstoneWireBlock.java +++ /dev/null @@ -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; - } -} diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 2bb5a0be..02fd69a6 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -79,7 +79,7 @@ public Object addShapesFrom(Block block) { } } 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))); @@ -99,18 +99,18 @@ public JsonObject toJSON() { private record Shapes(List 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); + } } } diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index dbea9f6e..f61dc62d 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -4,7 +4,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import dev.u9g.minecraftdatagenerator.Main; import dev.u9g.minecraftdatagenerator.mixin.BlockAccessor; import dev.u9g.minecraftdatagenerator.mixin.MiningToolItemAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; @@ -28,12 +27,8 @@ import java.util.Collection; 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 getItemsEffectiveForBlock(Block block) { List items = new ArrayList<>(); for (Item item : Registries.ITEMS) { diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index c89d0777..00000000 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -1,81 +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 GENERATORS = new ArrayList<>(); - private static final Logger logger = Main.LOGGER; - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new AttributesDataGenerator()); - register(new SoundsDataGenerator()); - } - - 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; - } -} diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 6aba51e0..ea880e45 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -16,7 +16,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); @NotNull Identifier registryKey = Objects.requireNonNull(Registries.STATUS_EFFECTS.getIdentifier(statusEffect)); diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index d5ef72ef..2554af41 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -21,7 +21,6 @@ import java.util.Objects; public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Class entityClass) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass); diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index fd68583a..f2ad50b6 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(FoodItem foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = Registries.ITEMS.getIdentifier(foodItem); diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java index 3aa51c41..dcb6c5be 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/InstrumentsDataGenerator.java @@ -4,8 +4,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.mixin.NoteBlockAccessor; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; -import net.minecraft.client.sound.SoundEvent; +import net.minecraft.sound.Sound; import java.util.Objects; @@ -19,10 +18,10 @@ public String getDataName() { public JsonElement generateDataJson() { JsonArray array = new JsonArray(); int i = 0; - for (SoundEvent sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) { + for (Sound sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) { JsonObject object = new JsonObject(); object.addProperty("id", i++); - object.addProperty("name", ((SoundAccessor) sound).id().getPath().split("\\.")[2]); + object.addProperty("name", sound.getId().getPath().split("\\.")[2]); array.add(object); } return array; diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 2b1a5085..36025a4d 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -5,7 +5,6 @@ import net.minecraft.client.particle.ParticleType; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(int id, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java index 32498dfa..553fbdf6 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/RecipeDataGenerator.java @@ -112,6 +112,11 @@ public JsonElement generateDataJson() { // 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); diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index 9429a29a..88e0e8a8 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -2,17 +2,14 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor; -import net.minecraft.client.sound.SoundEvent; - +import net.minecraft.sound.Sound; public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(SoundEvent soundEvent) { + public static JsonObject generateSound(Sound soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", SoundEvent.REGISTRY.getRawId(soundEvent)); - soundDesc.addProperty("name", ((SoundAccessor) soundEvent).id().getPath()); + soundDesc.addProperty("id", Sound.REGISTRY.getRawId(soundEvent)); + soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; } @@ -25,7 +22,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - SoundEvent.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound))); + Sound.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 8d1b2a84..1e193129 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -3,38 +3,32 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.BlockColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.GrassColors; -import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock; import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor; -import dev.u9g.minecraftdatagenerator.util.EmptyBlockView; +import dev.u9g.minecraftdatagenerator.util.DGU; import dev.u9g.minecraftdatagenerator.util.Registries; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.RedstoneWireBlock; +import net.minecraft.client.BlockColors; +import net.minecraft.client.color.world.FoliageColors; +import net.minecraft.client.color.world.GrassColors; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.biome.Biome; import java.util.*; public class TintsDataGenerator implements IDataGenerator { - - private static final BlockColors blockColors = BlockColors.create(); - public static BiomeTintColors generateBiomeTintColors() { BiomeTintColors colors = new BiomeTintColors(); for (Biome biome : Registries.BIOMES) { - EmptyBlockView bv = new EmptyBlockView() { - @Override - public Biome getBiome(BlockPos pos) { - return biome; - } - }; - int biomeGrassColor = GrassColors.getGrassColor(bv.getBiome(BlockPos.ORIGIN)); - int biomeFoliageColor = FoliageColors.getFoliageColor(bv.getBiome(BlockPos.ORIGIN)); + double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f); + double e = MathHelper.clamp(biome.getRainfall(), 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); @@ -45,30 +39,29 @@ public Biome getBiome(BlockPos pos) { } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { - int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel); + int color = RedstoneWireBlock.getColorIntensity(redstoneLevel); resultColors.put(redstoneLevel, color); } return resultColors; } private static int getBlockColor(Block block) { - return blockColors.method_13410(block.getDefaultState()); + return BlockColors.create().method_12157(block.getDefaultState(), DGU.getWorld(), BlockPos.ORIGIN, 0); } public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); // FIXME: ? // resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); // resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); resultColors.put(Blocks.LILY_PAD, 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)); + // 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); @@ -158,8 +151,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java index 4bc3bcb9..688aa1c6 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/NoteBlockAccessor.java @@ -1,7 +1,7 @@ package dev.u9g.minecraftdatagenerator.mixin; import net.minecraft.block.NoteBlock; -import net.minecraft.client.sound.SoundEvent; +import net.minecraft.sound.Sound; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @@ -10,7 +10,7 @@ @Mixin(NoteBlock.class) public interface NoteBlockAccessor { @Accessor("TUNES") - static List TUNES() { + static List TUNES() { return null; } } diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index f5608f0a..c1d96581 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.server.dedicated.MinecraftDedicatedServer; import org.spongepowered.asm.mixin.Mixin; @@ -9,19 +8,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -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 cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = DGU.getCurrentlyRunningServer().getVersion(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + DGU.getCurrentlyRunningServer().getVersion(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java deleted file mode 100644 index fe505910..00000000 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/mixin/SoundAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.minecraft.client.sound.SoundEvent; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(SoundEvent.class) -public interface SoundAccessor { - @Accessor("id") - Identifier id(); -} diff --git a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index 8edd9a23..95094eea 100644 --- a/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/1.9.4/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -1,75 +1,20 @@ package dev.u9g.minecraftdatagenerator.util; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.TypeAdapters; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; -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; -import java.io.IOException; - public class DGU { - -// @Environment(EnvType.CLIENT) -// private static MinecraftServer getCurrentlyRunningServerClient() { -// return MinecraftClient.getInstance().getServer(); -// } -// -// @SuppressWarnings("deprecation") -// private static MinecraftServer getCurrentlyRunningServerDedicated() { -// return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); -// } - - public static Gson gson = new GsonBuilder().registerTypeAdapterFactory(TypeAdapters.newFactory(double.class, Double.class, new TypeAdapter() { - @Override - public Number read(JsonReader in) throws IOException { - if (in.peek() == JsonToken.NULL) { - in.nextNull(); - return null; - } - return in.nextDouble(); - } - - @Override - public void write(JsonWriter out, Number value) throws IOException { - out.value(value); - } - })).create(); - + @SuppressWarnings("deprecation") public static MinecraftServer getCurrentlyRunningServer() { return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } - @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 ignored) { - } - 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 diff --git a/1.9.4/src/main/resources/fabric.mod.json b/1.9.4/src/main/resources/fabric.mod.json index ad1562f2..ffac96b0 100644 --- a/1.9.4/src/main/resources/fabric.mod.json +++ b/1.9.4/src/main/resources/fabric.mod.json @@ -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.9" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/1.9.4/src/main/resources/minecraft-data-generator.mixins.json b/1.9.4/src/main/resources/minecraft-data-generator.mixins.json index 4dd13158..3ed82340 100644 --- a/1.9.4/src/main/resources/minecraft-data-generator.mixins.json +++ b/1.9.4/src/main/resources/minecraft-data-generator.mixins.json @@ -14,11 +14,8 @@ "MiningToolItemAccessor", "NoteBlockAccessor", "ReadyMixin", - "SoundAccessor", "StatusEffectAccessor" ], - "client": [ - ], "injectors": { "defaultRequire": 1 }, diff --git a/22w19a/build.gradle b/22w19a/build.gradle index e85de392..c9d05885 100644 --- a/22w19a/build.gradle +++ b/22w19a/build.gradle @@ -1,15 +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' } -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +unimined.minecraft { + version "22w19a" + + mappings { + intermediary() + yarn(6) + + devFallbackNamespace "intermediary" + } + + runs.config("server") { + javaVersion = JavaVersion.VERSION_21 + } + + customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) { + it.loader libs.versions.fabric.loader.get() + } - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + defaultRemapJar = true +} + +dependencies { + implementation project(":common") } processResources { @@ -20,12 +38,10 @@ processResources { } } -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" +tasks.withType(RemapJarTask).configureEach { + onlyIf { false} } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" } diff --git a/22w19a/gradle.properties b/22w19a/gradle.properties deleted file mode 100644 index d6cfd057..00000000 --- a/22w19a/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=22w19a -yarn_mappings=22w19a+build.1 -loader_version=0.14.5 -# Dependencies -# check this on https://modmuss50.me/fabric.html -fabric_version=0.52.2+1.19 diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/Main.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/Main.java deleted file mode 100644 index f8d17372..00000000 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.u9g.minecraftdatagenerator; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Main implements ModInitializer { - public static final Logger LOGGER = LoggerFactory.getLogger("mc-data-gen-serv"); - - @Override - public void onInitialize() { - - } -} diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java index 1d365498..0dca8c4a 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BiomesDataGenerator.java @@ -2,42 +2,42 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import dev.u9g.minecraftdatagenerator.mixin.TheEndBiomeDataAccessor; import dev.u9g.minecraftdatagenerator.util.DGU; -import net.fabricmc.fabric.api.biome.v1.NetherBiomes; +import net.minecraft.tag.BiomeTags; import net.minecraft.util.Identifier; +import net.minecraft.util.registry.BuiltinRegistries; import net.minecraft.util.registry.DynamicRegistryManager; import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.biome.Biome; public class BiomesDataGenerator implements IDataGenerator { - - private static String guessBiomeDimensionFromCategory(Biome biome) { - // FIND A WAY TO FIND WHAT CATEGORY THE BIOME IS - var key = DynamicRegistryManager.BUILTIN.get().get(Registry.BIOME_KEY).getKey(biome).orElseThrow(); - System.out.println(DynamicRegistryManager.BUILTIN.get().get(Registry.BIOME_KEY).getKey(biome).orElseThrow()); - if (NetherBiomes.canGenerateInNether(key)) { + private static String guessBiomeDimensionFromCategory(RegistryKey biome) { + var biomeRegistry = BuiltinRegistries.BIOME; + if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_NETHER)) { return "nether"; - } else if (TheEndBiomeDataAccessor.END_BARRENS_MAP().containsKey(key) || TheEndBiomeDataAccessor.END_BIOMES_MAP().containsKey(key) || TheEndBiomeDataAccessor.END_MIDLANDS_MAP().containsKey(key)) { + } else if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_END)) { return "end"; + } else { + return "overworld"; } - return "overworld"; } public static JsonObject generateBiomeInfo(Registry registry, Biome biome) { JsonObject biomeDesc = new JsonObject(); - Identifier registryKey = registry.getKey(biome).orElseThrow().getValue(); - String localizationKey = String.format("biome.%s.%s", registryKey.getNamespace(), registryKey.getPath()); + RegistryKey registryKey = registry.getKey(biome).orElseThrow(); + Identifier identifier = registryKey.getValue(); + String localizationKey = String.format("biome.%s.%s", identifier.getNamespace(), identifier.getPath()); biomeDesc.addProperty("id", registry.getRawId(biome)); - biomeDesc.addProperty("name", registryKey.getPath()); + biomeDesc.addProperty("name", identifier.getPath()); //FIXME: this... biomeDesc.addProperty("category", ""); biomeDesc.addProperty("temperature", biome.getTemperature()); biomeDesc.addProperty("precipitation", biome.getPrecipitation().getName()); //biomeDesc.addProperty("depth", biome.getDepth()); - Doesn't exist anymore in minecraft source - biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome)); + biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(registryKey)); biomeDesc.addProperty("displayName", DGU.translateText(localizationKey)); biomeDesc.addProperty("color", biome.getSkyColor()); biomeDesc.addProperty("rainfall", biome.getDownfall()); diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java index 52c3181d..61e1b9e6 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlockCollisionShapesDataGenerator.java @@ -12,10 +12,7 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.EmptyBlockView; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class BlockCollisionShapesDataGenerator implements IDataGenerator { @@ -40,8 +37,8 @@ public JsonObject generateDataJson() { } private static class BlockShapesCache { - public final Map uniqueBlockShapes = new HashMap<>(); - public final Map> blockCollisionShapes = new HashMap<>(); + public final Map uniqueBlockShapes = new LinkedHashMap<>(); + public final Map> blockCollisionShapes = new LinkedHashMap<>(); private int lastCollisionShapeId = 0; public void processBlock(Block block) { @@ -70,7 +67,7 @@ public JsonObject dumpBlockShapeIndices(Registry blockRegistry) { long distinctShapesCount = blockCollisions.stream().distinct().count(); JsonElement blockCollision; if (distinctShapesCount == 1L) { - blockCollision = new JsonPrimitive(blockCollisions.get(0)); + blockCollision = new JsonPrimitive(blockCollisions.getFirst()); } else { blockCollision = new JsonArray(); for (int collisionId : blockCollisions) { diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java index 51139655..121e6c5f 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/BlocksDataGenerator.java @@ -105,7 +105,7 @@ private static String findMatchingBlockMaterial(BlockState blockState, List 1) { - var firstMaterial = matchingMaterials.get(0); + var firstMaterial = matchingMaterials.getFirst(); var otherMaterials = matchingMaterials.subList(1, matchingMaterials.size()); if (!otherMaterials.stream().allMatch(firstMaterial::includesMaterial)) { @@ -115,19 +115,19 @@ private static String findMatchingBlockMaterial(BlockState blockState, List blockRegistry, List materials, Block block) { + public static JsonObject generateBlock(List materials, Block block) { JsonObject blockDesc = new JsonObject(); List blockStates = block.getStateManager().getStates(); BlockState defaultState = block.getDefaultState(); - Identifier registryKey = blockRegistry.getKey(block).orElseThrow().getValue(); + Identifier registryKey = Registry.BLOCK.getKey(block).orElseThrow().getValue(); String localizationKey = block.getTranslationKey(); List effectiveTools = getItemsEffectiveForBlock(defaultState); - blockDesc.addProperty("id", blockRegistry.getRawId(block)); + blockDesc.addProperty("id", Registry.BLOCK.getRawId(block)); blockDesc.addProperty("name", registryKey.getPath()); blockDesc.addProperty("displayName", DGU.translateText(localizationKey)); @@ -148,8 +148,8 @@ public static JsonObject generateBlock(Registry blockRegistry, List property : block.getStateManager().getProperties()) { @@ -167,7 +167,7 @@ public static JsonObject generateBlock(Registry blockRegistry, List actualBlockDrops = new ArrayList<>(); - populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.get(0), actualBlockDrops); + populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.getFirst(), actualBlockDrops); JsonArray dropsArray = new JsonArray(); for (ItemStack dropStack : actualBlockDrops) { @@ -189,10 +189,9 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultBlocksArray = new JsonArray(); - Registry blockRegistry = Registry.BLOCK; List availableMaterials = MaterialsDataGenerator.getGlobalMaterialInfo(); - blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, availableMaterials, block))); + Registry.BLOCK.forEach(block -> resultBlocksArray.add(generateBlock(availableMaterials, block))); return resultBlocksArray; } } diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java deleted file mode 100644 index 1c755d5e..00000000 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java +++ /dev/null @@ -1,78 +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 org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -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.util.ArrayList; -import java.util.List; - -public class DataGenerators { - - private static final Logger logger = LoggerFactory.getLogger(DataGenerators.class); - private static final List GENERATORS = new ArrayList<>(); - - static { - register(new BiomesDataGenerator()); - register(new BlockCollisionShapesDataGenerator()); - register(new BlocksDataGenerator()); - register(new EffectsDataGenerator()); - register(new EnchantmentsDataGenerator()); - register(new EntitiesDataGenerator()); - register(new FoodsDataGenerator()); - register(new ItemsDataGenerator()); - register(new ParticlesDataGenerator()); - register(new TintsDataGenerator()); -// register(new MaterialsDataGenerator()); -// register(new RecipeDataGenerator()); - On hold until mcdata supports multiple materials for a recipe - register(new LanguageDataGenerator()); - register(new InstrumentsDataGenerator()); - register(new SoundsDataGenerator()); - } - - public static void register(IDataGenerator generator) { - GENERATORS.add(generator); - } - - public static boolean runDataGenerators(Path outputDirectory) { - try { - Files.createDirectories(outputDirectory); - } catch (IOException exception) { - logger.error("Failed to create data generator output directory at {}", outputDirectory, exception); - return false; - } - - int generatorsFailed = 0; - logger.info("Running minecraft data generators, output at {}", outputDirectory); - - for (IDataGenerator dataGenerator : GENERATORS) { - logger.info("Running generator {}", 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("Generator: {} -> {}", dataGenerator.getDataName(), outputFileName); - - } catch (Throwable exception) { - logger.error("Failed to run data generator {}", dataGenerator.getDataName(), exception); - generatorsFailed++; - } - } - - logger.info("Finishing running data generators"); - return generatorsFailed == 0; - } -} diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java index 1c9849e6..9b4beb53 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EffectsDataGenerator.java @@ -13,7 +13,6 @@ import java.util.stream.Collectors; public class EffectsDataGenerator implements IDataGenerator { - public static JsonObject generateEffect(Registry registry, StatusEffect statusEffect) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(statusEffect).orElseThrow().getValue(); diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java index e27fb68f..dce173a6 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EnchantmentsDataGenerator.java @@ -11,24 +11,10 @@ import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; public class EnchantmentsDataGenerator implements IDataGenerator { private static final ImmutableMap ENCHANTMENT_TARGET_NAMES = ImmutableMap.builder() - .put(EnchantmentTarget.ARMOR, "armor") - .put(EnchantmentTarget.ARMOR_FEET, "armor_feet") - .put(EnchantmentTarget.ARMOR_LEGS, "armor_legs") - .put(EnchantmentTarget.ARMOR_CHEST, "armor_chest") - .put(EnchantmentTarget.ARMOR_HEAD, "armor_head") - .put(EnchantmentTarget.WEAPON, "weapon") - .put(EnchantmentTarget.DIGGER, "digger") - .put(EnchantmentTarget.FISHING_ROD, "fishing_rod") - .put(EnchantmentTarget.TRIDENT, "trident") - .put(EnchantmentTarget.BREAKABLE, "breakable") - .put(EnchantmentTarget.BOW, "bow") - .put(EnchantmentTarget.WEARABLE, "wearable") - .put(EnchantmentTarget.CROSSBOW, "crossbow") .put(EnchantmentTarget.VANISHABLE, "vanishable") .build(); diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java index c11cb03c..d1973e75 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/EntitiesDataGenerator.java @@ -2,7 +2,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; import dev.u9g.minecraftdatagenerator.util.DGU; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -18,10 +17,7 @@ import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; -import java.lang.reflect.ParameterizedType; - public class EntitiesDataGenerator implements IDataGenerator { - public static JsonObject generateEntity(Registry> entityRegistry, EntityType entityType) { JsonObject entityDesc = new JsonObject(); Identifier registryKey = entityRegistry.getKey(entityType).orElseThrow().getValue(); @@ -50,17 +46,11 @@ public static JsonObject generateEntity(Registry> entityRegistry, private static String getCategoryFrom(EntityType entityType) { if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities - Class entityClazz = null; - try { - for (var field : EntityType.class.getFields()) - if (entityType == field.get(EntityType.class)) - entityClazz = (Class) ((ParameterizedType) TypeToken.get(field.getGenericType()).getType()).getActualTypeArguments()[0]; - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - if (entityClazz == null) throw new RuntimeException("Shouldn't be null..."); - return switch (entityClazz.getPackageName()) { + Entity entity = entityType.create(DGU.getWorld()); + if (entity == null) + throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey())); + entity.discard(); + return switch (entity.getClass().getPackageName()) { case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile"; case "net.minecraft.entity.boss", "net.minecraft.entity.mob", "net.minecraft.entity.boss.dragon" -> "Hostile mobs"; @@ -68,7 +58,7 @@ private static String getCategoryFrom(EntityType entityType) { case "net.minecraft.entity.passive" -> "Passive mobs"; case "net.minecraft.entity.vehicle" -> "Vehicles"; case "net.minecraft.entity" -> "UNKNOWN"; - default -> throw new Error("Unexpected entity type: " + entityClazz.getPackageName()); + default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName()); }; } diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java index 45a0b35f..de659be9 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/FoodsDataGenerator.java @@ -11,7 +11,6 @@ import java.util.Objects; public class FoodsDataGenerator implements IDataGenerator { - public static JsonObject generateFoodDescriptor(Registry registry, Item foodItem) { JsonObject foodDesc = new JsonObject(); Identifier registryKey = registry.getKey(foodItem).orElseThrow().getValue(); diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java deleted file mode 100644 index 81fe4e20..00000000 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.u9g.minecraftdatagenerator.generators; - -import com.google.gson.JsonElement; - -public interface IDataGenerator { - - String getDataName(); - - JsonElement generateDataJson(); -} diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java index 4253ae69..1739de21 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/MaterialsDataGenerator.java @@ -1,6 +1,5 @@ package dev.u9g.minecraftdatagenerator.generators; -import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.gson.JsonElement; @@ -40,7 +39,7 @@ private static String makeMaterialNameForTag(TagKey tag) { } private static void createCompositeMaterialInfo(List allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); List mappedMaterials = combinedMaterials.stream() .map(otherName -> allMaterials.stream() @@ -52,13 +51,13 @@ private static void createCompositeMaterialInfo(List allMaterials, mappedMaterials.stream().allMatch(it -> it.getPredicate().test(blockState)); MaterialInfo materialInfo = new MaterialInfo(compositeMaterialName, compositePredicate).includes(mappedMaterials); - allMaterials.add(0, materialInfo); + allMaterials.addFirst(materialInfo); } private static void createCompositeMaterial(Map> allMaterials, List combinedMaterials) { - String compositeMaterialName = Joiner.on(';').join(combinedMaterials); + String compositeMaterialName = String.join(";", combinedMaterials); - Map resultingToolSpeeds = new HashMap<>(); + Map resultingToolSpeeds = new LinkedHashMap<>(); combinedMaterials.stream() .map(allMaterials::get) .forEach(resultingToolSpeeds::putAll); @@ -105,14 +104,14 @@ public String getDataName() { public JsonElement generateDataJson() { Registry itemRegistry = Registry.ITEM; - Map> materialMiningSpeeds = new HashMap<>(); + Map> materialMiningSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put("default", ImmutableMap.of()); //Special materials used for shears and swords special mining speed logic - Map leavesMaterialSpeeds = new HashMap<>(); - Map cowebMaterialSpeeds = new HashMap<>(); - Map plantMaterialSpeeds = new HashMap<>(); - Map gourdMaterialSpeeds = new HashMap<>(); + Map leavesMaterialSpeeds = new LinkedHashMap<>(); + Map cowebMaterialSpeeds = new LinkedHashMap<>(); + Map plantMaterialSpeeds = new LinkedHashMap<>(); + Map gourdMaterialSpeeds = new LinkedHashMap<>(); materialMiningSpeeds.put(makeMaterialNameForTag(BlockTags.LEAVES), leavesMaterialSpeeds); materialMiningSpeeds.put("coweb", cowebMaterialSpeeds); @@ -131,7 +130,7 @@ public JsonElement generateDataJson() { TagKey effectiveBlocks = ((MiningToolItemAccessor) toolItem).getEffectiveBlocks(); String materialName = makeMaterialNameForTag(effectiveBlocks); - Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new HashMap<>()); + Map materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>()); float miningSpeed = ((MiningToolItemAccessor) toolItem).getMiningSpeed(); materialSpeeds.put(item, miningSpeed); } diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java index 5a6b1081..80cca516 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/ParticlesDataGenerator.java @@ -7,7 +7,6 @@ import net.minecraft.util.registry.Registry; public class ParticlesDataGenerator implements IDataGenerator { - public static JsonObject generateParticleType(Registry> registry, ParticleType particleType) { JsonObject effectDesc = new JsonObject(); Identifier registryKey = registry.getKey(particleType).orElseThrow().getValue(); diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java index edbc9869..585eb218 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/SoundsDataGenerator.java @@ -5,13 +5,11 @@ import net.minecraft.sound.SoundEvent; import net.minecraft.util.registry.Registry; - public class SoundsDataGenerator implements IDataGenerator { - - public static JsonObject generateSound(Registry registry, SoundEvent soundEvent) { + public static JsonObject generateSound(SoundEvent soundEvent) { JsonObject soundDesc = new JsonObject(); - soundDesc.addProperty("id", registry.getRawId(soundEvent)); + soundDesc.addProperty("id", Registry.SOUND_EVENT.getRawId(soundEvent)); soundDesc.addProperty("name", soundEvent.getId().getPath()); return soundDesc; @@ -25,8 +23,7 @@ public String getDataName() { @Override public JsonArray generateDataJson() { JsonArray resultsArray = new JsonArray(); - Registry soundEventRegistry = Registry.SOUND_EVENT; - soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, sound))); + Registry.SOUND_EVENT.forEach(sound -> resultsArray.add(generateSound(sound))); return resultsArray; } } diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java index 283cc437..40da4f4e 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/generators/TintsDataGenerator.java @@ -4,7 +4,6 @@ import com.google.gson.JsonObject; import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView; import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; import net.minecraft.block.Blocks; @@ -20,7 +19,6 @@ import java.util.*; public class TintsDataGenerator implements IDataGenerator { - public static BiomeTintColors generateBiomeTintColors(Registry biomeRegistry) { BiomeTintColors colors = new BiomeTintColors(); @@ -37,7 +35,7 @@ public static BiomeTintColors generateBiomeTintColors(Registry biomeRegis } public static Map generateRedstoneTintColors() { - Map resultColors = new HashMap<>(); + Map resultColors = new LinkedHashMap<>(); for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) { int color = RedstoneWireBlock.getWireColor(redstoneLevel); @@ -46,26 +44,23 @@ public static Map generateRedstoneTintColors() { return resultColors; } - @Environment(EnvType.CLIENT) - private static int getBlockColor(Block block, BlockColors blockColors) { - return blockColors.getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); + private static int getBlockColor(Block block) { + return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF); } - @Environment(EnvType.CLIENT) public static Map generateConstantTintColors() { - Map resultColors = new HashMap<>(); - BlockColors blockColors = BlockColors.create(); + Map resultColors = new LinkedHashMap<>(); resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor()); resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor()); - resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors)); - 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.LILY_PAD, getBlockColor(Blocks.LILY_PAD)); + 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(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors)); - resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors)); + resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM)); + resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM)); return resultColors; } @@ -161,8 +156,8 @@ public JsonObject generateDataJson() { } public static class BiomeTintColors { - final Map> grassColoursMap = new HashMap<>(); - final Map> foliageColoursMap = new HashMap<>(); - final Map> waterColourMap = new HashMap<>(); + final Map> grassColoursMap = new LinkedHashMap<>(); + final Map> foliageColoursMap = new LinkedHashMap<>(); + final Map> waterColourMap = new LinkedHashMap<>(); } } diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ClientPlayerInteractionManagerMixin.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ClientPlayerInteractionManagerMixin.java deleted file mode 100644 index 40e926af..00000000 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ClientPlayerInteractionManagerMixin.java +++ /dev/null @@ -1,57 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import com.google.common.base.Preconditions; -import net.minecraft.block.BlockState; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerInteractionManager; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ClientPlayerInteractionManager.class) -public abstract class ClientPlayerInteractionManagerMixin { - @Unique - private long blockBreakingStartTicks; - @Unique - private BlockState stateBeingBroken; - - @Inject(method = "attackBlock", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;currentBreakingProgress:F", opcode = Opcodes.PUTFIELD)) - private void onBlockAttacked(BlockPos pos, Direction direction, CallbackInfoReturnable callbackInfo) { - World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world); - this.blockBreakingStartTicks = world.getTime(); - } - - @Inject(method = "cancelBlockBreaking", at = @At("HEAD")) - private void onBlockBreakingCanceled(CallbackInfo callbackInfo) { - this.blockBreakingStartTicks = -1L; - } - - @Inject(method = "breakBlock", at = @At("HEAD")) - private void onBreakBlockHead(BlockPos pos, CallbackInfoReturnable callbackInfo) { - World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world); - this.stateBeingBroken = world.getBlockState(pos); - } - - @Inject(method = "breakBlock", at = @At("RETURN")) - private void onBreakBlockReturn(BlockPos pos, CallbackInfoReturnable callbackInfo) { - World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world); - if (callbackInfo.getReturnValue()) { - Preconditions.checkNotNull(stateBeingBroken); - if (blockBreakingStartTicks != -1L) { - long totalTicksElapsed = world.getTime() - this.blockBreakingStartTicks; - long totalTimeElapsed = totalTicksElapsed * 50L; - System.out.printf("Breaking block %s took %dms%n", stateBeingBroken.getBlock(), totalTimeElapsed); - } else { - System.out.printf("Breaking block %s took 0ms [INSTANT BREAK]%n", stateBeingBroken.getBlock()); - } - } - this.blockBreakingStartTicks = -1L; - } -} diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java index ba3b26b4..c904c153 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/ReadyMixin.java @@ -1,7 +1,6 @@ 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 net.minecraft.MinecraftVersion; import net.minecraft.server.dedicated.MinecraftDedicatedServer; @@ -10,18 +9,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.nio.file.Path; - @Mixin(MinecraftDedicatedServer.class) public class ReadyMixin { @Inject(method = "setupServer()Z", at = @At("TAIL")) private void init(CallbackInfoReturnable cir) { - Main.LOGGER.info("Starting data generation!"); - String versionName = MinecraftVersion.CURRENT.getName(); - Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath(); - Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); - DataGenerators.runDataGenerators(dataDumpDirectory); - Main.LOGGER.info("Done data generation!"); - Runtime.getRuntime().halt(0); + MinecraftDataGenerator.start( + MinecraftVersion.CURRENT.getName(), + DGU.getCurrentlyRunningServer().getRunDirectory().toPath() + ); } } diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java deleted file mode 100644 index 4a75ab37..00000000 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/mixin/TheEndBiomeDataAccessor.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.u9g.minecraftdatagenerator.mixin; - -import net.fabricmc.fabric.impl.biome.TheEndBiomeData; -import net.fabricmc.fabric.impl.biome.WeightedPicker; -import net.minecraft.util.registry.RegistryKey; -import net.minecraft.world.biome.Biome; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; - -@Mixin(TheEndBiomeData.class) -public interface TheEndBiomeDataAccessor { - @Accessor("END_BIOMES_MAP") - static Map, WeightedPicker>> END_BIOMES_MAP() { - throw new IllegalStateException("Should never be called."); - } - - @Accessor("END_MIDLANDS_MAP") - static Map, WeightedPicker>> END_MIDLANDS_MAP() { - throw new IllegalStateException("Should never be called."); - } - - @Accessor("END_BARRENS_MAP") - static Map, WeightedPicker>> END_BARRENS_MAP() { - throw new IllegalStateException("Should never be called."); - } -} diff --git a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java index 5945fa02..3946c1fe 100644 --- a/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java +++ b/22w19a/src/main/java/dev/u9g/minecraftdatagenerator/util/DGU.java @@ -1,57 +1,18 @@ 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.MinecraftClient; -import net.minecraft.client.resource.language.I18n; import net.minecraft.server.MinecraftServer; import net.minecraft.util.Language; import net.minecraft.world.World; public class DGU { - - private static final Language language = Language.getInstance(); - - @Environment(EnvType.CLIENT) - private static MinecraftServer getCurrentlyRunningServerClient() { - return MinecraftClient.getInstance().getServer(); - } - @SuppressWarnings("deprecation") - private static MinecraftServer getCurrentlyRunningServerDedicated() { - return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } - public static MinecraftServer getCurrentlyRunningServer() { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return getCurrentlyRunningServerClient(); - } else if (environmentType == EnvType.SERVER) { - return getCurrentlyRunningServerDedicated(); - } - throw new UnsupportedOperationException(); - } - - @Environment(EnvType.CLIENT) - private static String translateTextClient(String translationKey) { - return I18n.translate(translationKey); - } - - private static String translateTextFallback(String translationKey) { - try { - return language.get(translationKey); - } catch (Exception ignored) { - } - throw new RuntimeException("Failed to translate: '" + translationKey + "'"); + return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); } public static String translateText(String translationKey) { - EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (environmentType == EnvType.CLIENT) { - return translateTextClient(translationKey); - } - return translateTextFallback(translationKey); + return Language.getInstance().get(translationKey); } public static World getWorld() { diff --git a/22w19a/src/main/resources/fabric.mod.json b/22w19a/src/main/resources/fabric.mod.json index 9f6ef321..ffac96b0 100644 --- a/22w19a/src/main/resources/fabric.mod.json +++ b/22w19a/src/main/resources/fabric.mod.json @@ -10,18 +10,11 @@ ], "contact": {}, "license": "MIT", - "environment": "server", - "entrypoints": { - "main": [ - "dev.u9g.minecraftdatagenerator.Main" - ] - }, "mixins": [ "minecraft-data-generator.mixins.json" ], "depends": { - "fabricloader": ">=0.14.5", - "fabric": "*", - "minecraft": ">=1.18" + "fabricloader": "*", + "minecraft": "*" } } diff --git a/22w19a/src/main/resources/minecraft-data-generator.mixins.json b/22w19a/src/main/resources/minecraft-data-generator.mixins.json index 9e8d4163..b8f9bb32 100644 --- a/22w19a/src/main/resources/minecraft-data-generator.mixins.json +++ b/22w19a/src/main/resources/minecraft-data-generator.mixins.json @@ -4,10 +4,8 @@ "package": "dev.u9g.minecraftdatagenerator.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "ClientPlayerInteractionManagerMixin", "MiningToolItemAccessor", - "ReadyMixin", - "TheEndBiomeDataAccessor" + "ReadyMixin" ], "client": [ ], diff --git a/README.md b/README.md index a13bc785..209c5f08 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,13 @@ You can put any version that has a directory into the command below. Just replace `` with the version you want to generate. For Linux/Mac OS: + ```bash ./gradlew ::runServer ``` For Windows: + ```bash gradlew.bat ::runServer ``` diff --git a/build.gradle b/build.gradle index c638bd14..6b15530c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,20 @@ allprojects { version = "1.0.0-SNAPSHOT" group = "dev.u9g" + + repositories { + maven { + name = "wagyourtail releases" + url = "https://maven.wagyourtail.xyz/releases" + } + maven { + name = "legacyfabric" + url = "https://maven.legacyfabric.net/" + } + maven { + name = "fabric" + url = "https://maven.fabricmc.net/" + } + mavenCentral() + } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 00000000..78a17021 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,56 @@ +plugins { + `kotlin-dsl` +} + +repositories { + maven("https://maven.wagyourtail.xyz/releases") { + name = "WagYourReleases" + } + maven("https://maven.wagyourtail.xyz/snapshots") { + name = "WagYourSnapshots" + } + gradlePluginPortal() + mavenCentral() +} + +dependencies { + implementation("xyz.wagyourtail.unimined:xyz.wagyourtail.unimined.gradle.plugin:1.2.15-SNAPSHOT") + + // guava + implementation("com.google.guava:guava:31.1-jre") + + // gson + implementation("com.google.code.gson:gson:2.9.0") + + // asm + implementation("org.ow2.asm:asm:9.5") + implementation("org.ow2.asm:asm-commons:9.5") + implementation("org.ow2.asm:asm-tree:9.5") + implementation("org.ow2.asm:asm-analysis:9.5") + implementation("org.ow2.asm:asm-util:9.5") + + // remapper + implementation("net.fabricmc:tiny-remapper:0.8.7") { + exclude(group = "org.ow2.asm") + } + + // mappings + implementation("net.fabricmc:mapping-io:0.3.0") { + exclude(group = "org.ow2.asm") + } + + // jetbrains annotations + implementation("org.jetbrains:annotations-java5:23.0.0") + + // binpatcher + implementation("net.minecraftforge:binarypatcher:1.1.1") { + exclude(mapOf("group" to "commons-io")) + } + implementation("commons-io:commons-io:2.12.0") + + // pack200 provided by apache commons-compress + implementation("org.apache.commons:commons-compress:1.26.1") + + // aw + implementation("net.fabricmc:access-widener:2.1.0") +} diff --git a/buildSrc/src/main/kotlin/CustomLegacyFabricMinecraftTransformer.kt b/buildSrc/src/main/kotlin/CustomLegacyFabricMinecraftTransformer.kt new file mode 100644 index 00000000..7bd16a7b --- /dev/null +++ b/buildSrc/src/main/kotlin/CustomLegacyFabricMinecraftTransformer.kt @@ -0,0 +1,23 @@ +import org.gradle.api.Project +import xyz.wagyourtail.unimined.api.minecraft.EnvType +import xyz.wagyourtail.unimined.api.minecraft.MinecraftJar +import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider +import xyz.wagyourtail.unimined.internal.minecraft.patch.fabric.LegacyFabricMinecraftTransformer +import xyz.wagyourtail.unimined.internal.minecraft.transform.merge.ClassMerger + +// Prevents adding @Environment annotations to classes +@Suppress("UnstableApiUsage") +class CustomLegacyFabricMinecraftTransformer( + project: Project, + provider: MinecraftProvider +) : LegacyFabricMinecraftTransformer(project, provider) { + override val merger: ClassMerger = ClassMerger() + + override fun mergedJar(clientjar: MinecraftJar, serverjar: MinecraftJar): MinecraftJar { + return MinecraftJar( + clientjar, + envType = EnvType.COMBINED, + patches = listOf("$providerName-merged", "custom-no-environment") + clientjar.patches + serverjar.patches + ) + } +} diff --git a/buildSrc/src/main/kotlin/CustomOfficialFabricMinecraftTransformer.kt b/buildSrc/src/main/kotlin/CustomOfficialFabricMinecraftTransformer.kt new file mode 100644 index 00000000..741d1e63 --- /dev/null +++ b/buildSrc/src/main/kotlin/CustomOfficialFabricMinecraftTransformer.kt @@ -0,0 +1,23 @@ +import org.gradle.api.Project +import xyz.wagyourtail.unimined.api.minecraft.EnvType +import xyz.wagyourtail.unimined.api.minecraft.MinecraftJar +import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider +import xyz.wagyourtail.unimined.internal.minecraft.patch.fabric.OfficialFabricMinecraftTransformer +import xyz.wagyourtail.unimined.internal.minecraft.transform.merge.ClassMerger + +// Prevents adding @Environment annotations to classes +@Suppress("UnstableApiUsage") +class CustomOfficialFabricMinecraftTransformer( + project: Project, + provider: MinecraftProvider +) : OfficialFabricMinecraftTransformer(project, provider) { + override val merger: ClassMerger = ClassMerger() + + override fun mergedJar(clientjar: MinecraftJar, serverjar: MinecraftJar): MinecraftJar { + return MinecraftJar( + clientjar, + envType = EnvType.COMBINED, + patches = listOf("$providerName-merged", "custom-no-environment") + clientjar.patches + serverjar.patches + ) + } +} diff --git a/common/build.gradle b/common/build.gradle new file mode 100644 index 00000000..8d1503d4 --- /dev/null +++ b/common/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java' +} + +dependencies { + compileOnly 'com.google.code.gson:gson:2.10.1' + implementation 'io.github.classgraph:classgraph:4.8.172' + implementation "net.lenni0451:Reflect:1.3.3" + implementation 'org.slf4j:slf4j-api:2.0.13' + implementation "org.slf4j:jul-to-slf4j:2.0.13" +} + +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" +} + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} diff --git a/common/src/main/java/dev/u9g/minecraftdatagenerator/MinecraftDataGenerator.java b/common/src/main/java/dev/u9g/minecraftdatagenerator/MinecraftDataGenerator.java new file mode 100644 index 00000000..6671bef3 --- /dev/null +++ b/common/src/main/java/dev/u9g/minecraftdatagenerator/MinecraftDataGenerator.java @@ -0,0 +1,24 @@ +package dev.u9g.minecraftdatagenerator; + +import dev.u9g.minecraftdatagenerator.generators.DataGenerators; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.FileDescriptor; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.nio.file.Path; + +public class MinecraftDataGenerator { + private static final Logger LOGGER = LoggerFactory.getLogger(MinecraftDataGenerator.class); + + public static void start(String versionName, Path serverRootDirectory) { + System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); + System.setErr(new PrintStream(new FileOutputStream(FileDescriptor.err))); + MinecraftDataGenerator.LOGGER.info("Starting data generation!"); + Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName); + DataGenerators.runDataGenerators(dataDumpDirectory); + MinecraftDataGenerator.LOGGER.info("Done data generation!"); + Runtime.getRuntime().halt(0); + } +} diff --git a/common/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java b/common/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java new file mode 100644 index 00000000..ff7a3020 --- /dev/null +++ b/common/src/main/java/dev/u9g/minecraftdatagenerator/generators/DataGenerators.java @@ -0,0 +1,82 @@ +package dev.u9g.minecraftdatagenerator.generators; + +import com.google.gson.JsonElement; +import com.google.gson.internal.Streams; +import com.google.gson.stream.JsonWriter; +import io.github.classgraph.ClassGraph; +import io.github.classgraph.ScanResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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.util.ArrayList; +import java.util.List; + +public class DataGenerators { + private static final List GENERATORS = new ArrayList<>(); + private static final Logger LOGGER = LoggerFactory.getLogger(DataGenerators.class); + + static { + List> generators; + try (ScanResult scanResult = new ClassGraph() + .acceptPackages("dev.u9g.minecraftdatagenerator.generators") + .overrideClassLoaders(IDataGenerator.class.getClassLoader()) + .enableClassInfo().scan()) { + generators = scanResult + .getClassesImplementing(IDataGenerator.class) + .loadClasses(IDataGenerator.class); + } + + for (Class generatorClass : generators) { + try { + GENERATORS.add(generatorClass.getDeclaredConstructor().newInstance()); + } catch (ReflectiveOperationException e) { + LOGGER.error("Failed to instantiate data generator {}", generatorClass.getName(), e); + } + } + } + + public static boolean runDataGenerators(Path outputDirectory) { + try { + Files.createDirectories(outputDirectory); + } catch (IOException e) { + LOGGER.error("Failed to create data generator output directory at {}", outputDirectory, e); + return false; + } + + int generatorsFailed = 0; + LOGGER.info("Running minecraft data generators, output at {}", outputDirectory); + + for (IDataGenerator dataGenerator : GENERATORS) { + if (!dataGenerator.isEnabled()) { + LOGGER.info("Skipping disabled generator {}", dataGenerator.getDataName()); + continue; + } + + LOGGER.info("Running generator {}", 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("Generator: {} -> {}", dataGenerator.getDataName(), outputFileName); + } catch (Throwable e) { + LOGGER.error("Failed to run data generator {}", dataGenerator.getDataName(), e); + generatorsFailed++; + } + } + + LOGGER.info("Finishing running data generators"); + return generatorsFailed == 0; + } +} diff --git a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java b/common/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java similarity index 75% rename from 1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java rename to common/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java index 81fe4e20..faa74f9e 100644 --- a/1.10.2/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java +++ b/common/src/main/java/dev/u9g/minecraftdatagenerator/generators/IDataGenerator.java @@ -3,8 +3,11 @@ import com.google.gson.JsonElement; public interface IDataGenerator { - String getDataName(); JsonElement generateDataJson(); + + default boolean isEnabled() { + return true; + } } diff --git a/gradle.properties b/gradle.properties index bde2fd14..3693d2e5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,8 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx4G -Xms256m -XX:+UseParallelGC -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - org.gradle.daemon=true - org.gradle.configureondemand=true org.gradle.cache=true org.gradle.caching=true org.gradle.parallel=true - org.gradle.vfs.watch=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 943f0cbf..d64cd491 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3499ded5..b82aa23a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 65dcd68d..1aa94a42 100755 --- a/gradlew +++ b/gradlew @@ -83,10 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/settings.gradle b/settings.gradle index ab5a1968..62448b64 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,34 +1,17 @@ -pluginManagement { - repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - gradlePluginPortal() - } - plugins { - id 'fabric-loom' version "1.4.5" - } +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' } -dependencyResolutionManagement { - repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' +dependencyResolutionManagement { + versionCatalogs { + libs { + version('fabric-loader', '0.15.10') } - maven { - name = "legacy-fabric" - url = "https://maven.legacyfabric.net" - } - maven { - name = "u9g" - url = "https://maven.u9g.dev" - } - mavenCentral() } } +include "common" + [ "1.7", "1.8.9", @@ -47,4 +30,5 @@ dependencyResolutionManagement { "1.19.2", "1.20", "1.20.4", + "1.20.5", ].forEach { include it }