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 "22w19a"
|
||||
|
||||
mappings {
|
||||
intermediary()
|
||||
yarn(6)
|
||||
|
||||
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=22w19a
|
||||
yarn_mappings=22w19a+build.1
|
||||
loader_version=0.14.5
|
||||
# Dependencies
|
||||
# check this on https://modmuss50.me/fabric.html
|
||||
fabric_version=0.52.2+1.19
|
||||
@@ -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() {
|
||||
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -2,42 +2,42 @@ package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.mixin.TheEndBiomeDataAccessor;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import net.fabricmc.fabric.api.biome.v1.NetherBiomes;
|
||||
import net.minecraft.tag.BiomeTags;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class BiomesDataGenerator implements IDataGenerator {
|
||||
|
||||
private static String guessBiomeDimensionFromCategory(Biome biome) {
|
||||
// FIND A WAY TO FIND WHAT CATEGORY THE BIOME IS
|
||||
var key = DynamicRegistryManager.BUILTIN.get().get(Registry.BIOME_KEY).getKey(biome).orElseThrow();
|
||||
System.out.println(DynamicRegistryManager.BUILTIN.get().get(Registry.BIOME_KEY).getKey(biome).orElseThrow());
|
||||
if (NetherBiomes.canGenerateInNether(key)) {
|
||||
private static String guessBiomeDimensionFromCategory(RegistryKey<Biome> biome) {
|
||||
var biomeRegistry = BuiltinRegistries.BIOME;
|
||||
if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_NETHER)) {
|
||||
return "nether";
|
||||
} else if (TheEndBiomeDataAccessor.END_BARRENS_MAP().containsKey(key) || TheEndBiomeDataAccessor.END_BIOMES_MAP().containsKey(key) || TheEndBiomeDataAccessor.END_MIDLANDS_MAP().containsKey(key)) {
|
||||
} else if (biomeRegistry.getEntry(biome).orElseThrow().isIn(BiomeTags.IS_END)) {
|
||||
return "end";
|
||||
} else {
|
||||
return "overworld";
|
||||
}
|
||||
return "overworld";
|
||||
}
|
||||
|
||||
public static JsonObject generateBiomeInfo(Registry<Biome> registry, Biome biome) {
|
||||
JsonObject biomeDesc = new JsonObject();
|
||||
Identifier registryKey = registry.getKey(biome).orElseThrow().getValue();
|
||||
String localizationKey = String.format("biome.%s.%s", registryKey.getNamespace(), registryKey.getPath());
|
||||
RegistryKey<Biome> registryKey = registry.getKey(biome).orElseThrow();
|
||||
Identifier identifier = registryKey.getValue();
|
||||
String localizationKey = String.format("biome.%s.%s", identifier.getNamespace(), identifier.getPath());
|
||||
|
||||
biomeDesc.addProperty("id", registry.getRawId(biome));
|
||||
biomeDesc.addProperty("name", registryKey.getPath());
|
||||
biomeDesc.addProperty("name", identifier.getPath());
|
||||
|
||||
//FIXME: this...
|
||||
biomeDesc.addProperty("category", "");
|
||||
biomeDesc.addProperty("temperature", biome.getTemperature());
|
||||
biomeDesc.addProperty("precipitation", biome.getPrecipitation().getName());
|
||||
//biomeDesc.addProperty("depth", biome.getDepth()); - Doesn't exist anymore in minecraft source
|
||||
biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(biome));
|
||||
biomeDesc.addProperty("dimension", guessBiomeDimensionFromCategory(registryKey));
|
||||
biomeDesc.addProperty("displayName", DGU.translateText(localizationKey));
|
||||
biomeDesc.addProperty("color", biome.getSkyColor());
|
||||
biomeDesc.addProperty("rainfall", biome.getDownfall());
|
||||
|
||||
+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
-10
@@ -105,7 +105,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)) {
|
||||
@@ -115,19 +115,19 @@ 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("name", registryKey.getPath());
|
||||
blockDesc.addProperty("displayName", DGU.translateText(localizationKey));
|
||||
|
||||
@@ -148,8 +148,8 @@ public class BlocksDataGenerator implements IDataGenerator {
|
||||
blockDesc.addProperty("filterLight", defaultState.getOpacity(EmptyBlockView.INSTANCE, BlockPos.ORIGIN));
|
||||
|
||||
blockDesc.addProperty("defaultState", Block.getRawIdFromState(defaultState));
|
||||
blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.get(0)));
|
||||
blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.get(blockStates.size() - 1)));
|
||||
blockDesc.addProperty("minStateId", Block.getRawIdFromState(blockStates.getFirst()));
|
||||
blockDesc.addProperty("maxStateId", Block.getRawIdFromState(blockStates.getLast()));
|
||||
|
||||
JsonArray stateProperties = new JsonArray();
|
||||
for (Property<?> property : block.getStateManager().getProperties()) {
|
||||
@@ -167,7 +167,7 @@ public class BlocksDataGenerator implements IDataGenerator {
|
||||
}
|
||||
|
||||
List<ItemStack> actualBlockDrops = new ArrayList<>();
|
||||
populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.get(0), actualBlockDrops);
|
||||
populateDropsIfPossible(defaultState, effectiveTools.isEmpty() ? Items.AIR : effectiveTools.getFirst(), actualBlockDrops);
|
||||
|
||||
JsonArray dropsArray = new JsonArray();
|
||||
for (ItemStack dropStack : actualBlockDrops) {
|
||||
@@ -189,10 +189,9 @@ public class BlocksDataGenerator implements IDataGenerator {
|
||||
@Override
|
||||
public JsonArray generateDataJson() {
|
||||
JsonArray resultBlocksArray = new JsonArray();
|
||||
Registry<Block> blockRegistry = Registry.BLOCK;
|
||||
List<MaterialsDataGenerator.MaterialInfo> availableMaterials = MaterialsDataGenerator.getGlobalMaterialInfo();
|
||||
|
||||
blockRegistry.forEach(block -> resultBlocksArray.add(generateBlock(blockRegistry, availableMaterials, block)));
|
||||
Registry.BLOCK.forEach(block -> resultBlocksArray.add(generateBlock(availableMaterials, block)));
|
||||
return resultBlocksArray;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +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 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)) {
|
||||
JsonWriter jsonWriter = new JsonWriter(writer);
|
||||
jsonWriter.setIndent(" ");
|
||||
Streams.write(outputElement, jsonWriter);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
-1
@@ -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();
|
||||
|
||||
-14
@@ -11,24 +11,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();
|
||||
|
||||
|
||||
+6
-16
@@ -2,7 +2,6 @@ package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
@@ -18,10 +17,7 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
|
||||
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();
|
||||
@@ -50,17 +46,11 @@ public class EntitiesDataGenerator implements IDataGenerator {
|
||||
|
||||
private static String getCategoryFrom(EntityType<?> entityType) {
|
||||
if (entityType == EntityType.PLAYER) return "other"; // fail early for player entities
|
||||
Class<? extends Entity> entityClazz = null;
|
||||
try {
|
||||
for (var field : EntityType.class.getFields())
|
||||
if (entityType == field.get(EntityType.class))
|
||||
entityClazz = (Class<? extends Entity>) ((ParameterizedType) TypeToken.get(field.getGenericType()).getType()).getActualTypeArguments()[0];
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (entityClazz == null) throw new RuntimeException("Shouldn't be null...");
|
||||
return switch (entityClazz.getPackageName()) {
|
||||
Entity entity = entityType.create(DGU.getWorld());
|
||||
if (entity == null)
|
||||
throw new Error("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey()));
|
||||
entity.discard();
|
||||
return switch (entity.getClass().getPackageName()) {
|
||||
case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile";
|
||||
case "net.minecraft.entity.boss", "net.minecraft.entity.mob", "net.minecraft.entity.boss.dragon" ->
|
||||
"Hostile mobs";
|
||||
@@ -68,7 +58,7 @@ public class EntitiesDataGenerator implements IDataGenerator {
|
||||
case "net.minecraft.entity.passive" -> "Passive mobs";
|
||||
case "net.minecraft.entity.vehicle" -> "Vehicles";
|
||||
case "net.minecraft.entity" -> "UNKNOWN";
|
||||
default -> throw new Error("Unexpected entity type: " + entityClazz.getPackageName());
|
||||
default -> throw new Error("Unexpected entity type: " + entity.getClass().getPackageName());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.minecraft.util.registry.Registry;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FoodsDataGenerator implements IDataGenerator {
|
||||
|
||||
public static JsonObject generateFoodDescriptor(Registry<Item> registry, Item foodItem) {
|
||||
JsonObject foodDesc = new JsonObject();
|
||||
Identifier registryKey = registry.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();
|
||||
}
|
||||
+10
-11
@@ -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;
|
||||
@@ -40,7 +39,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()
|
||||
@@ -52,13 +51,13 @@ 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);
|
||||
@@ -105,14 +104,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);
|
||||
@@ -131,7 +130,7 @@ public class MaterialsDataGenerator implements IDataGenerator {
|
||||
TagKey<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();
|
||||
|
||||
+3
-6
@@ -5,13 +5,11 @@ import com.google.gson.JsonObject;
|
||||
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("id", Registry.SOUND_EVENT.getRawId(soundEvent));
|
||||
soundDesc.addProperty("name", soundEvent.getId().getPath());
|
||||
|
||||
return soundDesc;
|
||||
@@ -25,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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package dev.u9g.minecraftdatagenerator.mixin;
|
||||
|
||||
import net.fabricmc.fabric.impl.biome.TheEndBiomeData;
|
||||
import net.fabricmc.fabric.impl.biome.WeightedPicker;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(TheEndBiomeData.class)
|
||||
public interface TheEndBiomeDataAccessor {
|
||||
@Accessor("END_BIOMES_MAP")
|
||||
static Map<RegistryKey<Biome>, WeightedPicker<RegistryKey<Biome>>> END_BIOMES_MAP() {
|
||||
throw new IllegalStateException("Should never be called.");
|
||||
}
|
||||
|
||||
@Accessor("END_MIDLANDS_MAP")
|
||||
static Map<RegistryKey<Biome>, WeightedPicker<RegistryKey<Biome>>> END_MIDLANDS_MAP() {
|
||||
throw new IllegalStateException("Should never be called.");
|
||||
}
|
||||
|
||||
@Accessor("END_BARRENS_MAP")
|
||||
static Map<RegistryKey<Biome>, WeightedPicker<RegistryKey<Biome>>> END_BARRENS_MAP() {
|
||||
throw new IllegalStateException("Should never be called.");
|
||||
}
|
||||
}
|
||||
@@ -1,57 +1,18 @@
|
||||
package dev.u9g.minecraftdatagenerator.util;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Language;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class DGU {
|
||||
|
||||
private static final Language language = Language.getInstance();
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static MinecraftServer getCurrentlyRunningServerClient() {
|
||||
return MinecraftClient.getInstance().getServer();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static MinecraftServer getCurrentlyRunningServerDedicated() {
|
||||
public static MinecraftServer getCurrentlyRunningServer() {
|
||||
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
|
||||
}
|
||||
|
||||
public static MinecraftServer getCurrentlyRunningServer() {
|
||||
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
|
||||
if (environmentType == EnvType.CLIENT) {
|
||||
return getCurrentlyRunningServerClient();
|
||||
} else if (environmentType == EnvType.SERVER) {
|
||||
return getCurrentlyRunningServerDedicated();
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static String translateTextClient(String translationKey) {
|
||||
return I18n.translate(translationKey);
|
||||
}
|
||||
|
||||
private static String translateTextFallback(String translationKey) {
|
||||
try {
|
||||
return language.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.5",
|
||||
"fabric": "*",
|
||||
"minecraft": ">=1.18"
|
||||
"fabricloader": "*",
|
||||
"minecraft": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
"package": "dev.u9g.minecraftdatagenerator.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"ClientPlayerInteractionManagerMixin",
|
||||
"MiningToolItemAccessor",
|
||||
"ReadyMixin",
|
||||
"TheEndBiomeDataAccessor"
|
||||
"ReadyMixin"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user