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:
+30
-14
@@ -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'
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
defaultRemapJar = true
|
||||
}
|
||||
|
||||
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}"
|
||||
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
implementation project(":common")
|
||||
}
|
||||
|
||||
processResources {
|
||||
@@ -20,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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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() {
|
||||
|
||||
}
|
||||
}
|
||||
-36
@@ -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);
|
||||
}
|
||||
}
|
||||
-27
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
-34
@@ -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;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -37,8 +37,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) {
|
||||
@@ -67,7 +67,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) {
|
||||
|
||||
+6
-12
@@ -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 net.minecraft.block.AirBlock;
|
||||
@@ -26,13 +25,9 @@ import net.minecraft.world.EmptyBlockView;
|
||||
|
||||
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<Item> getItemsEffectiveForBlock(Block block) {
|
||||
return Registry.ITEM.stream()
|
||||
.filter(item -> item instanceof MiningToolItem)
|
||||
@@ -85,16 +80,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().getStates();
|
||||
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", registryKey.getPath());
|
||||
blockDesc.addProperty("displayName", DGU.translateText(localizationKey));
|
||||
|
||||
@@ -116,8 +111,8 @@ public class BlocksDataGenerator implements IDataGenerator {
|
||||
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 class BlocksDataGenerator implements IDataGenerator {
|
||||
@Override
|
||||
public JsonArray generateDataJson() {
|
||||
JsonArray resultBlocksArray = new JsonArray();
|
||||
Registry<Block> blockRegistry = Registry.BLOCK;
|
||||
|
||||
blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, block)));
|
||||
Registry.BLOCK.forEach(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;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EffectsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateEffect(Registry<StatusEffect> registry, StatusEffect statusEffect) {
|
||||
JsonObject effectDesc = new JsonObject();
|
||||
Identifier registryKey = registry.getId(statusEffect);
|
||||
|
||||
-13
@@ -16,19 +16,6 @@ import java.util.Objects;
|
||||
public class EnchantmentsDataGenerator implements IDataGenerator {
|
||||
|
||||
private static final ImmutableMap<EnchantmentTarget, String> ENCHANTMENT_TARGET_NAMES = ImmutableMap.<EnchantmentTarget, String>builder()
|
||||
.put(EnchantmentTarget.ARMOR, "armor")
|
||||
.put(EnchantmentTarget.ARMOR_FEET, "armor_feet")
|
||||
.put(EnchantmentTarget.ARMOR_LEGS, "armor_legs")
|
||||
.put(EnchantmentTarget.ARMOR_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();
|
||||
|
||||
|
||||
+8
-17
@@ -2,7 +2,6 @@ package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
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.Identifier;
|
||||
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<EntityType<?>> entityRegistry, EntityType<?> entityType) {
|
||||
JsonObject entityDesc = new JsonObject();
|
||||
Identifier registryKey = entityRegistry.getId(entityType);
|
||||
@@ -47,26 +44,20 @@ public class EntitiesDataGenerator implements IDataGenerator {
|
||||
|
||||
private static String getCategoryFrom(@NotNull EntityType<?> entityType) {
|
||||
if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities
|
||||
Class<? extends Entity> entityClazz = null;
|
||||
try {
|
||||
for (var field : EntityType.class.getFields())
|
||||
if (entityType == field.get(EntityType.class))
|
||||
entityClazz = (Class<? extends Entity>) ((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());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.minecraft.util.registry.Registry;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FoodsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateFoodDescriptor(Registry<Item> registry, Item 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();
|
||||
}
|
||||
-1
@@ -9,7 +9,6 @@ import net.minecraft.util.registry.Registry;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ParticlesDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateParticleType(Registry<ParticleType<?>> registry, ParticleType<?> particleType) {
|
||||
JsonObject effectDesc = new JsonObject();
|
||||
Identifier registryKey = registry.getId(particleType);
|
||||
|
||||
@@ -118,4 +118,9 @@ public class RecipeDataGenerator implements IDataGenerator {
|
||||
// return finalObj;
|
||||
return JsonNull.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return false; // TODO: Implement this
|
||||
}
|
||||
}
|
||||
|
||||
+4
-8
@@ -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.sound.SoundEvent;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
|
||||
public class SoundsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateSound(Registry<SoundEvent> 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 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, sound)));
|
||||
Registry.SOUND_EVENT.forEach(sound -> resultsArray.add(generateSound(sound)));
|
||||
return resultsArray;
|
||||
}
|
||||
}
|
||||
|
||||
+21
-23
@@ -2,32 +2,33 @@ package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
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<Biome> 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 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.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<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;
|
||||
}
|
||||
@@ -162,8 +160,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.MinecraftVersion;
|
||||
import net.minecraft.server.dedicated.MinecraftDedicatedServer;
|
||||
@@ -10,19 +9,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 = 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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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 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
|
||||
|
||||
@@ -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": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
"mixins": [
|
||||
"MiningToolItemAccessor",
|
||||
"ReadyMixin",
|
||||
"SoundAccessor",
|
||||
"StatusEffectAccessor"
|
||||
],
|
||||
"client": [
|
||||
|
||||
Reference in New Issue
Block a user