From 7653026cea4f87fbee8dfbe25e89f596a514728b Mon Sep 17 00:00:00 2001 From: EagleEyeLogic <69814047+EagleEyeLogic@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:55:21 +0200 Subject: [PATCH 1/2] Patch in dendro potion brewing Fixes https://github.com/DynamicTreesTeam/DynamicTrees/issues/819 --- .../util/DendroBrewingRecipe.java | 62 +++++++++++-------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/ferreusveritas/dynamictrees/util/DendroBrewingRecipe.java b/src/main/java/com/ferreusveritas/dynamictrees/util/DendroBrewingRecipe.java index d4e333f91..de23aef84 100644 --- a/src/main/java/com/ferreusveritas/dynamictrees/util/DendroBrewingRecipe.java +++ b/src/main/java/com/ferreusveritas/dynamictrees/util/DendroBrewingRecipe.java @@ -2,6 +2,9 @@ import com.ferreusveritas.dynamictrees.item.DendroPotion; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.item.alchemy.PotionUtils; import net.minecraftforge.common.brewing.IBrewingRecipe; /** @@ -23,37 +26,46 @@ public DendroBrewingRecipe(final ItemStack input, final ItemStack ingredient, fi @Override public boolean isInput(final ItemStack inputStack) { - // For transformation potion, only allow input if it doesn't already have a tree tag. - return DendroPotion.getPotionType(inputStack) == DendroPotion.getPotionType(this.input) && !inputStack.getOrCreateTag().contains(DendroPotion.TREE_TAG_KEY); - } + // Only allow Potion.AWKWARD or DendroPotion and for DendroPotion.TRANSFORM, only if it doesn't already have a tree tag. + if ((!inputStack.getOrCreateTag().contains(DendroPotion.TREE_TAG_KEY) && inputStack.getOrCreateTag().contains(DendroPotion.INDEX_TAG_KEY)) || inputStack.getItem() == Items.POTION) { + return true; + } + return false; + } @Override public boolean isIngredient(final ItemStack ingredientStack) { - return this.ingredient.getItem().equals(ingredientStack.getItem()); + return this.ingredient.getItem().equals(ingredientStack.getItem()); } @Override public ItemStack getOutput(final ItemStack inputStack, final ItemStack ingredientStack) { - if (!inputStack.isEmpty() && !ingredientStack.isEmpty() && isIngredient(ingredientStack)) { - // For transformation potion, only brew if it doesn't already have a tree tag (must check here too, in case potion is left in after being brewed). - if (!inputStack.getOrCreateTag().contains(DendroPotion.TREE_TAG_KEY)) { - return this.output.copy(); - } - } - - return ItemStack.EMPTY; + // We need to apply logic for the brewing or simply the ingredient defines the output and any input was allowed + // A smarter way would be nice, but it works + if (!inputStack.isEmpty() && !ingredientStack.isEmpty() && isIngredient(ingredientStack) && isInput(inputStack)) { + if (ingredientStack.is(Items.CHARCOAL) & PotionUtils.getPotion(inputStack) == Potion.byName("awkward")) { + return this.output.copy(); + } + if (ingredientStack.is(Items.CHARCOAL) | inputStack.getItem() == Items.POTION) { + return ItemStack.EMPTY; + } + if ((ingredientStack.is(Items.SLIME_BALL) || ingredientStack.is(Items.PUMPKIN_SEEDS) || ingredientStack.is(Items.GHAST_TEAR) || ingredientStack.is(Items.PRISMARINE_CRYSTALS)) & DendroPotion.getPotionType(inputStack) == DendroPotion.DendroPotionType.BIOCHAR) { + return this.output.copy(); + } + if ((ingredientStack.is(Items.SLIME_BALL) || ingredientStack.is(Items.PUMPKIN_SEEDS) || ingredientStack.is(Items.GHAST_TEAR) || ingredientStack.is(Items.PRISMARINE_CRYSTALS)) | DendroPotion.getPotionType(inputStack) != DendroPotion.DendroPotionType.TRANSFORM) { + return ItemStack.EMPTY; + } + return this.output.copy(); + } + return ItemStack.EMPTY; } - - public ItemStack getInput() { - return input; - } - - public ItemStack getIngredient() { - return ingredient; - } - - public ItemStack getOutput() { - return output; - } - + public ItemStack getInput() { + return input; + } + public ItemStack getIngredient() { + return ingredient; + } + public ItemStack getOutput() { + return output; + } } From 8a9b4c191f29a0de81d1b914e12208a95f87b17e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Massimo=20Cant=C3=BA?= Date: Fri, 12 Jul 2024 19:20:12 -0300 Subject: [PATCH 2/2] Made dendro brewing code more efficient --- .../dynamictrees/compat/DTJeiPlugin.java | 2 +- .../dynamictrees/init/DTConfigs.java | 3 + .../dynamictrees/item/DendroPotion.java | 56 +++++---------- .../util/DendroBrewingRecipe.java | 70 +++++-------------- 4 files changed, 39 insertions(+), 92 deletions(-) diff --git a/src/main/java/com/ferreusveritas/dynamictrees/compat/DTJeiPlugin.java b/src/main/java/com/ferreusveritas/dynamictrees/compat/DTJeiPlugin.java index d87807051..258afa1de 100644 --- a/src/main/java/com/ferreusveritas/dynamictrees/compat/DTJeiPlugin.java +++ b/src/main/java/com/ferreusveritas/dynamictrees/compat/DTJeiPlugin.java @@ -39,7 +39,7 @@ public void registerRecipes(final IRecipeRegistration registration) { final List brewingRecipes = new ArrayList<>(); DendroPotion.brewingRecipes.forEach(recipe -> - brewingRecipes.add(makeJeiBrewingRecipe(factory, recipe.getInput(), recipe.getIngredient(), recipe.getOutput()))); + brewingRecipes.add(makeJeiBrewingRecipe(factory, recipe.input(), recipe.ingredient(), recipe.output()))); registration.addRecipes(RecipeTypes.BREWING, brewingRecipes); } diff --git a/src/main/java/com/ferreusveritas/dynamictrees/init/DTConfigs.java b/src/main/java/com/ferreusveritas/dynamictrees/init/DTConfigs.java index 438c50d88..17c06562d 100644 --- a/src/main/java/com/ferreusveritas/dynamictrees/init/DTConfigs.java +++ b/src/main/java/com/ferreusveritas/dynamictrees/init/DTConfigs.java @@ -66,6 +66,7 @@ public class DTConfigs { public static final ForgeConfigSpec.BooleanValue PODZOL_GEN; public static final ForgeConfigSpec.BooleanValue GENERATE_DIRT_BUCKET_RECIPES; + public static final ForgeConfigSpec.ConfigValue BIOCHAR_BASE_BREWING_BASE; public static final ForgeConfigSpec.BooleanValue WORLD_GEN; public static final ForgeConfigSpec.ConfigValue> DIMENSION_BLACKLIST; @@ -180,6 +181,8 @@ public class DTConfigs { COMMON_BUILDER.comment("Miscellaneous Settings").push("misc"); GENERATE_DIRT_BUCKET_RECIPES = COMMON_BUILDER.comment("If enabled, dirt bucket recipes will be automatically generated.") .define("generateDirtBucketRecipes", true); + BIOCHAR_BASE_BREWING_BASE = COMMON_BUILDER.comment("The base potion the Biochar Base is brewed from. Minecraft potions use 'awkward'. If you change this, don't forget to update the patchouli manual page too.") + .define("biocharBrewingBase", "awkward"); COMMON_BUILDER.pop(); COMMON_BUILDER.comment("Mod Integration Settings").push("integration"); diff --git a/src/main/java/com/ferreusveritas/dynamictrees/item/DendroPotion.java b/src/main/java/com/ferreusveritas/dynamictrees/item/DendroPotion.java index f731aa1fb..4107ddc4f 100644 --- a/src/main/java/com/ferreusveritas/dynamictrees/item/DendroPotion.java +++ b/src/main/java/com/ferreusveritas/dynamictrees/item/DendroPotion.java @@ -4,6 +4,7 @@ import com.ferreusveritas.dynamictrees.api.substance.Emptiable; import com.ferreusveritas.dynamictrees.api.substance.SubstanceEffect; import com.ferreusveritas.dynamictrees.api.substance.SubstanceEffectProvider; +import com.ferreusveritas.dynamictrees.init.DTConfigs; import com.ferreusveritas.dynamictrees.init.DTRegistries; import com.ferreusveritas.dynamictrees.systems.substance.DenudeSubstance; import com.ferreusveritas.dynamictrees.systems.substance.DepleteSubstance; @@ -130,27 +131,17 @@ public static DendroPotionType getPotionType(ItemStack stack) { @Nullable @Override public SubstanceEffect getSubstanceEffect(ItemStack itemStack) { - switch (getPotionType(itemStack)) { - default: - case BIOCHAR: - return null; - case BURGEONING: - return new GrowthSubstance(); - case GIGAS: - return new MegaSubstance(); - case DEPLETION: - return new DepleteSubstance().setAmount(15); - case FERTILITY: - return new FertilizeSubstance().setAmount(15); - case PERSISTENCE: - return new FreezeSubstance(); - case TRANSFORM: - return new TransformSubstance(this.getTargetSpecies(itemStack)); - case HARVEST: - return new HarvestSubstance(); - case DENUDING: - return new DenudeSubstance(); - } + return switch (getPotionType(itemStack)) { + default -> null; + case BURGEONING -> new GrowthSubstance(); + case GIGAS -> new MegaSubstance(); + case DEPLETION -> new DepleteSubstance().setAmount(15); + case FERTILITY -> new FertilizeSubstance().setAmount(15); + case PERSISTENCE -> new FreezeSubstance(); + case TRANSFORM -> new TransformSubstance(this.getTargetSpecies(itemStack)); + case HARVEST -> new HarvestSubstance(); + case DENUDING -> new DenudeSubstance(); + }; } public Species getTargetSpecies(ItemStack itemStack) { @@ -167,20 +158,21 @@ public ItemStack setTargetSpecies(ItemStack itemStack, Species species) { } public void registerRecipes() { - final ItemStack awkwardStack = PotionUtils.setPotion(new ItemStack(Items.POTION), Potion.byName("awkward")); + final ItemStack baseStack = PotionUtils.setPotion(new ItemStack(Items.POTION), Potion.byName(DTConfigs.BIOCHAR_BASE_BREWING_BASE.get())); - brewingRecipes.add(this.getRecipe(awkwardStack, new ItemStack(Items.CHARCOAL), this.getPotionStack(DendroPotionType.BIOCHAR))); + //Biochar potion + brewingRecipes.add(this.getRecipe(baseStack, new ItemStack(Items.CHARCOAL), this.getPotionStack(DendroPotionType.BIOCHAR))); + //Regular potions for (int i = 1; i < DendroPotionType.values().length; i++) { final DendroPotionType type = DendroPotionType.values()[i]; - if (!type.isActive()) { - continue; - } + if (!type.isActive()) continue; brewingRecipes.add(this.getRecipe(type.getIngredient(), type)); } + //Transformation potions for (Species species : TreeRegistry.getPotionTransformableSpecies()) { brewingRecipes.add(new DendroBrewingRecipe(this.getPotionStack(DendroPotionType.TRANSFORM), species.getSeedStack(1), this.setTargetSpecies(this.getPotionStack(DendroPotionType.TRANSFORM), species))); @@ -189,22 +181,10 @@ public void registerRecipes() { brewingRecipes.forEach(BrewingRecipeRegistry::addRecipe); } - private DendroBrewingRecipe getRecipe(Item ingredient, DendroPotionType typeOut) { - return this.getRecipe(new ItemStack(ingredient), typeOut); - } - - private DendroBrewingRecipe getRecipe(Block ingredient, DendroPotionType typeOut) { - return this.getRecipe(new ItemStack(ingredient), typeOut); - } - private DendroBrewingRecipe getRecipe(ItemStack ingredient, DendroPotionType typeOut) { return this.getRecipe(this.getPotionStack(typeOut.getBasePotionType()), ingredient, this.getPotionStack(typeOut)); } - private DendroBrewingRecipe getRecipe(ItemStack ingredientStack, ItemStack stackOut) { - return this.getRecipe(this.getPotionStack(DendroPotionType.BIOCHAR), ingredientStack, stackOut); - } - private DendroBrewingRecipe getRecipe(ItemStack stackIn, ItemStack ingredientStack, ItemStack stackOut) { return new DendroBrewingRecipe(stackIn, ingredientStack, stackOut); } diff --git a/src/main/java/com/ferreusveritas/dynamictrees/util/DendroBrewingRecipe.java b/src/main/java/com/ferreusveritas/dynamictrees/util/DendroBrewingRecipe.java index de23aef84..2cec3dbb3 100644 --- a/src/main/java/com/ferreusveritas/dynamictrees/util/DendroBrewingRecipe.java +++ b/src/main/java/com/ferreusveritas/dynamictrees/util/DendroBrewingRecipe.java @@ -2,9 +2,6 @@ import com.ferreusveritas.dynamictrees.item.DendroPotion; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.alchemy.Potion; -import net.minecraft.world.item.alchemy.PotionUtils; import net.minecraftforge.common.brewing.IBrewingRecipe; /** @@ -12,60 +9,27 @@ * * @author Harley O'Connor */ -public final class DendroBrewingRecipe implements IBrewingRecipe { +public record DendroBrewingRecipe(ItemStack input, ItemStack ingredient, ItemStack output) implements IBrewingRecipe { - private final ItemStack input; - private final ItemStack ingredient; - private final ItemStack output; - - public DendroBrewingRecipe(final ItemStack input, final ItemStack ingredient, final ItemStack output) { - this.input = input; - this.ingredient = ingredient; - this.output = output; - } + @Override + public boolean isInput(final ItemStack inputStack) { + return ItemStack.isSameItemSameTags(input, inputStack); + } - @Override - public boolean isInput(final ItemStack inputStack) { - // Only allow Potion.AWKWARD or DendroPotion and for DendroPotion.TRANSFORM, only if it doesn't already have a tree tag. - if ((!inputStack.getOrCreateTag().contains(DendroPotion.TREE_TAG_KEY) && inputStack.getOrCreateTag().contains(DendroPotion.INDEX_TAG_KEY)) || inputStack.getItem() == Items.POTION) { - return true; + @Override + public boolean isIngredient(final ItemStack ingredientStack) { + return ItemStack.isSameItemSameTags(ingredient, ingredientStack); } - return false; + + @Override + public ItemStack getOutput(final ItemStack inputStack, final ItemStack ingredientStack) { + // We need to apply logic for the brewing or simply the ingredient defines the output and any input was allowed + // A smarter way would be nice, but it works + if (!inputStack.isEmpty() && !ingredientStack.isEmpty() && isIngredient(ingredientStack) && isInput(inputStack)) { + return this.output.copy(); + } + return ItemStack.EMPTY; } - @Override - public boolean isIngredient(final ItemStack ingredientStack) { - return this.ingredient.getItem().equals(ingredientStack.getItem()); - } - @Override - public ItemStack getOutput(final ItemStack inputStack, final ItemStack ingredientStack) { - // We need to apply logic for the brewing or simply the ingredient defines the output and any input was allowed - // A smarter way would be nice, but it works - if (!inputStack.isEmpty() && !ingredientStack.isEmpty() && isIngredient(ingredientStack) && isInput(inputStack)) { - if (ingredientStack.is(Items.CHARCOAL) & PotionUtils.getPotion(inputStack) == Potion.byName("awkward")) { - return this.output.copy(); - } - if (ingredientStack.is(Items.CHARCOAL) | inputStack.getItem() == Items.POTION) { - return ItemStack.EMPTY; - } - if ((ingredientStack.is(Items.SLIME_BALL) || ingredientStack.is(Items.PUMPKIN_SEEDS) || ingredientStack.is(Items.GHAST_TEAR) || ingredientStack.is(Items.PRISMARINE_CRYSTALS)) & DendroPotion.getPotionType(inputStack) == DendroPotion.DendroPotionType.BIOCHAR) { - return this.output.copy(); - } - if ((ingredientStack.is(Items.SLIME_BALL) || ingredientStack.is(Items.PUMPKIN_SEEDS) || ingredientStack.is(Items.GHAST_TEAR) || ingredientStack.is(Items.PRISMARINE_CRYSTALS)) | DendroPotion.getPotionType(inputStack) != DendroPotion.DendroPotionType.TRANSFORM) { - return ItemStack.EMPTY; - } - return this.output.copy(); - } - return ItemStack.EMPTY; - } - public ItemStack getInput() { - return input; - } - public ItemStack getIngredient() { - return ingredient; - } - public ItemStack getOutput() { - return output; - } }