Skip to content

Commit

Permalink
Made dendro brewing code more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
supermassimo committed Jul 12, 2024
1 parent 7653026 commit 8a9b4c1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void registerRecipes(final IRecipeRegistration registration) {
final List<IJeiBrewingRecipe> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> BIOCHAR_BASE_BREWING_BASE;

public static final ForgeConfigSpec.BooleanValue WORLD_GEN;
public static final ForgeConfigSpec.ConfigValue<List<String>> DIMENSION_BLACKLIST;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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)));
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,34 @@

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;

/**
* An implementation of {@link IBrewingRecipe} for the {@link DendroPotion} item.
*
* @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;
}
}

0 comments on commit 8a9b4c1

Please sign in to comment.