From 297771af815302e38141a5225df9e96a0f0a06ce Mon Sep 17 00:00:00 2001 From: Andrew Fontaine Date: Sun, 30 Dec 2018 19:14:27 -0500 Subject: [PATCH] Add Handlers for Ritual of Crushing (#1469) * Add Handlers for Ritual of Crushing Fixes the crushing ritual's corrosive will augment. * Simplify Handler Class Use Primitives, ensure return value is non-null * Make the Handler Handle Draining Per Use * Revert "Make the Handler Handle Draining Per Use" This reverts commit bacaa610febc5a609a7a891ceed41b0e0fb2f05d. --- .../java/WayofTime/bloodmagic/BloodMagic.java | 1 + .../bloodmagic/registry/ModRituals.java | 9 ++++ .../crushing/CrushingHandlerCuttingFluid.java | 49 +++++++++++++++++++ .../ritual/crushing/CrushingRegistry.java | 20 ++++++++ .../ritual/crushing/ICrushingHandler.java | 14 ++++++ .../ritual/types/RitualCrushing.java | 33 +++++-------- 6 files changed, 106 insertions(+), 20 deletions(-) create mode 100644 src/main/java/WayofTime/bloodmagic/ritual/crushing/CrushingHandlerCuttingFluid.java create mode 100644 src/main/java/WayofTime/bloodmagic/ritual/crushing/CrushingRegistry.java create mode 100644 src/main/java/WayofTime/bloodmagic/ritual/crushing/ICrushingHandler.java diff --git a/src/main/java/WayofTime/bloodmagic/BloodMagic.java b/src/main/java/WayofTime/bloodmagic/BloodMagic.java index c132d776..c0413361 100644 --- a/src/main/java/WayofTime/bloodmagic/BloodMagic.java +++ b/src/main/java/WayofTime/bloodmagic/BloodMagic.java @@ -91,6 +91,7 @@ public class BloodMagic { ModRecipes.init(); ModRituals.initHarvestHandlers(); + ModRituals.initCuttingFluids(); MeteorConfigHandler.init(new File(configDir, "meteors")); ModArmourTrackers.init(); NetworkRegistry.INSTANCE.registerGuiHandler(BloodMagic.instance, new GuiHandler()); diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java b/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java index f33bbf22..8b1822e9 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java @@ -1,5 +1,8 @@ package WayofTime.bloodmagic.registry; +import WayofTime.bloodmagic.item.alchemy.ItemCuttingFluid; +import WayofTime.bloodmagic.ritual.crushing.CrushingHandlerCuttingFluid; +import WayofTime.bloodmagic.ritual.crushing.CrushingRegistry; import WayofTime.bloodmagic.ritual.harvest.HarvestRegistry; import WayofTime.bloodmagic.ritual.harvest.HarvestHandlerPlantable; import WayofTime.bloodmagic.ritual.harvest.HarvestHandlerStem; @@ -19,4 +22,10 @@ public class ModRituals HarvestRegistry.registerHandler(new HarvestHandlerTall()); HarvestRegistry.registerHandler(new HarvestHandlerStem()); } + + public static void initCuttingFluids() + { + CrushingRegistry.registerCuttingFluid(new CrushingHandlerCuttingFluid(ItemCuttingFluid.FluidType.BASIC.getStack(), 250, 0.5)); + CrushingRegistry.registerCuttingFluid(new CrushingHandlerCuttingFluid(ItemCuttingFluid.FluidType.EXPLOSIVE.getStack(), 25, 0.05)); + } } diff --git a/src/main/java/WayofTime/bloodmagic/ritual/crushing/CrushingHandlerCuttingFluid.java b/src/main/java/WayofTime/bloodmagic/ritual/crushing/CrushingHandlerCuttingFluid.java new file mode 100644 index 00000000..6263059c --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/ritual/crushing/CrushingHandlerCuttingFluid.java @@ -0,0 +1,49 @@ +package WayofTime.bloodmagic.ritual.crushing; + +import WayofTime.bloodmagic.api.impl.BloodMagicAPI; +import WayofTime.bloodmagic.api.impl.recipe.RecipeAlchemyTable; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.List; + +public class CrushingHandlerCuttingFluid implements ICrushingHandler { + + private int lpDrain; + + private double willDrain; + + private ItemStack cuttingStack; + + public CrushingHandlerCuttingFluid(ItemStack cuttingStack, int lpDrain, double willDrain) { + this.lpDrain = lpDrain; + this.willDrain = willDrain; + this.cuttingStack = cuttingStack; + } + + @Override + @Nonnull + public ItemStack getRecipeOutput(ItemStack inputStack, World world, BlockPos pos) { + List inputList = new ArrayList<>(); + inputList.add(cuttingStack); + inputList.add(inputStack.copy()); + RecipeAlchemyTable recipeAlchemyTable = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getAlchemyTable(inputList); + + if (recipeAlchemyTable != null) { + return recipeAlchemyTable.getOutput().copy(); + } + + return ItemStack.EMPTY; + } + + public double getWillDrain() { + return willDrain; + } + + public int getLpDrain() { + return lpDrain; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/ritual/crushing/CrushingRegistry.java b/src/main/java/WayofTime/bloodmagic/ritual/crushing/CrushingRegistry.java new file mode 100644 index 00000000..696663ea --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/ritual/crushing/CrushingRegistry.java @@ -0,0 +1,20 @@ +package WayofTime.bloodmagic.ritual.crushing; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; + + +public class CrushingRegistry { + + private static List crushingHandlerList = new ArrayList<>(); + + public static void registerCuttingFluid(ICrushingHandler handler) { + crushingHandlerList.add(handler); + } + + public static List getCrushingHandlerList() { + return crushingHandlerList; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/ritual/crushing/ICrushingHandler.java b/src/main/java/WayofTime/bloodmagic/ritual/crushing/ICrushingHandler.java new file mode 100644 index 00000000..fb99faf7 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/ritual/crushing/ICrushingHandler.java @@ -0,0 +1,14 @@ +package WayofTime.bloodmagic.ritual.crushing; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import javax.annotation.Nonnull; + +public interface ICrushingHandler { + @Nonnull + ItemStack getRecipeOutput(ItemStack input, World world, BlockPos pos); + int getLpDrain(); + double getWillDrain(); +} diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrushing.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrushing.java index 8f1a5855..49940c87 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrushing.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrushing.java @@ -5,6 +5,8 @@ import WayofTime.bloodmagic.compress.CompressionRegistry; import WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTableRecipe; import WayofTime.bloodmagic.core.registry.AlchemyTableRecipeRegistry; import WayofTime.bloodmagic.ritual.*; +import WayofTime.bloodmagic.ritual.crushing.CrushingRegistry; +import WayofTime.bloodmagic.ritual.crushing.ICrushingHandler; import WayofTime.bloodmagic.soul.EnumDemonWillType; import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks; import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler; @@ -117,29 +119,19 @@ public class RitualCrushing extends Ritual { ItemStack copyStack = checkStack.copy(); - for (Entry entry : cuttingFluidLPMap.entrySet()) { - ItemStack cuttingStack = entry.getKey(); - int lpDrain = entry.getValue(); - double willDrain = cuttingFluidWillMap.containsKey(cuttingStack) ? cuttingFluidWillMap.get(cuttingStack) : 0; + for (ICrushingHandler handler : CrushingRegistry.getCrushingHandlerList()) { + int lpDrain = handler.getLpDrain(); + double willDrain = handler.getWillDrain(); - if (corrosiveWill < willDrain || currentEssence < lpDrain + getRefreshCost()) { - continue; - } + if (corrosiveWill < willDrain || currentEssence < lpDrain + getRefreshCost()) { + continue; + } - cuttingStack = cuttingStack.copy(); - List input = new ArrayList<>(); - input.add(cuttingStack); - input.add(copyStack); + ItemStack result = handler.getRecipeOutput(copyStack, world, pos); - AlchemyTableRecipe recipe = AlchemyTableRecipeRegistry.getMatchingRecipe(input, world, pos); - if (recipe == null) { - continue; - } - - ItemStack result = recipe.getRecipeOutput(input); - if (result.isEmpty()) { - continue; - } + if (result.isEmpty()) { + continue; + } if (tile != null) { result = Utils.insertStackIntoTile(result, tile, EnumFacing.DOWN); @@ -158,6 +150,7 @@ public class RitualCrushing extends Ritual { isBlockClaimed = true; } + } if (!isBlockClaimed && isSilkTouch && block.canSilkHarvest(world, newPos, state, getFakePlayer((WorldServer) world))) {