Skip to content

Commit

Permalink
1.21 (#25)
Browse files Browse the repository at this point in the history
* 1.20.5 recipes: null over -1

* add 1.21

* 1.21 (#26)

* update classname

* update moved class

* updated to equivelant method since gettranslatekey removed

* added isCursed list as bandaid alternative for now since isCursed() removed

* added isTreasure list as bandaid alternative for now since isTreasure() removed

* found alternative method to canCombine() since removed

* modified getEnchantmentTarget name to handle registryEntryList since getApplicableItems dosnt return tagKey anymore

* bandaid list solution for "tradeable" property since isTradeable removed and no alternative in mappings

* bandaid solution for discoverable property since removed and no alternative to isAvailiableForRandomSelection in 1.21 mappings

* removed .toPath since apparently it dosnt exist

* no longer outputs in tagkey format

* fixed not adding enchantcategories for items properly

* added SuperGamerTron tag solution

* Update build.yml

---------

Co-authored-by: Madlykeanu <[email protected]>
Co-authored-by: Romain Beaumont <[email protected]>
  • Loading branch information
3 people authored Oct 27, 2024
1 parent 131218c commit 2c423f7
Show file tree
Hide file tree
Showing 25 changed files with 1,681 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ jobs:
"1.19.2",
"1.20",
"1.20.4",
"1.20.5"
"1.20.5",
"1.21"
]

name: Build ${{ matrix.version }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,52 @@ public JsonElement generateDataJson() {
for (RecipeEntry<?> recipeE : Objects.requireNonNull(DGU.getWorld()).getRecipeManager().values()) {
Recipe<?> recipe = recipeE.value();
if (recipe instanceof ShapedRecipe sr) {
generateShapedRecipe(registryManager, finalObj, sr, 0);

var ingredients = sr.getIngredients();
List<Integer> ingr = new ArrayList<>();
for (int i = 0; i < 9; i++) {
if (i >= ingredients.size()) {
ingr.add(null);
continue;
}
var stacks = ingredients.get(i);
var matching = stacks.getMatchingStacks();
if (matching.length == 0) {
ingr.add(null);
} else {
ingr.add(getRawIdFor(matching[0].getItem()));
}
}
//Lists.reverse(ingr);

JsonArray inShape = new JsonArray();


var iter = ingr.iterator();
for (int y = 0; y < sr.getHeight(); y++) {
var jsonRow = new JsonArray();
for (int z = 0; z < sr.getWidth(); z++) {
jsonRow.add(iter.next());
}
inShape.add(jsonRow);
}

JsonObject finalRecipe = new JsonObject();
finalRecipe.add("inShape", inShape);

var resultObject = new JsonObject();
resultObject.addProperty("id", getRawIdFor(sr.getResult(registryManager).getItem()));
resultObject.addProperty("count", sr.getResult(registryManager).getCount());
finalRecipe.add("result", resultObject);

String id = ((Integer) getRawIdFor(sr.getResult(registryManager).getItem())).toString();

if (!finalObj.has(id)) {
finalObj.add(id, new JsonArray());
}
finalObj.get(id).getAsJsonArray().add(finalRecipe);


// var input = new JsonArray();
// var ingredients = sr.getIngredients().stream().toList();
// for (int y = 0; y < sr.getHeight(); y++) {
Expand Down
47 changes: 47 additions & 0 deletions 1.21/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask
import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider

plugins {
id 'xyz.wagyourtail.unimined'
}

unimined.minecraft {
version "1.21"

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 {
implementation project(":common")
}

processResources {
filteringCharset "UTF-8"

filesMatching("fabric.mod.json") {
expand "version": project.version
}
}

tasks.withType(RemapJarTask).configureEach {
onlyIf { false}
}

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
}
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.registry.DynamicRegistryManager;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BiomeTags;
import net.minecraft.util.Identifier;
import net.minecraft.world.biome.Biome;

public class BiomesDataGenerator implements IDataGenerator {
private static String guessBiomeDimensionFromCategory(Biome biome) {
var biomeRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.BIOME);
if (biomeRegistry.getEntry(biome).isIn(BiomeTags.IS_NETHER)) {
return "nether";
} else if (biomeRegistry.getEntry(biome).isIn(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();
Identifier registryKey = registry.getKey(biome).orElseThrow().getValue();
String localizationKey = String.format("biome.%s.%s", registryKey.getNamespace(), registryKey.getPath());
String name = registryKey.getPath();
biomeDesc.addProperty("id", registry.getRawId(biome));
biomeDesc.addProperty("name", name);
String dimension = guessBiomeDimensionFromCategory(biome);
biomeDesc.addProperty("category", guessCategoryBasedOnName(name, dimension));
biomeDesc.addProperty("temperature", biome.getTemperature());
//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();
DynamicRegistryManager registryManager = DGU.getWorld().getRegistryManager();
Registry<Biome> biomeRegistry = registryManager.get(RegistryKeys.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.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.EmptyBlockView;

import java.util.*;

public class BlockCollisionShapesDataGenerator implements IDataGenerator {

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

@Override
public JsonObject generateDataJson() {
Registry<Block> blockRegistry = DGU.getWorld().getRegistryManager().get(RegistryKeys.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.getStateManager().getStates();
List<Integer> blockCollisionShapes = new ArrayList<>();

for (BlockState blockState : blockStates) {
VoxelShape blockShape = blockState.getCollisionShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN);
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);
}
}

Identifier registryKey = blockRegistry.getKey(entry.getKey()).orElseThrow().getValue();
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().forEachBox((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

0 comments on commit 2c423f7

Please sign in to comment.