diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilFluidBase.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilFluidBase.java index 614f87f4..ac1ef35b 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilFluidBase.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilFluidBase.java @@ -1,14 +1,23 @@ package WayofTime.bloodmagic.item.sigil; +import WayofTime.bloodmagic.core.data.Binding; +import WayofTime.bloodmagic.core.data.SoulNetwork; +import WayofTime.bloodmagic.core.data.SoulTicket; +import WayofTime.bloodmagic.util.ISigilFluidItem; +import WayofTime.bloodmagic.util.SigilFluidWrapper; +import WayofTime.bloodmagic.util.helper.NetworkHelper; import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidBlock; @@ -20,7 +29,7 @@ import net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper; import javax.annotation.Nullable; -public abstract class ItemSigilFluidBase extends ItemSigilBase { +public abstract class ItemSigilFluidBase extends ItemSigilBase implements ISigilFluidItem { //Class for sigils that interact with fluids, either creating or deleting them. //Sigils still have to define their own onRightClick behavior, but the actual fluid-interacting code is largely limited to here. public final FluidStack sigilFluid; @@ -125,4 +134,45 @@ public abstract class ItemSigilFluidBase extends ItemSigilBase { handler = new BlockWrapper(block, world, blockPos); return tryInsertSigilFluid(handler, true); } + + @Override + public FluidStack getFluid(ItemStack sigil) { + return sigilFluid; + } + + @Override + public int getCapacity(ItemStack sigil) { + return 0; + } + + @Override + public FluidStack drain(ItemStack sigil, int maxDrain, boolean doDrain) { + Binding binding = getBinding(sigil); + + if (binding == null) + return null; + + SoulNetwork network = NetworkHelper.getSoulNetwork(binding); + + if (network.getCurrentEssence() < getLpUsed()) { + network.causeNausea(); + return null; + } + + if (doDrain) + network.syphon(SoulTicket.item(sigil, getLpUsed())); + + return sigilFluid; + } + + @Override + public int fill(ItemStack sigil, FluidStack resource, boolean doFill) { + return 0; + } + + @Override + public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt) { + return new SigilFluidWrapper(stack, this); + } + } \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilVoid.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilVoid.java index 702e692c..8b321eb4 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilVoid.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilVoid.java @@ -1,5 +1,7 @@ package WayofTime.bloodmagic.item.sigil; +import WayofTime.bloodmagic.core.data.Binding; +import WayofTime.bloodmagic.core.data.SoulNetwork; import WayofTime.bloodmagic.core.data.SoulTicket; import WayofTime.bloodmagic.iface.ISigil; import WayofTime.bloodmagic.util.helper.NetworkHelper; @@ -12,6 +14,7 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; public class ItemSigilVoid extends ItemSigilFluidBase { @@ -52,7 +55,43 @@ public class ItemSigilVoid extends ItemSigilFluidBase { } } } - return super.onItemRightClick(world, player, hand); } + + @Override + public FluidStack getFluid(ItemStack sigil) { + return null; + } + + @Override + public int getCapacity(ItemStack sigil) { + return 10000; + } + + @Override + public int fill(ItemStack sigil, FluidStack resource, boolean doFill) { + if (resource == null || resource.amount <= 0) + return 0; + + Binding binding = getBinding(sigil); + + if (binding == null) + return 0; + + int capacity = getCapacity(sigil); + + if (!doFill) + return Math.min(capacity, resource.amount); + + SoulNetwork network = NetworkHelper.getSoulNetwork(binding); + + if (network.getCurrentEssence() < getLpUsed()) { + network.causeNausea(); + return 0; + } + + network.syphon(SoulTicket.item(sigil, getLpUsed())); + return Math.min(capacity, resource.amount); + } } + diff --git a/src/main/java/WayofTime/bloodmagic/util/ISigilFluidItem.java b/src/main/java/WayofTime/bloodmagic/util/ISigilFluidItem.java new file mode 100644 index 00000000..920b21de --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/util/ISigilFluidItem.java @@ -0,0 +1,12 @@ +package WayofTime.bloodmagic.util; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public interface ISigilFluidItem { + FluidStack getFluid(ItemStack sigil); + int getCapacity(ItemStack sigil); + + int fill(ItemStack sigil, FluidStack resource, boolean doFill); + FluidStack drain(ItemStack sigil, int maxDrain, boolean doDrain); +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/util/SigilFluidWrapper.java b/src/main/java/WayofTime/bloodmagic/util/SigilFluidWrapper.java new file mode 100644 index 00000000..51319174 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/util/SigilFluidWrapper.java @@ -0,0 +1,81 @@ +package WayofTime.bloodmagic.util; + +import WayofTime.bloodmagic.item.sigil.ItemSigilFluidBase; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ICapabilityProvider; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; +import net.minecraftforge.fluids.capability.FluidTankProperties; +import net.minecraftforge.fluids.capability.IFluidHandlerItem; +import net.minecraftforge.fluids.capability.IFluidTankProperties; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class SigilFluidWrapper implements ICapabilityProvider { + + final ItemStack stack; + final ItemSigilFluidBase sigil; + final boolean canFill; + final boolean canDrain; + + public SigilFluidWrapper(ItemStack stackIn, ItemSigilFluidBase fluidSigil) { + stack = stackIn; + sigil = fluidSigil; + canFill = true; + canDrain = true; + } + + public SigilFluidWrapper(ItemStack stackIn, ItemSigilFluidBase fluidSigil, boolean canFillIn, boolean canDrainIn) { + stack = stackIn; + sigil = fluidSigil; + canFill = canFillIn; + canDrain = canDrainIn; + } + + @Override + public boolean hasCapability(Capability capability, EnumFacing from) { + return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY; + } + + @Override + public T getCapability(Capability capability, final EnumFacing from) { + if (!hasCapability(capability, from)) { + return null; + } + return CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY.cast(new IFluidHandlerItem() { + + @Override + public IFluidTankProperties[] getTankProperties() { + return new IFluidTankProperties[]{new FluidTankProperties(sigil.getFluid(stack), sigil.getCapacity(stack), canFill, canDrain)}; + } + + @Override + public int fill(FluidStack resource, boolean doFill) { + return 0; + } + + @Nullable + @Override + public FluidStack drain(FluidStack resource, boolean doDrain) { + return sigil.drain(stack, resource.amount, doDrain); + } + + @Nullable + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + return sigil.drain(stack, maxDrain, doDrain); + } + + @Nonnull + @Override + public ItemStack getContainer() { + return stack; + } + + }); + } + +} \ No newline at end of file