Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions mc/1.21.11/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider

plugins {
id 'dg-mc-conventions'
}

unimined.minecraft {
version "1.21.11"

mappings {
mojmap()

devFallbackNamespace "mojmap"
}

customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) {
it.loader libs.versions.fabric.loader.get()
}

runs.config("server") {
javaVersion = JavaVersion.VERSION_21
}

defaultRemapJar = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package dev.u9g.minecraftdatagenerator.generators;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.util.DGU;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.RangedAttribute;

import java.util.Objects;

public class AttributesDataGenerator implements IDataGenerator {
@Override
public String getDataName() {
return "attributes";
}

@Override
public JsonElement generateDataJson() {
JsonArray arr = new JsonArray();
var registry = DGU.getWorld().registryAccess().lookupOrThrow(Registries.ATTRIBUTE);
for (Attribute attribute : registry) {
JsonObject obj = new JsonObject();
String name = Objects.requireNonNull(registry.getKey(attribute)).getPath();
while(name.contains("_")) {
name = name.replaceFirst("_[a-z]", String.valueOf(Character.toUpperCase(name.charAt(name.indexOf("_") + 1))));
}
obj.addProperty("name", name);
obj.addProperty("resource", Objects.requireNonNull(registry.getKey(attribute)).toString());
obj.addProperty("min", ((RangedAttribute) attribute).getMinValue());
obj.addProperty("max", ((RangedAttribute) attribute).getMaxValue());
obj.addProperty("default", attribute.getDefaultValue());
arr.add(obj);
}
return arr;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package dev.u9g.minecraftdatagenerator.generators;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.util.DGU;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.level.biome.Biome;

public class BiomesDataGenerator implements IDataGenerator {
private static String guessBiomeDimensionFromCategory(Biome biome) {
var biomeRegistry = DGU.getWorld().registryAccess().lookupOrThrow(Registries.BIOME);
if (biomeRegistry.wrapAsHolder(biome).is(BiomeTags.IS_NETHER)) {
return "nether";
} else if (biomeRegistry.wrapAsHolder(biome).is(BiomeTags.IS_END)) {
return "end";
} else {
return "overworld";
}
}

private static String guessCategoryBasedOnName(String name, String dimension) {
if (dimension.equals("nether")) {
return "nether";
} else if (dimension.equals("end")) {
return "the_end";
}

if (name.contains("end")) {
System.out.println();
}

if (name.contains("hills")) {
return "extreme_hills";
} else if (name.contains("ocean")) {
return "ocean";
} else if (name.contains("plains")) {
return "plains";
} else if (name.contains("ice") || name.contains("frozen")) {
return "ice";
} else if (name.contains("jungle")) {
return "jungle";
} else if (name.contains("desert")) {
return "desert";
} else if (name.contains("forest") || name.contains("grove")) {
return "forest";
} else if (name.contains("taiga")) {
return "taiga";
} else if (name.contains("swamp")) {
return "swamp";
} else if (name.contains("river")) {
return "river";
} else if (name.equals("the_end")) {
return "the_end";
} else if (name.contains("mushroom")) {
return "mushroom";
} else if (name.contains("beach") || name.equals("stony_shore")) {
return "beach";
} else if (name.contains("savanna")) {
return "savanna";
} else if (name.contains("badlands")) {
return "mesa";
} else if (name.contains("peaks") || name.equals("snowy_slopes") || name.equals("meadow")) {
return "mountain";
} else if (name.equals("the_void")) {
return "none";
} else if (name.contains("cave") || name.equals("deep_dark")) {
return "underground";
} else {
System.out.println("Unable to find biome category for biome with name: '" + name + "'");
return "none";
}
}

public static JsonObject generateBiomeInfo(Registry<Biome> registry, Biome biome) {
JsonObject biomeDesc = new JsonObject();
ResourceLocation registryKey = registry.getKey(biome);
String localizationKey = String.format("biome.%s.%s", registryKey.getNamespace(), registryKey.getPath());
String name = registryKey.getPath();
biomeDesc.addProperty("id", registry.getId(biome));
biomeDesc.addProperty("name", name);
String dimension = guessBiomeDimensionFromCategory(biome);
biomeDesc.addProperty("category", guessCategoryBasedOnName(name, dimension));
biomeDesc.addProperty("temperature", biome.getBaseTemperature());
//biomeDesc.addProperty("precipitation", biome.getPrecipitation().getName());// - removed in 1.19.4
biomeDesc.addProperty("has_precipitation", biome.hasPrecipitation());
//biomeDesc.addProperty("depth", biome.getDepth()); - Doesn't exist anymore in minecraft source
biomeDesc.addProperty("dimension", dimension);
biomeDesc.addProperty("displayName", DGU.translateText(localizationKey));
biomeDesc.addProperty("color", biome.getSkyColor());
//biomeDesc.addProperty("rainfall", biome.getDownfall());// - removed in 1.19.4

return biomeDesc;
}

@Override
public String getDataName() {
return "biomes";
}

@Override
public JsonArray generateDataJson() {
JsonArray biomesArray = new JsonArray();
RegistryAccess registryManager = DGU.getWorld().registryAccess();
Registry<Biome> biomeRegistry = registryManager.lookupOrThrow(Registries.BIOME);

biomeRegistry.stream()
.map(biome -> generateBiomeInfo(biomeRegistry, biome))
.forEach(biomesArray::add);
return biomesArray;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package dev.u9g.minecraftdatagenerator.generators;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import dev.u9g.minecraftdatagenerator.util.DGU;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;

import java.util.*;

public class BlockCollisionShapesDataGenerator implements IDataGenerator {

@Override
public String getDataName() {
return "blockCollisionShapes";
}

@Override
public JsonObject generateDataJson() {
Registry<Block> blockRegistry = DGU.getWorld().registryAccess().lookupOrThrow(Registries.BLOCK);
BlockShapesCache blockShapesCache = new BlockShapesCache();

blockRegistry.forEach(blockShapesCache::processBlock);

JsonObject resultObject = new JsonObject();

resultObject.add("blocks", blockShapesCache.dumpBlockShapeIndices(blockRegistry));
resultObject.add("shapes", blockShapesCache.dumpShapesObject());

return resultObject;
}

private static class BlockShapesCache {
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) {
List<BlockState> blockStates = block.getStateDefinition().getPossibleStates();
List<Integer> blockCollisionShapes = new ArrayList<>();

for (BlockState blockState : blockStates) {
VoxelShape blockShape = blockState.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
Integer blockShapeIndex = uniqueBlockShapes.get(blockShape);

if (blockShapeIndex == null) {
blockShapeIndex = lastCollisionShapeId++;
uniqueBlockShapes.put(blockShape, blockShapeIndex);
}
blockCollisionShapes.add(blockShapeIndex);
}

this.blockCollisionShapes.put(block, blockCollisionShapes);
}

public JsonObject dumpBlockShapeIndices(Registry<Block> blockRegistry) {
JsonObject resultObject = new JsonObject();

for (var entry : blockCollisionShapes.entrySet()) {
List<Integer> blockCollisions = entry.getValue();
long distinctShapesCount = blockCollisions.stream().distinct().count();
JsonElement blockCollision;
if (distinctShapesCount == 1L) {
blockCollision = new JsonPrimitive(blockCollisions.getFirst());
} else {
blockCollision = new JsonArray();
for (int collisionId : blockCollisions) {
((JsonArray) blockCollision).add(collisionId);
}
}

ResourceLocation registryKey = blockRegistry.getKey(entry.getKey());
resultObject.add(registryKey.getPath(), blockCollision);
}

return resultObject;
}

public JsonObject dumpShapesObject() {
JsonObject shapesObject = new JsonObject();

for (var entry : uniqueBlockShapes.entrySet()) {
JsonArray boxesArray = new JsonArray();
entry.getKey().forAllBoxes((x1, y1, z1, x2, y2, z2) -> {
JsonArray oneBoxJsonArray = new JsonArray();

oneBoxJsonArray.add(x1);
oneBoxJsonArray.add(y1);
oneBoxJsonArray.add(z1);

oneBoxJsonArray.add(x2);
oneBoxJsonArray.add(y2);
oneBoxJsonArray.add(z2);

boxesArray.add(oneBoxJsonArray);
});
shapesObject.add(Integer.toString(entry.getValue()), boxesArray);
}
return shapesObject;
}
}
}
Loading
Loading