Capable fluid sigils (#1517)
* Inital commit. Water Sigil can now be used as infinite water tank item to fill machines with water (as long as you have LP) (Doesn't use LP yet). * Should now work for all fluid sigils. * Reverted Bound tool change * Moved the code out of the spacey loft IDE said it's ok... or something
This commit is contained in:
parent
31c606495c
commit
399c2723d3
|
@ -1,14 +1,23 @@
|
||||||
package WayofTime.bloodmagic.item.sigil;
|
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.Block;
|
||||||
import net.minecraft.block.BlockLiquid;
|
import net.minecraft.block.BlockLiquid;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.IFluidBlock;
|
import net.minecraftforge.fluids.IFluidBlock;
|
||||||
|
@ -20,7 +29,7 @@ import net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
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.
|
//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.
|
//Sigils still have to define their own onRightClick behavior, but the actual fluid-interacting code is largely limited to here.
|
||||||
public final FluidStack sigilFluid;
|
public final FluidStack sigilFluid;
|
||||||
|
@ -125,4 +134,45 @@ public abstract class ItemSigilFluidBase extends ItemSigilBase {
|
||||||
handler = new BlockWrapper(block, world, blockPos);
|
handler = new BlockWrapper(block, world, blockPos);
|
||||||
return tryInsertSigilFluid(handler, true);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package WayofTime.bloodmagic.item.sigil;
|
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.core.data.SoulTicket;
|
||||||
import WayofTime.bloodmagic.iface.ISigil;
|
import WayofTime.bloodmagic.iface.ISigil;
|
||||||
import WayofTime.bloodmagic.util.helper.NetworkHelper;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||||
|
|
||||||
public class ItemSigilVoid extends ItemSigilFluidBase {
|
public class ItemSigilVoid extends ItemSigilFluidBase {
|
||||||
|
@ -52,7 +55,43 @@ public class ItemSigilVoid extends ItemSigilFluidBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onItemRightClick(world, player, hand);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/main/java/WayofTime/bloodmagic/util/ISigilFluidItem.java
Normal file
12
src/main/java/WayofTime/bloodmagic/util/ISigilFluidItem.java
Normal file
|
@ -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);
|
||||||
|
}
|
|
@ -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> T getCapability(Capability<T> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue