Update cutting recipe generator

This commit is contained in:
Sollace 2024-06-30 01:12:29 +01:00
parent fcb58b759a
commit 6570248b32
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 97 additions and 57 deletions

View file

@ -14,6 +14,7 @@ import com.minelittlepony.unicopia.datagen.providers.loot.UChestAdditionsLootTab
import com.minelittlepony.unicopia.datagen.providers.loot.UChestLootTableProvider; import com.minelittlepony.unicopia.datagen.providers.loot.UChestLootTableProvider;
import com.minelittlepony.unicopia.datagen.providers.loot.UEntityAdditionsLootTableProvider; import com.minelittlepony.unicopia.datagen.providers.loot.UEntityAdditionsLootTableProvider;
import com.minelittlepony.unicopia.datagen.providers.loot.UEntityLootTableProvider; import com.minelittlepony.unicopia.datagen.providers.loot.UEntityLootTableProvider;
import com.minelittlepony.unicopia.datagen.providers.recipe.CuttingBoardRecipeJsonBuilder;
import com.minelittlepony.unicopia.datagen.providers.recipe.URecipeProvider; import com.minelittlepony.unicopia.datagen.providers.recipe.URecipeProvider;
import com.minelittlepony.unicopia.datagen.providers.tag.UBlockTagProvider; import com.minelittlepony.unicopia.datagen.providers.tag.UBlockTagProvider;
import com.minelittlepony.unicopia.datagen.providers.tag.UDamageTypeProvider; import com.minelittlepony.unicopia.datagen.providers.tag.UDamageTypeProvider;
@ -76,6 +77,7 @@ public class Datagen implements DataGeneratorEntrypoint {
@Override @Override
public void buildRegistry(RegistryBuilder builder) { public void buildRegistry(RegistryBuilder builder) {
CuttingBoardRecipeJsonBuilder.CuttingBoardRecipe.bootstrap();
builder.addRegistry(RegistryKeys.BIOME, UWorldGen.REGISTRY); builder.addRegistry(RegistryKeys.BIOME, UWorldGen.REGISTRY);
builder.addRegistry(RegistryKeys.DAMAGE_TYPE, UDamageTypes.REGISTRY); builder.addRegistry(RegistryKeys.DAMAGE_TYPE, UDamageTypes.REGISTRY);
} }

View file

@ -1,30 +1,38 @@
/*
package com.minelittlepony.unicopia.datagen.providers.recipe; package com.minelittlepony.unicopia.datagen.providers.recipe;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
import org.spongepowered.include.com.google.common.base.Preconditions; import org.spongepowered.include.com.google.common.base.Preconditions;
import com.google.gson.JsonArray; import com.mojang.serialization.Codec;
import com.google.gson.JsonObject; import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.advancement.Advancement; import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementCriterion; import net.minecraft.advancement.AdvancementCriterion;
import net.minecraft.advancement.AdvancementEntry;
import net.minecraft.advancement.AdvancementRequirements; import net.minecraft.advancement.AdvancementRequirements;
import net.minecraft.advancement.AdvancementRewards; import net.minecraft.advancement.AdvancementRewards;
import net.minecraft.advancement.criterion.RecipeUnlockedCriterion; import net.minecraft.advancement.criterion.RecipeUnlockedCriterion;
import net.minecraft.data.server.recipe.RecipeExporter; import net.minecraft.data.server.recipe.RecipeExporter;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.recipe.Ingredient; import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.RecipeType;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey; import net.minecraft.registry.tag.TagKey;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.dynamic.Codecs;
import net.minecraft.world.World;
public class CuttingBoardRecipeJsonBuilder { public class CuttingBoardRecipeJsonBuilder {
private final Map<String, AdvancementCriterion<?>> criterions = new LinkedHashMap<>(); private final Map<String, AdvancementCriterion<?>> criterions = new LinkedHashMap<>();
@ -32,9 +40,11 @@ public class CuttingBoardRecipeJsonBuilder {
private final ItemConvertible output; private final ItemConvertible output;
private final TagKey<Item> tool; private final TagKey<Item> tool;
private final List<Supplier<Identifier>> results = new ArrayList<>(); private final List<Result> results = new ArrayList<>();
private final List<Ingredient> ingredients = new ArrayList<>(); private final List<Ingredient> ingredients = new ArrayList<>();
private Identifier sound = new Identifier("minecraft:item.axe.strip");
public static CuttingBoardRecipeJsonBuilder create(ItemConvertible output, TagKey<Item> tool) { public static CuttingBoardRecipeJsonBuilder create(ItemConvertible output, TagKey<Item> tool) {
return new CuttingBoardRecipeJsonBuilder(output, tool); return new CuttingBoardRecipeJsonBuilder(output, tool);
} }
@ -45,18 +55,23 @@ public class CuttingBoardRecipeJsonBuilder {
result(output); result(output);
} }
public CuttingBoardRecipeJsonBuilder sound(SoundEvent sound) {
this.sound = Registries.SOUND_EVENT.getId(sound);
return this;
}
public CuttingBoardRecipeJsonBuilder input(ItemConvertible input) { public CuttingBoardRecipeJsonBuilder input(ItemConvertible input) {
ingredients.add(Ingredient.ofItems(input)); ingredients.add(Ingredient.ofItems(input));
return this; return this;
} }
public CuttingBoardRecipeJsonBuilder result(ItemConvertible result) { public CuttingBoardRecipeJsonBuilder result(ItemConvertible result) {
results.add(() -> Registries.ITEM.getId(result.asItem())); results.add(new Result(Registries.ITEM.getId(result.asItem()), 1));
return this; return this;
} }
public CuttingBoardRecipeJsonBuilder result(Identifier result) { public CuttingBoardRecipeJsonBuilder result(Identifier result) {
results.add(() -> result); results.add(new Result(result, 1));
return this; return this;
} }
@ -72,7 +87,15 @@ public class CuttingBoardRecipeJsonBuilder {
.criterion("has_the_recipe", RecipeUnlockedCriterion.create(id)) .criterion("has_the_recipe", RecipeUnlockedCriterion.create(id))
.rewards(AdvancementRewards.Builder.recipe(id)) .rewards(AdvancementRewards.Builder.recipe(id))
.criteriaMerger(AdvancementRequirements.CriterionMerger.OR); .criteriaMerger(AdvancementRequirements.CriterionMerger.OR);
exporter.accept(new JsonProvider(id, advancementBuilder.build(id.withPrefixedPath("recipes/")))); exporter.accept(id,
new CuttingBoardRecipe(
ingredients,
new Tool(new Identifier("farmersdelight:tool"), tool),
sound,
results
),
advancementBuilder.build(id.withPrefixedPath("recipes/"))
);
} }
public void offerTo(RecipeExporter exporter) { public void offerTo(RecipeExporter exporter) {
@ -87,57 +110,66 @@ public class CuttingBoardRecipeJsonBuilder {
offerTo(exporter, recipeId); offerTo(exporter, recipeId);
} }
private class JsonProvider implements RecipeJsonProvider { public record Tool(Identifier type, TagKey<Item> tag) {
private final Identifier recipeId; static final Codec<Tool> CODEC = RecordCodecBuilder.create(ii -> ii.group(
private final AdvancementEntry advancement; Identifier.CODEC.fieldOf("type").forGetter(Tool::type),
public JsonProvider(Identifier recipeId, AdvancementEntry advancement) { TagKey.codec(RegistryKeys.ITEM).fieldOf("tag").forGetter(Tool::tag)
this.recipeId = recipeId; ).apply(ii, Tool::new));
this.advancement = advancement; }
} public record Result(Identifier item, int count) {
public static final Codec<Result> CODEC = RecordCodecBuilder.create(i -> i.group(
Identifier.CODEC.fieldOf("item").forGetter(Result::item),
Codecs.createStrictOptionalFieldCodec(Codecs.POSITIVE_INT, "count", 1).forGetter(Result::count)
).apply(i, Result::new));
}
@Override public record CuttingBoardRecipe(
public JsonObject toJson() { List<Ingredient> ingredients,
JsonObject jsonObject = new JsonObject(); Tool tool,
jsonObject.addProperty("type", "farmersdelight:cutting"); Identifier sound,
serialize(jsonObject); List<Result> result
return jsonObject; ) implements Recipe<Inventory> {
} static final Identifier ID = new Identifier("farmersdelight", "cutting");
static final RecipeType<CuttingBoardRecipe> TYPE = Registry.register(Registries.RECIPE_TYPE, ID, new RecipeType<>() {
@Override @Override
public void serialize(JsonObject json) { public String toString() {
JsonArray ingredientsJson = new JsonArray(); return "farmersdelight:cutting";
for (var ingredient : ingredients) {
ingredientsJson.add(ingredient.toJson(false));
} }
json.add("ingredients", ingredientsJson); });
JsonObject toolJson = new JsonObject(); static final RecipeSerializer<CuttingBoardRecipe> SERIALIZER = Registry.register(Registries.RECIPE_SERIALIZER, ID, new RecipeSerializer<>() {
toolJson.addProperty("type", "farmersdelight:tool"); @Override
toolJson.addProperty("tag", tool.id().toString()); public Codec<CuttingBoardRecipe> codec() { return CODEC; }
json.add("tool", toolJson);
JsonArray resultJson = new JsonArray(); @Override
for (var result : results) { public CuttingBoardRecipe read(PacketByteBuf buf) { return null; }
JsonObject o = new JsonObject();
o.addProperty("item", result.get().toString()); @Override
resultJson.add(o); public void write(PacketByteBuf buf, CuttingBoardRecipe recipe) { }
} });
json.add("result", resultJson); static final Codec<CuttingBoardRecipe> CODEC = RecordCodecBuilder.create(i -> i.group(
} Ingredient.DISALLOW_EMPTY_CODEC.listOf().fieldOf("ingredients").forGetter(CuttingBoardRecipe::ingredients),
Tool.CODEC.fieldOf("tool").forGetter(CuttingBoardRecipe::tool),
Identifier.CODEC.fieldOf("sound").forGetter(CuttingBoardRecipe::sound),
Result.CODEC.listOf().fieldOf("result").forGetter(CuttingBoardRecipe::result)
).apply(i, CuttingBoardRecipe::new));
public static void bootstrap() {}
@Override @Override
public Identifier id() { public boolean matches(Inventory inventory, World world) { return false; }
return recipeId;
}
@Override @Override
public RecipeSerializer<?> serializer() { public ItemStack craft(Inventory inventory, DynamicRegistryManager registryManager) { return ItemStack.EMPTY; }
return RecipeSerializer.SHAPELESS;
}
@Override @Override
public AdvancementEntry advancement() { public boolean fits(int width, int height) { return false; }
return advancement;
}
@Override
public ItemStack getResult(DynamicRegistryManager registryManager) { return ItemStack.EMPTY; }
@Override
public RecipeSerializer<?> getSerializer() { return SERIALIZER; }
@Override
public RecipeType<?> getType() { return TYPE; }
} }
} }
*/

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.datagen.providers.recipe;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -27,12 +28,14 @@ import com.mojang.datafixers.util.Either;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider; import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
import net.fabricmc.fabric.api.resource.conditions.v1.DefaultResourceConditions;
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags; import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags;
import net.minecraft.advancement.AdvancementCriterion; import net.minecraft.advancement.AdvancementCriterion;
import net.minecraft.advancement.criterion.Criteria; import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.advancement.criterion.InventoryChangedCriterion; import net.minecraft.advancement.criterion.InventoryChangedCriterion;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.data.family.BlockFamily.Variant;
import net.minecraft.data.server.recipe.ComplexRecipeJsonBuilder; import net.minecraft.data.server.recipe.ComplexRecipeJsonBuilder;
import net.minecraft.data.server.recipe.RecipeExporter; import net.minecraft.data.server.recipe.RecipeExporter;
import net.minecraft.data.server.recipe.RecipeProvider; import net.minecraft.data.server.recipe.RecipeProvider;
@ -49,6 +52,8 @@ import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.ItemTags; import net.minecraft.registry.tag.ItemTags;
import net.minecraft.registry.tag.TagKey; import net.minecraft.registry.tag.TagKey;
import net.minecraft.resource.featuretoggle.FeatureSet; import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;
public class URecipeProvider extends FabricRecipeProvider { public class URecipeProvider extends FabricRecipeProvider {
private static final List<Item> WOOLS = List.of(Items.BLACK_WOOL, Items.BLUE_WOOL, Items.BROWN_WOOL, Items.CYAN_WOOL, Items.GRAY_WOOL, Items.GREEN_WOOL, Items.LIGHT_BLUE_WOOL, Items.LIGHT_GRAY_WOOL, Items.LIME_WOOL, Items.MAGENTA_WOOL, Items.ORANGE_WOOL, Items.PINK_WOOL, Items.PURPLE_WOOL, Items.RED_WOOL, Items.YELLOW_WOOL, Items.WHITE_WOOL); private static final List<Item> WOOLS = List.of(Items.BLACK_WOOL, Items.BLUE_WOOL, Items.BROWN_WOOL, Items.CYAN_WOOL, Items.GRAY_WOOL, Items.GREEN_WOOL, Items.LIGHT_BLUE_WOOL, Items.LIGHT_GRAY_WOOL, Items.LIME_WOOL, Items.MAGENTA_WOOL, Items.ORANGE_WOOL, Items.PINK_WOOL, Items.PURPLE_WOOL, Items.RED_WOOL, Items.YELLOW_WOOL, Items.WHITE_WOOL);
@ -85,7 +90,7 @@ public class URecipeProvider extends FabricRecipeProvider {
.offerTo(exporter, convertBetween(UItems.SUNGLASSES, UItems.BROKEN_SUNGLASSES)); .offerTo(exporter, convertBetween(UItems.SUNGLASSES, UItems.BROKEN_SUNGLASSES));
// farmers delight // farmers delight
//offerFarmersDelightCuttingRecipes(withConditions(exporter, DefaultResourceConditions.allModsLoaded("farmersdelight"))); offerFarmersDelightCuttingRecipes(withConditions(exporter, DefaultResourceConditions.allModsLoaded("farmersdelight")));
} }
private void generateVanillaRecipeExtensions(RecipeExporter exporter) { private void generateVanillaRecipeExtensions(RecipeExporter exporter) {
@ -693,9 +698,7 @@ public class URecipeProvider extends FabricRecipeProvider {
PatternTemplate.SEVEN_COLOR.offerTo(exporter, UItems.RAINBOW_BED_SHEETS, UItems.RAINBOW_BED_SHEETS, Items.LIGHT_BLUE_WOOL, Items.RED_WOOL, Items.ORANGE_WOOL, Items.YELLOW_WOOL, Items.BLUE_WOOL, Items.GREEN_WOOL, Items.PURPLE_WOOL); PatternTemplate.SEVEN_COLOR.offerTo(exporter, UItems.RAINBOW_BED_SHEETS, UItems.RAINBOW_BED_SHEETS, Items.LIGHT_BLUE_WOOL, Items.RED_WOOL, Items.ORANGE_WOOL, Items.YELLOW_WOOL, Items.BLUE_WOOL, Items.GREEN_WOOL, Items.PURPLE_WOOL);
} }
/*
private void offerFarmersDelightCuttingRecipes(RecipeExporter exporter) { private void offerFarmersDelightCuttingRecipes(RecipeExporter exporter) {
// unwaxing // unwaxing
UBlockFamilies.WAXED_ZAP.getVariants().forEach((variant, waxed) -> { UBlockFamilies.WAXED_ZAP.getVariants().forEach((variant, waxed) -> {
if (variant == Variant.WALL_SIGN) return; if (variant == Variant.WALL_SIGN) return;
@ -703,6 +706,7 @@ public class URecipeProvider extends FabricRecipeProvider {
CuttingBoardRecipeJsonBuilder.create(unwaxed, ItemTags.AXES) CuttingBoardRecipeJsonBuilder.create(unwaxed, ItemTags.AXES)
.input(waxed).criterion(hasItem(waxed), conditionsFromItem(waxed)) .input(waxed).criterion(hasItem(waxed), conditionsFromItem(waxed))
.result(Items.HONEYCOMB) .result(Items.HONEYCOMB)
.sound(SoundEvents.ITEM_AXE_WAX_OFF)
.offerTo(exporter, getItemPath(unwaxed) + "_from_waxed"); .offerTo(exporter, getItemPath(unwaxed) + "_from_waxed");
}); });
List.of(UBlockFamilies.ZAP, UBlockFamilies.PALM).forEach(family -> { List.of(UBlockFamilies.ZAP, UBlockFamilies.PALM).forEach(family -> {
@ -710,11 +714,13 @@ public class URecipeProvider extends FabricRecipeProvider {
if (variant == Variant.WALL_SIGN) return; if (variant == Variant.WALL_SIGN) return;
CuttingBoardRecipeJsonBuilder.create(family.getBaseBlock(), ItemTags.AXES) CuttingBoardRecipeJsonBuilder.create(family.getBaseBlock(), ItemTags.AXES)
.input(block).criterion(hasItem(block), conditionsFromItem(block)) .input(block).criterion(hasItem(block), conditionsFromItem(block))
.sound(SoundEvents.ITEM_AXE_STRIP)
.offerTo(exporter, getItemPath(block)); .offerTo(exporter, getItemPath(block));
}); });
}); });
CuttingBoardRecipeJsonBuilder.create(UBlocks.PALM_PLANKS, ItemTags.AXES) CuttingBoardRecipeJsonBuilder.create(UBlocks.PALM_PLANKS, ItemTags.AXES)
.input(UBlocks.PALM_HANGING_SIGN).criterion(hasItem(UBlocks.PALM_HANGING_SIGN), conditionsFromItem(UBlocks.PALM_HANGING_SIGN)) .input(UBlocks.PALM_HANGING_SIGN).criterion(hasItem(UBlocks.PALM_HANGING_SIGN), conditionsFromItem(UBlocks.PALM_HANGING_SIGN))
.sound(SoundEvents.ITEM_AXE_STRIP)
.offerTo(exporter); .offerTo(exporter);
Map.of( Map.of(
@ -725,11 +731,11 @@ public class URecipeProvider extends FabricRecipeProvider {
).forEach((unstripped, stripped) -> { ).forEach((unstripped, stripped) -> {
CuttingBoardRecipeJsonBuilder.create(stripped, ItemTags.AXES) CuttingBoardRecipeJsonBuilder.create(stripped, ItemTags.AXES)
.input(unstripped).criterion(hasItem(unstripped), conditionsFromItem(unstripped)) .input(unstripped).criterion(hasItem(unstripped), conditionsFromItem(unstripped))
.sound(SoundEvents.ITEM_AXE_STRIP)
.result(new Identifier("farmersdelight:tree_bark")) .result(new Identifier("farmersdelight:tree_bark"))
.offerTo(exporter, convertBetween(stripped, unstripped)); .offerTo(exporter, convertBetween(stripped, unstripped));
}); });
} }
*/
public static void offerCompactingRecipe(RecipeExporter exporter, RecipeCategory category, ItemConvertible output, ItemConvertible input, int resultCount) { public static void offerCompactingRecipe(RecipeExporter exporter, RecipeCategory category, ItemConvertible output, ItemConvertible input, int resultCount) {
offerCompactingRecipe(exporter, category, output, input, hasItem(input), resultCount); offerCompactingRecipe(exporter, category, output, input, hasItem(input), resultCount);