From 971fdd652fd18bf96fba1d098dde4a15862c7d36 Mon Sep 17 00:00:00 2001 From: Mrbysco Date: Tue, 5 Mar 2024 21:14:05 +0100 Subject: [PATCH] Add Coffee Machine JEI category Create a recipe type replacement for CoffeeIngredient --- .../cf73036c8429237f1243c873fdd92cabc277e5ec | 10 + .../coffee_ingredient/blaze_powder.json | 14 ++ .../fermented_spider_eye.json | 14 ++ .../recipes/coffee_ingredient/ghast_tear.json | 14 ++ .../coffee_ingredient/golden_carrot.json | 14 ++ .../coffee_ingredient/magma_cream.json | 14 ++ .../coffee_ingredient/milk_bucket.json | 8 + .../coffee_ingredient/milk_tagged.json | 17 ++ .../recipes/coffee_ingredient/pufferfish.json | 14 ++ .../recipes/coffee_ingredient/sugar.json | 14 ++ .../api/ActuallyAdditionsAPI.java | 5 +- .../api/internal/IMethodHandler.java | 4 + .../data/ActuallyAdditionsData.java | 1 + .../data/CoffeeIngredientGenerator.java | 78 +++++++ .../mod/crafting/ActuallyRecipes.java | 2 + .../mod/crafting/CoffeeIngredientRecipe.java | 200 ++++++++++++++++++ .../mod/inventory/ContainerCoffeeMachine.java | 2 +- .../mod/items/ActuallyItems.java | 2 +- .../mod/items/ItemCoffee.java | 126 ++++++----- .../mod/jei/JEIActuallyAdditionsPlugin.java | 11 +- .../mod/jei/coffee/CoffeeMachineCategory.java | 79 +++++++ .../mod/misc/apiimpl/MethodHandler.java | 24 +++ .../mod/tile/TileEntityCoffeeMachine.java | 13 +- .../mod/util/ResourceReloader.java | 3 + .../assets/actuallyadditions/lang/en_us.json | 6 +- 25 files changed, 607 insertions(+), 82 deletions(-) create mode 100644 src/generated/resources/.cache/cf73036c8429237f1243c873fdd92cabc277e5ec create mode 100644 src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/blaze_powder.json create mode 100644 src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/fermented_spider_eye.json create mode 100644 src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/ghast_tear.json create mode 100644 src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/golden_carrot.json create mode 100644 src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/magma_cream.json create mode 100644 src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/milk_bucket.json create mode 100644 src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/milk_tagged.json create mode 100644 src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/pufferfish.json create mode 100644 src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/sugar.json create mode 100644 src/main/java/de/ellpeck/actuallyadditions/data/CoffeeIngredientGenerator.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CoffeeIngredientRecipe.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineCategory.java diff --git a/src/generated/resources/.cache/cf73036c8429237f1243c873fdd92cabc277e5ec b/src/generated/resources/.cache/cf73036c8429237f1243c873fdd92cabc277e5ec new file mode 100644 index 000000000..e0f5dfde4 --- /dev/null +++ b/src/generated/resources/.cache/cf73036c8429237f1243c873fdd92cabc277e5ec @@ -0,0 +1,10 @@ +// 1.20.4 2024-03-05T21:12:08.3849935 Coffee Ingredient Recipes +68a4a8ca4b24d8cc042c0a384069196f708a4dd9 data/actuallyadditions/recipes/coffee_ingredient/blaze_powder.json +f18e6b3fee9f1610c0366feabc0dd3ffe2455224 data/actuallyadditions/recipes/coffee_ingredient/fermented_spider_eye.json +5402f0078e820175f117c4c3b63907f29daa6209 data/actuallyadditions/recipes/coffee_ingredient/ghast_tear.json +58f7831e3e547732cb9b0605334d21f45730b566 data/actuallyadditions/recipes/coffee_ingredient/golden_carrot.json +708f899155df8a114e30f15e7e5940f75fb2a9e9 data/actuallyadditions/recipes/coffee_ingredient/magma_cream.json +113a26d8cd82641cf612e39e4bf026f769e4597b data/actuallyadditions/recipes/coffee_ingredient/milk_bucket.json +60fa6da54a062d5bbd2f25c09f00f833ea8ff2bf data/actuallyadditions/recipes/coffee_ingredient/milk_tagged.json +228b27e7fb0ea183b8c34561ceb6b7b6a48fc0fe data/actuallyadditions/recipes/coffee_ingredient/pufferfish.json +1f74a319b1677a66f1fc83ccc6c284dc51db88ef data/actuallyadditions/recipes/coffee_ingredient/sugar.json diff --git a/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/blaze_powder.json b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/blaze_powder.json new file mode 100644 index 000000000..2ccd99169 --- /dev/null +++ b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/blaze_powder.json @@ -0,0 +1,14 @@ +{ + "type": "actuallyadditions:coffee_ingredient", + "effects": [ + { + "amplifier": 0, + "duration": 15, + "effect": "minecraft:strength" + } + ], + "ingredient": { + "item": "minecraft:blaze_powder" + }, + "maxAmplifier": 4 +} \ No newline at end of file diff --git a/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/fermented_spider_eye.json b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/fermented_spider_eye.json new file mode 100644 index 000000000..56392634f --- /dev/null +++ b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/fermented_spider_eye.json @@ -0,0 +1,14 @@ +{ + "type": "actuallyadditions:coffee_ingredient", + "effects": [ + { + "amplifier": 0, + "duration": 25, + "effect": "minecraft:invisibility" + } + ], + "ingredient": { + "item": "minecraft:fermented_spider_eye" + }, + "maxAmplifier": 2 +} \ No newline at end of file diff --git a/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/ghast_tear.json b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/ghast_tear.json new file mode 100644 index 000000000..7078b9b74 --- /dev/null +++ b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/ghast_tear.json @@ -0,0 +1,14 @@ +{ + "type": "actuallyadditions:coffee_ingredient", + "effects": [ + { + "amplifier": 0, + "duration": 5, + "effect": "minecraft:regeneration" + } + ], + "ingredient": { + "item": "minecraft:ghast_tear" + }, + "maxAmplifier": 3 +} \ No newline at end of file diff --git a/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/golden_carrot.json b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/golden_carrot.json new file mode 100644 index 000000000..e1689656f --- /dev/null +++ b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/golden_carrot.json @@ -0,0 +1,14 @@ +{ + "type": "actuallyadditions:coffee_ingredient", + "effects": [ + { + "amplifier": 0, + "duration": 30, + "effect": "minecraft:night_vision" + } + ], + "ingredient": { + "item": "minecraft:golden_carrot" + }, + "maxAmplifier": 2 +} \ No newline at end of file diff --git a/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/magma_cream.json b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/magma_cream.json new file mode 100644 index 000000000..3da104528 --- /dev/null +++ b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/magma_cream.json @@ -0,0 +1,14 @@ +{ + "type": "actuallyadditions:coffee_ingredient", + "effects": [ + { + "amplifier": 0, + "duration": 20, + "effect": "minecraft:fire_resistance" + } + ], + "ingredient": { + "item": "minecraft:magma_cream" + }, + "maxAmplifier": 2 +} \ No newline at end of file diff --git a/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/milk_bucket.json b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/milk_bucket.json new file mode 100644 index 000000000..cd444a8f1 --- /dev/null +++ b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/milk_bucket.json @@ -0,0 +1,8 @@ +{ + "type": "actuallyadditions:coffee_ingredient", + "extraText": "jei.actuallyadditions.coffee.extra.milk", + "ingredient": { + "item": "minecraft:milk_bucket" + }, + "maxAmplifier": 0 +} \ No newline at end of file diff --git a/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/milk_tagged.json b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/milk_tagged.json new file mode 100644 index 000000000..8fb00b777 --- /dev/null +++ b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/milk_tagged.json @@ -0,0 +1,17 @@ +{ + "neoforge:conditions": [ + { + "type": "neoforge:not", + "value": { + "type": "neoforge:tag_empty", + "tag": "forge:milk" + } + } + ], + "type": "actuallyadditions:coffee_ingredient", + "extraText": "jei.actuallyadditions.coffee.extra.milk", + "ingredient": { + "tag": "forge:milk" + }, + "maxAmplifier": 0 +} \ No newline at end of file diff --git a/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/pufferfish.json b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/pufferfish.json new file mode 100644 index 000000000..325b25f75 --- /dev/null +++ b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/pufferfish.json @@ -0,0 +1,14 @@ +{ + "type": "actuallyadditions:coffee_ingredient", + "effects": [ + { + "amplifier": 0, + "duration": 10, + "effect": "minecraft:water_breathing" + } + ], + "ingredient": { + "item": "minecraft:pufferfish" + }, + "maxAmplifier": 2 +} \ No newline at end of file diff --git a/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/sugar.json b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/sugar.json new file mode 100644 index 000000000..bf889d560 --- /dev/null +++ b/src/generated/resources/data/actuallyadditions/recipes/coffee_ingredient/sugar.json @@ -0,0 +1,14 @@ +{ + "type": "actuallyadditions:coffee_ingredient", + "effects": [ + { + "amplifier": 0, + "duration": 30, + "effect": "minecraft:speed" + } + ], + "ingredient": { + "item": "minecraft:sugar" + }, + "maxAmplifier": 4 +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index fa006af74..cb4c97390 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -21,6 +21,7 @@ import de.ellpeck.actuallyadditions.api.lens.LensConversion; import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient; import de.ellpeck.actuallyadditions.api.recipe.WeightedOre; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe; import de.ellpeck.actuallyadditions.mod.crafting.ColorChangeRecipe; import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe; import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe; @@ -66,7 +67,7 @@ public final class ActuallyAdditionsAPI { * Farmer behaviors are sorted when first accessed, this will not be done until after loading, but do not add behaviors at runtime. */ public static final List FARMER_BEHAVIORS = new ArrayList<>(); - public static final List COFFEE_MACHINE_INGREDIENTS = new ArrayList<>(); + public static final List> COFFEE_MACHINE_INGREDIENTS = new ArrayList<>(); // public static final List COMPOST_RECIPES = new ArrayList<>(); public static final List BOOKLET_ENTRIES = new ArrayList<>(); //This is added to automatically, you don't need to add anything to this list @@ -241,7 +242,7 @@ public final class ActuallyAdditionsAPI { * @param ingredient The ingredient to add */ public static void addCoffeeMachineIngredient(CoffeeIngredient ingredient) { - COFFEE_MACHINE_INGREDIENTS.add(ingredient); +// COFFEE_MACHINE_INGREDIENTS.add(ingredient); } /** diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java b/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java index 896ed12c1..31a37e9e5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.api.internal; import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient; +import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe; import net.minecraft.core.BlockPos; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.item.ItemStack; @@ -25,8 +26,11 @@ import java.util.List; */ public interface IMethodHandler { + @Deprecated boolean addEffectToStack(ItemStack stack, CoffeeIngredient ingredient); + boolean addRecipeEffectToStack(ItemStack stack, CoffeeIngredientRecipe ingredient); + MobEffectInstance getSameEffectFromStack(ItemStack stack, MobEffectInstance effect); void addEffectProperties(ItemStack stack, MobEffectInstance effect, boolean addDur, boolean addAmp); diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java b/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java index d85d74f3c..8b1ca59c3 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java @@ -57,6 +57,7 @@ public class ActuallyAdditionsData { generator.addProvider(true, new FuelRecipeGenerator(packOutput)); generator.addProvider(true, new MiscMachineRecipeGenerator(packOutput)); generator.addProvider(true, new MiningLensGenerator(packOutput)); + generator.addProvider(true, new CoffeeIngredientGenerator(packOutput)); generator.addProvider(true, new SoundsGenerator(packOutput, helper)); diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/CoffeeIngredientGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/CoffeeIngredientGenerator.java new file mode 100644 index 000000000..2d18fcabb --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/data/CoffeeIngredientGenerator.java @@ -0,0 +1,78 @@ +package de.ellpeck.actuallyadditions.data; + +import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe; +import net.minecraft.core.NonNullList; +import net.minecraft.data.PackOutput; +import net.minecraft.data.recipes.RecipeOutput; +import net.minecraft.data.recipes.RecipeProvider; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.ItemTags; +import net.minecraft.tags.TagKey; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.level.ItemLike; +import net.neoforged.neoforge.common.conditions.NotCondition; +import net.neoforged.neoforge.common.conditions.TagEmptyCondition; + +import javax.annotation.Nonnull; + +public class CoffeeIngredientGenerator extends RecipeProvider { + public CoffeeIngredientGenerator(PackOutput packOutput) { + super(packOutput); + } + + @Override + public String getName() { + return "Coffee Ingredient " + super.getName(); + } + + @Override + protected void buildRecipes(@Nonnull RecipeOutput recipeOutput) { + buildIngredient(recipeOutput, Items.MILK_BUCKET, 0, "jei." + ActuallyAdditions.MODID + ".coffee.extra.milk"); + + //Pam's puts milk in a tag, so we'll use that + TagKey milkTag = ItemTags.create(new ResourceLocation("forge", "milk")); + RecipeOutput tagOutput = recipeOutput.withConditions(new NotCondition(new TagEmptyCondition(milkTag.location()))); + buildIngredient(tagOutput, new ResourceLocation(ActuallyAdditions.MODID, "coffee_ingredient/milk_tagged"), + Ingredient.of(milkTag), 0, "jei." + ActuallyAdditions.MODID + ".coffee.extra.milk"); + + buildIngredient(recipeOutput, Items.SUGAR, 4, new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 30, 0)); + buildIngredient(recipeOutput, Items.MAGMA_CREAM, 2, new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 20, 0)); + buildIngredient(recipeOutput, Items.PUFFERFISH, 2, new MobEffectInstance(MobEffects.WATER_BREATHING, 10, 0)); + buildIngredient(recipeOutput, Items.GOLDEN_CARROT, 2, new MobEffectInstance(MobEffects.NIGHT_VISION, 30, 0)); + buildIngredient(recipeOutput, Items.GHAST_TEAR, 3, new MobEffectInstance(MobEffects.REGENERATION, 5, 0)); + buildIngredient(recipeOutput, Items.BLAZE_POWDER, 4, new MobEffectInstance(MobEffects.DAMAGE_BOOST, 15, 0)); + buildIngredient(recipeOutput, Items.FERMENTED_SPIDER_EYE, 2, new MobEffectInstance(MobEffects.INVISIBILITY, 25, 0)); + } + + private void buildIngredient(RecipeOutput recipeOutput, ItemLike ingredient, int maxAmplifier, MobEffectInstance... effects) { + buildIngredient(recipeOutput, ingredient, maxAmplifier, "", effects); + } + + private void buildIngredient(RecipeOutput recipeOutput, ItemLike ingredient, int maxAmplifier, String extraText, MobEffectInstance... effects) { + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, "coffee_ingredient/" + getItemName(ingredient)); + NonNullList instances = NonNullList.create(); + for (MobEffectInstance effect : effects) { + instances.add(new CoffeeIngredientRecipe.EffectInstance(effect)); + } + CoffeeIngredientRecipe recipe = new CoffeeIngredientRecipe(Ingredient.of(ingredient), instances, maxAmplifier, extraText); + recipeOutput.accept(id, recipe, null); + } + + private void buildIngredient(RecipeOutput recipeOutput, ResourceLocation id, Ingredient ingredient, int maxAmplifier, MobEffectInstance... effects) { + buildIngredient(recipeOutput, id, ingredient, maxAmplifier, "", effects); + } + + private void buildIngredient(RecipeOutput recipeOutput, ResourceLocation id, Ingredient ingredient, int maxAmplifier, String extraText, MobEffectInstance... effects) { + NonNullList instances = NonNullList.create(); + for (MobEffectInstance effect : effects) { + instances.add(new CoffeeIngredientRecipe.EffectInstance(effect)); + } + CoffeeIngredientRecipe recipe = new CoffeeIngredientRecipe(ingredient, instances, maxAmplifier, extraText); + recipeOutput.accept(id, recipe, null); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java index b6da98562..2084443cd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java @@ -30,6 +30,7 @@ public class ActuallyRecipes { public static final Supplier> FERMENTING_RECIPE = SERIALIZERS.register(FermentingRecipe.NAME, FermentingRecipe.Serializer::new); public static final Supplier> COLOR_CHANGE_RECIPE = SERIALIZERS.register(ColorChangeRecipe.NAME, ColorChangeRecipe.Serializer::new); public static final Supplier> MINING_LENS_RECIPE = SERIALIZERS.register(MiningLensRecipe.NAME, MiningLensRecipe.Serializer::new); + public static final Supplier> COFFEE_INGREDIENT_RECIPE = SERIALIZERS.register(CoffeeIngredientRecipe.NAME, CoffeeIngredientRecipe.Serializer::new); @@ -45,6 +46,7 @@ public class ActuallyRecipes { public static final Supplier> FERMENTING = RECIPE_TYPES.register("fermenting", () -> new RecipeType<>() {}); public static final Supplier> COLOR_CHANGE = RECIPE_TYPES.register("color_change", () -> new RecipeType<>() {}); public static final Supplier> MINING_LENS = RECIPE_TYPES.register("mining_lens", () -> new RecipeType<>() {}); + public static final Supplier> COFFEE_INGREDIENT = RECIPE_TYPES.register("coffee_ingredient", () -> new RecipeType<>() {}); } public static class Ingredients { public static final DeferredRegister> INGREDIENTS = DeferredRegister.create(NeoForgeRegistries.Keys.INGREDIENT_TYPES, ActuallyAdditions.MODID); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CoffeeIngredientRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CoffeeIngredientRecipe.java new file mode 100644 index 000000000..15ee73f18 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CoffeeIngredientRecipe.java @@ -0,0 +1,200 @@ +package de.ellpeck.actuallyadditions.mod.crafting; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; +import net.minecraft.core.NonNullList; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Container; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.level.Level; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class CoffeeIngredientRecipe implements Recipe { + public static final String NAME = "coffee_ingredient"; + + protected final Ingredient ingredient; + protected final NonNullList instances; //Just a record used to populate the effects list + protected final List effects; + protected final int maxAmplifier; + protected final String extraText; + + public CoffeeIngredientRecipe(Ingredient ingredient, NonNullList effectInstances, int maxAmplifier, String extraText) { + this.ingredient = ingredient; + this.maxAmplifier = maxAmplifier; + + this.instances = effectInstances; + List instances = new ArrayList<>(); + for (EffectInstance instance : effectInstances) { + MobEffect effect = BuiltInRegistries.MOB_EFFECT.get(instance.effect()); + if (effect == null) break; + instances.add(new MobEffectInstance(effect, instance.duration, instance.amplifier)); + } + this.effects = instances; + this.extraText = extraText; + } + + public Ingredient getIngredient() { + return ingredient; + } + + public List getEffects() { + return effects; + } + + public int getMaxAmplifier() { + return maxAmplifier; + } + + public String getExtraText() { + return extraText; + } + + @Override + public boolean matches(Container container, Level level) { + return false; + } + + public boolean matches(ItemStack itemStack) { + return ingredient.test(itemStack); + } + + @Override + public ItemStack assemble(Container container, RegistryAccess registryAccess) { + return getResultItem(registryAccess); + } + + @Override + public boolean canCraftInDimensions(int pWidth, int pHeight) { + return false; + } + + @Override + public ItemStack getResultItem(RegistryAccess registryAccess) { + return ItemStack.EMPTY; + } + + @Override + public boolean isSpecial() { + return true; + } + + @Override + public RecipeSerializer getSerializer() { + return ActuallyRecipes.COFFEE_INGREDIENT_RECIPE.get(); + } + + @Override + public RecipeType getType() { + return ActuallyRecipes.Types.COFFEE_INGREDIENT.get(); + } + + public boolean effect(ItemStack stack) { + return ActuallyAdditionsAPI.methodHandler.addRecipeEffectToStack(stack, this); + } + + public static Optional> getIngredientForStack(ItemStack ingredient) { + return ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS.stream().filter(recipe -> recipe.value().matches(ingredient)).findFirst(); + } + + public record EffectInstance(ResourceLocation effect, int duration, int amplifier) { //Simplified record for the effect instance + public static final EffectInstance EMPTY = new EffectInstance(new ResourceLocation("darkness"), 0, 0); + public static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + ResourceLocation.CODEC.fieldOf("effect").forGetter(effect -> effect.effect), + Codec.INT.fieldOf("duration").forGetter(effect -> effect.duration), + Codec.INT.fieldOf("amplifier").forGetter(effect -> effect.amplifier) + ) + .apply(instance, EffectInstance::new) + ); + + public EffectInstance(MobEffectInstance effect) { + this(BuiltInRegistries.MOB_EFFECT.getKey(effect.getEffect()), effect.getDuration(), effect.getAmplifier()); + } + + public static EffectInstance fromNetwork(FriendlyByteBuf pBuffer) { + ResourceLocation effect = pBuffer.readResourceLocation(); + int duration = pBuffer.readVarInt(); + int amplifier = pBuffer.readVarInt(); + return new EffectInstance(effect, duration, amplifier); + } + + public void toNetwork(FriendlyByteBuf pBuffer) { + pBuffer.writeResourceLocation(effect); + pBuffer.writeVarInt(duration); + pBuffer.writeVarInt(amplifier); + } + } + + public static class Serializer implements RecipeSerializer { + private static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + Ingredient.CODEC_NONEMPTY.fieldOf("ingredient").forGetter(recipe -> recipe.ingredient), + EffectInstance.CODEC + .listOf() + .optionalFieldOf("effects", new ArrayList<>()) + .flatXmap( + list -> { + for (EffectInstance effect : list) { + if (!BuiltInRegistries.MOB_EFFECT.containsKey(effect.effect)) { + return DataResult.error(() -> "Unknown effect: %s".formatted(effect.effect)); + } + } + return DataResult.success(NonNullList.of(EffectInstance.EMPTY, list.toArray(EffectInstance[]::new))); + }, + DataResult::success + ) + .forGetter(recipe -> recipe.instances), + Codec.INT.fieldOf("maxAmplifier").forGetter(recipe -> recipe.maxAmplifier), + Codec.STRING.optionalFieldOf("extraText", "").forGetter(recipe -> recipe.extraText) + ) + .apply(instance, CoffeeIngredientRecipe::new) + ); + + @Override + public Codec codec() { + return CODEC; + } + + @Nullable + @Override + public CoffeeIngredientRecipe fromNetwork(@Nonnull FriendlyByteBuf pBuffer) { + Ingredient ingredient = Ingredient.fromNetwork(pBuffer); + int i = pBuffer.readVarInt(); + NonNullList list = NonNullList.withSize(i, EffectInstance.EMPTY); + for (int j = 0; j < list.size(); ++j) { + list.set(j, EffectInstance.fromNetwork(pBuffer)); + } + int maxAmplifier = pBuffer.readInt(); + String extraText = pBuffer.readUtf(32767); + return new CoffeeIngredientRecipe(ingredient, list, maxAmplifier, extraText); + } + + @Override + public void toNetwork(@Nonnull FriendlyByteBuf pBuffer, CoffeeIngredientRecipe pRecipe) { + pRecipe.ingredient.toNetwork(pBuffer); + pBuffer.writeVarInt(pRecipe.instances.size()); + for (EffectInstance effect : pRecipe.instances) { + effect.toNetwork(pBuffer); + } + pBuffer.writeInt(pRecipe.maxAmplifier); + pBuffer.writeUtf(pRecipe.extraText); + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerCoffeeMachine.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerCoffeeMachine.java index 646fd63e5..ace80c417 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerCoffeeMachine.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerCoffeeMachine.java @@ -85,7 +85,7 @@ public class ContainerCoffeeMachine extends AbstractContainerMenu { if (!this.moveItemStackTo(newStack, TileEntityCoffeeMachine.SLOT_INPUT, TileEntityCoffeeMachine.SLOT_INPUT + 1, false)) { return ItemStack.EMPTY; } - } else if (ItemCoffee.getIngredientFromStack(newStack) != null) { + } else if (ItemCoffee.getIngredientRecipeFromStack(newStack) != null) { if (!this.moveItemStackTo(newStack, 3, 11, false)) { return ItemStack.EMPTY; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java index b6c026ebc..ec5cb6613 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java @@ -39,7 +39,7 @@ public final class ActuallyItems { // MISC ITEMS public static final DeferredItem CANOLA = ITEMS.register("canola", () -> new ItemBase()); - public static final DeferredItem COFFEE_CUP = ITEMS.register("coffee_cup", () -> new ItemBase()); + public static final DeferredItem COFFEE_CUP = ITEMS.register("coffee_cup", () -> new ItemCoffee()); public static final DeferredItem PAPER_CONE = ITEMS.register("paper_cone", () -> new ItemBase()); public static final DeferredItem DOUGH = ITEMS.register("dough", () -> new ItemBase()); public static final DeferredItem RING = ITEMS.register("ring", () -> new ItemBase()); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java index b73a71b06..508afcd74 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java @@ -13,110 +13,104 @@ package de.ellpeck.actuallyadditions.mod.items; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; -import de.ellpeck.actuallyadditions.mod.items.base.ItemFoodBase; -import de.ellpeck.actuallyadditions.mod.util.ItemUtil; +import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe; +import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; +import net.minecraft.ChatFormatting; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; +import net.minecraft.util.StringUtil; +import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.item.Item; +import net.minecraft.world.food.FoodProperties; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.UseAnim; import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.level.Level; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.fml.ModList; import javax.annotation.Nullable; import java.util.List; -public class ItemCoffee extends ItemFoodBase { +public class ItemCoffee extends ItemBase { + private static final FoodProperties FOOD = new FoodProperties.Builder().nutrition(8).saturationMod(5.0F).alwaysEat().build(); public ItemCoffee() { - super(8, 5.0F, false); //, name); - //this.setMaxDamage(3); - //this.setAlwaysEdible(); - //this.setMaxStackSize(1); - //this.setNoRepair(); + super(ActuallyItems.defaultProps().food(FOOD).durability(3)); } public static void initIngredients() { - ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.of(Items.MILK_BUCKET))); - //Pam's Soy Milk (For Jemx because he's lactose intolerant. YER HAPPY NAO!?) - if (ModList.get().isLoaded("harvestcraft")) { - Item item = ItemUtil.getItemFromName("harvestcraft:soymilkitem"); - if (item != null) { - ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.of(item))); - } - } - - //ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.SUGAR), 4, new PotionEffect(MobEffects.SPEED, 30, 0))); - //ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.MAGMA_CREAM), 2, new PotionEffect(MobEffects.FIRE_RESISTANCE, 20, 0))); - //ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(new ItemStack(Items.FISH, 1, 3)), 2, new PotionEffect(MobEffects.WATER_BREATHING, 10, 0))); - //ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.GOLDEN_CARROT), 2, new PotionEffect(MobEffects.NIGHT_VISION, 30, 0))); - //ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.GHAST_TEAR), 3, new PotionEffect(MobEffects.REGENERATION, 5, 0))); - //ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.BLAZE_POWDER), 4, new PotionEffect(MobEffects.STRENGTH, 15, 0))); - //ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.FERMENTED_SPIDER_EYE), 2, new PotionEffect(MobEffects.INVISIBILITY, 25, 0))); +// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.of(Items.MILK_BUCKET))); +// //Pam's Soy Milk (For Jemx because he's lactose intolerant. YER HAPPY NAO!?) +// if (ModList.get().isLoaded("harvestcraft")) { +// Item item = ItemUtil.getItemFromName("harvestcraft:soymilkitem"); +// if (item != null) { +// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.of(item))); +// } +// } +// +// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.SUGAR), 4, new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 30, 0))); +// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.MAGMA_CREAM), 2, new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 20, 0))); +// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.PUFFERFISH), 2, new MobEffectInstance(MobEffects.WATER_BREATHING, 10, 0))); +// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.GOLDEN_CARROT), 2, new MobEffectInstance(MobEffects.NIGHT_VISION, 30, 0))); +// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.GHAST_TEAR), 3, new MobEffectInstance(MobEffects.REGENERATION, 5, 0))); +// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.BLAZE_POWDER), 4, new MobEffectInstance(MobEffects.DAMAGE_BOOST, 15, 0))); +// ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.of(Items.FERMENTED_SPIDER_EYE), 2, new MobEffectInstance(MobEffects.INVISIBILITY, 25, 0))); } @Nullable - public static CoffeeIngredient getIngredientFromStack(ItemStack stack) { - for (CoffeeIngredient ingredient : ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS) { - if (ingredient.getInput().test(stack)) { - return ingredient; + public static RecipeHolder getIngredientRecipeFromStack(ItemStack stack) { + for (RecipeHolder recipeHolder : ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS) { + if (recipeHolder.value().getIngredient().test(stack)) { + return recipeHolder; } } return null; } - public static void applyPotionEffectsFromStack(ItemStack stack, LivingEntity player) {/* - PotionEffect[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack); + public static void applyPotionEffectsFromStack(ItemStack stack, LivingEntity player) { + MobEffectInstance[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack); if (effects != null && effects.length > 0) { - for (PotionEffect effect : effects) { - player.addPotionEffect(new PotionEffect(effect.getPotion(), effect.getDuration() * 20, effect.getAmplifier())); + for (MobEffectInstance effect : effects) { + player.addEffect(new MobEffectInstance(effect.getEffect(), effect.getDuration() * 20, effect.getAmplifier())); } } - */ } - //@Override - public ItemStack onItemUseFinish(ItemStack stack, Level world, LivingEntity player) { + @Override + public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity livingEntity) { ItemStack theStack = stack.copy(); - super.finishUsingItem(stack, world, player); - applyPotionEffectsFromStack(stack, player); - //theStack.setItemDamage(theStack.getItemDamage() + 1); - //if (theStack.getMaxDamage() - theStack.getItemDamage() < 0) { - // return new ItemStack(ActuallyItems.COFFEE_CUP.get()); - //} else { - // return theStack; - //} - return ItemStack.EMPTY; + super.finishUsingItem(stack, level, livingEntity); + applyPotionEffectsFromStack(stack, livingEntity); + theStack.setDamageValue(theStack.getDamageValue() + 1); + if (theStack.getMaxDamage() - theStack.getDamageValue() < 0) { + return new ItemStack(ActuallyItems.COFFEE_CUP.get()); + } else { + return theStack; + } } - //@Override - //public EnumAction getItemUseAction(ItemStack stack) { - // return EnumAction.DRINK; - //} - -// @Nullable -// @Override -// public CompoundTag getShareTag(ItemStack stack) { -// return super.getShareTag(stack); -// } + @Override + public UseAnim getUseAnimation(ItemStack pStack) { + return UseAnim.DRINK; + } @OnlyIn(Dist.CLIENT) @Override public void appendHoverText(ItemStack stack, @Nullable Level playerIn, List tooltip, TooltipFlag advanced) { - //PotionEffect[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack); - //if (effects != null) { - // for (PotionEffect effect : effects) { - // tooltip.add(StringUtil.localize(effect.getEffectName()) + " " + (effect.getAmplifier() + 1) + ", " + StringUtils.formatTickDuration(effect.getDuration() * 20)); - // } - //} else { - // tooltip.add(StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".coffeeCup.noEffect")); - //} + MobEffectInstance[] effects = ActuallyAdditionsAPI.methodHandler.getEffectsFromStack(stack); + if (effects != null) { + for (MobEffectInstance effect : effects) { + tooltip.add(Component.translatable(effect.getDescriptionId()) + .append(" " + (effect.getAmplifier() + 1) + ", " + StringUtil.formatTickDuration(effect.getDuration(), 20)) + .withStyle(ChatFormatting.GRAY)); + } + } else { + tooltip.add(Component.translatable("tooltip." + ActuallyAdditions.MODID + ".coffeeCup.noEffect").withStyle(ChatFormatting.GRAY)); + } } @Override @@ -157,7 +151,7 @@ public class ItemCoffee extends ItemFoodBase { @Override public String getExtraText() { - return I18n.get("container.nei." + ActuallyAdditions.MODID + ".coffee.extra.milk"); + return I18n.get("jei." + ActuallyAdditions.MODID + ".coffee.extra.milk"); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java index 8b475b510..1f47bc646 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java @@ -13,10 +13,12 @@ package de.ellpeck.actuallyadditions.mod.jei; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes; +import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe; import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe; import de.ellpeck.actuallyadditions.mod.crafting.FermentingRecipe; import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; +import de.ellpeck.actuallyadditions.mod.jei.coffee.CoffeeMachineCategory; import de.ellpeck.actuallyadditions.mod.jei.empowerer.EmpowererRecipeCategory; import de.ellpeck.actuallyadditions.mod.jei.fermenting.FermentingCategory; import de.ellpeck.actuallyadditions.mod.jei.laser.LaserRecipeCategory; @@ -45,6 +47,7 @@ public class JEIActuallyAdditionsPlugin implements IModPlugin { public static final RecipeType FERMENTING = RecipeType.create(ActuallyAdditions.MODID, "fermenting", FermentingRecipe.class); public static final RecipeType LASER = RecipeType.create(ActuallyAdditions.MODID, "laser", LaserRecipe.class); public static final RecipeType EMPOWERER = RecipeType.create(ActuallyAdditions.MODID, "empowerer", EmpowererRecipe.class); + public static final RecipeType COFFEE_MACHINE = RecipeType.create(ActuallyAdditions.MODID, "coffee_machine", CoffeeIngredientRecipe.class); @Override public void registerCategories(IRecipeCategoryRegistration registry) { @@ -53,8 +56,7 @@ public class JEIActuallyAdditionsPlugin implements IModPlugin { registry.addRecipeCategories(new FermentingCategory(helpers.getGuiHelper())); registry.addRecipeCategories(new LaserRecipeCategory(helpers.getGuiHelper())); registry.addRecipeCategories(new EmpowererRecipeCategory(helpers.getGuiHelper())); - - //registry.addRecipeCategories(new CoffeeMachineRecipeCategory(helpers.getGuiHelper()), new CompostRecipeCategory(helpers.getGuiHelper()), new CrusherRecipeCategory(helpers.getGuiHelper()), new ReconstructorRecipeCategory(helpers.getGuiHelper()), new EmpowererRecipeCategory(helpers.getGuiHelper()), new BookletRecipeCategory(helpers.getGuiHelper())); + registry.addRecipeCategories(new CoffeeMachineCategory(helpers.getGuiHelper())); } @Override @@ -64,11 +66,10 @@ public class JEIActuallyAdditionsPlugin implements IModPlugin { registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.FERMENTING_BARREL.getItem()), FERMENTING); registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.ATOMIC_RECONSTRUCTOR.getItem()), LASER); registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.EMPOWERER.getItem()), EMPOWERER); + registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.COFFEE_MACHINE.getItem()), COFFEE_MACHINE); -// registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockFurnaceDouble.get()), VanillaRecipeCategoryUid.SMELTING); // registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockGrinder.get()), CrusherRecipeCategory.NAME); // registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockGrinderDouble.get()), CrusherRecipeCategory.NAME); -// registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockCoffeeMachine.get()), CoffeeMachineRecipeCategory.NAME); // registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockAtomicReconstructor.get()), ReconstructorRecipeCategory.NAME); // registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockEmpowerer.get()), EmpowererRecipeCategory.NAME); // registry.addRecipeCatalyst(new ItemStack(ActuallyItems.itemBooklet.get()), BookletRecipeCategory.NAME); @@ -83,7 +84,7 @@ public class JEIActuallyAdditionsPlugin implements IModPlugin { registry.addRecipes(LASER, level.getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.LASER.get()).stream().map(RecipeHolder::value).toList()); registry.addRecipes(EMPOWERER, level.getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.EMPOWERING.get()).stream().map(RecipeHolder::value).toList()); - + registry.addRecipes(COFFEE_MACHINE, level.getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.COFFEE_INGREDIENT.get()).stream().map(RecipeHolder::value).toList()); //registry.addRecipes(ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_OR_FLUID_DATA, BookletRecipeCategory.NAME); //registry.addRecipes(ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS, CoffeeMachineRecipeCategory.NAME); //registry.addRecipes(ActuallyAdditionsAPI.CRUSHER_RECIPES, CrusherRecipeCategory.NAME); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineCategory.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineCategory.java new file mode 100644 index 000000000..57f7bda9d --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineCategory.java @@ -0,0 +1,79 @@ +package de.ellpeck.actuallyadditions.mod.jei.coffee; + +import com.google.common.base.Strings; +import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; +import de.ellpeck.actuallyadditions.api.ActuallyTags; +import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe; +import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; +import de.ellpeck.actuallyadditions.mod.jei.JEIActuallyAdditionsPlugin; +import de.ellpeck.actuallyadditions.mod.util.AssetUtil; +import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; +import mezz.jei.api.gui.drawable.IDrawable; +import mezz.jei.api.gui.drawable.IDrawableStatic; +import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +import mezz.jei.api.helpers.IGuiHelper; +import mezz.jei.api.recipe.IFocusGroup; +import mezz.jei.api.recipe.RecipeIngredientRole; +import mezz.jei.api.recipe.RecipeType; +import mezz.jei.api.recipe.category.IRecipeCategory; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; + +public class CoffeeMachineCategory implements IRecipeCategory { + private final IDrawableStatic background; + + public CoffeeMachineCategory(IGuiHelper helper) { + this.background = helper.drawableBuilder(AssetUtil.getGuiLocation("gui_nei_coffee_machine"), 0, 0, 126, 92).setTextureSize(256,256).build(); + } + + @Override + public RecipeType getRecipeType() { + return JEIActuallyAdditionsPlugin.COFFEE_MACHINE; + } + + @Override + public Component getTitle() { + return Component.translatable("container.actuallyadditions.coffeeMachine"); + } + + @Override + public IDrawable getBackground() { + return background; + } + + @Override + public IDrawable getIcon() { + return null; + } + + @Override + public void setRecipe(IRecipeLayoutBuilder builder, CoffeeIngredientRecipe recipe, IFocusGroup focuses) { + builder.addSlot(RecipeIngredientRole.INPUT, 2, 39).addIngredients(Ingredient.of(ActuallyTags.Items.COFFEE_BEANS)); + builder.addSlot(RecipeIngredientRole.INPUT, 90, 21).addIngredients(recipe.getIngredient()); + builder.addSlot(RecipeIngredientRole.INPUT, 45, 39).addItemStack(new ItemStack(ActuallyItems.EMPTY_CUP.get())); + + ItemStack output = new ItemStack(ActuallyItems.COFFEE_CUP.get()); + ActuallyAdditionsAPI.methodHandler.addRecipeEffectToStack(output, recipe); + builder.addSlot(RecipeIngredientRole.OUTPUT, 45, 70).addItemStack(output); + } + + @Override + public void draw(CoffeeIngredientRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) { + IRecipeCategory.super.draw(recipe, recipeSlotsView, guiGraphics, mouseX, mouseY); + + Minecraft mc = Minecraft.getInstance(); + if (!Strings.isNullOrEmpty(recipe.getExtraText())) { + guiGraphics.drawString(mc.font, Component.translatable("jei." + ActuallyAdditions.MODID + ".coffee.special").append( ":"), 2, 4, 4210752, false); + guiGraphics.drawString(mc.font, I18n.get(recipe.getExtraText()), 2, 16, 4210752, false); + } + + if (recipe.getMaxAmplifier() > 0) { + guiGraphics.drawString(mc.font, Component.translatable("jei." + ActuallyAdditions.MODID + ".coffee.maxAmount").append(": " + recipe.getMaxAmplifier()), 2, 28, 4210752, false); + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java index 260df8cbe..9f54feaca 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java @@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.api.internal.IMethodHandler; import de.ellpeck.actuallyadditions.api.lens.Lens; import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient; import de.ellpeck.actuallyadditions.mod.blocks.BlockLaserRelay; +import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe; import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe; import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor; import de.ellpeck.actuallyadditions.mod.util.StackUtil; @@ -62,6 +63,29 @@ public class MethodHandler implements IMethodHandler { return worked; } + @Override + public boolean addRecipeEffectToStack(ItemStack stack, CoffeeIngredientRecipe ingredient) { + boolean worked = false; + if (ingredient != null) { + List effects = ingredient.getEffects(); + if (!effects.isEmpty()) { + for (MobEffectInstance effect : effects) { + MobEffectInstance effectHas = this.getSameEffectFromStack(stack, effect); + if (effectHas != null) { + if (effectHas.getAmplifier() < ingredient.getMaxAmplifier() - 1) { + this.addEffectProperties(stack, effect, false, true); + worked = true; + } + } else { + this.addEffectToStack(stack, effect); + worked = true; + } + } + } + } + return worked; + } + @Override public MobEffectInstance getSameEffectFromStack(ItemStack stack, MobEffectInstance effect) { MobEffectInstance[] effectsStack = this.getEffectsFromStack(stack); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java index e6d97bf04..be93072ec 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java @@ -11,9 +11,9 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.api.ActuallyTags; -import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient; import de.ellpeck.actuallyadditions.mod.AASounds; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe; import de.ellpeck.actuallyadditions.mod.inventory.ContainerCoffeeMachine; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import de.ellpeck.actuallyadditions.mod.items.ItemCoffee; @@ -31,6 +31,7 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; @@ -158,12 +159,12 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements @Override public IAcceptor getAcceptor() { - return (slot, stack, automation) -> !automation || slot >= 3 && ItemCoffee.getIngredientFromStack(stack) != null || slot == SLOT_COFFEE_BEANS && stack.is(ActuallyTags.Items.COFFEE_BEANS) || slot == SLOT_INPUT && stack.getItem() == ActuallyItems.COFFEE_CUP.get(); + return (slot, stack, automation) -> !automation || slot >= 3 && ItemCoffee.getIngredientRecipeFromStack(stack) != null || slot == SLOT_COFFEE_BEANS && stack.is(ActuallyTags.Items.COFFEE_BEANS) || slot == SLOT_INPUT && stack.getItem() == ActuallyItems.COFFEE_CUP.get(); } @Override public IRemover getRemover() { - return (slot, automation) -> !automation || slot == SLOT_OUTPUT || slot >= 3 && slot < this.inv.getSlots() && ItemCoffee.getIngredientFromStack(this.inv.getStackInSlot(slot)) == null; + return (slot, automation) -> !automation || slot == SLOT_OUTPUT || slot >= 3 && slot < this.inv.getSlots() && ItemCoffee.getIngredientRecipeFromStack(this.inv.getStackInSlot(slot)) == null; } public void storeCoffee() { @@ -195,9 +196,9 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements ItemStack output = new ItemStack(ActuallyItems.COFFEE_BEANS.get()); for (int i = 3; i < this.inv.getSlots(); i++) { if (StackUtil.isValid(this.inv.getStackInSlot(i))) { - CoffeeIngredient ingredient = ItemCoffee.getIngredientFromStack(this.inv.getStackInSlot(i)); - if (ingredient != null) { - if (ingredient.effect(output)) { + RecipeHolder recipeHolder = ItemCoffee.getIngredientRecipeFromStack(this.inv.getStackInSlot(i)); + if (recipeHolder != null) { + if (recipeHolder.value().effect(output)) { this.inv.setStackInSlot(i, StackUtil.shrinkForContainer(this.inv.getStackInSlot(i), 1)); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ResourceReloader.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ResourceReloader.java index dfe4d9b84..f9de804fa 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ResourceReloader.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ResourceReloader.java @@ -44,5 +44,8 @@ public class ResourceReloader implements ResourceManagerReloadListener { ActuallyAdditionsAPI.CRUSHER_RECIPES.clear(); ActuallyAdditionsAPI.CRUSHER_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.CRUSHING.get())); + + ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS.clear(); + ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.COFFEE_INGREDIENT.get())); } } diff --git a/src/main/resources/assets/actuallyadditions/lang/en_us.json b/src/main/resources/assets/actuallyadditions/lang/en_us.json index b41c82952..69904bd4a 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_us.json +++ b/src/main/resources/assets/actuallyadditions/lang/en_us.json @@ -978,5 +978,9 @@ "booklet.actuallyadditions.chapter.crystalClusters.text.1": "Crystal Clusters are blocks that generate naturally inside of Lush Caves. When broken, they drop one or more Crystal Shards that can be crafted together to create Crystals. Crystal Clusters emit a bit of light, making them perfect for decoration. To harvest them in their block form, Silk Touch can be used.", "booklet.actuallyadditions.chapter.trialsIntro": "Intro to Trials", "booklet.actuallyadditions.chapter.trialsIntro.text.1": "Trials are a set of fun and interesting challenges that you can use to get inspiration on what to build next. Once you complete a Trial, you can press the button in the bottom right to mark the trial as completed, turning its name in the list green. Since there is no way to check if a trial is actually completed, Trials are meant as personal goals. To visit the Trials page, you can click the bookmark in the top right corner of the manual GUI.", - "booklet.actuallyadditions.chapter.trialsIntro.text.2": "Note that Trials are designed in a way that they should be completed with the concepts of Minecraft and Actually Additions alone." + "booklet.actuallyadditions.chapter.trialsIntro.text.2": "Note that Trials are designed in a way that they should be completed with the concepts of Minecraft and Actually Additions alone.", + "_comment": "JEI", + "jei.actuallyadditions.coffee.special": "Special Feature", + "jei.actuallyadditions.coffee.maxAmount": "Max Amount", + "jei.actuallyadditions.coffee.extra.milk": "+01:00, -1 Level" }