this just in: farmers may be delighted

This commit is contained in:
yrsegal@gmail.com 2022-07-27 23:08:55 -04:00
parent e6767ae224
commit a5d25eba2e
20 changed files with 481 additions and 21 deletions

View file

@ -1,5 +1,6 @@
package at.petrak.hexcasting.datagen;
import at.petrak.hexcasting.datagen.recipe.builders.ToolIngredient;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.crafting.Ingredient;
@ -23,4 +24,8 @@ public interface IXplatIngredients {
EnumMap<DyeColor, Ingredient> dyes();
Ingredient stick();
ToolIngredient axeStrip();
ToolIngredient axeDig();
}

View file

@ -14,6 +14,7 @@ import at.petrak.hexcasting.common.recipe.ingredient.VillagerIngredient;
import at.petrak.hexcasting.datagen.IXplatIngredients;
import at.petrak.hexcasting.datagen.recipe.builders.BrainsweepRecipeBuilder;
import at.petrak.hexcasting.datagen.recipe.builders.CreateCrushingRecipeBuilder;
import at.petrak.hexcasting.datagen.recipe.builders.FarmersDelightCuttingRecipeBuilder;
import at.petrak.paucal.api.datagen.PaucalRecipeProvider;
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
@ -21,6 +22,7 @@ import net.minecraft.core.Registry;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.recipes.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.DyeItem;
@ -384,6 +386,36 @@ public class HexplatRecipes extends PaucalRecipeProvider {
.withOutput(HexItems.AMETHYST_DUST, 4)
.withOutput(0.5f, HexItems.AMETHYST_DUST)
.save(recipes, modLoc("compat/create/crushing/amethyst_shard"));
// FD compat
new FarmersDelightCuttingRecipeBuilder()
.withInput(HexBlocks.AKASHIC_LOG)
.withTool(ingredients.axeStrip())
.withOutput(HexBlocks.AKASHIC_LOG_STRIPPED)
.withOutput("farmersdelight:tree_bark")
.withSound(SoundEvents.AXE_STRIP)
.save(recipes, modLoc("compat/farmersdelight/cutting/akashic_log"));
new FarmersDelightCuttingRecipeBuilder()
.withInput(HexBlocks.AKASHIC_WOOD)
.withTool(ingredients.axeStrip())
.withOutput(HexBlocks.AKASHIC_WOOD_STRIPPED)
.withOutput("farmersdelight:tree_bark")
.withSound(SoundEvents.AXE_STRIP)
.save(recipes, modLoc("compat/farmersdelight/cutting/akashic_wood"));
new FarmersDelightCuttingRecipeBuilder()
.withInput(HexBlocks.AKASHIC_TRAPDOOR)
.withTool(ingredients.axeDig())
.withOutput(HexBlocks.AKASHIC_PLANKS)
.save(recipes, modLoc("compat/farmersdelight/cutting/akashic_trapdoor"));
new FarmersDelightCuttingRecipeBuilder()
.withInput(HexBlocks.AKASHIC_DOOR)
.withTool(ingredients.axeDig())
.withOutput(HexBlocks.AKASHIC_PLANKS)
.save(recipes, modLoc("compat/farmersdelight/cutting/akashic_door"));
}
private void wandRecipe(Consumer<FinishedRecipe> recipes, ItemWand wand, Item plank) {

View file

@ -0,0 +1,18 @@
package at.petrak.hexcasting.datagen.recipe.builders;
import com.google.gson.JsonObject;
public record CompatProcessingOutput(String name, int count, float chance) implements ProcessingOutput {
@Override
public JsonObject serialize() {
JsonObject json = new JsonObject();
json.addProperty("item", name);
if (count != 1) {
json.addProperty("count", count);
}
if (chance != 1) {
json.addProperty("chance", chance);
}
return json;
}
}

View file

@ -2,9 +2,7 @@ package at.petrak.hexcasting.datagen.recipe.builders;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minecraft.advancements.CriterionTriggerInstance;
import net.minecraft.core.Registry;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.data.recipes.RecipeBuilder;
import net.minecraft.resources.ResourceLocation;
@ -78,7 +76,24 @@ public abstract class CreateCrushingRecipeBuilder implements RecipeBuilder {
}
public CreateCrushingRecipeBuilder withOutput(ItemStack output, float chance) {
this.results.add(new ProcessingOutput(output, chance));
this.results.add(new ItemProcessingOutput(output, chance));
return this;
}
public CreateCrushingRecipeBuilder withOutput(String name) {
return withOutput(1f, name, 1);
}
public CreateCrushingRecipeBuilder withOutput(String name, int count) {
return withOutput(1f, name, count);
}
public CreateCrushingRecipeBuilder withOutput(float chance, String name) {
return withOutput(chance, name, 1);
}
public CreateCrushingRecipeBuilder withOutput(float chance, String name, int count) {
this.results.add(new CompatProcessingOutput(name, count, chance));
return this;
}
@ -153,22 +168,4 @@ public abstract class CreateCrushingRecipeBuilder implements RecipeBuilder {
}
}
private record ProcessingOutput(ItemStack stack, float chance) {
private JsonObject serialize() {
JsonObject json = new JsonObject();
ResourceLocation resourceLocation = Registry.ITEM.getKey(stack.getItem());
json.addProperty("item", resourceLocation.toString());
int count = stack.getCount();
if (count != 1) {
json.addProperty("count", count);
}
if (stack.hasTag()) {
json.add("nbt", JsonParser.parseString(stack.getTag().toString()));
}
if (chance != 1) {
json.addProperty("chance", chance);
}
return json;
}
}
}

View file

@ -0,0 +1,165 @@
package at.petrak.hexcasting.datagen.recipe.builders;
import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.advancements.CriterionTriggerInstance;
import net.minecraft.core.Registry;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.data.recipes.RecipeBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.level.ItemLike;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.function.Consumer;
public class FarmersDelightCuttingRecipeBuilder implements RecipeBuilder {
private String group = "";
private final List<ProcessingOutput> outputs = Lists.newArrayList();
private Ingredient input;
private ToolIngredient toolAction;
private SoundEvent sound;
@Override
public FarmersDelightCuttingRecipeBuilder unlockedBy(String s, CriterionTriggerInstance criterionTriggerInstance) {
return this;
}
@Override
public @NotNull FarmersDelightCuttingRecipeBuilder group(@Nullable String name) {
group = name;
return this;
}
@Override
public Item getResult() {
return Items.AIR; // Irrelevant, we implement serialization ourselves
}
public FarmersDelightCuttingRecipeBuilder withInput(ItemLike item) {
return withInput(Ingredient.of(item));
}
public FarmersDelightCuttingRecipeBuilder withInput(ItemStack stack) {
return withInput(Ingredient.of(stack));
}
public FarmersDelightCuttingRecipeBuilder withInput(Ingredient ingredient) {
this.input = ingredient;
return this;
}
public FarmersDelightCuttingRecipeBuilder withOutput(ItemLike output) {
return withOutput(1f, output, 1);
}
public FarmersDelightCuttingRecipeBuilder withOutput(float chance, ItemLike output) {
return withOutput(chance, output, 1);
}
public FarmersDelightCuttingRecipeBuilder withOutput(ItemLike output, int count) {
return withOutput(1f, output, count);
}
public FarmersDelightCuttingRecipeBuilder withOutput(float chance, ItemLike output, int count) {
return withOutput(new ItemStack(output, count), chance);
}
public FarmersDelightCuttingRecipeBuilder withOutput(ItemStack output, float chance) {
this.outputs.add(new ItemProcessingOutput(output, chance));
return this;
}
public FarmersDelightCuttingRecipeBuilder withOutput(String name) {
return withOutput(1f, name, 1);
}
public FarmersDelightCuttingRecipeBuilder withOutput(String name, int count) {
return withOutput(1f, name, count);
}
public FarmersDelightCuttingRecipeBuilder withOutput(float chance, String name) {
return withOutput(chance, name, 1);
}
public FarmersDelightCuttingRecipeBuilder withOutput(float chance, String name, int count) {
this.outputs.add(new CompatProcessingOutput(name, count, chance));
return this;
}
public FarmersDelightCuttingRecipeBuilder withTool(ToolIngredient ingredient) {
this.toolAction = ingredient;
return this;
}
public FarmersDelightCuttingRecipeBuilder withSound(SoundEvent sound) {
this.sound = sound;
return this;
}
@Override
public void save(Consumer<FinishedRecipe> consumer, ResourceLocation resourceLocation) {
consumer.accept(new CuttingRecipe(resourceLocation));
}
public class CuttingRecipe implements FinishedRecipe {
private final ResourceLocation id;
public CuttingRecipe(ResourceLocation id) {
this.id = id;
}
@Override
public void serializeRecipeData(@NotNull JsonObject json) {
json.addProperty("type", "farmersdelight:cutting");
if (!group.isEmpty()) {
json.addProperty("group", group);
}
JsonArray jsonIngredients = new JsonArray();
JsonArray jsonOutputs = new JsonArray();
jsonIngredients.add(input.toJson());
outputs.forEach(o -> jsonOutputs.add(o.serialize()));
json.add("ingredients", jsonIngredients);
json.add("tool", toolAction.serialize());
json.add("result", jsonOutputs);
if (sound != null) {
json.addProperty("sound", Registry.SOUND_EVENT.getKey(sound).toString());
}
}
@Override
public @NotNull ResourceLocation getId() {
return id;
}
@Override
public @NotNull RecipeSerializer<?> getType() {
return RecipeSerializer.SHAPELESS_RECIPE; // Irrelevant, we implement serialization ourselves
}
@Override
public JsonObject serializeAdvancement() {
return null;
}
@Override
public ResourceLocation getAdvancementId() {
return null;
}
}
}

View file

@ -0,0 +1,27 @@
package at.petrak.hexcasting.datagen.recipe.builders;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
public record ItemProcessingOutput(ItemStack stack, float chance) implements ProcessingOutput {
@Override
public JsonObject serialize() {
JsonObject json = new JsonObject();
ResourceLocation resourceLocation = Registry.ITEM.getKey(stack.getItem());
json.addProperty("item", resourceLocation.toString());
int count = stack.getCount();
if (count != 1) {
json.addProperty("count", count);
}
if (stack.hasTag()) {
json.add("nbt", JsonParser.parseString(stack.getTag().toString()));
}
if (chance != 1) {
json.addProperty("chance", chance);
}
return json;
}
}

View file

@ -0,0 +1,7 @@
package at.petrak.hexcasting.datagen.recipe.builders;
import com.google.gson.JsonObject;
public interface ProcessingOutput {
JsonObject serialize();
}

View file

@ -0,0 +1,7 @@
package at.petrak.hexcasting.datagen.recipe.builders;
import com.google.gson.JsonObject;
public interface ToolIngredient {
JsonObject serialize();
}

View file

@ -62,6 +62,7 @@ ad85e0162a7c68d431fd700700906ccbcadf91ce data/hexcasting/recipes/compat/create/c
c11dc4388c18dadff5d93126eb0f7ae848d627b9 data/hexcasting/advancements/recipes/brainsweep/brainsweep/directrix_redstone.json
5f3e3813757d8300acad523d45ac7c4d85728399 data/minecraft/tags/items/buttons.json
4066f098ef104eadf6729bb372d9e643c598b477 data/hexcasting/advancements/recipes/hexcasting.creative_tab/akashic_wood_stripped.json
42a8f3ea310d25760b3374c7b7338f445d51a005 data/hexcasting/recipes/compat/farmersdelight/cutting/akashic_door.json
310e2440f26f130c81d32d9fcd93a3384c2b1e72 data/hexcasting/advancements/recipes/hexcasting.creative_tab/dye_colorizer_brown.json
5f3e3813757d8300acad523d45ac7c4d85728399 data/minecraft/tags/blocks/buttons.json
30950c6dd31102cf145f8f7d2979df0736a7ba1e data/hexcasting/advancements/recipes/hexcasting.creative_tab/wand_oak.json
@ -159,6 +160,7 @@ a84bf48a188d7b250db5c971a6d9b63d82279ba3 data/hexcasting/recipes/akashic_wood.js
3f9756b2c5137b285c4faa88ab43c4996b6b2bb6 data/hexcasting/recipes/ancient_scroll_paper_lantern.json
c375ba3f7105d6f57ef982f6f4e9326ad88a947d data/hexcasting/loot_tables/blocks/ancient_scroll_paper_lantern.json
b596d96eebb4f7bad5930f4eebc589f292b59c98 data/hexcasting/tags/blocks/akashic_planks.json
e60c478db2f8552e8c1e9ee5d361658dd8eafaa4 data/hexcasting/recipes/compat/farmersdelight/cutting/akashic_wood.json
a27a2514fd3acb6cf0a4f2a6b176ca4c2a3ee064 data/hexcasting/advancements/recipes/hexcasting.creative_tab/dye_colorizer_cyan.json
1d19457c9843d97d2ed59199d9077940d9e5e46a data/hexcasting/recipes/akashic_button.json
b596d96eebb4f7bad5930f4eebc589f292b59c98 data/minecraft/tags/blocks/planks.json
@ -238,6 +240,7 @@ db8a00478e1c4b0f9b143b5946d1ba25e489591d data/hexcasting/recipes/dynamic/seal_fo
076dd8bb2ce1508293384fa93fa138a369d10751 data/hexcasting/advancements/recipes/hexcasting.creative_tab/dye_colorizer_green.json
3147422bed290cb47ea3763dbdc6f0e96eed5c2a data/hexcasting/loot_tables/inject/scroll_loot_few.json
aab3082b3303f358cc265fb10bc9bbe08c96eef0 data/hexcasting/recipes/trinket.json
c15a0780a2cd9c92dad948479049ab8495a33635 data/hexcasting/recipes/compat/farmersdelight/cutting/akashic_trapdoor.json
c3aed1dbaa46e084711a116d1bb4522df9a7405a data/hexcasting/advancements/recipes/hexcasting.creative_tab/dye_colorizer_light_blue.json
3a376402af89128dc37adaa0a72b6de66d58309d data/hexcasting/recipes/dynamic/seal_spellbook.json
2ec90cd941acad6eabfb38d21466ef8e9b9bf2c1 data/hexcasting/recipes/wand_jungle.json
@ -250,6 +253,7 @@ f3c6b6917e504e1c3d5d8875f7cce6f311e791d2 data/hexcasting/tags/items/akashic_logs
c64f5e56ca18eb68d2e58827920ca0e3ae4617ca data/hexcasting/recipes/dye_colorizer_blue.json
5f3e3813757d8300acad523d45ac7c4d85728399 data/minecraft/tags/blocks/wooden_buttons.json
e125117befadda0785e370969a8e04eff070d057 data/hexcasting/loot_tables/blocks/amethyst_sconce.json
37461a314331d79691c48cd13b6540260021cba4 data/hexcasting/recipes/compat/farmersdelight/cutting/akashic_log.json
4da41a82a17f58c9342944f214e745696c1d8ed7 data/hexcasting/loot_tables/blocks/impetus_storedplayer.json
67d4c536be3762833a4af33cd7cdfc68eb4ad629 data/hexcasting/advancements/recipes/hexcasting.creative_tab/wand_dark_oak.json
22ad2496732633bb5539a1fa761051d7add48055 data/hexcasting/advancements/recipes/hexcasting.creative_tab/slate.json

View file

@ -0,0 +1,17 @@
{
"type": "farmersdelight:cutting",
"ingredients": [
{
"item": "hexcasting:akashic_door"
}
],
"tool": {
"type": "farmersdelight:tool",
"tag": "fabric:tools/axes"
},
"result": [
{
"item": "hexcasting:akashic_planks"
}
]
}

View file

@ -0,0 +1,21 @@
{
"type": "farmersdelight:cutting",
"ingredients": [
{
"item": "hexcasting:akashic_log"
}
],
"tool": {
"type": "farmersdelight:tool",
"tag": "fabric:tools/axes"
},
"result": [
{
"item": "hexcasting:akashic_log_stripped"
},
{
"item": "farmersdelight:tree_bark"
}
],
"sound": "minecraft:item.axe.strip"
}

View file

@ -0,0 +1,17 @@
{
"type": "farmersdelight:cutting",
"ingredients": [
{
"item": "hexcasting:akashic_trapdoor"
}
],
"tool": {
"type": "farmersdelight:tool",
"tag": "fabric:tools/axes"
},
"result": [
{
"item": "hexcasting:akashic_planks"
}
]
}

View file

@ -0,0 +1,21 @@
{
"type": "farmersdelight:cutting",
"ingredients": [
{
"item": "hexcasting:akashic_wood"
}
],
"tool": {
"type": "farmersdelight:tool",
"tag": "fabric:tools/axes"
},
"result": [
{
"item": "hexcasting:akashic_wood_stripped"
},
{
"item": "farmersdelight:tree_bark"
}
],
"sound": "minecraft:item.axe.strip"
}

View file

@ -6,8 +6,10 @@ import at.petrak.hexcasting.datagen.HexItemTagProvider;
import at.petrak.hexcasting.datagen.HexLootTables;
import at.petrak.hexcasting.datagen.IXplatIngredients;
import at.petrak.hexcasting.datagen.recipe.HexplatRecipes;
import at.petrak.hexcasting.datagen.recipe.builders.ToolIngredient;
import at.petrak.hexcasting.fabric.datagen.builders.FabricCreateCrushingRecipeBuilder;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.google.gson.JsonObject;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.minecraft.core.Registry;
@ -113,6 +115,23 @@ public class HexFabricDataGenerators implements DataGeneratorEntrypoint {
new Ingredient.TagValue(tag("wood_sticks"))
));
}
private final ToolIngredient AXE_INGREDIENT = () -> {
JsonObject object = new JsonObject();
object.addProperty("type", "farmersdelight:tool");
object.addProperty("tag", "fabric:tools/axes");
return object;
};
@Override
public ToolIngredient axeStrip() {
return AXE_INGREDIENT;
}
@Override
public ToolIngredient axeDig() {
return AXE_INGREDIENT;
}
};
private static TagKey<Item> tag(String s) {

View file

@ -157,6 +157,10 @@ d7f85ce9d46aacc7ec89dc7aa0f88a331ccfbae7 data/hexcasting/recipes/brainsweep/akas
ab5d271371323d93ff6eed18179ee4f7fd8c939c data/hexcasting/recipes/brainsweep/impetus_rightclick.json
d5c6f9a31a8310ec440fc8c14da8988f0d166586 data/hexcasting/recipes/brainsweep/impetus_storedplayer.json
ad85e0162a7c68d431fd700700906ccbcadf91ce data/hexcasting/recipes/compat/create/crushing/amethyst_shard.json
27665eed65acfdb692027afe52588b30cec085ea data/hexcasting/recipes/compat/farmersdelight/cutting/akashic_door.json
1ed27f68186cb70984eeeae13365fc3c3149ebc3 data/hexcasting/recipes/compat/farmersdelight/cutting/akashic_log.json
4c842bb202b181cc861544a08a4ad53f399aaa30 data/hexcasting/recipes/compat/farmersdelight/cutting/akashic_trapdoor.json
e339675f24dd528d429a1386666d69fc8f23c426 data/hexcasting/recipes/compat/farmersdelight/cutting/akashic_wood.json
bc140b6c5d999b4bc5d12c302297f56bde3b161c data/hexcasting/recipes/cypher.json
8c22db477365a800ce1e715aeaad896550467047 data/hexcasting/recipes/dye_colorizer_black.json
c64f5e56ca18eb68d2e58827920ca0e3ae4617ca data/hexcasting/recipes/dye_colorizer_blue.json

View file

@ -0,0 +1,17 @@
{
"type": "farmersdelight:cutting",
"ingredients": [
{
"item": "hexcasting:akashic_door"
}
],
"tool": {
"type": "farmersdelight:tool_action",
"action": "axe_dig"
},
"result": [
{
"item": "hexcasting:akashic_planks"
}
]
}

View file

@ -0,0 +1,21 @@
{
"type": "farmersdelight:cutting",
"ingredients": [
{
"item": "hexcasting:akashic_log"
}
],
"tool": {
"type": "farmersdelight:tool_action",
"action": "axe_strip"
},
"result": [
{
"item": "hexcasting:akashic_log_stripped"
},
{
"item": "farmersdelight:tree_bark"
}
],
"sound": "minecraft:item.axe.strip"
}

View file

@ -0,0 +1,17 @@
{
"type": "farmersdelight:cutting",
"ingredients": [
{
"item": "hexcasting:akashic_trapdoor"
}
],
"tool": {
"type": "farmersdelight:tool_action",
"action": "axe_dig"
},
"result": [
{
"item": "hexcasting:akashic_planks"
}
]
}

View file

@ -0,0 +1,21 @@
{
"type": "farmersdelight:cutting",
"ingredients": [
{
"item": "hexcasting:akashic_wood"
}
],
"tool": {
"type": "farmersdelight:tool_action",
"action": "axe_strip"
},
"result": [
{
"item": "hexcasting:akashic_wood_stripped"
},
{
"item": "farmersdelight:tree_bark"
}
],
"sound": "minecraft:item.axe.strip"
}

View file

@ -3,11 +3,13 @@ package at.petrak.hexcasting.forge.datagen;
import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.datagen.*;
import at.petrak.hexcasting.datagen.recipe.HexplatRecipes;
import at.petrak.hexcasting.datagen.recipe.builders.ToolIngredient;
import at.petrak.hexcasting.forge.datagen.builders.ForgeCreateCrushingRecipeBuilder;
import at.petrak.hexcasting.forge.datagen.xplat.HexBlockStatesAndModels;
import at.petrak.hexcasting.forge.datagen.xplat.HexItemModels;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import at.petrak.paucal.api.forge.datagen.PaucalForgeDatagenWrappers;
import com.google.gson.JsonObject;
import net.minecraft.data.DataGenerator;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
@ -16,6 +18,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.ToolActions;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
@ -119,5 +122,25 @@ public class HexForgeDataGenerators {
new Ingredient.TagValue(ItemTags.create(new ResourceLocation("forge", "rods/wooden")))
));
}
@Override
public ToolIngredient axeStrip() {
return () -> {
JsonObject object = new JsonObject();
object.addProperty("type", "farmersdelight:tool_action");
object.addProperty("action", ToolActions.AXE_STRIP.name());
return object;
};
}
@Override
public ToolIngredient axeDig() {
return () -> {
JsonObject object = new JsonObject();
object.addProperty("type", "farmersdelight:tool_action");
object.addProperty("action", ToolActions.AXE_DIG.name());
return object;
};
}
};
}