|
| 1 | +package com.cleanroommc.groovyscript.compat.mods.evilcraft; |
| 2 | + |
| 3 | +import com.cleanroommc.groovyscript.api.GroovyLog; |
| 4 | +import com.cleanroommc.groovyscript.compat.mods.ModSupport; |
| 5 | +import com.cleanroommc.groovyscript.helper.SimpleObjectStream; |
| 6 | +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; |
| 7 | +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; |
| 8 | +import net.minecraft.item.ItemStack; |
| 9 | +import net.minecraftforge.fluids.Fluid; |
| 10 | +import net.minecraftforge.fluids.FluidRegistry; |
| 11 | +import net.minecraftforge.fluids.FluidStack; |
| 12 | +import org.cyclops.cyclopscore.recipe.custom.api.IRecipe; |
| 13 | +import org.cyclops.cyclopscore.recipe.custom.component.IngredientRecipeComponent; |
| 14 | +import org.cyclops.evilcraft.core.recipe.custom.DurationXpRecipeProperties; |
| 15 | +import org.cyclops.evilcraft.core.recipe.custom.IngredientFluidStackAndTierRecipeComponent; |
| 16 | +import org.jetbrains.annotations.Nullable; |
| 17 | + |
| 18 | +public class BloodInfuser extends VirtualizedRegistry<IRecipe<IngredientFluidStackAndTierRecipeComponent, IngredientRecipeComponent, DurationXpRecipeProperties>> { |
| 19 | + |
| 20 | + public BloodInfuser() { |
| 21 | + super(); |
| 22 | + } |
| 23 | + |
| 24 | + public RecipeBuilder recipeBuilder() { |
| 25 | + return new RecipeBuilder(); |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public void onReload() { |
| 30 | + removeScripted().forEach(org.cyclops.evilcraft.block.BloodInfuser.getInstance().getRecipeRegistry().allRecipes()::remove); |
| 31 | + restoreFromBackup().forEach(org.cyclops.evilcraft.block.BloodInfuser.getInstance().getRecipeRegistry().allRecipes()::add); |
| 32 | + } |
| 33 | + |
| 34 | + public void add(IRecipe<IngredientFluidStackAndTierRecipeComponent, IngredientRecipeComponent, DurationXpRecipeProperties> recipe) { |
| 35 | + this.add(recipe, true); |
| 36 | + } |
| 37 | + |
| 38 | + public void add(IRecipe<IngredientFluidStackAndTierRecipeComponent, IngredientRecipeComponent, DurationXpRecipeProperties> recipe, boolean add) { |
| 39 | + if (recipe == null) return; |
| 40 | + addScripted(recipe); |
| 41 | + if (add) org.cyclops.evilcraft.block.BloodInfuser.getInstance().getRecipeRegistry().allRecipes().add(recipe); |
| 42 | + } |
| 43 | + |
| 44 | + public boolean remove(IRecipe<IngredientFluidStackAndTierRecipeComponent, IngredientRecipeComponent, DurationXpRecipeProperties> recipe) { |
| 45 | + if (recipe == null) return false; |
| 46 | + addBackup(recipe); |
| 47 | + org.cyclops.evilcraft.block.BloodInfuser.getInstance().getRecipeRegistry().allRecipes().remove(recipe); |
| 48 | + return true; |
| 49 | + } |
| 50 | + |
| 51 | + public boolean removeByInput(ItemStack input) { |
| 52 | + return org.cyclops.evilcraft.block.BloodInfuser.getInstance().getRecipeRegistry().allRecipes().removeIf(r -> { |
| 53 | + if (r.getInput().getIngredient().test(input)) { |
| 54 | + addBackup(r); |
| 55 | + return true; |
| 56 | + } |
| 57 | + return false; |
| 58 | + }); |
| 59 | + } |
| 60 | + |
| 61 | + public boolean removeByOutput(ItemStack input) { |
| 62 | + return org.cyclops.evilcraft.block.BloodInfuser.getInstance().getRecipeRegistry().allRecipes().removeIf(r -> { |
| 63 | + if (r.getOutput().getIngredient().test(input)) { |
| 64 | + addBackup(r); |
| 65 | + return true; |
| 66 | + } |
| 67 | + return false; |
| 68 | + }); |
| 69 | + } |
| 70 | + |
| 71 | + public void removeAll() { |
| 72 | + org.cyclops.evilcraft.block.BloodInfuser.getInstance().getRecipeRegistry().allRecipes().forEach(this::addBackup); |
| 73 | + org.cyclops.evilcraft.block.BloodInfuser.getInstance().getRecipeRegistry().allRecipes().clear(); |
| 74 | + } |
| 75 | + |
| 76 | + public SimpleObjectStream<IRecipe<IngredientFluidStackAndTierRecipeComponent, IngredientRecipeComponent, DurationXpRecipeProperties>> streamRecipes() { |
| 77 | + return new SimpleObjectStream<>(org.cyclops.evilcraft.block.BloodInfuser.getInstance().getRecipeRegistry().allRecipes()) |
| 78 | + .setRemover(this::remove); |
| 79 | + } |
| 80 | + |
| 81 | + public static class RecipeBuilder extends AbstractRecipeBuilder<IRecipe<IngredientFluidStackAndTierRecipeComponent, IngredientRecipeComponent, DurationXpRecipeProperties>> { |
| 82 | + |
| 83 | + private static final Fluid bloodFluid = FluidRegistry.getFluid("evilcraftblood"); |
| 84 | + |
| 85 | + private int tier = 0; |
| 86 | + private int duration = 0; |
| 87 | + private float xp = 0; |
| 88 | + |
| 89 | + public RecipeBuilder tier(int tier) { |
| 90 | + this.tier = tier; |
| 91 | + return this; |
| 92 | + } |
| 93 | + |
| 94 | + public RecipeBuilder duration(int duration) { |
| 95 | + this.duration = duration; |
| 96 | + return this; |
| 97 | + } |
| 98 | + |
| 99 | + public RecipeBuilder xp(float xp) { |
| 100 | + this.xp = xp; |
| 101 | + return this; |
| 102 | + } |
| 103 | + |
| 104 | + public RecipeBuilder blood(int amount) { |
| 105 | + this.fluidInput.add(new FluidStack(bloodFluid, amount)); |
| 106 | + return this; |
| 107 | + } |
| 108 | + |
| 109 | + public RecipeBuilder fluidInput(int amount) { |
| 110 | + this.fluidInput.add(new FluidStack(bloodFluid, amount)); |
| 111 | + return this; |
| 112 | + } |
| 113 | + |
| 114 | + @Override |
| 115 | + public String getErrorMsg() { |
| 116 | + return "Error adding EvilCraft Blood Infuser Recipe"; |
| 117 | + } |
| 118 | + |
| 119 | + @Override |
| 120 | + public void validate(GroovyLog.Msg msg) { |
| 121 | + validateItems(msg, 1, 1, 1, 1); |
| 122 | + validateFluids(msg, 1, 1, 0, 0); |
| 123 | + msg.add(tier < 0 || tier > 3, "tier must be between 0 and 3, yet it was {}", tier); |
| 124 | + msg.add(duration < 0, "duration must be a non negative integer, yet it was {}", duration); |
| 125 | + msg.add(xp < 0, "xp must be a non negative integer, yet it was {}", xp); |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public @Nullable IRecipe<IngredientFluidStackAndTierRecipeComponent, IngredientRecipeComponent, DurationXpRecipeProperties> register() { |
| 130 | + if (!validate()) return null; |
| 131 | + IRecipe<IngredientFluidStackAndTierRecipeComponent, IngredientRecipeComponent, DurationXpRecipeProperties> recipe = |
| 132 | + org.cyclops.evilcraft.block.BloodInfuser.getInstance().getRecipeRegistry().registerRecipe( |
| 133 | + new IngredientFluidStackAndTierRecipeComponent(input.get(0).toMcIngredient(), fluidInput.get(0), tier), |
| 134 | + new IngredientRecipeComponent(output.get(0)), |
| 135 | + new DurationXpRecipeProperties(duration, xp) |
| 136 | + ); |
| 137 | + ModSupport.EVILCRAFT.get().bloodInfuser.add(recipe, false); |
| 138 | + return recipe; |
| 139 | + } |
| 140 | + } |
| 141 | +} |
0 commit comments