Reduce duplicate code (#18)
* Reduce duplicate code * Fix gradle task name * Revert name changes * Revert action name * Cleanup * Revert to java 17 * Fix generation * Cleanup * Simplify code of DGU * Remove unnecessary annotations * Remove unused var * Halt with error on error * Remove unused mixins * Update fabric loader * Ignore success result * Update gradle and use merged jar * Implement new client and server merged environment for running fabric * Set server run dir as asset dir * More cleanup * More cleanup 2 * More improvements * Remove more duplicate code * Use newer java methods * More cleanup * Remove SoundAccessors * More cleanup * Use java 21 for build * Initial work on 1.20.5 * Cleanup a lot of stuff * Do not generate mod jars to speed up builds * Override merger on now open classes directly * Use recommended approach * Readd custom merger * Working materials data generator * Fix inconsistencies * Fix collision order to be random * Use LinkedHashMap for more reproducibility * Fix imports
This commit is contained in:
+30
-14
@@ -1,15 +1,33 @@
|
||||
import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask
|
||||
import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider
|
||||
|
||||
plugins {
|
||||
id 'fabric-loom'
|
||||
id 'xyz.wagyourtail.unimined'
|
||||
}
|
||||
|
||||
unimined.minecraft {
|
||||
version "1.18"
|
||||
|
||||
mappings {
|
||||
intermediary()
|
||||
yarn(1)
|
||||
|
||||
devFallbackNamespace "intermediary"
|
||||
}
|
||||
|
||||
runs.config("server") {
|
||||
javaVersion = JavaVersion.VERSION_21
|
||||
}
|
||||
|
||||
customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) {
|
||||
it.loader libs.versions.fabric.loader.get()
|
||||
}
|
||||
|
||||
defaultRemapJar = true
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// To change the versions see the gradle.properties file
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
implementation project(":common")
|
||||
}
|
||||
|
||||
processResources {
|
||||
@@ -20,12 +38,10 @@ processResources {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(RemapJarTask).configureEach {
|
||||
onlyIf { false}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
# Fabric Properties
|
||||
# check these on https://modmuss50.me/fabric.html
|
||||
minecraft_version=1.18
|
||||
yarn_mappings=1.18+build.1
|
||||
loader_version=0.14.4
|
||||
# Dependencies
|
||||
# check this on https://modmuss50.me/fabric.html
|
||||
fabric_version=0.44.0+1.18
|
||||
@@ -1,14 +0,0 @@
|
||||
package dev.u9g.minecraftdatagenerator;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Main implements ModInitializer {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("mc-data-gen-serv");
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
|
||||
}
|
||||
}
|
||||
+4
-7
@@ -12,10 +12,7 @@ import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.EmptyBlockView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class BlockCollisionShapesDataGenerator implements IDataGenerator {
|
||||
|
||||
@@ -40,8 +37,8 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator {
|
||||
}
|
||||
|
||||
private static class BlockShapesCache {
|
||||
public final Map<VoxelShape, Integer> uniqueBlockShapes = new HashMap<>();
|
||||
public final Map<Block, List<Integer>> blockCollisionShapes = new HashMap<>();
|
||||
public final Map<VoxelShape, Integer> uniqueBlockShapes = new LinkedHashMap<>();
|
||||
public final Map<Block, List<Integer>> blockCollisionShapes = new LinkedHashMap<>();
|
||||
private int lastCollisionShapeId = 0;
|
||||
|
||||
public void processBlock(Block block) {
|
||||
@@ -70,7 +67,7 @@ public class BlockCollisionShapesDataGenerator implements IDataGenerator {
|
||||
long distinctShapesCount = blockCollisions.stream().distinct().count();
|
||||
JsonElement blockCollision;
|
||||
if (distinctShapesCount == 1L) {
|
||||
blockCollision = new JsonPrimitive(blockCollisions.get(0));
|
||||
blockCollision = new JsonPrimitive(blockCollisions.getFirst());
|
||||
} else {
|
||||
blockCollision = new JsonArray();
|
||||
for (int collisionId : blockCollisions) {
|
||||
|
||||
+9
-9
@@ -104,7 +104,7 @@ public class BlocksDataGenerator implements IDataGenerator {
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (matchingMaterials.size() > 1) {
|
||||
var firstMaterial = matchingMaterials.get(0);
|
||||
var firstMaterial = matchingMaterials.getFirst();
|
||||
var otherMaterials = matchingMaterials.subList(1, matchingMaterials.size());
|
||||
|
||||
if (!otherMaterials.stream().allMatch(firstMaterial::includesMaterial)) {
|
||||
@@ -114,25 +114,25 @@ public class BlocksDataGenerator implements IDataGenerator {
|
||||
if (matchingMaterials.isEmpty()) {
|
||||
return "default";
|
||||
}
|
||||
return matchingMaterials.get(0).getMaterialName();
|
||||
return matchingMaterials.getFirst().getMaterialName();
|
||||
}
|
||||
|
||||
public static JsonObject generateBlock(Registry<Block> blockRegistry, List<MaterialsDataGenerator.MaterialInfo> materials, Block block) {
|
||||
public static JsonObject generateBlock(List<MaterialsDataGenerator.MaterialInfo> materials, Block block) {
|
||||
JsonObject blockDesc = new JsonObject();
|
||||
|
||||
List<BlockState> blockStates = block.getStateManager().getStates();
|
||||
BlockState defaultState = block.getDefaultState();
|
||||
Identifier registryKey = blockRegistry.getKey(block).orElseThrow().getValue();
|
||||
Identifier registryKey = Registry.BLOCK.getKey(block).orElseThrow().getValue();
|
||||
String localizationKey = block.getTranslationKey();
|
||||
List<Item> effectiveTools = getItemsEffectiveForBlock(defaultState);
|
||||
|
||||
blockDesc.addProperty("id", blockRegistry.getRawId(block));
|
||||
blockDesc.addProperty("id", Registry.BLOCK.getRawId(block));
|
||||
blockDesc.addProperty("displayName", DGU.translateText(localizationKey));
|
||||
blockDesc.addProperty("name", registryKey.getPath());
|
||||
blockDesc.addProperty("hardness", block.getHardness());
|
||||
blockDesc.addProperty("resistance", block.getBlastResistance());
|
||||
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));
|
||||
@@ -140,7 +140,7 @@ public class BlocksDataGenerator implements IDataGenerator {
|
||||
blockDesc.add("states", stateProperties);
|
||||
// Let's not generate block drops...
|
||||
// List<ItemStack> actualBlockDrops = new ArrayList<>();
|
||||
// populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.get(0), actualBlockDrops);
|
||||
// populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.getFirst(), actualBlockDrops);
|
||||
|
||||
// for (ItemStack dropStack : actualBlockDrops) {
|
||||
// dropsArray.add(Item.getRawId(dropStack.getItem()));
|
||||
@@ -184,7 +184,7 @@ public class BlocksDataGenerator implements IDataGenerator {
|
||||
Registry<Block> blockRegistry = Registry.BLOCK;
|
||||
List<MaterialsDataGenerator.MaterialInfo> availableMaterials = MaterialsDataGenerator.getGlobalMaterialInfo();
|
||||
|
||||
blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, availableMaterials, block)));
|
||||
blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(availableMaterials, block)));
|
||||
return resultBlocksArray;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DataGenerators {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataGenerators.class);
|
||||
private static final List<IDataGenerator> GENERATORS = new ArrayList<>();
|
||||
|
||||
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 MaterialsDataGenerator());
|
||||
// register(new RecipeDataGenerator()); - On hold until mcdata supports multiple materials for a recipe
|
||||
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.error("Failed to create data generator output directory at {}", outputDirectory, exception);
|
||||
return false;
|
||||
}
|
||||
|
||||
int generatorsFailed = 0;
|
||||
logger.info("Running minecraft data generators, output at {}", outputDirectory);
|
||||
|
||||
for (IDataGenerator dataGenerator : GENERATORS) {
|
||||
logger.info("Running generator {}", 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)) {
|
||||
DGU.JSON_ELEMENT.write(DGU.GSON.newJsonWriter(writer), outputElement);
|
||||
}
|
||||
logger.info("Generator: {} -> {}", dataGenerator.getDataName(), outputFileName);
|
||||
|
||||
} catch (Throwable exception) {
|
||||
logger.error("Failed to run data generator {}", dataGenerator.getDataName(), exception);
|
||||
generatorsFailed++;
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Finishing running data generators");
|
||||
return generatorsFailed == 0;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EffectsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateEffect(Registry<StatusEffect> registry, StatusEffect statusEffect) {
|
||||
JsonObject effectDesc = new JsonObject();
|
||||
Identifier registryKey = registry.getKey(statusEffect).orElseThrow().getValue();
|
||||
|
||||
+1
-21
@@ -1,6 +1,5 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
@@ -11,29 +10,10 @@ import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EnchantmentsDataGenerator implements IDataGenerator {
|
||||
|
||||
private static final ImmutableMap<EnchantmentTarget, String> ENCHANTMENT_TARGET_NAMES = ImmutableMap.<EnchantmentTarget, String>builder()
|
||||
.put(EnchantmentTarget.ARMOR, "armor")
|
||||
.put(EnchantmentTarget.ARMOR_FEET, "armor_feet")
|
||||
.put(EnchantmentTarget.ARMOR_LEGS, "armor_legs")
|
||||
.put(EnchantmentTarget.ARMOR_CHEST, "armor_chest")
|
||||
.put(EnchantmentTarget.ARMOR_HEAD, "armor_head")
|
||||
.put(EnchantmentTarget.WEAPON, "weapon")
|
||||
.put(EnchantmentTarget.DIGGER, "digger")
|
||||
.put(EnchantmentTarget.FISHING_ROD, "fishing_rod")
|
||||
.put(EnchantmentTarget.TRIDENT, "trident")
|
||||
.put(EnchantmentTarget.BREAKABLE, "breakable")
|
||||
.put(EnchantmentTarget.BOW, "bow")
|
||||
.put(EnchantmentTarget.WEARABLE, "wearable")
|
||||
.put(EnchantmentTarget.CROSSBOW, "crossbow")
|
||||
.put(EnchantmentTarget.VANISHABLE, "vanishable")
|
||||
.build();
|
||||
|
||||
public static String getEnchantmentTargetName(EnchantmentTarget target) {
|
||||
return ENCHANTMENT_TARGET_NAMES.getOrDefault(target, target.name().toLowerCase(Locale.ROOT));
|
||||
return target.name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
//Equation enchantment costs follow is a * level + b, so we can easily retrieve a and b by passing zero level
|
||||
|
||||
-1
@@ -18,7 +18,6 @@ import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
public class EntitiesDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateEntity(Registry<EntityType<?>> entityRegistry, EntityType<?> entityType) {
|
||||
JsonObject entityDesc = new JsonObject();
|
||||
Identifier registryKey = entityRegistry.getKey(entityType).orElseThrow().getValue();
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.minecraft.util.registry.Registry;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FoodsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateFoodDescriptor(Registry<Item> registry, Item foodItem) {
|
||||
JsonObject foodDesc = new JsonObject();
|
||||
Identifier registryKey = registry.getKey(foodItem).orElseThrow().getValue();
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
public interface IDataGenerator {
|
||||
|
||||
String getDataName();
|
||||
|
||||
JsonElement generateDataJson();
|
||||
}
|
||||
+14
-12
@@ -1,6 +1,5 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -41,7 +40,7 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
||||
}
|
||||
|
||||
private static void createCompositeMaterialInfo(List<MaterialInfo> allMaterials, List<String> combinedMaterials) {
|
||||
String compositeMaterialName = Joiner.on(';').join(combinedMaterials);
|
||||
String compositeMaterialName = String.join(";", combinedMaterials);
|
||||
|
||||
List<MaterialInfo> mappedMaterials = combinedMaterials.stream()
|
||||
.map(otherName -> allMaterials.stream()
|
||||
@@ -53,16 +52,19 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
||||
mappedMaterials.stream().allMatch(it -> it.getPredicate().test(blockState));
|
||||
|
||||
MaterialInfo materialInfo = new MaterialInfo(compositeMaterialName, compositePredicate).includes(mappedMaterials);
|
||||
allMaterials.add(0, materialInfo);
|
||||
allMaterials.addFirst(materialInfo);
|
||||
}
|
||||
|
||||
private static void createCompositeMaterial(Map<String, Map<Item, Float>> allMaterials, List<String> combinedMaterials) {
|
||||
String compositeMaterialName = Joiner.on(';').join(combinedMaterials);
|
||||
String compositeMaterialName = String.join(";", combinedMaterials);
|
||||
|
||||
Map<Item, Float> resultingToolSpeeds = new HashMap<>();
|
||||
Map<Item, Float> resultingToolSpeeds = new LinkedHashMap<>();
|
||||
combinedMaterials.stream()
|
||||
.map(allMaterials::get)
|
||||
.forEach(resultingToolSpeeds::putAll);
|
||||
.forEach(v -> {
|
||||
System.out.println(v);
|
||||
resultingToolSpeeds.putAll(v);
|
||||
});
|
||||
allMaterials.put(compositeMaterialName, resultingToolSpeeds);
|
||||
}
|
||||
|
||||
@@ -106,14 +108,14 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
||||
public JsonElement generateDataJson() {
|
||||
Registry<Item> itemRegistry = Registry.ITEM;
|
||||
|
||||
Map<String, Map<Item, Float>> materialMiningSpeeds = new HashMap<>();
|
||||
Map<String, Map<Item, Float>> materialMiningSpeeds = new LinkedHashMap<>();
|
||||
materialMiningSpeeds.put("default", ImmutableMap.of());
|
||||
|
||||
//Special materials used for shears and swords special mining speed logic
|
||||
Map<Item, Float> leavesMaterialSpeeds = new HashMap<>();
|
||||
Map<Item, Float> cowebMaterialSpeeds = new HashMap<>();
|
||||
Map<Item, Float> plantMaterialSpeeds = new HashMap<>();
|
||||
Map<Item, Float> gourdMaterialSpeeds = new HashMap<>();
|
||||
Map<Item, Float> leavesMaterialSpeeds = new LinkedHashMap<>();
|
||||
Map<Item, Float> cowebMaterialSpeeds = new LinkedHashMap<>();
|
||||
Map<Item, Float> plantMaterialSpeeds = new LinkedHashMap<>();
|
||||
Map<Item, Float> gourdMaterialSpeeds = new LinkedHashMap<>();
|
||||
|
||||
materialMiningSpeeds.put(makeMaterialNameForTag(BlockTags.LEAVES), leavesMaterialSpeeds);
|
||||
materialMiningSpeeds.put("coweb", cowebMaterialSpeeds);
|
||||
@@ -132,7 +134,7 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
||||
Tag<Block> effectiveBlocks = ((MiningToolItemAccessor) toolItem).getEffectiveBlocks();
|
||||
String materialName = makeMaterialNameForTag(effectiveBlocks);
|
||||
|
||||
Map<Item, Float> materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new HashMap<>());
|
||||
Map<Item, Float> materialSpeeds = materialMiningSpeeds.computeIfAbsent(materialName, k -> new LinkedHashMap<>());
|
||||
float miningSpeed = ((MiningToolItemAccessor) toolItem).getMiningSpeed();
|
||||
materialSpeeds.put(item, miningSpeed);
|
||||
}
|
||||
|
||||
-1
@@ -7,7 +7,6 @@ import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
public class ParticlesDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateParticleType(Registry<ParticleType<?>> registry, ParticleType<?> particleType) {
|
||||
JsonObject effectDesc = new JsonObject();
|
||||
Identifier registryKey = registry.getKey(particleType).orElseThrow().getValue();
|
||||
|
||||
+4
-8
@@ -2,18 +2,15 @@ package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.mixin.SoundAccessor;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
|
||||
public class SoundsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateSound(Registry<SoundEvent> registry, SoundEvent soundEvent) {
|
||||
public static JsonObject generateSound(SoundEvent soundEvent) {
|
||||
JsonObject soundDesc = new JsonObject();
|
||||
|
||||
soundDesc.addProperty("id", registry.getRawId(soundEvent));
|
||||
soundDesc.addProperty("name", ((SoundAccessor)soundEvent).id().getPath());
|
||||
soundDesc.addProperty("id", Registry.SOUND_EVENT.getRawId(soundEvent));
|
||||
soundDesc.addProperty("name", soundEvent.getId().getPath());
|
||||
|
||||
return soundDesc;
|
||||
}
|
||||
@@ -26,8 +23,7 @@ public class SoundsDataGenerator implements IDataGenerator {
|
||||
@Override
|
||||
public JsonArray generateDataJson() {
|
||||
JsonArray resultsArray = new JsonArray();
|
||||
Registry<SoundEvent> soundEventRegistry = Registry.SOUND_EVENT;
|
||||
soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, sound)));
|
||||
Registry.SOUND_EVENT.forEach(sound -> resultsArray.add(generateSound(sound)));
|
||||
return resultsArray;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-17
@@ -4,7 +4,6 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
@@ -20,7 +19,6 @@ import net.minecraft.world.biome.Biome;
|
||||
import java.util.*;
|
||||
|
||||
public class TintsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static BiomeTintColors generateBiomeTintColors(Registry<Biome> biomeRegistry) {
|
||||
BiomeTintColors colors = new BiomeTintColors();
|
||||
|
||||
@@ -37,7 +35,7 @@ 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 = RedstoneWireBlock.getWireColor(redstoneLevel);
|
||||
@@ -46,26 +44,23 @@ public class TintsDataGenerator implements IDataGenerator {
|
||||
return resultColors;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static int getBlockColor(Block block, BlockColors blockColors) {
|
||||
return blockColors.getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF);
|
||||
private static int getBlockColor(Block block) {
|
||||
return BlockColors.create().getColor(block.getDefaultState(), EmptyRenderBlockView.INSTANCE, BlockPos.ORIGIN, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static Map<Block, Integer> generateConstantTintColors() {
|
||||
Map<Block, Integer> resultColors = new HashMap<>();
|
||||
BlockColors blockColors = BlockColors.create();
|
||||
Map<Block, Integer> resultColors = new LinkedHashMap<>();
|
||||
|
||||
resultColors.put(Blocks.BIRCH_LEAVES, FoliageColors.getBirchColor());
|
||||
resultColors.put(Blocks.SPRUCE_LEAVES, FoliageColors.getSpruceColor());
|
||||
|
||||
resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD, blockColors));
|
||||
resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM, blockColors));
|
||||
resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM, blockColors));
|
||||
resultColors.put(Blocks.LILY_PAD, getBlockColor(Blocks.LILY_PAD));
|
||||
resultColors.put(Blocks.ATTACHED_MELON_STEM, getBlockColor(Blocks.ATTACHED_MELON_STEM));
|
||||
resultColors.put(Blocks.ATTACHED_PUMPKIN_STEM, getBlockColor(Blocks.ATTACHED_PUMPKIN_STEM));
|
||||
|
||||
//not really constant, depend on the block age, but kinda have to be handled since textures are literally white without them
|
||||
resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM, blockColors));
|
||||
resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM, blockColors));
|
||||
resultColors.put(Blocks.MELON_STEM, getBlockColor(Blocks.MELON_STEM));
|
||||
resultColors.put(Blocks.PUMPKIN_STEM, getBlockColor(Blocks.PUMPKIN_STEM));
|
||||
|
||||
return resultColors;
|
||||
}
|
||||
@@ -161,8 +156,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<>();
|
||||
}
|
||||
}
|
||||
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerInteractionManager;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ClientPlayerInteractionManager.class)
|
||||
public abstract class ClientPlayerInteractionManagerMixin {
|
||||
@Unique
|
||||
private long blockBreakingStartTicks;
|
||||
@Unique
|
||||
private BlockState stateBeingBroken;
|
||||
|
||||
@Inject(method = "attackBlock", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;currentBreakingProgress:F", opcode = Opcodes.PUTFIELD))
|
||||
private void onBlockAttacked(BlockPos pos, Direction direction, CallbackInfoReturnable<Boolean> callbackInfo) {
|
||||
World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world);
|
||||
this.blockBreakingStartTicks = world.getTime();
|
||||
}
|
||||
|
||||
@Inject(method = "cancelBlockBreaking", at = @At("HEAD"))
|
||||
private void onBlockBreakingCanceled(CallbackInfo callbackInfo) {
|
||||
this.blockBreakingStartTicks = -1L;
|
||||
}
|
||||
|
||||
@Inject(method = "breakBlock", at = @At("HEAD"))
|
||||
private void onBreakBlockHead(BlockPos pos, CallbackInfoReturnable<Boolean> callbackInfo) {
|
||||
World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world);
|
||||
this.stateBeingBroken = world.getBlockState(pos);
|
||||
}
|
||||
|
||||
@Inject(method = "breakBlock", at = @At("RETURN"))
|
||||
private void onBreakBlockReturn(BlockPos pos, CallbackInfoReturnable<Boolean> callbackInfo) {
|
||||
World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world);
|
||||
if (callbackInfo.getReturnValue()) {
|
||||
Preconditions.checkNotNull(stateBeingBroken);
|
||||
if (blockBreakingStartTicks != -1L) {
|
||||
long totalTicksElapsed = world.getTime() - this.blockBreakingStartTicks;
|
||||
long totalTimeElapsed = totalTicksElapsed * 50L;
|
||||
System.out.printf("Breaking block %s took %dms%n", stateBeingBroken.getBlock(), totalTimeElapsed);
|
||||
} else {
|
||||
System.out.printf("Breaking block %s took 0ms [INSTANT BREAK]%n", stateBeingBroken.getBlock());
|
||||
}
|
||||
}
|
||||
this.blockBreakingStartTicks = -1L;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin;
|
||||
|
||||
import dev.u9g.minecraftdatagenerator.Main;
|
||||
import dev.u9g.minecraftdatagenerator.generators.DataGenerators;
|
||||
import dev.u9g.minecraftdatagenerator.MinecraftDataGenerator;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import net.minecraft.MinecraftVersion;
|
||||
import net.minecraft.server.dedicated.MinecraftDedicatedServer;
|
||||
@@ -10,18 +9,13 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@Mixin(MinecraftDedicatedServer.class)
|
||||
public class ReadyMixin {
|
||||
@Inject(method = "setupServer()Z", at = @At("TAIL"))
|
||||
private void init(CallbackInfoReturnable<Boolean> cir) {
|
||||
Main.LOGGER.info("Starting data generation!");
|
||||
String versionName = MinecraftVersion.CURRENT.getName();
|
||||
Path serverRootDirectory = DGU.getCurrentlyRunningServer().getRunDirectory().toPath().toAbsolutePath();
|
||||
Path dataDumpDirectory = serverRootDirectory.resolve("minecraft-data").resolve(versionName);
|
||||
DataGenerators.runDataGenerators(dataDumpDirectory);
|
||||
Main.LOGGER.info("Done data generation!");
|
||||
Runtime.getRuntime().halt(0);
|
||||
MinecraftDataGenerator.start(
|
||||
MinecraftVersion.CURRENT.getName(),
|
||||
DGU.getCurrentlyRunningServer().getRunDirectory().toPath()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin;
|
||||
|
||||
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(SoundEvent.class)
|
||||
public interface SoundAccessor {
|
||||
@Accessor("id")
|
||||
Identifier id();
|
||||
}
|
||||
@@ -1,143 +1,18 @@
|
||||
package dev.u9g.minecraftdatagenerator.util;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.internal.LazilyParsedNumber;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
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.server.MinecraftServer;
|
||||
import net.minecraft.util.Language;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class DGU {
|
||||
|
||||
public static final TypeAdapter<JsonElement> JSON_ELEMENT = new TypeAdapter<>() {
|
||||
@Override
|
||||
public JsonElement read(JsonReader in) throws IOException {
|
||||
switch (in.peek()) {
|
||||
case STRING:
|
||||
return new JsonPrimitive(in.nextString());
|
||||
case NUMBER:
|
||||
String number = in.nextString();
|
||||
return new JsonPrimitive(new LazilyParsedNumber(number));
|
||||
case BOOLEAN:
|
||||
return new JsonPrimitive(in.nextBoolean());
|
||||
case NULL:
|
||||
in.nextNull();
|
||||
return JsonNull.INSTANCE;
|
||||
case BEGIN_ARRAY:
|
||||
JsonArray array = new JsonArray();
|
||||
in.beginArray();
|
||||
while (in.hasNext()) {
|
||||
array.add(read(in));
|
||||
}
|
||||
in.endArray();
|
||||
return array;
|
||||
case BEGIN_OBJECT:
|
||||
JsonObject object = new JsonObject();
|
||||
in.beginObject();
|
||||
while (in.hasNext()) {
|
||||
object.add(in.nextName(), read(in));
|
||||
}
|
||||
in.endObject();
|
||||
return object;
|
||||
case END_DOCUMENT:
|
||||
case NAME:
|
||||
case END_OBJECT:
|
||||
case END_ARRAY:
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, JsonElement value) throws IOException {
|
||||
if (value == null || value.isJsonNull()) {
|
||||
out.nullValue();
|
||||
} else if (value.isJsonPrimitive()) {
|
||||
JsonPrimitive primitive = value.getAsJsonPrimitive();
|
||||
if (primitive.isNumber()) {
|
||||
if (primitive.getAsDouble() == primitive.getAsLong()) {
|
||||
out.value(primitive.getAsLong());
|
||||
} else {
|
||||
out.value(primitive.getAsNumber());
|
||||
}
|
||||
} else if (primitive.isBoolean()) {
|
||||
out.value(primitive.getAsBoolean());
|
||||
} else {
|
||||
out.value(primitive.getAsString());
|
||||
}
|
||||
|
||||
} else if (value.isJsonArray()) {
|
||||
out.beginArray();
|
||||
for (JsonElement e : value.getAsJsonArray()) {
|
||||
write(out, e);
|
||||
}
|
||||
out.endArray();
|
||||
|
||||
} else if (value.isJsonObject()) {
|
||||
out.beginObject();
|
||||
for (Map.Entry<String, JsonElement> e : value.getAsJsonObject().entrySet()) {
|
||||
out.name(e.getKey());
|
||||
write(out, e.getValue());
|
||||
}
|
||||
out.endObject();
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException("Couldn't write " + value.getClass());
|
||||
}
|
||||
}
|
||||
};
|
||||
public static final Gson GSON = new GsonBuilder()
|
||||
.registerTypeAdapter(JsonElement.class, JSON_ELEMENT).setPrettyPrinting().create();
|
||||
private static final Language language = Language.getInstance();
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static MinecraftServer getCurrentlyRunningServerClient() {
|
||||
return MinecraftClient.getInstance().getServer();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static MinecraftServer getCurrentlyRunningServerDedicated() {
|
||||
public static MinecraftServer getCurrentlyRunningServer() {
|
||||
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
|
||||
}
|
||||
|
||||
public static MinecraftServer getCurrentlyRunningServer() {
|
||||
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
|
||||
if (environmentType == EnvType.CLIENT) {
|
||||
return getCurrentlyRunningServerClient();
|
||||
} else if (environmentType == EnvType.SERVER) {
|
||||
return getCurrentlyRunningServerDedicated();
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static String translateTextClient(String translationKey) {
|
||||
return I18n.translate(translationKey);
|
||||
}
|
||||
|
||||
private static String translateTextFallback(String translationKey) {
|
||||
try {
|
||||
return language.get(translationKey);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
throw new RuntimeException("Failed to translate: '" + translationKey + "'");
|
||||
}
|
||||
|
||||
public static String translateText(String translationKey) {
|
||||
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
|
||||
if (environmentType == EnvType.CLIENT) {
|
||||
return translateTextClient(translationKey);
|
||||
}
|
||||
return translateTextFallback(translationKey);
|
||||
return Language.getInstance().get(translationKey);
|
||||
}
|
||||
|
||||
public static World getWorld() {
|
||||
|
||||
@@ -10,18 +10,11 @@
|
||||
],
|
||||
"contact": {},
|
||||
"license": "MIT",
|
||||
"environment": "server",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"dev.u9g.minecraftdatagenerator.Main"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"minecraft-data-generator.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.18"
|
||||
"fabricloader": "*",
|
||||
"minecraft": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,9 @@
|
||||
"package": "dev.u9g.minecraftdatagenerator.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"ClientPlayerInteractionManagerMixin",
|
||||
"EULAMixin",
|
||||
"MiningToolItemAccessor",
|
||||
"ReadyMixin",
|
||||
"SoundAccessor"
|
||||
"ReadyMixin"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user