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.8.9"
mappings {
legacyIntermediary()
legacyYarn(541)
devFallbackNamespace "intermediary"
}
}
loom {
setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar');
customMinecraftManifest.set("https://meta.legacyfabric.net/v2/manifest/${minecraft_version}")
runs.config("server") {
javaVersion = JavaVersion.VERSION_21
}
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.8.9
yarn_mappings=1.8.9+build.202206020145
loader_version=0.14.3
# Dependencies
# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/
@@ -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,81 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.block.*;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.util.math.BlockPos;
import static net.minecraft.block.RedstoneWireBlock.POWER;
public class BiomeBlockColors {
// generated manually from each Biome's Biome#getBlockColor
public static int getBlockColor(Block block, BlockState state) {
if (block instanceof AbstractFluidBlock) {
return BiomeColors.getWaterColor(EmptyBlockView.INSTANCE, BlockPos.ORIGIN);
} else if (block instanceof AttachedStemBlock) {
return getAttachedStemColor(state, block);
} else if (block instanceof DoublePlantBlock) {
EmptyBlockView bv = new EmptyBlockView() {
@Override
public BlockState getBlockState(BlockPos pos) {
return state;
}
};
DoublePlantBlock.DoublePlantType doublePlantType = ((DoublePlantBlock) block).getVariant(bv, BlockPos.ORIGIN);
if (doublePlantType == DoublePlantBlock.DoublePlantType.GRASS || doublePlantType == DoublePlantBlock.DoublePlantType.FERN) {
return BiomeColors.getGrassColor(bv, BlockPos.ORIGIN);
}
} else if (block instanceof FlowerPotBlock) {
// FIXME: Yeah, flower pot block's color depends on the block inside of it, since we dont compute that, let's just not do anything
// Item item;
// BlockEntity blockEntity = view.getBlockEntity(pos);
// if (blockEntity instanceof FlowerPotBlockEntity && (item = ((FlowerPotBlockEntity)blockEntity).getItem()) instanceof BlockItem) {
// return Block.getBlockFromItem(item).getBlockColor(view, pos, id);
// }
} else if (block instanceof GrassBlock) {
return BiomeColors.getGrassColor(EmptyBlockView.INSTANCE, BlockPos.ORIGIN);
} else if (block instanceof Leaves1Block) {
return getLeaves1Color(state, block);
} else if (block instanceof LeavesBlock) {
return getLeavesColor();
} else if (block instanceof RedstoneWireBlock) {
if (state.getBlock() == block) {
return ServerSideRedstoneWireBlock.getWireColor(state.get(POWER));
}
} else if (block instanceof SugarCaneBlock || block instanceof TallPlantBlock) {
return GrassColors.getGrassColor(EmptyBlockView.INSTANCE.getBiome(BlockPos.ORIGIN));
} else if (block instanceof VineBlock) {
return dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors.getFoliageColor(EmptyBlockView.INSTANCE.getBiome(BlockPos.ORIGIN));
}
return 0xFFFFFF;
}
private static int getLeaves1Color(BlockState blockState, Block block) {
if (blockState.getBlock() == block) {
PlanksBlock.WoodType woodType = blockState.get(Leaves1Block.VARIANT);
if (woodType == PlanksBlock.WoodType.SPRUCE) {
return net.minecraft.client.color.world.FoliageColors.getSpruceColor();
}
if (woodType == PlanksBlock.WoodType.BIRCH) {
return FoliageColors.getBirchColor();
}
}
return getLeavesColor();
}
private static int getLeavesColor() {
return FoliageColors.getColor(0.5, 1.0);
}
private static int getAttachedStemColor(BlockState state, Block block) {
if (state.getBlock() != block) {
return 0xFFFFFF;
}
int i = state.get(AttachedStemBlock.AGE);
int j = i * 32;
int k = 255 - i * 8;
int l = i * 4;
return j << 16 | k << 8 | l;
}
}
@@ -1,46 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.biome.Biome;
import java.util.Iterator;
public class BiomeColors {
private static final ColorProvider GRASS_COLOR = Biome::getGrassColor;
private static final ColorProvider FOLIAGE_COLOR = Biome::getFoliageColor;
private static final ColorProvider WATER_COLOR = (biome, pos) -> biome.waterColor;
private static int getColor(BlockView view, BlockPos pos, ColorProvider provider) {
int i = 0;
int j = 0;
int k = 0;
int l;
for (Iterator<BlockPos.Mutable> iterator = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); iterator.hasNext(); k += l & 255) {
BlockPos.Mutable mutable = (BlockPos.Mutable) iterator.next();
l = provider.getColorAtPos(view.getBiome(mutable), mutable);
i += (l & 16711680) >> 16;
j += (l & '\uff00') >> 8;
}
return (i / 9 & 255) << 16 | (j / 9 & 255) << 8 | k / 9 & 255;
}
public static int getGrassColor(BlockView view, BlockPos pos) {
return getColor(view, pos, GRASS_COLOR);
}
public static int getFoliageColor(BlockView view, BlockPos pos) {
return getColor(view, pos, FOLIAGE_COLOR);
}
public static int getWaterColor(BlockView view, BlockPos pos) {
return getColor(view, pos, WATER_COLOR);
}
interface ColorProvider {
int getColorAtPos(Biome biome, BlockPos pos);
}
}
@@ -1,38 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
public class FoliageColors {
private static int[] colorMap = new int[65536];
public static void setColorMap(int[] pixels) {
colorMap = pixels;
}
public static int getColor(double temperature, double humidity) {
humidity *= temperature;
int i = (int) ((1.0D - temperature) * 255.0D);
int j = (int) ((1.0D - humidity) * 255.0D);
return colorMap[j << 8 | i];
}
public static int getSpruceColor() {
return 6396257;
}
public static int getBirchColor() {
return 8431445;
}
public static int getDefaultColor() {
return 4764952;
}
public static int getFoliageColor(Biome biome) {
double d = MathHelper.clamp(biome.temperature, 0.0f, 1.0f);
double e = MathHelper.clamp(biome.downfall, 0.0f, 1.0f);
return FoliageColors.getColor(d, e);
}
}
@@ -1,29 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
public class GrassColors {
private static int[] colorMap = new int[65536];
public static void setColorMap(int[] map) {
colorMap = map;
}
public static int getColor(double temperature, double humidity) {
humidity *= temperature;
int i = (int) ((1.0D - temperature) * 255.0D);
int j = (int) ((1.0D - humidity) * 255.0D);
int k = j << 8 | i;
return k > colorMap.length ? -65281 : colorMap[k];
}
public static int getGrassColor(Biome biome) {
double d = MathHelper.clamp(biome.temperature, 0.0f, 1.0f);
double e = MathHelper.clamp(biome.downfall, 0.0f, 1.0f);
return GrassColors.getColor(d, e);
}
}
@@ -1,28 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.util.math.MathHelper;
public class ServerSideRedstoneWireBlock {
public static int getWireColor(int powerLevel) {
float f = (float) powerLevel / 15.0F;
float g = f * 0.6F + 0.4F;
if (powerLevel == 0) {
g = 0.3F;
}
float h = f * f * 0.7F - 0.5F;
float j = f * f * 0.6F - 0.7F;
if (h < 0.0F) {
h = 0.0F;
}
if (j < 0.0F) {
j = 0.0F;
}
int k = MathHelper.clamp((int) (g * 255.0F), 0, 255);
int l = MathHelper.clamp((int) (h * 255.0F), 0, 255);
int m = MathHelper.clamp((int) (j * 255.0F), 0, 255);
return -16777216 | k << 16 | l << 8 | m;
}
}
@@ -5,7 +5,6 @@ import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor;
import dev.u9g.minecraftdatagenerator.util.Registries;
import net.minecraft.world.biome.*;
import org.apache.commons.lang3.StringUtils;
import java.util.Locale;
@@ -20,91 +19,6 @@ public class BiomesDataGenerator implements IDataGenerator {
return "overworld";
}
private static int getBiomeColorFor(String biomeDisplayNamed) {
if (biomeDisplayNamed.equals("Redwood Taiga Hills M")) {
biomeDisplayNamed = "MegaTaigaHills";
}
String biomeDisplayName = StringUtils.join(biomeDisplayNamed.split(" "), "");
return switch (biomeDisplayName) {
case "Ocean" -> 112;
case "Plains" -> 9286496;
case "Desert" -> 16421912;
case "ExtremeHills", "Extreme Hills" -> 6316128;
case "Forest" -> 353825;
case "Taiga" -> 747097;
case "Swampland" -> 522674;
case "River" -> 255;
case "Hell" -> 16711680;
case "TheEnd", "The End" -> 8421631;
case "FrozenOcean", "Frozen Ocean" -> 7368918;
case "FrozenRiver", "Frozen River" -> 10526975;
case "IcePlains", "Ice Plains" -> 16777215;
case "IceMountains", "Ice Mountains" -> 10526880;
case "MushroomIsland", "Mushroom Island" -> 16711935;
case "MushroomIslandShore", "Mushroom Island Shore" -> 10486015;
case "Beach" -> 16440917;
case "DesertHills", "Desert Hills" -> 13786898;
case "ForestHills", "Forest Hills" -> 2250012;
case "TaigaHills", "Taiga Hills" -> 1456435;
case "ExtremeHillsEdge", "Extreme Hills Edge" -> 7501978;
case "Jungle" -> 5470985;
case "JungleHills", "Jungle Hills" -> 2900485;
case "JungleEdge", "Jungle Edge" -> 6458135;
case "DeepOcean", "Deep Ocean" -> 48;
case "StoneBeach", "Stone Beach" -> 10658436;
case "ColdBeach", "Cold Beach" -> 16445632;
case "BirchForest", "Birch Forest" -> 3175492;
case "BirchForestHills", "Birch Forest Hills" -> 2055986;
case "RoofedForest", "Roofed Forest" -> 4215066;
case "ColdTaiga", "Cold Taiga" -> 3233098;
case "ColdTaigaHills", "Cold Taiga Hills" -> 2375478;
case "MegaTaiga", "Mega Taiga" -> 5858897;
case "MegaTaigaHills", "Mega Taiga Hills" -> 4542270;
case "ExtremeHills+", "Extreme Hills+" -> 5271632;
case "Savanna" -> 12431967;
case "SavannaPlateau", "Savanna Plateau" -> 10984804;
case "Mesa" -> 14238997;
case "MesaPlateauF", "Mesa Plateau F" -> 11573093;
case "MesaPlateau", "Mesa Plateau" -> 13274213;
case "TheEnd-Floatingislands", "The End - Floating islands" -> 8421631;
case "TheEnd-Mediumisland", "The End - Medium island" -> 8421631;
case "TheEnd-Highisland", "The End - High island" -> 8421631;
case "TheEnd-Barrenisland", "The End - Barren island" -> 8421631;
case "WarmOcean", "Warm Ocean" -> 172;
case "LukewarmOcean", "Lukewarm Ocean" -> 144;
case "ColdOcean", "Cold Ocean" -> 2105456;
case "WarmDeepOcean", "Warm Deep Ocean" -> 80;
case "LukewarmDeepOcean", "Lukewarm Deep Ocean" -> 64;
case "ColdDeepOcean", "Cold Deep Ocean" -> 2105400;
case "FrozenDeepOcean", "Frozen Deep Ocean" -> 4210832;
case "TheVoid", "The Void" -> 0;
case "SunflowerPlains", "Sunflower Plains" -> 11918216;
case "DesertM", "Desert M" -> 16759872;
case "ExtremeHillsM", "Extreme Hills M" -> 8947848;
case "FlowerForest", "Flower Forest" -> 2985545;
case "TaigaM", "Taiga M" -> 3378817;
case "SwamplandM", "Swampland M" -> 3145690;
case "IcePlainsSpikes", "Ice Plains Spikes" -> 11853020;
case "JungleM", "Jungle M" -> 8102705;
case "JungleEdgeM", "Jungle Edge M" -> 9089855;
case "BirchForestM", "Birch Forest M" -> 5807212;
case "BirchForestHillsM", "Birch Forest Hills M" -> 4687706;
case "RoofedForestM", "Roofed Forest M" -> 6846786;
case "ColdTaigaM", "Cold Taiga M" -> 5864818;
case "MegaSpruceTaiga", "Mega Spruce Taiga" -> 8490617;
case "MegaSpruceTaiga(Hills)", "Mega Spruce Taiga (Hills)" -> 7173990;
case "ExtremeHills+M", "Extreme Hills+ M" -> 7903352;
case "SavannaM", "Savanna M" -> 15063687;
case "SavannaPlateauM", "Savanna Plateau M" -> 13616524;
case "Mesa(Bryce)", "Mesa (Bryce)" -> 16739645;
case "MesaPlateauFM", "Mesa Plateau F M" -> 14204813;
case "MesaPlateauM", "Mesa Plateau M" -> 15905933;
case "BambooJungle", "Bamboo Jungle" -> 7769620;
case "BambooJungleHills", "Bamboo Jungle Hills" -> 3884810;
default -> throw new Error("Unexpected biome, with name: '" + biomeDisplayName + "'");
};
}
public static JsonObject generateBiomeInfo(Biome biome) {
JsonObject biomeDesc = new JsonObject();
// Identifier registryKey = registry.getIdentifier(biome);
@@ -117,7 +31,7 @@ public class BiomesDataGenerator implements IDataGenerator {
biomeDesc.addProperty("depth", biome.depth);
biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome));
biomeDesc.addProperty("displayName", ((BiomeAccessor) biome).name());
biomeDesc.addProperty("color", getBiomeColorFor(((BiomeAccessor) biome).name()));
biomeDesc.addProperty("color", biome.getSkyColor(biome.temperature));
biomeDesc.addProperty("rainfall", biome.downfall);
return biomeDesc;
@@ -79,7 +79,7 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator {
}
}
if (indexesOfBoxesInTheShapesCache.stream().distinct().count() < 2) {
return indexesOfBoxesInTheShapesCache.get(0);
return indexesOfBoxesInTheShapesCache.getFirst();
} else {
JsonArray shapeIndexes = new JsonArray();
indexesOfBoxesInTheShapesCache.forEach(shapeIndex -> shapeIndexes.add(new JsonPrimitive(shapeIndex)));
@@ -99,18 +99,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);
}
}
}
@@ -4,7 +4,6 @@ import com.google.common.base.CaseFormat;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import dev.u9g.minecraftdatagenerator.Main;
import dev.u9g.minecraftdatagenerator.mixin.BlockAccessor;
import dev.u9g.minecraftdatagenerator.mixin.MiningToolItemAccessor;
import dev.u9g.minecraftdatagenerator.util.DGU;
@@ -27,12 +26,8 @@ import java.util.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,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 AttributesDataGenerator());
}
public static void register(IDataGenerator generator) {
GENERATORS.add(generator);
}
public static boolean runDataGenerators(Path outputDirectory) {
try {
Files.createDirectories(outputDirectory);
} catch (IOException exception) {
logger.info("Failed to create data generator output directory at " + outputDirectory);
exception.printStackTrace();
return false;
}
int generatorsFailed = 0;
logger.info(MessageFormat.format("Running minecraft data generators, output at {0}", outputDirectory));
for (IDataGenerator dataGenerator : GENERATORS) {
logger.info(MessageFormat.format("Running generator {0}", dataGenerator.getDataName()));
try {
String outputFileName = String.format("%s.json", dataGenerator.getDataName());
JsonElement outputElement = dataGenerator.generateDataJson();
Path outputFilePath = outputDirectory.resolve(outputFileName);
try (Writer writer = Files.newBufferedWriter(outputFilePath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
JsonWriter jsonWriter = new JsonWriter(writer);
jsonWriter.setIndent(" ");
Streams.write(outputElement, jsonWriter);
}
logger.info(MessageFormat.format("Generator: {0} -> {1}", dataGenerator.getDataName(), outputFileName));
} catch (Throwable exception) {
logger.info(MessageFormat.format("Failed to run data generator {0}", dataGenerator.getDataName()));
exception.printStackTrace();
generatorsFailed++;
}
}
logger.info("Finishing running data generators");
return generatorsFailed == 0;
}
}
@@ -15,7 +15,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));
@@ -21,7 +21,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();
}
@@ -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);
@@ -3,36 +3,30 @@ package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.BiomeBlockColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.GrassColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock;
import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import dev.u9g.minecraftdatagenerator.util.Registries;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.client.color.world.GrassColors;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
import java.lang.reflect.Method;
import java.util.*;
public class TintsDataGenerator implements IDataGenerator {
public static BiomeTintColors generateBiomeTintColors() {
BiomeTintColors colors = new BiomeTintColors();
for (Biome biome : Registries.BIOMES) {
EmptyBlockView bv = new EmptyBlockView() {
@Override
public Biome getBiome(BlockPos pos) {
return biome;
}
};
int biomeGrassColor = GrassColors.getGrassColor(bv.getBiome(BlockPos.ORIGIN));
int biomeFoliageColor = FoliageColors.getFoliageColor(bv.getBiome(BlockPos.ORIGIN));
double d = MathHelper.clamp(biome.temperature, 0.0F, 1.0F);
double e = MathHelper.clamp(biome.downfall, 0.0F, 1.0F);
int biomeGrassColor = GrassColors.getColor(d, e);
int biomeFoliageColor = FoliageColors.getColor(d, e);
int biomeWaterColor = ((BiomeAccessor) biome).waterColor();
colors.grassColoursMap.computeIfAbsent(biomeGrassColor, k -> new ArrayList<>()).add(biome);
@@ -43,33 +37,37 @@ public 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);
resultColors.put(redstoneLevel, color);
RedstoneWireBlock redstoneWireBlock = new RedstoneWireBlock();
try {
Method colorIntensity = RedstoneWireBlock.class.getDeclaredMethod("getColorIntensity", int.class);
colorIntensity.setAccessible(true);
for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) {
int color = (int) colorIntensity.invoke(redstoneWireBlock, redstoneLevel);
resultColors.put(redstoneLevel, color);
}
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
return resultColors;
}
private static int getBlockColor(Block block) {
return BiomeBlockColors.getBlockColor(block, block.getDefaultState());
}
public static Map<Block, Integer> generateConstantTintColors() {
Map<Block, Integer> resultColors = new HashMap<>();
Map<Block, Integer> resultColors = new LinkedHashMap<>();
// FIXME: ?
// resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor());
// resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor());
resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD));
resultColors.put(Blocks.LILY_PAD, Blocks.LILY_PAD.getColor());
// FIXME: ?
// resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM, blockColors));
// resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM, blockColors));
// resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM));
// resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM));
//not really constant, depend on the block age, but kinda have to be handled since textures are literally white without them
resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM));
resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM));
resultColors.put(Blocks.MELON_STEM, Blocks.MELON_STEM.getColor());
resultColors.put(Blocks.PUMPKIN_STEM, Blocks.PUMPKIN_STEM.getColor());
return resultColors;
}
@@ -154,8 +152,8 @@ public 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,43 +0,0 @@
package dev.u9g.minecraftdatagenerator.mixin.overwrite;
import net.minecraft.block.BlockState;
import net.minecraft.block.CocoaBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Unique;
@Mixin(CocoaBlock.class)
public class CocoaBlockOverwrite {
@Unique
private static Box collisionBox(BlockState state) {
Direction direction = state.get(CocoaBlock.FACING);
int i = state.get(CocoaBlock.AGE);
int j = 4 + i * 2;
int k = 5 + i * 2;
float f = (float) j / 2.0f;
return switch (direction) {
case SOUTH ->
new Box((8.0f - f) / 16.0f, (12.0f - (float) k) / 16.0f, (15.0f - (float) j) / 16.0f, (8.0f + f) / 16.0f, 0.75f, 0.9375f);
case NORTH ->
new Box((8.0f - f) / 16.0f, (12.0f - (float) k) / 16.0f, 0.0625f, (8.0f + f) / 16.0f, 0.75f, (1.0f + (float) j) / 16.0f);
case WEST ->
new Box(0.0625f, (12.0f - (float) k) / 16.0f, (8.0f - f) / 16.0f, (1.0f + (float) j) / 16.0f, 0.75f, (8.0f + f) / 16.0f);
case EAST ->
new Box((15.0f - (float) j) / 16.0f, (12.0f - (float) k) / 16.0f, (8.0f - f) / 16.0f, 0.9375f, 0.75f, (8.0f + f) / 16.0f);
default -> throw new Error("Should never hit here");
};
}
/**
* @author a
* @reason a
*/
@Overwrite
public Box getCollisionBox(World world, BlockPos pos, BlockState state) {
return collisionBox(state);
}
}
@@ -1,34 +0,0 @@
package dev.u9g.minecraftdatagenerator.mixin.overwrite;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.EndPortalFrameBlock;
import net.minecraft.block.Material;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import java.util.List;
@Mixin(EndPortalFrameBlock.class)
public class EndPortalFrameBlockOverwrite extends Block {
protected EndPortalFrameBlockOverwrite(Material material) {
super(material);
}
/**
* @author a
* @reason a
*/
@Overwrite()
public void appendCollisionBoxes(World world, BlockPos pos, BlockState state, Box box, List<Box> list, Entity entity) {
this.setBoundingBox(0.0F, 0.0F, 0.0F, 1.0F, 0.8125F, 1.0F);
super.appendCollisionBoxes(world, pos, state, box, list, entity);
this.setBoundingBox(0.3125F, 0.8125F, 0.3125F, 0.6875F, 1.0F, 0.6875F);
super.appendCollisionBoxes(world, pos, state, box, list, entity);
this.setBlockItemBounds();
}
}
@@ -1,24 +0,0 @@
package dev.u9g.minecraftdatagenerator.mixin.overwrite;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
@Mixin(ItemEntity.class)
public abstract class ItemEntityOverwrite extends Entity {
public ItemEntityOverwrite(World world) {
super(world);
}
/**
* @author a
* @reason a
*/
@Overwrite
public String getTranslationKey() {
return super.getTranslationKey();
}
}
@@ -1,28 +0,0 @@
package dev.u9g.minecraftdatagenerator.mixin.overwrite;
import net.minecraft.block.BlockState;
import net.minecraft.block.SkeletonSkullBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
@Mixin(SkeletonSkullBlock.class)
public class SkeletonSkullBlockOverwrite {
@Unique
private static Box boundingBox(BlockState state) {
return switch (state.get(SkeletonSkullBlock.FACING)) {
default -> new Box(0.25f, 0.0f, 0.25f, 0.75f, 0.5f, 0.75f);
case NORTH -> new Box(0.25f, 0.25f, 0.5f, 0.75f, 0.75f, 1.0f);
case SOUTH -> new Box(0.25f, 0.25f, 0.0f, 0.75f, 0.75f, 0.5f);
case WEST -> new Box(0.5f, 0.25f, 0.25f, 1.0f, 0.75f, 0.75f);
case EAST -> new Box(0.0f, 0.25f, 0.25f, 0.5f, 0.75f, 0.75f);
};
}
@Unique
public Box getCollisionBox(World world, BlockPos pos, BlockState state) {
return boundingBox(state);
}
}
@@ -1,153 +0,0 @@
package dev.u9g.minecraftdatagenerator.mixin.overwrite;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.StairsBlock;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import java.util.List;
import static net.minecraft.block.StairsBlock.HALF;
@Mixin(StairsBlock.class)
public abstract class StairBlockOverwrite extends Block {
protected StairBlockOverwrite(Material material) {
super(material);
}
@Shadow
public abstract void setBoundingBox(BlockView view, BlockPos pos);
@Shadow
public abstract boolean method_8911(BlockView blockView, BlockPos blockPos);
/**
* @author a
* @reason a
*/
@Overwrite
public void appendCollisionBoxes(World world, BlockPos pos, BlockState state, Box box, List<Box> list, Entity entity) {
list.add(someFuncThatIRemade(state));
super.appendCollisionBoxes(world, pos, state, box, list, entity);
EmptyBlockView bv = new EmptyBlockView() {
@Override
public BlockState getBlockState(BlockPos pos) {
return state;
}
};
boolean bl = this.method_8911(bv, pos);
list.add(this.getCollisionBox(world, pos, state));
if (bl && calculateWhichTypeOfStairThisIsButDoesntWorkBecauseWeDontHaveAdjBlocks(state)) {
list.add(this.getCollisionBox(world, pos, state));
}
this.setBoundingBox(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
}
@Unique
public Box someFuncThatIRemade(BlockState state) {
if (state.get(HALF) == StairsBlock.Half.TOP) {
return new Box(0.0f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f);
} else {
return new Box(0.0f, 0.0f, 0.0f, 1.0f, 0.5f, 1.0f);
}
}
@Unique
public boolean calculateWhichTypeOfStairThisIsButDoesntWorkBecauseWeDontHaveAdjBlocks(BlockState state) {
EmptyBlockView blockView = new EmptyBlockView() {
@Override
public BlockState getBlockState(BlockPos pos) {
return state;
}
};
BlockState blockState2;
Block block;
BlockState blockState = blockView.getBlockState(BlockPos.ORIGIN);
Direction direction = blockState.get(StairsBlock.FACING);
StairsBlock.Half half = blockState.get(HALF);
boolean bl = half == StairsBlock.Half.TOP;
float f = 0.5f;
float g = 1.0f;
if (bl) {
f = 0.0f;
g = 0.5f;
}
float h = 0.0f;
float i = 0.5f;
float j = 0.5f;
float k = 1.0f;
boolean bl2 = false;
if (direction == Direction.EAST) {
BlockState blockState22 = blockView.getBlockState(BlockPos.ORIGIN);
Block block2 = blockState22.getBlock();
if (StairsBlock.method_6513(block2) && half == blockState22.get(HALF)) {
Direction direction2 = blockState22.get(StairsBlock.FACING);
if (direction2 == Direction.NORTH && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) {
j = 0.0f;
k = 0.5f;
bl2 = true;
} else if (direction2 == Direction.SOUTH && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) {
j = 0.5f;
k = 1.0f;
bl2 = true;
}
}
} else if (direction == Direction.WEST) {
BlockState blockState23 = blockView.getBlockState(BlockPos.ORIGIN);
Block block3 = blockState23.getBlock();
if (StairsBlock.method_6513(block3) && half == blockState23.get(HALF)) {
h = 0.5f;
i = 1.0f;
Direction direction2 = blockState23.get(StairsBlock.FACING);
if (direction2 == Direction.NORTH && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) {
j = 0.0f;
k = 0.5f;
bl2 = true;
} else if (direction2 == Direction.SOUTH && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) {
j = 0.5f;
k = 1.0f;
bl2 = true;
}
}
} else if (direction == Direction.SOUTH) {
BlockState blockState24 = blockView.getBlockState(BlockPos.ORIGIN);
Block block4 = blockState24.getBlock();
if (StairsBlock.method_6513(block4) && half == blockState24.get(HALF)) {
j = 0.0f;
k = 0.5f;
Direction direction2 = blockState24.get(StairsBlock.FACING);
if (direction2 == Direction.WEST && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) {
bl2 = true;
} else if (direction2 == Direction.EAST && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) {
h = 0.5f;
i = 1.0f;
bl2 = true;
}
}
} else if (direction == Direction.NORTH && StairsBlock.method_6513(block = (blockState2 = blockView.getBlockState(BlockPos.ORIGIN)).getBlock()) && half == blockState2.get(HALF)) {
Direction direction2 = blockState2.get(StairsBlock.FACING);
if (direction2 == Direction.WEST && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) {
bl2 = true;
} else if (direction2 == Direction.EAST && !StairsBlock.method_8907(blockView, BlockPos.ORIGIN, blockState)) {
h = 0.5f;
i = 1.0f;
bl2 = true;
}
}
if (bl2) {
this.setBoundingBox(h, f, j, i, g, k);
}
return bl2;
}
}
@@ -1,9 +1,5 @@
package dev.u9g.minecraftdatagenerator.util;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
@@ -12,28 +8,11 @@ import org.jetbrains.annotations.NotNull;
public class DGU {
public static MinecraftServer getCurrentlyRunningServer() {
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
}
@Environment(EnvType.CLIENT)
private static String translateTextClient(String translationKey) {
return I18n.translate(translationKey);
}
private static String translateTextFallback(String translationKey) {
try {
return Registries.LANGUAGE.translate(translationKey);
} catch (Exception ignored) {
}
throw new RuntimeException("Failed to translate: '" + translationKey + "'");
return MinecraftServer.getServer();
}
public static String translateText(String translationKey) {
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
if (environmentType == EnvType.CLIENT) {
return translateTextClient(translationKey);
}
return translateTextFallback(translationKey);
return Registries.LANGUAGE.translate(translationKey);
}
@NotNull
+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.8.9"
"fabricloader": "*",
"minecraft": "*"
}
}
@@ -12,14 +12,7 @@
"MiningToolItemAccessor",
"NoteBlockAccessor",
"ReadyMixin",
"StatusEffectAccessor",
"overwrite.CocoaBlockOverwrite",
"overwrite.EndPortalFrameBlockOverwrite",
"overwrite.ItemEntityOverwrite",
"overwrite.SkeletonSkullBlockOverwrite",
"overwrite.StairBlockOverwrite"
],
"client": [
"StatusEffectAccessor"
],
"injectors": {
"defaultRequire": 1