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
+23 -4
View File
@@ -11,7 +11,26 @@ jobs:
build:
strategy:
matrix:
version: ["1.7", "1.8.9", "1.9.4", "1.10.2", "1.11.2", "1.12.2", "1.13", "1.14", "1.15", "1.16", "1.17", "1.18", "22w19a", "1.19", "1.19.2", "1.20", "1.20.4"]
version: [
"1.7",
"1.8.9",
"1.9.4",
"1.10.2",
"1.11.2",
"1.12.2",
"1.13",
"1.14",
"1.15",
"1.16",
"1.17",
"1.18",
"22w19a",
"1.19",
"1.19.2",
"1.20",
"1.20.4",
"1.20.5"
]
name: Build ${{ matrix.version }}
timeout-minutes: 10
@@ -25,10 +44,10 @@ jobs:
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
- name: Generate ${{ matrix.version }}
@@ -40,5 +59,5 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: data-${{ matrix.version }}
path: ${{ matrix.version }}/run/minecraft-data
path: ${{ matrix.version }}/run/server/minecraft-data
if-no-files-found: error
+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.10.2"
mappings {
legacyIntermediary()
legacyYarn(541)
devFallbackNamespace "intermediary"
}
}
loom {
setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar');
customMinecraftManifest.set("https://meta.legacyfabric.net/v2/manifest/${minecraft_version}")
runs.config("server") {
javaVersion = JavaVersion.VERSION_21
}
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.10.2
yarn_mappings=1.10.2+build.202206020145
loader_version=0.14.3
# Dependencies
# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/
@@ -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,47 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.Biome;
import java.util.Iterator;
public class BiomeColors {
private static final ColorProvider GRASS_COLOR = Biome::getGrassColor;
private static final ColorProvider FOLIAGE_COLOR = Biome::getFoliageColor;
private static final ColorProvider WATER_COLOR = (biome, pos) -> biome.getWaterColor();
private static int getColor(EmptyBlockView view, BlockPos pos, ColorProvider provider) {
int i = 0;
int j = 0;
int k = 0;
int l;
for (Iterator<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(EmptyBlockView view, BlockPos pos) {
return getColor(view, pos, GRASS_COLOR);
}
public static int getFoliageColor(EmptyBlockView view, BlockPos pos) {
return getColor(view, pos, FOLIAGE_COLOR);
}
public static int getWaterColor(EmptyBlockView view, BlockPos pos) {
return getColor(view, pos, WATER_COLOR);
}
interface ColorProvider {
int getColorAtPos(Biome biome, BlockPos pos);
}
}
@@ -1,10 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;
public interface BlockColorable {
int method_12155(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i);
}
@@ -1,96 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.FlowerPotBlockEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.util.collection.IdList;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;
public class BlockColors {
private final IdList<BlockColorable> BlockColor2Id = new IdList<>(32);
public BlockColors() {
}
public static BlockColors create() {
final BlockColors blockColors = new BlockColors();
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
DoublePlantBlock.DoublePlantType doublePlantType = blockState.get(DoublePlantBlock.VARIANT);
return blockView == null || blockPos == null || doublePlantType != DoublePlantBlock.DoublePlantType.GRASS && doublePlantType != DoublePlantBlock.DoublePlantType.FERN ? -1 : BiomeColors.getGrassColor(blockView, blockPos);
}, Blocks.DOUBLE_PLANT);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
if (blockView != null && blockPos != null) {
BlockEntity blockEntity = blockView.getBlockEntity(blockPos);
if (blockEntity instanceof FlowerPotBlockEntity) {
Item item = ((FlowerPotBlockEntity) blockEntity).getItem();
if (item instanceof BlockItem) {
BlockState blockState2 = Block.getBlockFromItem(item).getDefaultState();
return blockColors.method_12157(blockState2, blockView, blockPos, i);
}
}
}
return -1;
}, Blocks.FLOWER_POT);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : GrassColors.getColor(0.5D, 1.0D), Blocks.GRASS);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
PlanksBlock.WoodType woodType = blockState.get(Leaves1Block.VARIANT);
if (woodType == PlanksBlock.WoodType.SPRUCE) {
return FoliageColors.getSpruceColor();
} else if (woodType == PlanksBlock.WoodType.BIRCH) {
return FoliageColors.getBirchColor();
} else {
return blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor();
}
}, Blocks.LEAVES);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.LEAVES2);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getWaterColor(blockView, blockPos) : -1, Blocks.WATER, Blocks.FLOWING_WATER);
blockColors.method_12158((blockState, blockView, blockPos, i) -> RedstoneWireBlock.method_8877(blockState.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : -1, Blocks.SUGARCANE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
int j = blockState.get(AttachedStemBlock.AGE);
int k = j * 32;
int l = 255 - j * 8;
int m = j * 4;
return k << 16 | l << 8 | m;
}, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
if (blockView != null && blockPos != null) {
return BiomeColors.getGrassColor(blockView, blockPos);
} else {
return blockState.get(TallPlantBlock.TYPE) == TallPlantBlock.GrassType.DEAD_BUSH ? 16777215 : GrassColors.getColor(0.5D, 1.0D);
}
}, Blocks.TALLGRASS);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.VINE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? 2129968 : 7455580, Blocks.LILY_PAD);
return blockColors;
}
public int method_13410(BlockState blockState) {
BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
if (blockColorable != null) {
return blockColorable.method_12155(blockState, null, null, 0);
} else {
MaterialColor materialColor = blockState.getMaterialColor();
return materialColor != null ? materialColor.color : -1;
}
}
public int method_12157(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i) {
BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
return blockColorable == null ? -1 : blockColorable.method_12155(blockState, blockView, blockPos, i);
}
public void method_12158(BlockColorable blockColorable, Block... blocks) {
int i = blocks.length;
for (Block block : blocks) {
this.BlockColor2Id.set(blockColorable, Block.getIdByBlock(block));
}
}
}
@@ -1,37 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
public class FoliageColors {
private static int[] colorMap = new int[65536];
public static void setColorMap(int[] pixels) {
colorMap = pixels;
}
public static int getColor(double temperature, double humidity) {
humidity *= temperature;
int i = (int) ((1.0D - temperature) * 255.0D);
int j = (int) ((1.0D - humidity) * 255.0D);
return colorMap[j << 8 | i];
}
public static int getSpruceColor() {
return 6396257;
}
public static int getBirchColor() {
return 8431445;
}
public static int getDefaultColor() {
return 4764952;
}
public static int getFoliageColor(Biome biome) {
double d = MathHelper.clamp(biome.getTemperature(), 0.0F, 1.0F);
double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
return FoliageColors.getColor(d, e);
}
}
@@ -1,29 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
public class GrassColors {
private static int[] colorMap = new int[65536];
public static void setColorMap(int[] map) {
colorMap = map;
}
public static int getColor(double temperature, double humidity) {
humidity *= temperature;
int i = (int) ((1.0D - temperature) * 255.0D);
int j = (int) ((1.0D - humidity) * 255.0D);
int k = j << 8 | i;
return k > colorMap.length ? -65281 : colorMap[k];
}
public static int getGrassColor(Biome biome) {
double d = MathHelper.clamp(biome.getTemperature(), 0.0F, 1.0F);
double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
return GrassColors.getColor(d, e);
}
}
@@ -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;
}
}
@@ -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;
@@ -28,12 +27,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.logging.Logger;
public class BlocksDataGenerator implements IDataGenerator {
private static final Logger logger = Main.LOGGER;
private static List<Item> getItemsEffectiveForBlock(Block block) {
List<Item> items = new ArrayList<>();
for (Item item : Registries.ITEMS) {
@@ -1,81 +0,0 @@
package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonElement;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonWriter;
import dev.u9g.minecraftdatagenerator.Main;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DataGenerators {
private static final List<IDataGenerator> GENERATORS = new ArrayList<>();
private static final Logger logger = Main.LOGGER;
static {
register(new BiomesDataGenerator());
register(new BlockCollisionShapesDataGenerator());
register(new BlocksDataGenerator());
register(new EffectsDataGenerator());
register(new EnchantmentsDataGenerator());
register(new EntitiesDataGenerator());
register(new FoodsDataGenerator());
register(new ItemsDataGenerator());
register(new ParticlesDataGenerator());
register(new TintsDataGenerator());
register(new LanguageDataGenerator());
register(new InstrumentsDataGenerator());
register(new AttributesDataGenerator());
register(new SoundsDataGenerator());
}
public static void register(IDataGenerator generator) {
GENERATORS.add(generator);
}
public static boolean runDataGenerators(Path outputDirectory) {
try {
Files.createDirectories(outputDirectory);
} catch (IOException exception) {
logger.info("Failed to create data generator output directory at " + outputDirectory);
exception.printStackTrace();
return false;
}
int generatorsFailed = 0;
logger.info(MessageFormat.format("Running minecraft data generators, output at {0}", outputDirectory));
for (IDataGenerator dataGenerator : GENERATORS) {
logger.info(MessageFormat.format("Running generator {0}", dataGenerator.getDataName()));
try {
String outputFileName = String.format("%s.json", dataGenerator.getDataName());
JsonElement outputElement = dataGenerator.generateDataJson();
Path outputFilePath = outputDirectory.resolve(outputFileName);
try (Writer writer = Files.newBufferedWriter(outputFilePath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
JsonWriter jsonWriter = new JsonWriter(writer);
jsonWriter.setIndent(" ");
Streams.write(outputElement, jsonWriter);
}
logger.info(MessageFormat.format("Generator: {0} -> {1}", dataGenerator.getDataName(), outputFileName));
} catch (Throwable exception) {
logger.info(MessageFormat.format("Failed to run data generator {0}", dataGenerator.getDataName()));
exception.printStackTrace();
generatorsFailed++;
}
}
logger.info("Finishing running data generators");
return generatorsFailed == 0;
}
}
@@ -16,7 +16,6 @@ import java.util.Objects;
import java.util.stream.Collectors;
public class EffectsDataGenerator implements IDataGenerator {
public static JsonObject generateEffect(StatusEffect statusEffect) {
JsonObject effectDesc = new JsonObject();
@NotNull Identifier registryKey = Objects.requireNonNull(Registries.STATUS_EFFECTS.getIdentifier(statusEffect));
@@ -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);
@@ -4,8 +4,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.mixin.NoteBlockAccessor;
import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.sound.Sound;
import java.util.Objects;
@@ -19,10 +18,10 @@ public class InstrumentsDataGenerator implements IDataGenerator {
public JsonElement generateDataJson() {
JsonArray array = new JsonArray();
int i = 0;
for (SoundEvent sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) {
for (Sound sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) {
JsonObject object = new JsonObject();
object.addProperty("id", i++);
object.addProperty("name", ((SoundAccessor) sound).id().getPath().split("\\.")[2]);
object.addProperty("name", sound.getId().getPath().split("\\.")[2]);
array.add(object);
}
return array;
@@ -5,7 +5,6 @@ import com.google.gson.JsonObject;
import net.minecraft.client.particle.ParticleType;
public class ParticlesDataGenerator implements IDataGenerator {
public static JsonObject generateParticleType(int id, ParticleType particleType) {
JsonObject effectDesc = new JsonObject();
@@ -112,6 +112,11 @@ public class RecipeDataGenerator implements IDataGenerator {
// return finalObj;
return JsonNull.INSTANCE;
}
@Override
public boolean isEnabled() {
return false; // TODO: Implement this
}
//
// private static int getRawIdFor (Item item) {
// return Registry.ITEM.getRawId(item);
@@ -2,17 +2,14 @@ package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.sound.Sound;
public class SoundsDataGenerator implements IDataGenerator {
public static JsonObject generateSound(SoundEvent soundEvent) {
public static JsonObject generateSound(Sound soundEvent) {
JsonObject soundDesc = new JsonObject();
soundDesc.addProperty("id", SoundEvent.REGISTRY.getRawId(soundEvent));
soundDesc.addProperty("name", ((SoundAccessor) soundEvent).id().getPath());
soundDesc.addProperty("id", Sound.REGISTRY.getRawId(soundEvent));
soundDesc.addProperty("name", soundEvent.getId().getPath());
return soundDesc;
}
@@ -25,7 +22,7 @@ public class SoundsDataGenerator implements IDataGenerator {
@Override
public JsonArray generateDataJson() {
JsonArray resultsArray = new JsonArray();
SoundEvent.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound)));
Sound.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound)));
return resultsArray;
}
}
@@ -3,38 +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.BlockColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.GrassColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock;
import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import dev.u9g.minecraftdatagenerator.util.Registries;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.client.BlockColors;
import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.client.color.world.GrassColors;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
import java.util.*;
public class TintsDataGenerator implements IDataGenerator {
private static final BlockColors blockColors = BlockColors.create();
public static BiomeTintColors generateBiomeTintColors() {
BiomeTintColors colors = new BiomeTintColors();
for (Biome biome : Registries.BIOMES) {
EmptyBlockView bv = new EmptyBlockView() {
@Override
public Biome getBiome(BlockPos pos) {
return biome;
}
};
int biomeGrassColor = GrassColors.getGrassColor(bv.getBiome(BlockPos.ORIGIN));
int biomeFoliageColor = FoliageColors.getFoliageColor(bv.getBiome(BlockPos.ORIGIN));
double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f);
double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f);
int biomeGrassColor = GrassColors.getColor(d, e);
int biomeFoliageColor = FoliageColors.getColor(d, e);
int biomeWaterColor = ((BiomeAccessor) biome).waterColor();
colors.grassColoursMap.computeIfAbsent(biomeGrassColor, k -> new ArrayList<>()).add(biome);
@@ -45,30 +37,29 @@ public class TintsDataGenerator implements IDataGenerator {
}
public static Map<Integer, Integer> generateRedstoneTintColors() {
Map<Integer, Integer> resultColors = new HashMap<>();
Map<Integer, Integer> resultColors = new LinkedHashMap<>();
for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) {
int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel);
int color = RedstoneWireBlock.getColorIntensity(redstoneLevel);
resultColors.put(redstoneLevel, color);
}
return resultColors;
}
private static int getBlockColor(Block block) {
return blockColors.method_13410(block.getDefaultState());
return BlockColors.create().method_13410(block.getDefaultState());
}
public static Map<Block, Integer> generateConstantTintColors() {
Map<Block, Integer> resultColors = new HashMap<>();
BlockColors blockColors = BlockColors.create();
Map<Block, Integer> resultColors = new LinkedHashMap<>();
// FIXME: ?
// resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor());
// resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor());
resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD));
// FIXME: ?
// resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM, blockColors));
// resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM, blockColors));
// resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM));
// resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM));
//not really constant, depend on the block age, but kinda have to be handled since textures are literally white without them
resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM));
@@ -158,8 +149,8 @@ public class TintsDataGenerator implements IDataGenerator {
}
public static class BiomeTintColors {
final Map<Integer, List<Biome>> grassColoursMap = new HashMap<>();
final Map<Integer, List<Biome>> foliageColoursMap = new HashMap<>();
final Map<Integer, List<Biome>> waterColourMap = new HashMap<>();
final Map<Integer, List<Biome>> grassColoursMap = new LinkedHashMap<>();
final Map<Integer, List<Biome>> foliageColoursMap = new LinkedHashMap<>();
final Map<Integer, List<Biome>> waterColourMap = new LinkedHashMap<>();
}
}
@@ -1,7 +1,7 @@
package dev.u9g.minecraftdatagenerator.mixin;
import net.minecraft.block.NoteBlock;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.sound.Sound;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@@ -10,7 +10,7 @@ import java.util.List;
@Mixin(NoteBlock.class)
public interface NoteBlockAccessor {
@Accessor("TUNES")
static List<SoundEvent> TUNES() {
static List<Sound> TUNES() {
return null;
}
}
@@ -1,7 +1,6 @@
package dev.u9g.minecraftdatagenerator.mixin;
import dev.u9g.minecraftdatagenerator.Main;
import dev.u9g.minecraftdatagenerator.generators.DataGenerators;
import dev.u9g.minecraftdatagenerator.MinecraftDataGenerator;
import dev.u9g.minecraftdatagenerator.util.DGU;
import net.minecraft.server.dedicated.MinecraftDedicatedServer;
import org.spongepowered.asm.mixin.Mixin;
@@ -9,19 +8,13 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.nio.file.Path;
import java.util.logging.Level;
@Mixin(MinecraftDedicatedServer.class)
public class ReadyMixin {
@Inject(method = "setupServer()Z", at = @At("TAIL"))
private void init(CallbackInfoReturnable<Boolean> cir) {
Main.LOGGER.info("Starting data generation!");
String versionName = DGU.getCurrentlyRunningServer().getVersion();
Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath();
Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName);
DataGenerators.runDataGenerators(dataDumpDirectory);
Main.LOGGER.info("Done data generation!");
Runtime.getRuntime().halt(0);
MinecraftDataGenerator.start(
DGU.getCurrentlyRunningServer().getVersion(),
DGU.getCurrentlyRunningServer().getRunDirectory().toPath()
);
}
}
@@ -1,12 +0,0 @@
package dev.u9g.minecraftdatagenerator.mixin;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(SoundEvent.class)
public interface SoundAccessor {
@Accessor("id")
Identifier id();
}
@@ -1,82 +1,20 @@
package dev.u9g.minecraftdatagenerator.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.internal.bind.TypeAdapters;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class DGU {
public static Gson gson = new GsonBuilder().registerTypeAdapterFactory(TypeAdapters.newFactory(double.class, Double.class, new TypeAdapter<Number>() {
@Override
public Number read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return in.nextDouble();
}
@Override
public void write(JsonWriter out, Number value) throws IOException {
out.value(value);
}
})).create();
@Environment(EnvType.CLIENT)
private static MinecraftServer getCurrentlyRunningServerClient() {
return MinecraftClient.getInstance().getServer();
}
@SuppressWarnings("deprecation")
private static MinecraftServer getCurrentlyRunningServerDedicated() {
public static MinecraftServer getCurrentlyRunningServer() {
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
}
public static MinecraftServer getCurrentlyRunningServer() {
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
if (environmentType == EnvType.CLIENT) {
return getCurrentlyRunningServerClient();
} else if (environmentType == EnvType.SERVER) {
return getCurrentlyRunningServerDedicated();
}
throw new UnsupportedOperationException();
}
@Environment(EnvType.CLIENT)
private static String translateTextClient(String translationKey) {
return I18n.translate(translationKey);
}
private static String translateTextFallback(String translationKey) {
try {
return Registries.LANGUAGE.translate(translationKey);
} catch (Exception ignored) {
}
throw new RuntimeException("Failed to translate: '" + translationKey + "'");
}
public static String translateText(String translationKey) {
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
if (environmentType == EnvType.CLIENT) {
return translateTextClient(translationKey);
}
return translateTextFallback(translationKey);
return Registries.LANGUAGE.translate(translationKey);
}
@NotNull
+2 -8
View File
@@ -10,17 +10,11 @@
],
"contact": {},
"license": "MIT",
"environment": "server",
"entrypoints": {
"main": [
"dev.u9g.minecraftdatagenerator.Main"
]
},
"mixins": [
"minecraft-data-generator.mixins.json"
],
"depends": {
"fabricloader": ">=0.13.3",
"minecraft": ">=1.10"
"fabricloader": "*",
"minecraft": "*"
}
}
@@ -14,11 +14,8 @@
"MiningToolItemAccessor",
"NoteBlockAccessor",
"ReadyMixin",
"SoundAccessor",
"StatusEffectAccessor"
],
"client": [
],
"injectors": {
"defaultRequire": 1
},
+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.11.2"
mappings {
legacyIntermediary()
legacyYarn(541)
devFallbackNamespace "intermediary"
}
}
loom {
setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar');
customMinecraftManifest.set("https://meta.legacyfabric.net/v2/manifest/${minecraft_version}")
runs.config("server") {
javaVersion = JavaVersion.VERSION_21
}
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.11.2
yarn_mappings=1.11.2+build.202206020145
loader_version=0.14.3
# Dependencies
# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/
@@ -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,55 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
import java.util.Iterator;
public class BiomeColors {
private static final ColorProvider GRASS_COLOR = (biome, pos) -> {
double d = MathHelper.clamp(biome.getTemperature(pos), 0.0F, 1.0F);
double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
return GrassColors.getColor(d, e);
};
private static final ColorProvider FOLIAGE_COLOR = (biome, pos) -> {
double d = MathHelper.clamp(biome.getTemperature(pos), 0.0F, 1.0F);
double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
return FoliageColors.getColor(d, e);
};
private static final ColorProvider WATER_COLOR = (biome, pos) -> biome.getWaterColor();
private static int getColor(EmptyBlockView view, BlockPos pos, ColorProvider provider) {
int i = 0;
int j = 0;
int k = 0;
int l;
for (Iterator<BlockPos.Mutable> var6 = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); var6.hasNext(); k += l & 255) {
BlockPos.Mutable mutable = (BlockPos.Mutable) var6.next();
l = provider.getColorAtPos(view.getBiome(mutable), mutable);
i += (l & 16711680) >> 16;
j += (l & '\uff00') >> 8;
}
return (i / 9 & 255) << 16 | (j / 9 & 255) << 8 | k / 9 & 255;
}
public static int getGrassColor(EmptyBlockView view, BlockPos pos) {
return getColor(view, pos, GRASS_COLOR);
}
public static int getFoliageColor(EmptyBlockView view, BlockPos pos) {
return getColor(view, pos, FOLIAGE_COLOR);
}
public static int getWaterColor(EmptyBlockView view, BlockPos pos) {
return getColor(view, pos, WATER_COLOR);
}
interface ColorProvider {
int getColorAtPos(Biome biome, BlockPos pos);
}
}
@@ -1,10 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;
public interface BlockColorable {
int method_12155(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i);
}
@@ -1,95 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.FlowerPotBlockEntity;
import net.minecraft.item.Item;
import net.minecraft.util.collection.IdList;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;
public class BlockColors {
private final IdList<BlockColorable> BlockColor2Id = new IdList<>(32);
public BlockColors() {
}
public static BlockColors create() {
final BlockColors blockColors = new BlockColors();
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
DoublePlantBlock.DoublePlantType doublePlantType = blockState.get(DoublePlantBlock.VARIANT);
return blockView != null && blockPos != null && (doublePlantType == DoublePlantBlock.DoublePlantType.GRASS || doublePlantType == DoublePlantBlock.DoublePlantType.FERN) ? BiomeColors.getGrassColor(blockView, blockState.get(DoublePlantBlock.HALF) == DoublePlantBlock.HalfType.UPPER ? blockPos.down() : blockPos) : -1;
}, Blocks.DOUBLE_PLANT);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
if (blockView != null && blockPos != null) {
BlockEntity blockEntity = blockView.getBlockEntity(blockPos);
if (blockEntity instanceof FlowerPotBlockEntity) {
Item item = ((FlowerPotBlockEntity) blockEntity).getItem();
BlockState blockState2 = Block.getBlockFromItem(item).getDefaultState();
return blockColors.method_12157(blockState2, blockView, blockPos, i);
} else {
return -1;
}
} else {
return -1;
}
}, Blocks.FLOWER_POT);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : GrassColors.getColor(0.5D, 1.0D), Blocks.GRASS);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
PlanksBlock.WoodType woodType = blockState.get(Leaves1Block.VARIANT);
if (woodType == PlanksBlock.WoodType.SPRUCE) {
return net.minecraft.client.color.world.FoliageColors.getSpruceColor();
} else if (woodType == PlanksBlock.WoodType.BIRCH) {
return net.minecraft.client.color.world.FoliageColors.getBirchColor();
} else {
return blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor();
}
}, Blocks.LEAVES);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.LEAVES2);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getWaterColor(blockView, blockPos) : -1, Blocks.WATER, Blocks.FLOWING_WATER);
blockColors.method_12158((blockState, blockView, blockPos, i) -> RedstoneWireBlock.method_8877(blockState.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : -1, Blocks.SUGARCANE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
int j = blockState.get(AttachedStemBlock.AGE);
int k = j * 32;
int l = 255 - j * 8;
int m = j * 4;
return k << 16 | l << 8 | m;
}, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
if (blockView != null && blockPos != null) {
return BiomeColors.getGrassColor(blockView, blockPos);
} else {
return blockState.get(TallPlantBlock.TYPE) == TallPlantBlock.GrassType.DEAD_BUSH ? 16777215 : GrassColors.getColor(0.5D, 1.0D);
}
}, Blocks.TALLGRASS);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.VINE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? 2129968 : 7455580, Blocks.LILY_PAD);
return blockColors;
}
public int method_13410(BlockState blockState) {
BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
if (blockColorable != null) {
return blockColorable.method_12155(blockState, null, null, 0);
} else {
MaterialColor materialColor = blockState.getMaterialColor();
return materialColor != null ? materialColor.color : -1;
}
}
public int method_12157(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i) {
BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
return blockColorable == null ? -1 : blockColorable.method_12155(blockState, blockView, blockPos, i);
}
public void method_12158(BlockColorable blockColorable, Block... blocks) {
int var4 = blocks.length;
for (Block block : blocks) {
this.BlockColor2Id.set(blockColorable, Block.getIdByBlock(block));
}
}
}
@@ -1,28 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
public class FoliageColors {
private static int[] colorMap = new int[65536];
public static void setColorMap(int[] pixels) {
colorMap = pixels;
}
public static int getColor(double temperature, double humidity) {
humidity *= temperature;
int i = (int) ((1.0D - temperature) * 255.0D);
int j = (int) ((1.0D - humidity) * 255.0D);
return colorMap[j << 8 | i];
}
public static int getSpruceColor() {
return 6396257;
}
public static int getBirchColor() {
return 8431445;
}
public static int getDefaultColor() {
return 4764952;
}
}
@@ -1,19 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
public class GrassColors {
private static int[] colorMap = new int[65536];
public static void setColorMap(int[] map) {
colorMap = map;
}
public static int getColor(double temperature, double humidity) {
humidity *= temperature;
int i = (int) ((1.0D - temperature) * 255.0D);
int j = (int) ((1.0D - humidity) * 255.0D);
int k = j << 8 | i;
return k > colorMap.length ? -65281 : colorMap[k];
}
}
@@ -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;
}
}
@@ -1,74 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
public class SkyColor {
public static int getSkyColor(Biome biome) {
return realSkyColor(biome.getTemperature());
}
private static int realSkyColor(float temperature) {
temperature /= 3.0F;
temperature = MathHelper.clamp(temperature, -1.0F, 1.0F);
return hsvToRgb(0.62222224F - temperature * 0.05F, 0.5F + temperature * 0.1F, 1.0F);
}
public static int hsvToRgb(float hue, float saturation, float value) {
int i = (int) (hue * 6.0F) % 6;
float f = hue * 6.0F - (float) i;
float g = value * (1.0F - saturation);
float h = value * (1.0F - f * saturation);
float j = value * (1.0F - (1.0F - f) * saturation);
float k;
float l;
float m;
switch (i) {
case 0:
k = value;
l = j;
m = g;
break;
case 1:
k = h;
l = value;
m = g;
break;
case 2:
k = g;
l = value;
m = j;
break;
case 3:
k = g;
l = h;
m = value;
break;
case 4:
k = j;
l = g;
m = value;
break;
case 5:
k = value;
l = g;
m = h;
break;
default:
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + ", " + value);
}
int n = clamp((int) (k * 255.0F), 0, 255);
int o = clamp((int) (l * 255.0F), 0, 255);
int p = clamp((int) (m * 255.0F), 0, 255);
return n << 16 | o << 8 | p;
}
public static int clamp(int value, int min, int max) {
if (value < min) {
return min;
} else {
return Math.min(value, max);
}
}
}
@@ -2,7 +2,6 @@ package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.SkyColor;
import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.SimpleRegistry;
@@ -23,7 +22,6 @@ public class BiomesDataGenerator implements IDataGenerator {
public static JsonObject generateBiomeInfo(SimpleRegistry<Identifier, Biome> registry, Biome biome) {
JsonObject biomeDesc = new JsonObject();
Identifier registryKey = registry.getIdentifier(biome);
biomeDesc.addProperty("id", registry.getRawId(biome));
biomeDesc.addProperty("name", String.join("_", ((BiomeAccessor) biome).name().toLowerCase(Locale.ENGLISH).split(" ")));
@@ -33,7 +31,7 @@ public class BiomesDataGenerator implements IDataGenerator {
biomeDesc.addProperty("depth", biome.getDepth());
biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome));
biomeDesc.addProperty("displayName", ((BiomeAccessor) biome).name());
biomeDesc.addProperty("color", SkyColor.getSkyColor(biome));
biomeDesc.addProperty("color", biome.getSkyColor(biome.getTemperature()));
biomeDesc.addProperty("rainfall", biome.getRainfall());
return biomeDesc;
@@ -6,11 +6,14 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import dev.u9g.minecraftdatagenerator.util.DGU;
import dev.u9g.minecraftdatagenerator.util.Registries;
import net.minecraft.block.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class BlockCollisionShapesDataGenerator implements IDataGenerator {
private static final Box ENTITY_BOX = new Box(0.0D, 0.0D, 0.0D, 1.0D, 2.0D, 1.0D);
@@ -76,7 +79,7 @@ public 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)));
@@ -96,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;
@@ -28,12 +27,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.logging.Logger;
public class BlocksDataGenerator implements IDataGenerator {
private static final Logger logger = Main.LOGGER;
private static List<Item> getItemsEffectiveForBlock(Block block) {
List<Item> items = new ArrayList<>();
for (Item item : Registries.ITEMS) {
@@ -1,81 +0,0 @@
package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonElement;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonWriter;
import dev.u9g.minecraftdatagenerator.Main;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DataGenerators {
private static final List<IDataGenerator> GENERATORS = new ArrayList<>();
private static final Logger logger = Main.LOGGER;
static {
register(new BiomesDataGenerator());
register(new BlockCollisionShapesDataGenerator());
register(new BlocksDataGenerator());
register(new EffectsDataGenerator());
register(new EnchantmentsDataGenerator());
register(new EntitiesDataGenerator());
register(new FoodsDataGenerator());
register(new ItemsDataGenerator());
register(new ParticlesDataGenerator());
register(new TintsDataGenerator());
register(new LanguageDataGenerator());
register(new InstrumentsDataGenerator());
register(new AttributesDataGenerator());
register(new SoundsDataGenerator());
}
public static void register(IDataGenerator generator) {
GENERATORS.add(generator);
}
public static boolean runDataGenerators(Path outputDirectory) {
try {
Files.createDirectories(outputDirectory);
} catch (IOException exception) {
logger.info("Failed to create data generator output directory at " + outputDirectory);
exception.printStackTrace();
return false;
}
int generatorsFailed = 0;
logger.info(MessageFormat.format("Running minecraft data generators, output at {0}", outputDirectory));
for (IDataGenerator dataGenerator : GENERATORS) {
logger.info(MessageFormat.format("Running generator {0}", dataGenerator.getDataName()));
try {
String outputFileName = String.format("%s.json", dataGenerator.getDataName());
JsonElement outputElement = dataGenerator.generateDataJson();
Path outputFilePath = outputDirectory.resolve(outputFileName);
try (Writer writer = Files.newBufferedWriter(outputFilePath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
JsonWriter jsonWriter = new JsonWriter(writer);
jsonWriter.setIndent(" ");
Streams.write(outputElement, jsonWriter);
}
logger.info(MessageFormat.format("Generator: {0} -> {1}", dataGenerator.getDataName(), outputFileName));
} catch (Throwable exception) {
logger.info(MessageFormat.format("Failed to run data generator {0}", dataGenerator.getDataName()));
exception.printStackTrace();
generatorsFailed++;
}
}
logger.info("Finishing running data generators");
return generatorsFailed == 0;
}
}
@@ -16,7 +16,6 @@ import java.util.Objects;
import java.util.stream.Collectors;
public class EffectsDataGenerator implements IDataGenerator {
public static JsonObject generateEffect(StatusEffect statusEffect) {
JsonObject effectDesc = new JsonObject();
@NotNull Identifier registryKey = Objects.requireNonNull(Registries.STATUS_EFFECTS.getIdentifier(statusEffect));
@@ -6,10 +6,14 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import dev.u9g.minecraftdatagenerator.util.DGU;
import dev.u9g.minecraftdatagenerator.util.Registries;
import net.minecraft.enchantment.*;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.util.Identifier;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
public class EnchantmentsDataGenerator implements IDataGenerator {
@@ -4,8 +4,14 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.util.DGU;
import dev.u9g.minecraftdatagenerator.util.Registries;
import net.minecraft.entity.*;
import net.minecraft.entity.mob.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.AmbientEntity;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.mob.WaterCreatureEntity;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.PassiveEntity;
import net.minecraft.entity.player.PlayerEntity;
@@ -18,7 +24,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public class EntitiesDataGenerator implements IDataGenerator {
public static JsonObject generateEntity(Class<? extends Entity> entityClass) {
JsonObject entityDesc = new JsonObject();
Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass);
@@ -11,7 +11,6 @@ import net.minecraft.util.Identifier;
import java.util.Objects;
public class FoodsDataGenerator implements IDataGenerator {
public static JsonObject generateFoodDescriptor(FoodItem foodItem) {
JsonObject foodDesc = new JsonObject();
Identifier registryKey = Registries.ITEMS.getIdentifier(foodItem);
@@ -1,10 +0,0 @@
package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonElement;
public interface IDataGenerator {
String getDataName();
JsonElement generateDataJson();
}
@@ -4,8 +4,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.mixin.NoteBlockAccessor;
import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.sound.Sound;
import java.util.Objects;
@@ -19,10 +18,10 @@ public class InstrumentsDataGenerator implements IDataGenerator {
public JsonElement generateDataJson() {
JsonArray array = new JsonArray();
int i = 0;
for (SoundEvent sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) {
for (Sound sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) {
JsonObject object = new JsonObject();
object.addProperty("id", i++);
object.addProperty("name", ((SoundAccessor) sound).id().getPath().split("\\.")[2]);
object.addProperty("name", sound.getId().getPath().split("\\.")[2]);
array.add(object);
}
return array;
@@ -5,7 +5,6 @@ import com.google.gson.JsonObject;
import net.minecraft.client.particle.ParticleType;
public class ParticlesDataGenerator implements IDataGenerator {
public static JsonObject generateParticleType(int id, ParticleType particleType) {
JsonObject effectDesc = new JsonObject();
@@ -112,6 +112,11 @@ public class RecipeDataGenerator implements IDataGenerator {
// return finalObj;
return JsonNull.INSTANCE;
}
@Override
public boolean isEnabled() {
return false; // TODO: Implement this
}
//
// private static int getRawIdFor (Item item) {
// return Registry.ITEM.getRawId(item);
@@ -2,17 +2,14 @@ package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.sound.Sound;
public class SoundsDataGenerator implements IDataGenerator {
public static JsonObject generateSound(SoundEvent soundEvent) {
public static JsonObject generateSound(Sound soundEvent) {
JsonObject soundDesc = new JsonObject();
soundDesc.addProperty("id", SoundEvent.REGISTRY.getRawId(soundEvent));
soundDesc.addProperty("name", ((SoundAccessor) soundEvent).id().getPath());
soundDesc.addProperty("id", Sound.REGISTRY.getRawId(soundEvent));
soundDesc.addProperty("name", soundEvent.getId().getPath());
return soundDesc;
}
@@ -25,7 +22,7 @@ public class SoundsDataGenerator implements IDataGenerator {
@Override
public JsonArray generateDataJson() {
JsonArray resultsArray = new JsonArray();
SoundEvent.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound)));
Sound.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound)));
return resultsArray;
}
}
@@ -3,37 +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.BiomeColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.BlockColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock;
import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import dev.u9g.minecraftdatagenerator.util.Registries;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.client.BlockColors;
import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.client.color.world.GrassColors;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
import java.util.*;
public class TintsDataGenerator implements IDataGenerator {
private static final BlockColors blockColors = BlockColors.create();
public static BiomeTintColors generateBiomeTintColors() {
BiomeTintColors colors = new BiomeTintColors();
for (Biome biome : Registries.BIOMES) {
EmptyBlockView bv = new EmptyBlockView() {
@Override
public Biome getBiome(BlockPos pos) {
return biome;
}
};
int biomeGrassColor = BiomeColors.getGrassColor(bv, BlockPos.ORIGIN);
int biomeFoliageColor = BiomeColors.getFoliageColor(bv, BlockPos.ORIGIN);
double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f);
double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f);
int biomeGrassColor = GrassColors.getColor(d, e);
int biomeFoliageColor = FoliageColors.getColor(d, e);
int biomeWaterColor = ((BiomeAccessor) biome).waterColor();
colors.grassColoursMap.computeIfAbsent(biomeGrassColor, k -> new ArrayList<>()).add(biome);
@@ -44,30 +37,29 @@ public class TintsDataGenerator implements IDataGenerator {
}
public static Map<Integer, Integer> generateRedstoneTintColors() {
Map<Integer, Integer> resultColors = new HashMap<>();
Map<Integer, Integer> resultColors = new LinkedHashMap<>();
for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) {
int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel);
int color = RedstoneWireBlock.getColorIntensity(redstoneLevel);
resultColors.put(redstoneLevel, color);
}
return resultColors;
}
private static int getBlockColor(Block block) {
return blockColors.method_13410(block.getDefaultState());
return BlockColors.create().method_13410(block.getDefaultState());
}
public static Map<Block, Integer> generateConstantTintColors() {
Map<Block, Integer> resultColors = new HashMap<>();
BlockColors blockColors = BlockColors.create();
Map<Block, Integer> resultColors = new LinkedHashMap<>();
// FIXME: ?
// resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor());
// resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor());
resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD));
// FIXME: ?
// resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM, blockColors));
// resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM, blockColors));
// resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM));
// resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM));
//not really constant, depend on the block age, but kinda have to be handled since textures are literally white without them
resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM));
@@ -157,8 +149,8 @@ public class TintsDataGenerator implements IDataGenerator {
}
public static class BiomeTintColors {
final Map<Integer, List<Biome>> grassColoursMap = new HashMap<>();
final Map<Integer, List<Biome>> foliageColoursMap = new HashMap<>();
final Map<Integer, List<Biome>> waterColourMap = new HashMap<>();
final Map<Integer, List<Biome>> grassColoursMap = new LinkedHashMap<>();
final Map<Integer, List<Biome>> foliageColoursMap = new LinkedHashMap<>();
final Map<Integer, List<Biome>> waterColourMap = new LinkedHashMap<>();
}
}
@@ -1,7 +1,7 @@
package dev.u9g.minecraftdatagenerator.mixin;
import net.minecraft.block.NoteBlock;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.sound.Sound;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@@ -10,7 +10,7 @@ import java.util.List;
@Mixin(NoteBlock.class)
public interface NoteBlockAccessor {
@Accessor("TUNES")
static List<SoundEvent> TUNES() {
static List<Sound> TUNES() {
return null;
}
}
@@ -1,7 +1,6 @@
package dev.u9g.minecraftdatagenerator.mixin;
import dev.u9g.minecraftdatagenerator.Main;
import dev.u9g.minecraftdatagenerator.generators.DataGenerators;
import dev.u9g.minecraftdatagenerator.MinecraftDataGenerator;
import dev.u9g.minecraftdatagenerator.util.DGU;
import net.minecraft.server.dedicated.MinecraftDedicatedServer;
import org.spongepowered.asm.mixin.Mixin;
@@ -9,19 +8,13 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.nio.file.Path;
import java.util.logging.Level;
@Mixin(MinecraftDedicatedServer.class)
public class ReadyMixin {
@Inject(method = "setupServer()Z", at = @At("TAIL"))
private void init(CallbackInfoReturnable<Boolean> cir) {
Main.LOGGER.info("Starting data generation!");
String versionName = DGU.getCurrentlyRunningServer().getVersion();
Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath();
Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName);
DataGenerators.runDataGenerators(dataDumpDirectory);
Main.LOGGER.info("Done data generation!");
Runtime.getRuntime().halt(0);
MinecraftDataGenerator.start(
DGU.getCurrentlyRunningServer().getVersion(),
DGU.getCurrentlyRunningServer().getRunDirectory().toPath()
);
}
}
@@ -1,12 +0,0 @@
package dev.u9g.minecraftdatagenerator.mixin;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(SoundEvent.class)
public interface SoundAccessor {
@Accessor("id")
Identifier id();
}
@@ -1,82 +1,20 @@
package dev.u9g.minecraftdatagenerator.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.internal.bind.TypeAdapters;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class DGU {
public static Gson gson = new GsonBuilder().registerTypeAdapterFactory(TypeAdapters.newFactory(double.class, Double.class, new TypeAdapter<Number>() {
@Override
public Number read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return in.nextDouble();
}
@Override
public void write(JsonWriter out, Number value) throws IOException {
out.value(value);
}
})).create();
@Environment(EnvType.CLIENT)
private static MinecraftServer getCurrentlyRunningServerClient() {
return MinecraftClient.getInstance().getServer();
}
@SuppressWarnings("deprecation")
private static MinecraftServer getCurrentlyRunningServerDedicated() {
public static MinecraftServer getCurrentlyRunningServer() {
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
}
public static MinecraftServer getCurrentlyRunningServer() {
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
if (environmentType == EnvType.CLIENT) {
return getCurrentlyRunningServerClient();
} else if (environmentType == EnvType.SERVER) {
return getCurrentlyRunningServerDedicated();
}
throw new UnsupportedOperationException();
}
@Environment(EnvType.CLIENT)
private static String translateTextClient(String translationKey) {
return I18n.translate(translationKey);
}
private static String translateTextFallback(String translationKey) {
try {
return Registries.LANGUAGE.translate(translationKey);
} catch (Exception ignored) {
}
throw new RuntimeException("Failed to translate: '" + translationKey + "'");
}
public static String translateText(String translationKey) {
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
if (environmentType == EnvType.CLIENT) {
return translateTextClient(translationKey);
}
return translateTextFallback(translationKey);
return Registries.LANGUAGE.translate(translationKey);
}
@NotNull
+2 -8
View File
@@ -10,17 +10,11 @@
],
"contact": {},
"license": "MIT",
"environment": "server",
"entrypoints": {
"main": [
"dev.u9g.minecraftdatagenerator.Main"
]
},
"mixins": [
"minecraft-data-generator.mixins.json"
],
"depends": {
"fabricloader": ">=0.13.3",
"minecraft": ">=1.11"
"fabricloader": "*",
"minecraft": "*"
}
}
@@ -12,11 +12,8 @@
"MiningToolItemAccessor",
"NoteBlockAccessor",
"ReadyMixin",
"SoundAccessor",
"StatusEffectAccessor"
],
"client": [
],
"injectors": {
"defaultRequire": 1
},
+26 -42
View File
@@ -1,47 +1,33 @@
import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask
import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider
plugins {
id 'fabric-loom'
id 'xyz.wagyourtail.unimined'
}
repositories {
maven {
name = "legacy-fabric"
url = "https://maven.legacyfabric.net"
unimined.minecraft {
version "1.12.2"
mappings {
legacyIntermediary()
legacyYarn(541)
devFallbackNamespace "intermediary"
}
}
loom {
setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar');
customMinecraftManifest.set("https://meta.legacyfabric.net/v2/manifest/${minecraft_version}")
runs.config("server") {
javaVersion = JavaVersion.VERSION_21
}
customPatcher(new CustomLegacyFabricMinecraftTransformer(project, delegate as MinecraftProvider)) {
it.loader libs.versions.fabric.loader.get()
}
defaultRemapJar = true
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API provides hooks for events, item registration, and more. As most mods will need this, it's included by default.
// If you know for a fact you don't, it's not required and can be safely removed.
// modImplementation ("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${fabric_version}") {
// exclude module: "legacy-fabric-entity-events-v1"
// }
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
implementation 'org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209'
implementation 'org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209'
implementation 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
}
}
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
configurations.configureEach {
resolutionStrategy {
dependencySubstitution {
substitute module('org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209')
substitute module('org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209')
}
force 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
}
}
implementation project(":common")
}
processResources {
@@ -52,12 +38,10 @@ processResources {
}
}
tasks.withType(RemapJarTask).configureEach {
onlyIf { false}
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
-7
View File
@@ -1,7 +0,0 @@
# Fabric Properties
# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/
minecraft_version=1.12.2
yarn_mappings=1.12.2+build.202206020145
loader_version=0.14.3
# Dependencies
# More versions available at: https://grayray75.github.io/LegacyFabric-Versions/
@@ -1,13 +0,0 @@
package dev.u9g.minecraftdatagenerator;
import net.fabricmc.api.ModInitializer;
import java.util.logging.Logger;
public class Main implements ModInitializer {
public static final Logger LOGGER = Logger.getLogger("mc-data-gen-serv");
@Override
public void onInitialize() {
}
}
@@ -1,46 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.biome.Biome;
import java.util.Iterator;
public class BiomeColors {
private static final ColorProvider GRASS_COLOR = Biome::getGrassColor;
private static final ColorProvider FOLIAGE_COLOR = Biome::getFoliageColor;
private static final ColorProvider WATER_COLOR = (biome, pos) -> biome.getWaterColor();
private static int getColor(BlockView view, BlockPos pos, ColorProvider provider) {
int i = 0;
int j = 0;
int k = 0;
int l;
for (Iterator<BlockPos.Mutable> var6 = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); var6.hasNext(); k += l & 255) {
BlockPos.Mutable mutable = var6.next();
l = provider.getColorAtPos(view.getBiome(mutable), mutable);
i += (l & 16711680) >> 16;
j += (l & '\uff00') >> 8;
}
return (i / 9 & 255) << 16 | (j / 9 & 255) << 8 | k / 9 & 255;
}
public static int getGrassColor(BlockView view, BlockPos pos) {
return getColor(view, pos, GRASS_COLOR);
}
public static int getFoliageColor(BlockView view, BlockPos pos) {
return getColor(view, pos, FOLIAGE_COLOR);
}
public static int getWaterColor(BlockView view, BlockPos pos) {
return getColor(view, pos, WATER_COLOR);
}
interface ColorProvider {
int getColorAtPos(Biome biome, BlockPos pos);
}
}
@@ -1,10 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import org.jetbrains.annotations.Nullable;
public interface BlockColorable {
int method_12155(BlockState blockState, @Nullable BlockView blockView, @Nullable BlockPos blockPos, int i);
}
@@ -1,98 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.FlowerPotBlockEntity;
import net.minecraft.item.Item;
import net.minecraft.util.collection.IdList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
public class BlockColors {
private final IdList<BlockColorable> BlockColor2Id = new IdList<>(32);
public BlockColors() {
}
public static BlockColors create() {
final BlockColors blockColors = new BlockColors();
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
DoublePlantBlock.DoublePlantType doublePlantType = blockState.get(DoublePlantBlock.VARIANT);
return blockView != null && blockPos != null &&
(doublePlantType == DoublePlantBlock.DoublePlantType.GRASS || doublePlantType == DoublePlantBlock.DoublePlantType.FERN) ?
BiomeColors.getGrassColor(blockView, blockState.get(DoublePlantBlock.HALF) == DoublePlantBlock.HalfType.UPPER ? blockPos.down() : blockPos) : -1;
}, Blocks.DOUBLE_PLANT);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
if (blockView != null && blockPos != null) {
BlockEntity blockEntity = blockView.getBlockEntity(blockPos);
if (blockEntity instanceof FlowerPotBlockEntity) {
Item item = ((FlowerPotBlockEntity) blockEntity).getItem();
BlockState blockState2 = Block.getBlockFromItem(item).getDefaultState();
return blockColors.method_12157(blockState2, blockView, blockPos, i);
} else {
return -1;
}
} else {
return -1;
}
}, Blocks.FLOWER_POT);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : GrassColors.getColor(0.5D, 1.0D), Blocks.GRASS);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
PlanksBlock.WoodType woodType = blockState.get(Leaves1Block.VARIANT);
if (woodType == PlanksBlock.WoodType.SPRUCE) {
return FoliageColors.getSpruceColor();
} else if (woodType == PlanksBlock.WoodType.BIRCH) {
return FoliageColors.getBirchColor();
} else {
return blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor();
}
}, Blocks.LEAVES);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.LEAVES2);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getWaterColor(blockView, blockPos) : -1, Blocks.WATER, Blocks.FLOWING_WATER);
blockColors.method_12158((blockState, blockView, blockPos, i) -> RedstoneWireBlock.method_8877(blockState.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : -1, Blocks.SUGARCANE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
int j = blockState.get(AttachedStemBlock.AGE);
int k = j * 32;
int l = 255 - j * 8;
int m = j * 4;
return k << 16 | l << 8 | m;
}, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM);
// blockColors.method_12158((blockState, blockView, blockPos, i) -> {
// if (blockView != null && blockPos != null) {
// return BiomeColors.getGrassColor(blockView, blockPos);
// } else {
// return blockState.get(TallPlantBlock.TYPE) == TallPlantBlock.GrassType.DEAD_BUSH ? 16777215 : GrassColors.getColor(0.5D, 1.0D);
// }
// }, Blocks.TALLGRASS);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : blockState.get(TallPlantBlock.TYPE) == TallPlantBlock.GrassType.DEAD_BUSH ? 16777215 : GrassColors.getColor(0.5D, 1.0D), Blocks.TALLGRASS);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.VINE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? 2129968 : 7455580, Blocks.LILY_PAD);
return blockColors;
}
public int method_13410(BlockState blockState, World world, BlockPos blockPos) {
BlockColorable blockColorable = BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
if (blockColorable != null) {
return blockColorable.method_12155(blockState, null, null, 0);
} else {
MaterialColor materialColor = blockState.getMaterialColor(world, blockPos);
return materialColor != null ? materialColor.color : -1;
}
}
public int method_12157(BlockState blockState, @Nullable BlockView blockView, @Nullable BlockPos blockPos, int i) {
net.minecraft.client.BlockColorable blockColorable = (net.minecraft.client.BlockColorable) this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
return blockColorable == null ? -1 : blockColorable.method_12155(blockState, blockView, blockPos, i);
}
public void method_12158(BlockColorable blockColorable, Block... blocks) {
int var4 = blocks.length;
for (Block block : blocks) {
this.BlockColor2Id.set(blockColorable, Block.getIdByBlock(block));
}
}
}
@@ -1,36 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
public class FoliageColors {
private static int[] colorMap = new int[65536];
public static void setColorMap(int[] pixels) {
colorMap = pixels;
}
private static int getColor(double temperature, double humidity) {
int i = (int) ((1.0 - temperature) * 255.0);
int j = (int) ((1.0 - (humidity *= temperature)) * 255.0);
return colorMap[j << 8 | i];
}
public static int getSpruceColor() {
return 0x619961;
}
public static int getBirchColor() {
return 8431445;
}
public static int getDefaultColor() {
return 4764952;
}
public static int getFoliageColor(Biome biome) {
double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f);
double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f);
return getColor(d, e);
}
}
@@ -1,29 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
public class GrassColors {
private static int[] colorMap = new int[65536];
public static void setColorMap(int[] map) {
colorMap = map;
}
public static int getColor(double temperature, double humidity) {
int j = (int) ((1.0 - (humidity *= temperature)) * 255.0);
int i = (int) ((1.0 - temperature) * 255.0);
int k = j << 8 | i;
if (k > colorMap.length) {
return -65281;
}
return colorMap[k];
}
public static int getGrassColor(Biome biome) {
double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f);
double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f);
return getColor(d, e);
}
}
@@ -1,25 +0,0 @@
package dev.u9g.minecraftdatagenerator.clientsideannoyances;
import net.minecraft.util.math.MathHelper;
public class ServerSideRedstoneWireBlock {
public static int getWireColor(int powerLevel) {
float f = (float) powerLevel / 15.0f;
float g = f * 0.6f + 0.4f;
if (powerLevel == 0) {
g = 0.3f;
}
float h = f * f * 0.7f - 0.5f;
float j = f * f * 0.6f - 0.7f;
if (h < 0.0f) {
h = 0.0f;
}
if (j < 0.0f) {
j = 0.0f;
}
int k = MathHelper.clamp((int) (g * 255.0f), 0, 255);
int l = MathHelper.clamp((int) (h * 255.0f), 0, 255);
int m = MathHelper.clamp((int) (j * 255.0f), 0, 255);
return 0xFF000000 | k << 16 | l << 8 | m;
}
}
@@ -78,7 +78,7 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator {
}
}
if (indexesOfBoxesInTheShapesCache.stream().distinct().count() < 2) {
return indexesOfBoxesInTheShapesCache.get(0);
return indexesOfBoxesInTheShapesCache.getFirst();
} else {
JsonArray shapeIndexes = new JsonArray();
indexesOfBoxesInTheShapesCache.forEach(shapeIndexes::add);
@@ -98,18 +98,18 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator {
private record Shapes(List<Box> boxes) {
public JsonArray toJSON() {
JsonArray arr = new JsonArray();
boxes.forEach(box -> arr.add(jsonOf(box)));
return arr;
}
JsonArray arr = new JsonArray();
boxes.forEach(box -> arr.add(jsonOf(box)));
return arr;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Shapes shapes = (Shapes) o;
return Objects.equals(boxes, shapes.boxes);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Shapes shapes = (Shapes) o;
return Objects.equals(boxes, shapes.boxes);
}
}
}
@@ -3,7 +3,6 @@ package dev.u9g.minecraftdatagenerator.generators;
import com.google.common.base.CaseFormat;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.Main;
import dev.u9g.minecraftdatagenerator.mixin.BlockAccessor;
import dev.u9g.minecraftdatagenerator.mixin.MiningToolItemAccessor;
import dev.u9g.minecraftdatagenerator.util.DGU;
@@ -27,12 +26,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.logging.Logger;
public class BlocksDataGenerator implements IDataGenerator {
private static final Logger logger = Main.LOGGER;
private static List<Item> getItemsEffectiveForBlock(Block block) {
List<Item> items = new ArrayList<>();
for (Item item : Registries.ITEMS) {
@@ -1,81 +0,0 @@
package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonElement;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonWriter;
import dev.u9g.minecraftdatagenerator.Main;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DataGenerators {
private static final List<IDataGenerator> GENERATORS = new ArrayList<>();
private static final Logger logger = Main.LOGGER;
static {
register(new BiomesDataGenerator());
register(new BlockCollisionShapesDataGenerator());
register(new BlocksDataGenerator());
register(new EffectsDataGenerator());
register(new EnchantmentsDataGenerator());
register(new EntitiesDataGenerator());
register(new FoodsDataGenerator());
register(new ItemsDataGenerator());
register(new ParticlesDataGenerator());
register(new TintsDataGenerator());
register(new LanguageDataGenerator());
register(new InstrumentsDataGenerator());
register(new AttributesDataGenerator());
register(new SoundsDataGenerator());
}
public static void register(IDataGenerator generator) {
GENERATORS.add(generator);
}
public static boolean runDataGenerators(Path outputDirectory) {
try {
Files.createDirectories(outputDirectory);
} catch (IOException exception) {
logger.info("Failed to create data generator output directory at " + outputDirectory);
exception.printStackTrace();
return false;
}
int generatorsFailed = 0;
logger.info(MessageFormat.format("Running minecraft data generators, output at {0}", outputDirectory));
for (IDataGenerator dataGenerator : GENERATORS) {
logger.info(MessageFormat.format("Running generator {0}", dataGenerator.getDataName()));
try {
String outputFileName = String.format("%s.json", dataGenerator.getDataName());
JsonElement outputElement = dataGenerator.generateDataJson();
Path outputFilePath = outputDirectory.resolve(outputFileName);
try (Writer writer = Files.newBufferedWriter(outputFilePath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
JsonWriter jsonWriter = new JsonWriter(writer);
jsonWriter.setIndent(" ");
Streams.write(outputElement, jsonWriter);
}
logger.info(MessageFormat.format("Generator: {0} -> {1}", dataGenerator.getDataName(), outputFileName));
} catch (Throwable exception) {
logger.info(MessageFormat.format("Failed to run data generator {0}", dataGenerator.getDataName()));
exception.printStackTrace();
generatorsFailed++;
}
}
logger.info("Finishing running data generators");
return generatorsFailed == 0;
}
}
@@ -16,7 +16,6 @@ import java.util.Objects;
import java.util.stream.Collectors;
public class EffectsDataGenerator implements IDataGenerator {
public static JsonObject generateEffect(StatusEffect statusEffect) {
JsonObject effectDesc = new JsonObject();
@NotNull Identifier registryKey = Objects.requireNonNull(Registries.STATUS_EFFECTS.getIdentifier(statusEffect));
@@ -24,7 +24,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public class EntitiesDataGenerator implements IDataGenerator {
public static JsonObject generateEntity(Class<? extends Entity> entityClass) {
JsonObject entityDesc = new JsonObject();
Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass);
@@ -11,7 +11,6 @@ import net.minecraft.util.Identifier;
import java.util.Objects;
public class FoodsDataGenerator implements IDataGenerator {
public static JsonObject generateFoodDescriptor(FoodItem foodItem) {
JsonObject foodDesc = new JsonObject();
Identifier registryKey = Registries.ITEMS.getIdentifier(foodItem);
@@ -1,10 +0,0 @@
package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonElement;
public interface IDataGenerator {
String getDataName();
JsonElement generateDataJson();
}
@@ -4,8 +4,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.mixin.NoteBlockAccessor;
import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.sound.Sound;
import java.util.Objects;
@@ -19,10 +18,10 @@ public class InstrumentsDataGenerator implements IDataGenerator {
public JsonElement generateDataJson() {
JsonArray array = new JsonArray();
int i = 0;
for (SoundEvent sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) {
for (Sound sound : Objects.requireNonNull(NoteBlockAccessor.TUNES())) {
JsonObject object = new JsonObject();
object.addProperty("id", i++);
object.addProperty("name", ((SoundAccessor) sound).id().getPath().split("\\.")[2]);
object.addProperty("name", sound.getId().getPath().split("\\.")[2]);
array.add(object);
}
return array;
@@ -5,7 +5,6 @@ import com.google.gson.JsonObject;
import net.minecraft.client.particle.ParticleType;
public class ParticlesDataGenerator implements IDataGenerator {
public static JsonObject generateParticleType(int id, ParticleType particleType) {
JsonObject effectDesc = new JsonObject();
@@ -112,6 +112,11 @@ public class RecipeDataGenerator implements IDataGenerator {
// return finalObj;
return JsonNull.INSTANCE;
}
@Override
public boolean isEnabled() {
return false; // TODO: Implement this
}
//
// private static int getRawIdFor (Item item) {
// return Registry.ITEM.getRawId(item);
@@ -2,18 +2,14 @@ package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.sound.Sound;
public class SoundsDataGenerator implements IDataGenerator {
public static JsonObject generateSound(SoundEvent soundEvent) {
public static JsonObject generateSound(Sound soundEvent) {
JsonObject soundDesc = new JsonObject();
soundDesc.addProperty("id", SoundEvent.REGISTRY.getRawId(soundEvent));
soundDesc.addProperty("name", ((SoundAccessor) soundEvent).id().getPath());
soundDesc.addProperty("id", Sound.REGISTRY.getRawId(soundEvent));
soundDesc.addProperty("name", soundEvent.getId().getPath());
return soundDesc;
}
@@ -26,7 +22,7 @@ public class SoundsDataGenerator implements IDataGenerator {
@Override
public JsonArray generateDataJson() {
JsonArray resultsArray = new JsonArray();
SoundEvent.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound)));
Sound.REGISTRY.forEach(sound -> resultsArray.add(generateSound(sound)));
return resultsArray;
}
}
@@ -2,32 +2,32 @@ package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.BlockColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.GrassColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock;
import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor;
import dev.u9g.minecraftdatagenerator.util.DGU;
import dev.u9g.minecraftdatagenerator.util.Registries;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.client.BlockColors;
import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.client.color.world.GrassColors;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
import java.util.*;
public class TintsDataGenerator implements IDataGenerator {
private static final BlockColors blockColors = BlockColors.create();
public static BiomeTintColors generateBiomeTintColors() {
BiomeTintColors colors = new BiomeTintColors();
for (Biome biome : Registries.BIOMES) {
int biomeGrassColor = GrassColors.getGrassColor(biome);
int biomeFoliageColor = FoliageColors.getFoliageColor(biome);
double d = MathHelper.clamp(biome.getTemperature(), 0.0f, 1.0f);
double e = MathHelper.clamp(biome.getRainfall(), 0.0f, 1.0f);
int biomeGrassColor = GrassColors.getColor(d, e);
int biomeFoliageColor = FoliageColors.getColor(d, e);
int biomeWaterColor = ((BiomeAccessor) biome).waterColor();
colors.grassColoursMap.computeIfAbsent(biomeGrassColor, k -> new ArrayList<>()).add(biome);
@@ -38,30 +38,29 @@ public class TintsDataGenerator implements IDataGenerator {
}
public static Map<Integer, Integer> generateRedstoneTintColors() {
Map<Integer, Integer> resultColors = new HashMap<>();
Map<Integer, Integer> resultColors = new LinkedHashMap<>();
for (int redstoneLevel : RedstoneWireBlock.POWER.getValues()) {
int color = ServerSideRedstoneWireBlock.getWireColor(redstoneLevel);
int color = RedstoneWireBlock.getColorIntensity(redstoneLevel);
resultColors.put(redstoneLevel, color);
}
return resultColors;
}
private static int getBlockColor(Block block) {
return blockColors.method_13410(block.getDefaultState(), DGU.getWorld(), BlockPos.ORIGIN);
return BlockColors.create().method_13410(block.getDefaultState(), DGU.getWorld(), BlockPos.ORIGIN);
}
public static Map<Block, Integer> generateConstantTintColors() {
Map<Block, Integer> resultColors = new HashMap<>();
BlockColors blockColors = BlockColors.create();
Map<Block, Integer> resultColors = new LinkedHashMap<>();
// FIXME: ?
// resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor());
// resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor());
resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD));
// FIXME: ?
// resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM, blockColors));
// resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM, blockColors));
// resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM));
// resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM));
//not really constant, depend on the block age, but kinda have to be handled since textures are literally white without them
resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM));
@@ -152,8 +151,8 @@ public class TintsDataGenerator implements IDataGenerator {
}
public static class BiomeTintColors {
final Map<Integer, List<Biome>> grassColoursMap = new HashMap<>();
final Map<Integer, List<Biome>> foliageColoursMap = new HashMap<>();
final Map<Integer, List<Biome>> waterColourMap = new HashMap<>();
final Map<Integer, List<Biome>> grassColoursMap = new LinkedHashMap<>();
final Map<Integer, List<Biome>> foliageColoursMap = new LinkedHashMap<>();
final Map<Integer, List<Biome>> waterColourMap = new LinkedHashMap<>();
}
}
@@ -1,7 +1,7 @@
package dev.u9g.minecraftdatagenerator.mixin;
import net.minecraft.block.NoteBlock;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.sound.Sound;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@@ -10,7 +10,7 @@ import java.util.List;
@Mixin(NoteBlock.class)
public interface NoteBlockAccessor {
@Accessor("TUNES")
static List<SoundEvent> TUNES() {
static List<Sound> TUNES() {
return null;
}
}
@@ -1,7 +1,6 @@
package dev.u9g.minecraftdatagenerator.mixin;
import dev.u9g.minecraftdatagenerator.Main;
import dev.u9g.minecraftdatagenerator.generators.DataGenerators;
import dev.u9g.minecraftdatagenerator.MinecraftDataGenerator;
import dev.u9g.minecraftdatagenerator.util.DGU;
import net.minecraft.server.dedicated.MinecraftDedicatedServer;
import org.spongepowered.asm.mixin.Mixin;
@@ -9,19 +8,13 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.nio.file.Path;
import java.util.logging.Level;
@Mixin(MinecraftDedicatedServer.class)
public class ReadyMixin {
@Inject(method = "setupServer()Z", at = @At("TAIL"))
private void init(CallbackInfoReturnable<Boolean> cir) {
Main.LOGGER.info("Starting data generation!");
String versionName = DGU.getCurrentlyRunningServer().getVersion();
Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath();
Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName);
DataGenerators.runDataGenerators(dataDumpDirectory);
Main.LOGGER.info("Done data generation!");
Runtime.getRuntime().halt(0);
MinecraftDataGenerator.start(
DGU.getCurrentlyRunningServer().getVersion(),
DGU.getCurrentlyRunningServer().getRunDirectory().toPath()
);
}
}
@@ -1,12 +0,0 @@
package dev.u9g.minecraftdatagenerator.mixin;
import net.minecraft.client.sound.SoundEvent;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(SoundEvent.class)
public interface SoundAccessor {
@Accessor("id")
Identifier id();
}
@@ -1,82 +1,20 @@
package dev.u9g.minecraftdatagenerator.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.internal.bind.TypeAdapters;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class DGU {
public static Gson gson = new GsonBuilder().registerTypeAdapterFactory(TypeAdapters.newFactory(double.class, Double.class, new TypeAdapter<Number>() {
@Override
public Number read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return in.nextDouble();
}
@Override
public void write(JsonWriter out, Number value) throws IOException {
out.value(value);
}
})).create();
@Environment(EnvType.CLIENT)
private static MinecraftServer getCurrentlyRunningServerClient() {
return MinecraftClient.getInstance().getServer();
}
@SuppressWarnings("deprecation")
private static MinecraftServer getCurrentlyRunningServerDedicated() {
public static MinecraftServer getCurrentlyRunningServer() {
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
}
public static MinecraftServer getCurrentlyRunningServer() {
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
if (environmentType == EnvType.CLIENT) {
return getCurrentlyRunningServerClient();
} else if (environmentType == EnvType.SERVER) {
return getCurrentlyRunningServerDedicated();
}
throw new UnsupportedOperationException();
}
@Environment(EnvType.CLIENT)
private static String translateTextClient(String translationKey) {
return I18n.translate(translationKey);
}
private static String translateTextFallback(String translationKey) {
try {
return Registries.LANGUAGE.translate(translationKey);
} catch (Exception ignored) {
}
throw new RuntimeException("Failed to translate: '" + translationKey + "'");
}
public static String translateText(String translationKey) {
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
if (environmentType == EnvType.CLIENT) {
return translateTextClient(translationKey);
}
return translateTextFallback(translationKey);
return Registries.LANGUAGE.translate(translationKey);
}
@NotNull
+2 -8
View File
@@ -10,17 +10,11 @@
],
"contact": {},
"license": "MIT",
"environment": "server",
"entrypoints": {
"main": [
"dev.u9g.minecraftdatagenerator.Main"
]
},
"mixins": [
"minecraft-data-generator.mixins.json"
],
"depends": {
"fabricloader": ">=0.13.3",
"minecraft": ">=1.12"
"fabricloader": "*",
"minecraft": "*"
}
}
@@ -12,11 +12,8 @@
"MiningToolItemAccessor",
"NoteBlockAccessor",
"ReadyMixin",
"SoundAccessor",
"StatusEffectAccessor"
],
"client": [
],
"injectors": {
"defaultRequire": 1
},
+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();
}

Some files were not shown because too many files have changed in this diff Show More