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.
This commit is contained in:
Andrew Fontaine 2018-12-30 19:14:27 -05:00 committed by Nick Ignoffo
parent 6b1e9f4014
commit 297771af81
6 changed files with 106 additions and 20 deletions

View file

@ -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());

View file

@ -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));
}
}

View file

@ -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<ItemStack> 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;
}
}

View file

@ -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<ICrushingHandler> crushingHandlerList = new ArrayList<>();
public static void registerCuttingFluid(ICrushingHandler handler) {
crushingHandlerList.add(handler);
}
public static List<ICrushingHandler> getCrushingHandlerList() {
return crushingHandlerList;
}
}

View file

@ -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();
}

View file

@ -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<ItemStack, Integer> 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<ItemStack> 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))) {