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.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
}
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))
}
}
-8
View File
@@ -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
@@ -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,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<BlockPos.Mutable> 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);
}
}
@@ -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);
}
@@ -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<BlockColorable> 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));
}
}
}
@@ -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;
}
}
@@ -38,8 +38,8 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator {
}
private static class BlockShapesCache {
public final Map<VoxelShape, Integer> uniqueBlockShapes = new HashMap<>();
public final Map<Block, List<Integer>> blockCollisionShapes = new HashMap<>();
public final Map<VoxelShape, Integer> uniqueBlockShapes = new LinkedHashMap<>();
public final Map<Block, List<Integer>> blockCollisionShapes = new LinkedHashMap<>();
private int lastCollisionShapeId = 0;
public void processBlock(Block block) {
@@ -68,7 +68,7 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator {
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) {
@@ -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.MiningToolItemAccessor;
import dev.u9g.minecraftdatagenerator.util.DGU;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
@@ -26,13 +25,9 @@ import java.util.ArrayList;
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<Item> getItemsEffectiveForBlock(Block block) {
return Registry.ITEM.stream()
.filter(item -> item instanceof ToolItem)
@@ -81,16 +76,16 @@ public class BlocksDataGenerator implements IDataGenerator {
return propertyObject;
}
public static JsonObject generateBlock(Registry<Block> blockRegistry, Block block) {
public static JsonObject generateBlock(Block block) {
JsonObject blockDesc = new JsonObject();
List<BlockState> blockStates = block.getStateManager().getBlockStates();
BlockState defaultState = block.getDefaultState();
Identifier registryKey = blockRegistry.getId(block);
Identifier registryKey = Registry.BLOCK.getId(block);
String localizationKey = block.getTranslationKey();
List<Item> 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 class BlocksDataGenerator implements IDataGenerator {
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 class BlocksDataGenerator implements IDataGenerator {
JsonArray resultBlocksArray = new JsonArray();
Registry<Block> blockRegistry = Registry.BLOCK;
for (Block block : (Iterable<Block>) blockRegistry) {
resultBlocksArray.add(generateBlock(blockRegistry, block));
resultBlocksArray.add(generateBlock(block));
}
return resultBlocksArray;
}
@@ -1,80 +0,0 @@
package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonElement;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonWriter;
import dev.u9g.minecraftdatagenerator.Main;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DataGenerators {
private static final List<IDataGenerator> GENERATORS = new ArrayList<>();
private static final Logger logger = Main.LOGGER;
static {
register(new BiomesDataGenerator());
register(new BlockCollisionShapesDataGenerator());
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;
}
}
@@ -16,7 +16,6 @@ import java.util.Objects;
import java.util.stream.Collectors;
public class EffectsDataGenerator implements IDataGenerator {
public static JsonObject generateEffect(Registry<StatusEffect> registry, StatusEffect statusEffect) {
JsonObject effectDesc = new JsonObject();
@NotNull Identifier registryKey = Objects.requireNonNull(registry.getId(statusEffect));
@@ -24,7 +24,6 @@ import java.lang.reflect.ParameterizedType;
import java.util.Objects;
public class EntitiesDataGenerator implements IDataGenerator {
public static JsonObject generateEntity(Registry<EntityType<?>> entityRegistry, EntityType<?> entityType) {
JsonObject entityDesc = new JsonObject();
Identifier registryKey = entityRegistry.getId(entityType);
@@ -12,7 +12,6 @@ import net.minecraft.util.registry.Registry;
import java.util.Objects;
public class FoodsDataGenerator implements IDataGenerator {
public static JsonObject generateFoodDescriptor(Registry<Item> registry, FoodItem foodItem) {
JsonObject foodDesc = new JsonObject();
Identifier registryKey = registry.getId(foodItem);
@@ -1,10 +0,0 @@
package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonElement;
public interface IDataGenerator {
String getDataName();
JsonElement generateDataJson();
}
@@ -9,12 +9,11 @@ import net.minecraft.util.registry.Registry;
import java.util.Objects;
public class ParticlesDataGenerator implements IDataGenerator {
public static JsonObject generateParticleType(Registry<ParticleType<?>> 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 class ParticlesDataGenerator implements IDataGenerator {
return "particles";
}
@SuppressWarnings("unchecked")
@Override
public JsonArray generateDataJson() {
JsonArray resultsArray = new JsonArray();
Registry<ParticleType<?>> particleTypeRegistry = Registry.PARTICLE_TYPE;
for (ParticleType<?> particleType : (Iterable<ParticleType>) particleTypeRegistry) {
resultsArray.add(generateParticleType(particleTypeRegistry, particleType));
}
Registry.PARTICLE_TYPE.forEach(particleType ->
resultsArray.add(generateParticleType((ParticleType<?>) particleType)));
return resultsArray;
}
}
@@ -118,4 +118,9 @@ public class RecipeDataGenerator implements IDataGenerator {
// return finalObj;
return JsonNull.INSTANCE;
}
@Override
public boolean isEnabled() {
return false; // TODO: Implement this
}
}
@@ -2,18 +2,15 @@ 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;
import net.minecraft.util.registry.Registry;
public class SoundsDataGenerator implements IDataGenerator {
public static JsonObject generateSound(Registry<SoundEvent> registry, SoundEvent soundEvent) {
public static JsonObject generateSound(Registry<Sound> 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 class SoundsDataGenerator implements IDataGenerator {
@Override
public JsonArray generateDataJson() {
JsonArray resultsArray = new JsonArray();
Registry<SoundEvent> soundEventRegistry = Registry.SOUND_EVENT;
soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, (SoundEvent) sound)));
Registry<Sound> soundEventRegistry = Registry.SOUND_EVENT;
soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, (Sound) sound)));
return resultsArray;
}
}
@@ -2,28 +2,30 @@ 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.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<Biome> biomeRegistry) {
BiomeTintColors colors = new BiomeTintColors();
for (Biome biome : (Iterable<Biome>) 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 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, 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<Block, Integer> generateConstantTintColors() {
Map<Block, Integer> resultColors = new HashMap<>();
BlockColors blockColors = BlockColors.create();
Map<Block, Integer> 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 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,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,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 net.minecraft.world.dimension.DimensionType;
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() {
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 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 Language.getInstance().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.13"
"fabricloader": "*",
"minecraft": "*"
}
}
@@ -6,11 +6,8 @@
"mixins": [
"MiningToolItemAccessor",
"ReadyMixin",
"SoundAccessor",
"StatusEffectAccessor"
],
"client": [
],
"injectors": {
"defaultRequire": 1
},