Skip to content

Commit 38a4c0a

Browse files
Add version 1.21.9
1 parent e988c56 commit 38a4c0a

25 files changed

+1773
-1
lines changed

mc/1.21.9/build.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider
2+
3+
plugins {
4+
id 'dg-mc-conventions'
5+
}
6+
7+
unimined.minecraft {
8+
version "1.21.9"
9+
10+
mappings {
11+
mojmap()
12+
13+
devFallbackNamespace "mojmap"
14+
}
15+
16+
customPatcher(new CustomOfficialFabricMinecraftTransformer(project, delegate as MinecraftProvider)) {
17+
it.loader libs.versions.fabric.loader.get()
18+
}
19+
20+
runs.config("server") {
21+
javaVersion = JavaVersion.VERSION_21
22+
}
23+
24+
defaultRemapJar = true
25+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package dev.u9g.minecraftdatagenerator.generators;
2+
3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonElement;
5+
import com.google.gson.JsonObject;
6+
import dev.u9g.minecraftdatagenerator.util.DGU;
7+
import net.minecraft.core.registries.Registries;
8+
import net.minecraft.world.entity.ai.attributes.Attribute;
9+
import net.minecraft.world.entity.ai.attributes.RangedAttribute;
10+
11+
import java.util.Objects;
12+
13+
public class AttributesDataGenerator implements IDataGenerator {
14+
@Override
15+
public String getDataName() {
16+
return "attributes";
17+
}
18+
19+
@Override
20+
public JsonElement generateDataJson() {
21+
JsonArray arr = new JsonArray();
22+
var registry = DGU.getWorld().registryAccess().lookupOrThrow(Registries.ATTRIBUTE);
23+
for (Attribute attribute : registry) {
24+
JsonObject obj = new JsonObject();
25+
String name = Objects.requireNonNull(registry.getKey(attribute)).getPath();
26+
while(name.contains("_")) {
27+
name = name.replaceFirst("_[a-z]", String.valueOf(Character.toUpperCase(name.charAt(name.indexOf("_") + 1))));
28+
}
29+
obj.addProperty("name", name);
30+
obj.addProperty("resource", Objects.requireNonNull(registry.getKey(attribute)).toString());
31+
obj.addProperty("min", ((RangedAttribute) attribute).getMinValue());
32+
obj.addProperty("max", ((RangedAttribute) attribute).getMaxValue());
33+
obj.addProperty("default", attribute.getDefaultValue());
34+
arr.add(obj);
35+
}
36+
return arr;
37+
}
38+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package dev.u9g.minecraftdatagenerator.generators;
2+
3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonObject;
5+
import dev.u9g.minecraftdatagenerator.util.DGU;
6+
import net.minecraft.core.Registry;
7+
import net.minecraft.core.RegistryAccess;
8+
import net.minecraft.core.registries.Registries;
9+
import net.minecraft.resources.ResourceLocation;
10+
import net.minecraft.tags.BiomeTags;
11+
import net.minecraft.world.level.biome.Biome;
12+
13+
public class BiomesDataGenerator implements IDataGenerator {
14+
private static String guessBiomeDimensionFromCategory(Biome biome) {
15+
var biomeRegistry = DGU.getWorld().registryAccess().lookupOrThrow(Registries.BIOME);
16+
if (biomeRegistry.wrapAsHolder(biome).is(BiomeTags.IS_NETHER)) {
17+
return "nether";
18+
} else if (biomeRegistry.wrapAsHolder(biome).is(BiomeTags.IS_END)) {
19+
return "end";
20+
} else {
21+
return "overworld";
22+
}
23+
}
24+
25+
private static String guessCategoryBasedOnName(String name, String dimension) {
26+
if (dimension.equals("nether")) {
27+
return "nether";
28+
} else if (dimension.equals("end")) {
29+
return "the_end";
30+
}
31+
32+
if (name.contains("end")) {
33+
System.out.println();
34+
}
35+
36+
if (name.contains("hills")) {
37+
return "extreme_hills";
38+
} else if (name.contains("ocean")) {
39+
return "ocean";
40+
} else if (name.contains("plains")) {
41+
return "plains";
42+
} else if (name.contains("ice") || name.contains("frozen")) {
43+
return "ice";
44+
} else if (name.contains("jungle")) {
45+
return "jungle";
46+
} else if (name.contains("desert")) {
47+
return "desert";
48+
} else if (name.contains("forest") || name.contains("grove")) {
49+
return "forest";
50+
} else if (name.contains("taiga")) {
51+
return "taiga";
52+
} else if (name.contains("swamp")) {
53+
return "swamp";
54+
} else if (name.contains("river")) {
55+
return "river";
56+
} else if (name.equals("the_end")) {
57+
return "the_end";
58+
} else if (name.contains("mushroom")) {
59+
return "mushroom";
60+
} else if (name.contains("beach") || name.equals("stony_shore")) {
61+
return "beach";
62+
} else if (name.contains("savanna")) {
63+
return "savanna";
64+
} else if (name.contains("badlands")) {
65+
return "mesa";
66+
} else if (name.contains("peaks") || name.equals("snowy_slopes") || name.equals("meadow")) {
67+
return "mountain";
68+
} else if (name.equals("the_void")) {
69+
return "none";
70+
} else if (name.contains("cave") || name.equals("deep_dark")) {
71+
return "underground";
72+
} else {
73+
System.out.println("Unable to find biome category for biome with name: '" + name + "'");
74+
return "none";
75+
}
76+
}
77+
78+
public static JsonObject generateBiomeInfo(Registry<Biome> registry, Biome biome) {
79+
JsonObject biomeDesc = new JsonObject();
80+
ResourceLocation registryKey = registry.getKey(biome);
81+
String localizationKey = String.format("biome.%s.%s", registryKey.getNamespace(), registryKey.getPath());
82+
String name = registryKey.getPath();
83+
biomeDesc.addProperty("id", registry.getId(biome));
84+
biomeDesc.addProperty("name", name);
85+
String dimension = guessBiomeDimensionFromCategory(biome);
86+
biomeDesc.addProperty("category", guessCategoryBasedOnName(name, dimension));
87+
biomeDesc.addProperty("temperature", biome.getBaseTemperature());
88+
//biomeDesc.addProperty("precipitation", biome.getPrecipitation().getName());// - removed in 1.19.4
89+
biomeDesc.addProperty("has_precipitation", biome.hasPrecipitation());
90+
//biomeDesc.addProperty("depth", biome.getDepth()); - Doesn't exist anymore in minecraft source
91+
biomeDesc.addProperty("dimension", dimension);
92+
biomeDesc.addProperty("displayName", DGU.translateText(localizationKey));
93+
biomeDesc.addProperty("color", biome.getSkyColor());
94+
//biomeDesc.addProperty("rainfall", biome.getDownfall());// - removed in 1.19.4
95+
96+
return biomeDesc;
97+
}
98+
99+
@Override
100+
public String getDataName() {
101+
return "biomes";
102+
}
103+
104+
@Override
105+
public JsonArray generateDataJson() {
106+
JsonArray biomesArray = new JsonArray();
107+
RegistryAccess registryManager = DGU.getWorld().registryAccess();
108+
Registry<Biome> biomeRegistry = registryManager.lookupOrThrow(Registries.BIOME);
109+
110+
biomeRegistry.stream()
111+
.map(biome -> generateBiomeInfo(biomeRegistry, biome))
112+
.forEach(biomesArray::add);
113+
return biomesArray;
114+
}
115+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package dev.u9g.minecraftdatagenerator.generators;
2+
3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonElement;
5+
import com.google.gson.JsonObject;
6+
import com.google.gson.JsonPrimitive;
7+
import dev.u9g.minecraftdatagenerator.util.DGU;
8+
import net.minecraft.core.BlockPos;
9+
import net.minecraft.core.Registry;
10+
import net.minecraft.core.registries.Registries;
11+
import net.minecraft.resources.ResourceLocation;
12+
import net.minecraft.world.level.EmptyBlockGetter;
13+
import net.minecraft.world.level.block.Block;
14+
import net.minecraft.world.level.block.state.BlockState;
15+
import net.minecraft.world.phys.shapes.VoxelShape;
16+
17+
import java.util.*;
18+
19+
public class BlockCollisionShapesDataGenerator implements IDataGenerator {
20+
21+
@Override
22+
public String getDataName() {
23+
return "blockCollisionShapes";
24+
}
25+
26+
@Override
27+
public JsonObject generateDataJson() {
28+
Registry<Block> blockRegistry = DGU.getWorld().registryAccess().lookupOrThrow(Registries.BLOCK);
29+
BlockShapesCache blockShapesCache = new BlockShapesCache();
30+
31+
blockRegistry.forEach(blockShapesCache::processBlock);
32+
33+
JsonObject resultObject = new JsonObject();
34+
35+
resultObject.add("blocks", blockShapesCache.dumpBlockShapeIndices(blockRegistry));
36+
resultObject.add("shapes", blockShapesCache.dumpShapesObject());
37+
38+
return resultObject;
39+
}
40+
41+
private static class BlockShapesCache {
42+
public final Map<VoxelShape, Integer> uniqueBlockShapes = new LinkedHashMap<>();
43+
public final Map<Block, List<Integer>> blockCollisionShapes = new LinkedHashMap<>();
44+
private int lastCollisionShapeId = 0;
45+
46+
public void processBlock(Block block) {
47+
List<BlockState> blockStates = block.getStateDefinition().getPossibleStates();
48+
List<Integer> blockCollisionShapes = new ArrayList<>();
49+
50+
for (BlockState blockState : blockStates) {
51+
VoxelShape blockShape = blockState.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
52+
Integer blockShapeIndex = uniqueBlockShapes.get(blockShape);
53+
54+
if (blockShapeIndex == null) {
55+
blockShapeIndex = lastCollisionShapeId++;
56+
uniqueBlockShapes.put(blockShape, blockShapeIndex);
57+
}
58+
blockCollisionShapes.add(blockShapeIndex);
59+
}
60+
61+
this.blockCollisionShapes.put(block, blockCollisionShapes);
62+
}
63+
64+
public JsonObject dumpBlockShapeIndices(Registry<Block> blockRegistry) {
65+
JsonObject resultObject = new JsonObject();
66+
67+
for (var entry : blockCollisionShapes.entrySet()) {
68+
List<Integer> blockCollisions = entry.getValue();
69+
long distinctShapesCount = blockCollisions.stream().distinct().count();
70+
JsonElement blockCollision;
71+
if (distinctShapesCount == 1L) {
72+
blockCollision = new JsonPrimitive(blockCollisions.getFirst());
73+
} else {
74+
blockCollision = new JsonArray();
75+
for (int collisionId : blockCollisions) {
76+
((JsonArray) blockCollision).add(collisionId);
77+
}
78+
}
79+
80+
ResourceLocation registryKey = blockRegistry.getKey(entry.getKey());
81+
resultObject.add(registryKey.getPath(), blockCollision);
82+
}
83+
84+
return resultObject;
85+
}
86+
87+
public JsonObject dumpShapesObject() {
88+
JsonObject shapesObject = new JsonObject();
89+
90+
for (var entry : uniqueBlockShapes.entrySet()) {
91+
JsonArray boxesArray = new JsonArray();
92+
entry.getKey().forAllBoxes((x1, y1, z1, x2, y2, z2) -> {
93+
JsonArray oneBoxJsonArray = new JsonArray();
94+
95+
oneBoxJsonArray.add(x1);
96+
oneBoxJsonArray.add(y1);
97+
oneBoxJsonArray.add(z1);
98+
99+
oneBoxJsonArray.add(x2);
100+
oneBoxJsonArray.add(y2);
101+
oneBoxJsonArray.add(z2);
102+
103+
boxesArray.add(oneBoxJsonArray);
104+
});
105+
shapesObject.add(Integer.toString(entry.getValue()), boxesArray);
106+
}
107+
return shapesObject;
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)