Fix and add farmer's delight cutting table recipes for all the palm and zap wood blocks

This commit is contained in:
Sollace 2024-05-18 21:10:10 +01:00
parent 0c9c3caae2
commit c09b02d8c8
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 190 additions and 1 deletions

View file

@ -0,0 +1,146 @@
package com.minelittlepony.unicopia.datagen.providers.recipe;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.spongepowered.include.com.google.common.base.Preconditions;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementRewards;
import net.minecraft.advancement.CriterionMerger;
import net.minecraft.advancement.criterion.CriterionConditions;
import net.minecraft.advancement.criterion.RecipeUnlockedCriterion;
import net.minecraft.data.server.recipe.CraftingRecipeJsonBuilder;
import net.minecraft.data.server.recipe.RecipeJsonProvider;
import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
public class CuttingBoardRecipeJsonBuilder {
private final Advancement.Builder advancementBuilder = Advancement.Builder.createUntelemetered();
private final ItemConvertible output;
private final TagKey<Item> tool;
private final List<Supplier<Identifier>> results = new ArrayList<>();
private final List<Ingredient> ingredients = new ArrayList<>();
public static CuttingBoardRecipeJsonBuilder create(ItemConvertible output, TagKey<Item> tool) {
return new CuttingBoardRecipeJsonBuilder(output, tool);
}
protected CuttingBoardRecipeJsonBuilder(ItemConvertible output, TagKey<Item> tool) {
this.output = output;
this.tool = tool;
result(output);
}
public CuttingBoardRecipeJsonBuilder input(ItemConvertible input) {
ingredients.add(Ingredient.ofItems(input));
return this;
}
public CuttingBoardRecipeJsonBuilder result(ItemConvertible result) {
results.add(() -> Registries.ITEM.getId(result.asItem()));
return this;
}
public CuttingBoardRecipeJsonBuilder result(Identifier result) {
results.add(() -> result);
return this;
}
public CuttingBoardRecipeJsonBuilder criterion(String name, CriterionConditions condition) {
advancementBuilder.criterion(name, condition);
return this;
}
public void offerTo(Consumer<RecipeJsonProvider> exporter, Identifier id) {
id = id.withPrefixedPath("cutting/");
Preconditions.checkState(!advancementBuilder.getCriteria().isEmpty(), "No way of obtaining recipe " + id);
advancementBuilder
.parent(CraftingRecipeJsonBuilder.ROOT)
.criterion("has_the_recipe", RecipeUnlockedCriterion.create(id))
.rewards(AdvancementRewards.Builder.recipe(id))
.criteriaMerger(CriterionMerger.OR);
exporter.accept(new JsonProvider(id, id.withPrefixedPath("recipes/")));
}
public void offerTo(Consumer<RecipeJsonProvider> exporter) {
offerTo(exporter, Registries.ITEM.getId(output.asItem()));
}
public void offerTo(Consumer<RecipeJsonProvider> exporter, String recipePath) {
Identifier recipeId = new Identifier(recipePath);
if (recipeId.equals(Registries.ITEM.getId(output.asItem()))) {
throw new IllegalStateException("Recipe " + recipePath + " should remove its 'save' argument as it is equal to default one");
}
offerTo(exporter, recipeId);
}
private class JsonProvider implements RecipeJsonProvider {
private final Identifier recipeId;
private final Identifier advancementId;
public JsonProvider(Identifier recipeId, Identifier advancementId) {
this.recipeId = recipeId;
this.advancementId = advancementId;
}
@Override
public JsonObject toJson() {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("type", "farmersdelight:cutting");
serialize(jsonObject);
return jsonObject;
}
@Override
public void serialize(JsonObject json) {
JsonArray ingredientsJson = new JsonArray();
for (var ingredient : ingredients) {
ingredientsJson.add(ingredient.toJson());
}
json.add("ingredients", ingredientsJson);
JsonObject toolJson = new JsonObject();
toolJson.addProperty("type", "farmersdelight:tool");
toolJson.addProperty("tag", tool.id().toString());
json.add("tool", toolJson);
JsonArray resultJson = new JsonArray();
for (var result : results) {
JsonObject o = new JsonObject();
o.addProperty("item", result.get().toString());
resultJson.add(o);
}
json.add("result", resultJson);
}
@Override
public Identifier getRecipeId() {
return recipeId;
}
@Override
public RecipeSerializer<?> getSerializer() {
return RecipeSerializer.SHAPELESS;
}
@Override
public JsonObject toAdvancementJson() {
return advancementBuilder.toJson();
}
@Override
public Identifier getAdvancementId() {
return advancementId;
}
}
}

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.datagen.providers.recipe;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Stream;
@ -23,10 +24,12 @@ import com.mojang.datafixers.util.Either;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
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.minecraft.advancement.criterion.InventoryChangedCriterion;
import net.minecraft.block.Block;
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.RecipeJsonProvider;
import net.minecraft.data.server.recipe.RecipeProvider;
@ -43,6 +46,7 @@ import net.minecraft.recipe.book.RecipeCategory;
import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
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);
@ -77,6 +81,9 @@ public class URecipeProvider extends FabricRecipeProvider {
.input(ConventionalItemTags.GLASS_BLOCKS)
.input(UItems.SUNGLASSES).criterion("has_broken_sunglasses", conditionsFromItem(UItems.BROKEN_SUNGLASSES))
.offerTo(exporter, convertBetween(UItems.SUNGLASSES, UItems.BROKEN_SUNGLASSES));
// farmers delight
offerFarmersDelightCuttingRecipes(withConditions(exporter, DefaultResourceConditions.allModsLoaded("farmersdelight")));
}
private void generateVanillaRecipeExtensions(Consumer<RecipeJsonProvider> exporter) {
@ -681,6 +688,42 @@ 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);
}
private void offerFarmersDelightCuttingRecipes(Consumer<RecipeJsonProvider> exporter) {
// unwaxing
UBlockFamilies.WAXED_ZAP.getVariants().forEach((variant, waxed) -> {
if (variant == Variant.WALL_SIGN) return;
var unwaxed = UBlockFamilies.ZAP.getVariant(variant);
CuttingBoardRecipeJsonBuilder.create(unwaxed, ItemTags.AXES)
.input(waxed).criterion(hasItem(waxed), conditionsFromItem(waxed))
.result(Items.HONEYCOMB)
.offerTo(exporter, getItemPath(unwaxed) + "_from_waxed");
});
List.of(UBlockFamilies.ZAP, UBlockFamilies.PALM).forEach(family -> {
family.getVariants().forEach((variant, block) -> {
if (variant == Variant.WALL_SIGN) return;
CuttingBoardRecipeJsonBuilder.create(family.getBaseBlock(), ItemTags.AXES)
.input(block).criterion(hasItem(block), conditionsFromItem(block))
.offerTo(exporter, getItemPath(block));
});
});
CuttingBoardRecipeJsonBuilder.create(UBlocks.PALM_PLANKS, ItemTags.AXES)
.input(UBlocks.PALM_HANGING_SIGN).criterion(hasItem(UBlocks.PALM_HANGING_SIGN), conditionsFromItem(UBlocks.PALM_HANGING_SIGN))
.offerTo(exporter);
Map.of(
UBlocks.PALM_LOG, UBlocks.STRIPPED_PALM_LOG,
UBlocks.PALM_WOOD, UBlocks.STRIPPED_PALM_WOOD,
UBlocks.ZAP_LOG, UBlocks.STRIPPED_ZAP_LOG,
UBlocks.ZAP_WOOD, UBlocks.STRIPPED_ZAP_WOOD
).forEach((unstripped, stripped) -> {
CuttingBoardRecipeJsonBuilder.create(stripped, ItemTags.AXES)
.input(unstripped).criterion(hasItem(unstripped), conditionsFromItem(unstripped))
.result(new Identifier("farmersdelight:tree_bark"))
.offerTo(exporter, convertBetween(stripped, unstripped));
});
}
public static void offerCompactingRecipe(Consumer<RecipeJsonProvider> exporter, RecipeCategory category, ItemConvertible output, ItemConvertible input, int resultCount) {
offerCompactingRecipe(exporter, category, output, input, hasItem(input), resultCount);
}

View file

@ -7,7 +7,7 @@
],
"tool": {
"type": "farmersdelight:tool",
"tag": "c:tools/axes"
"tag": "minecraft:axes"
},
"result": [
{