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:
@@ -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() {
|
||||
}
|
||||
}
|
||||
-47
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-10
@@ -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);
|
||||
}
|
||||
-96
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
-37
@@ -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);
|
||||
}
|
||||
}
|
||||
-29
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
-28
@@ -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;
|
||||
}
|
||||
}
|
||||
+12
-12
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
-1
@@ -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));
|
||||
|
||||
-1
@@ -21,7 +21,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EntitiesDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateEntity(Class<? extends Entity> entityClass) {
|
||||
JsonObject entityDesc = new JsonObject();
|
||||
Identifier registryKey = Registries.ENTITY_TYPES.getIdentifier(entityClass);
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.minecraft.util.Identifier;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FoodsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateFoodDescriptor(FoodItem foodItem) {
|
||||
JsonObject foodDesc = new JsonObject();
|
||||
Identifier registryKey = Registries.ITEMS.getIdentifier(foodItem);
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
public interface IDataGenerator {
|
||||
|
||||
String getDataName();
|
||||
|
||||
JsonElement generateDataJson();
|
||||
}
|
||||
+3
-4
@@ -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;
|
||||
|
||||
-1
@@ -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();
|
||||
|
||||
|
||||
+5
@@ -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);
|
||||
|
||||
+5
-8
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-27
@@ -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
|
||||
|
||||
@@ -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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user