Reduce duplicate code (#18)

* Reduce duplicate code

* Fix gradle task name

* Revert name changes

* Revert action name

* Cleanup

* Revert to java 17

* Fix generation

* Cleanup

* Simplify code of DGU

* Remove unnecessary annotations

* Remove unused var

* Halt with error on error

* Remove unused mixins

* Update fabric loader

* Ignore success result

* Update gradle and use merged jar

* Implement new client and server merged environment for running fabric

* Set server run dir as asset dir

* More cleanup

* More cleanup 2

* More improvements

* Remove more duplicate code

* Use newer java methods

* More cleanup

* Remove SoundAccessors

* More cleanup

* Use java 21 for build

* Initial work on 1.20.5

* Cleanup a lot of stuff

* Do not generate mod jars to speed up builds

* Override merger on now open classes directly

* Use recommended approach

* Readd custom merger

* Working materials data generator

* Fix inconsistencies

* Fix collision order to be random

* Use LinkedHashMap for more reproducibility

* Fix imports
This commit is contained in:
Alex
2024-07-14 09:23:34 +02:00
committed by GitHub
parent 44f49b4ab5
commit 71070c32bc
459 changed files with 3421 additions and 9078 deletions
+26 -42
View File
@@ -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
}
customPatcher(new CustomLegacyFabricMinecraftTransformer(project, delegate as MinecraftProvider)) {
it.loader libs.versions.fabric.loader.get()
}
defaultRemapJar = true
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API provides hooks for events, item registration, and more. As most mods will need this, it's included by default.
// If you know for a fact you don't, it's not required and can be safely removed.
// modImplementation ("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${fabric_version}") {
// exclude module: "legacy-fabric-entity-events-v1"
// }
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
implementation 'org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209'
implementation 'org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209'
implementation 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
}
}
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
configurations.configureEach {
resolutionStrategy {
dependencySubstitution {
substitute module('org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209')
substitute module('org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209')
}
force 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
}
}
implementation project(":common")
}
processResources {
@@ -52,12 +38,10 @@ processResources {
}
}
tasks.withType(RemapJarTask).configureEach {
onlyIf { false}
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
-7
View File
@@ -1,7 +0,0 @@
# Fabric Properties
# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/
minecraft_version=1.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/
@@ -1,13 +0,0 @@
package dev.u9g.minecraftdatagenerator;
import net.fabricmc.api.ModInitializer;
import java.util.logging.Logger;
public class Main implements ModInitializer {
public static final Logger LOGGER = Logger.getLogger("mc-data-gen-serv");
@Override
public void onInitialize() {
}
}
@@ -1,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<BlockPos.Mutable> 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);
}
}
@@ -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);
}
@@ -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<BlockColorable> 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));
}
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -78,7 +78,7 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator {
}
}
if (indexesOfBoxesInTheShapesCache.stream().distinct().count() < 2) {
return indexesOfBoxesInTheShapesCache.get(0);
return indexesOfBoxesInTheShapesCache.getFirst();
} else {
JsonArray shapeIndexes = new JsonArray();
indexesOfBoxesInTheShapesCache.forEach(shapeIndexes::add);
@@ -98,18 +98,18 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator {
private record Shapes(List<Box> boxes) {
public JsonArray toJSON() {
JsonArray arr = new JsonArray();
boxes.forEach(box -> arr.add(jsonOf(box)));
return arr;
}
JsonArray arr = new JsonArray();
boxes.forEach(box -> arr.add(jsonOf(box)));
return arr;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Shapes shapes = (Shapes) o;
return Objects.equals(boxes, shapes.boxes);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Shapes shapes = (Shapes) o;
return Objects.equals(boxes, shapes.boxes);
}
}
}
@@ -3,7 +3,6 @@ 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.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.ArrayList;
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<Item> getItemsEffectiveForBlock(Block block) {
List<Item> items = new ArrayList<>();
for (Item item : Registries.ITEMS) {
@@ -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<IDataGenerator> 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;
}
}
@@ -16,7 +16,6 @@ import java.util.Objects;
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));
@@ -24,7 +24,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public class EntitiesDataGenerator implements IDataGenerator {
public static JsonObject generateEntity(Class<? extends Entity> entityClass) {
JsonObject entityDesc = new JsonObject();
Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass);
@@ -11,7 +11,6 @@ import net.minecraft.util.Identifier;
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);
@@ -1,10 +0,0 @@
package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonElement;
public interface IDataGenerator {
String getDataName();
JsonElement generateDataJson();
}
@@ -4,8 +4,7 @@ import com.google.gson.JsonArray;
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 class InstrumentsDataGenerator implements IDataGenerator {
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;
@@ -5,7 +5,6 @@ import com.google.gson.JsonObject;
import net.minecraft.client.particle.ParticleType;
public class ParticlesDataGenerator implements IDataGenerator {
public static JsonObject generateParticleType(int id, ParticleType particleType) {
JsonObject effectDesc = new JsonObject();
@@ -112,6 +112,11 @@ public class RecipeDataGenerator implements IDataGenerator {
// return finalObj;
return JsonNull.INSTANCE;
}
@Override
public boolean isEnabled() {
return false; // TODO: Implement this
}
//
// private static int getRawIdFor (Item item) {
// return Registry.ITEM.getRawId(item);
@@ -2,18 +2,14 @@ package dev.u9g.minecraftdatagenerator.generators;
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 class SoundsDataGenerator implements IDataGenerator {
@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;
}
}
@@ -2,32 +2,32 @@ package dev.u9g.minecraftdatagenerator.generators;
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 class TintsDataGenerator implements IDataGenerator {
}
public static Map<Integer, Integer> generateRedstoneTintColors() {
Map<Integer, Integer> resultColors = new HashMap<>();
Map<Integer, Integer> 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<Block, Integer> generateConstantTintColors() {
Map<Block, Integer> resultColors = new HashMap<>();
BlockColors blockColors = BlockColors.create();
Map<Block, Integer> 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 class TintsDataGenerator implements IDataGenerator {
}
public static class BiomeTintColors {
final Map<Integer, List<Biome>> grassColoursMap = new HashMap<>();
final Map<Integer, List<Biome>> foliageColoursMap = new HashMap<>();
final Map<Integer, List<Biome>> waterColourMap = new HashMap<>();
final Map<Integer, List<Biome>> grassColoursMap = new LinkedHashMap<>();
final Map<Integer, List<Biome>> foliageColoursMap = new LinkedHashMap<>();
final Map<Integer, List<Biome>> waterColourMap = new LinkedHashMap<>();
}
}
@@ -1,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 @@ import java.util.List;
@Mixin(NoteBlock.class)
public interface NoteBlockAccessor {
@Accessor("TUNES")
static List<SoundEvent> TUNES() {
static List<Sound> TUNES() {
return null;
}
}
@@ -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.At;
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<Boolean> 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()
);
}
}
@@ -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();
}
@@ -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<Number>() {
@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() {
public static MinecraftServer getCurrentlyRunningServer() {
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 + "'");
}
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
+2 -8
View File
@@ -10,17 +10,11 @@
],
"contact": {},
"license": "MIT",
"environment": "server",
"entrypoints": {
"main": [
"dev.u9g.minecraftdatagenerator.Main"
]
},
"mixins": [
"minecraft-data-generator.mixins.json"
],
"depends": {
"fabricloader": ">=0.13.3",
"minecraft": ">=1.12"
"fabricloader": "*",
"minecraft": "*"
}
}
@@ -12,11 +12,8 @@
"MiningToolItemAccessor",
"NoteBlockAccessor",
"ReadyMixin",
"SoundAccessor",
"StatusEffectAccessor"
],
"client": [
],
"injectors": {
"defaultRequire": 1
},