Actually fail CI if generation fails (#30)
* Actually fail unit tests if generation fails * Do not fail fast * Fix 1.8.9 spam * Fix 1.8.9 generation * Fix 1.8.9 generation * Fix entity generation on 4 versions * Fix projectile thrown package * Disable 1.17 recipe generator
This commit is contained in:
+8
-8
@@ -2,6 +2,7 @@ package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.FieldHelper;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
@@ -17,6 +18,8 @@ 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();
|
||||
@@ -45,20 +48,17 @@ public class EntitiesDataGenerator implements IDataGenerator {
|
||||
}
|
||||
|
||||
private static String getCategoryFrom(EntityType<?> entityType) {
|
||||
if (entityType == EntityType.PLAYER) return "UNKNOWN"; // fail early for player entities
|
||||
Entity entity = EntityType.createInstanceFromId(Registry.ENTITY_TYPE.getRawId(entityType), DGU.getWorld());
|
||||
if (entity == null)
|
||||
throw new IllegalStateException("Entity was null after trying to create a: " + DGU.translateText(entityType.getTranslationKey()));
|
||||
entity.discard();
|
||||
return switch (entity.getClass().getPackageName()) {
|
||||
ParameterizedType entityTypeClass = (ParameterizedType) FieldHelper.findStaticFieldWithValue(EntityType.class, entityType).getGenericType();
|
||||
Class<?> entityClass = (Class<?>) entityTypeClass.getActualTypeArguments()[0];
|
||||
return switch (entityClass.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";
|
||||
case "net.minecraft.entity.projectile", "net.minecraft.entity.projectile.thrown" -> "Projectiles";
|
||||
case "net.minecraft.entity.passive" -> "Passive mobs";
|
||||
case "net.minecraft.entity.vehicle" -> "Vehicles";
|
||||
case "net.minecraft.entity" -> "UNKNOWN";
|
||||
default -> throw new IllegalStateException("Unexpected entity type: " + entity.getClass().getPackageName());
|
||||
case "net.minecraft.entity.player", "net.minecraft.entity" -> "other";
|
||||
default -> throw new IllegalStateException("Unexpected entity type: " + entityClass.getPackageName());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+97
-104
@@ -1,23 +1,10 @@
|
||||
package dev.u9g.minecraftdatagenerator.generators;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.u9g.minecraftdatagenerator.util.DGU;
|
||||
import com.google.gson.JsonNull;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.recipe.ShapelessRecipe;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RecipeDataGenerator implements IDataGenerator {
|
||||
|
||||
private static int getRawIdFor(Item item) {
|
||||
@@ -31,102 +18,108 @@ public class RecipeDataGenerator implements IDataGenerator {
|
||||
|
||||
@Override
|
||||
public JsonElement generateDataJson() {
|
||||
JsonObject finalObj = new JsonObject();
|
||||
Multimap<Integer, JsonObject> recipes = ArrayListMultimap.create();
|
||||
for (Recipe<?> recipe : Objects.requireNonNull(DGU.getWorld()).getRecipeManager().values()) {
|
||||
if (recipe instanceof ShapedRecipe sr) {
|
||||
var ingredients = sr.getIngredients();
|
||||
List<Integer> ingr = new ArrayList<>();
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (i >= ingredients.size()) {
|
||||
ingr.add(-1);
|
||||
continue;
|
||||
}
|
||||
var stacks = ingredients.get(i);
|
||||
// var matching = stacks.getMatchingStacks();
|
||||
// if (matching.length == 0) {
|
||||
// JsonObject finalObj = new JsonObject();
|
||||
// Multimap<Integer, JsonObject> recipes = ArrayListMultimap.create();
|
||||
// for (Recipe<?> recipe : Objects.requireNonNull(DGU.getWorld()).getRecipeManager().values()) {
|
||||
// if (recipe instanceof ShapedRecipe sr) {
|
||||
// var ingredients = sr.getIngredients();
|
||||
// List<Integer> ingr = new ArrayList<>();
|
||||
// for (int i = 0; i < 9; i++) {
|
||||
// if (i >= ingredients.size()) {
|
||||
// ingr.add(-1);
|
||||
// } else {
|
||||
// ingr.add(getRawIdFor(matching[0].getItem()));
|
||||
// continue;
|
||||
// }
|
||||
}
|
||||
Lists.reverse(ingr);
|
||||
|
||||
JsonArray inShape = new JsonArray();
|
||||
|
||||
var iter = ingr.iterator();
|
||||
for (int y = 0; y < 3; y++) {
|
||||
var jsonRow = new JsonArray();
|
||||
int one = iter.next();
|
||||
int two = iter.next();
|
||||
int three = iter.next();
|
||||
if (y > 0 && one == -1 && two == -1 && three == -1) continue;
|
||||
jsonRow.add(one);
|
||||
jsonRow.add(two);
|
||||
jsonRow.add(three);
|
||||
inShape.add(jsonRow);
|
||||
}
|
||||
|
||||
JsonObject finalRecipe = new JsonObject();
|
||||
finalRecipe.add("inShape", inShape);
|
||||
|
||||
var resultObject = new JsonObject();
|
||||
resultObject.addProperty("id", getRawIdFor(sr.getOutput().getItem()));
|
||||
resultObject.addProperty("count", sr.getOutput().getCount());
|
||||
finalRecipe.add("result", resultObject);
|
||||
|
||||
String id = ((Integer) getRawIdFor(sr.getOutput().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++) {
|
||||
// var arr = new JsonArray();
|
||||
// for (int x = 0; x < sr.getWidth(); x++) {
|
||||
// if ((y*3)+x >= ingredients.size()) {
|
||||
// arr.add(JsonNull.INSTANCE);
|
||||
// continue;
|
||||
// }
|
||||
// var ingredient = ingredients.get((y*3)+x).getMatchingStacks(); // FIXME: fix when there are more than one matching stack
|
||||
// if (ingredient.length == 0) {
|
||||
// arr.add(JsonNull.INSTANCE);
|
||||
// } else {
|
||||
// arr.add(getRawIdFor(ingredient[0].getItem()));
|
||||
// }
|
||||
// }
|
||||
// input.add(arr);
|
||||
// var stacks = ingredients.get(i);
|
||||
//// var matching = stacks.getMatchingStacks();
|
||||
//// if (matching.length == 0) {
|
||||
//// ingr.add(-1);
|
||||
//// } else {
|
||||
//// ingr.add(getRawIdFor(matching[0].getItem()));
|
||||
//// }
|
||||
// }
|
||||
// var rootRecipeObject = new JsonObject();
|
||||
// rootRecipeObject.add("inShape", input);
|
||||
// Lists.reverse(ingr);
|
||||
//
|
||||
// JsonArray inShape = new JsonArray();
|
||||
//
|
||||
// var iter = ingr.iterator();
|
||||
// for (int y = 0; y < 3; y++) {
|
||||
// var jsonRow = new JsonArray();
|
||||
// int one = iter.next();
|
||||
// int two = iter.next();
|
||||
// int three = iter.next();
|
||||
// if (y > 0 && one == -1 && two == -1 && three == -1) continue;
|
||||
// jsonRow.add(one);
|
||||
// jsonRow.add(two);
|
||||
// jsonRow.add(three);
|
||||
// inShape.add(jsonRow);
|
||||
// }
|
||||
//
|
||||
// JsonObject finalRecipe = new JsonObject();
|
||||
// finalRecipe.add("inShape", inShape);
|
||||
//
|
||||
// var resultObject = new JsonObject();
|
||||
// resultObject.addProperty("id", getRawIdFor(sr.getOutput().getItem()));
|
||||
// resultObject.addProperty("count", sr.getOutput().getCount());
|
||||
// finalRecipe.add("result", resultObject);
|
||||
//
|
||||
// String id = ((Integer) getRawIdFor(sr.getOutput().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++) {
|
||||
//// var arr = new JsonArray();
|
||||
//// for (int x = 0; x < sr.getWidth(); x++) {
|
||||
//// if ((y*3)+x >= ingredients.size()) {
|
||||
//// arr.add(JsonNull.INSTANCE);
|
||||
//// continue;
|
||||
//// }
|
||||
//// var ingredient = ingredients.get((y*3)+x).getMatchingStacks(); // FIXME: fix when there are more than one matching stack
|
||||
//// if (ingredient.length == 0) {
|
||||
//// arr.add(JsonNull.INSTANCE);
|
||||
//// } else {
|
||||
//// arr.add(getRawIdFor(ingredient[0].getItem()));
|
||||
//// }
|
||||
//// }
|
||||
//// input.add(arr);
|
||||
//// }
|
||||
//// var rootRecipeObject = new JsonObject();
|
||||
//// rootRecipeObject.add("inShape", input);
|
||||
//// var resultObject = new JsonObject();
|
||||
//// resultObject.addProperty("id", getRawIdFor(sr.getOutput().getItem()));
|
||||
//// resultObject.addProperty("count", sr.getOutput().getCount());
|
||||
//// rootRecipeObject.add("result", resultObject);
|
||||
//// recipes.put(getRawIdFor(sr.getOutput().getItem()), rootRecipeObject);
|
||||
// } else if (recipe instanceof ShapelessRecipe sl) {
|
||||
// var ingredients = new JsonArray();
|
||||
// for (Ingredient ingredient : sl.getIngredients()) {
|
||||
// if (ingredient.isEmpty()) continue;
|
||||
//// ingredients.add(getRawIdFor(ingredient.getMatchingStacks()[0].getItem()));
|
||||
// }
|
||||
// var rootRecipeObject = new JsonObject();
|
||||
// rootRecipeObject.add("ingredients", ingredients);
|
||||
// var resultObject = new JsonObject();
|
||||
// resultObject.addProperty("id", getRawIdFor(sl.getOutput().getItem()));
|
||||
// resultObject.addProperty("count", sl.getOutput().getCount());
|
||||
// rootRecipeObject.add("result", resultObject);
|
||||
// recipes.put(getRawIdFor(sr.getOutput().getItem()), rootRecipeObject);
|
||||
} else if (recipe instanceof ShapelessRecipe sl) {
|
||||
var ingredients = new JsonArray();
|
||||
for (Ingredient ingredient : sl.getIngredients()) {
|
||||
if (ingredient.isEmpty()) continue;
|
||||
// ingredients.add(getRawIdFor(ingredient.getMatchingStacks()[0].getItem()));
|
||||
}
|
||||
var rootRecipeObject = new JsonObject();
|
||||
rootRecipeObject.add("ingredients", ingredients);
|
||||
var resultObject = new JsonObject();
|
||||
resultObject.addProperty("id", getRawIdFor(sl.getOutput().getItem()));
|
||||
resultObject.addProperty("count", sl.getOutput().getCount());
|
||||
rootRecipeObject.add("result", resultObject);
|
||||
recipes.put(getRawIdFor(sl.getOutput().getItem()), rootRecipeObject);
|
||||
}
|
||||
}
|
||||
recipes.forEach((a, b) -> {
|
||||
if (!finalObj.has(a.toString())) {
|
||||
finalObj.add(a.toString(), new JsonArray());
|
||||
}
|
||||
finalObj.get(a.toString()).getAsJsonArray().add(b);
|
||||
});
|
||||
return finalObj;
|
||||
// recipes.put(getRawIdFor(sl.getOutput().getItem()), rootRecipeObject);
|
||||
// }
|
||||
// }
|
||||
// recipes.forEach((a, b) -> {
|
||||
// if (!finalObj.has(a.toString())) {
|
||||
// finalObj.add(a.toString(), new JsonArray());
|
||||
// }
|
||||
// finalObj.get(a.toString()).getAsJsonArray().add(b);
|
||||
// });
|
||||
// return finalObj;
|
||||
return JsonNull.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return false; // TODO: Implement this
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user