2015-11-08 02:37:12 +00:00
|
|
|
package WayofTime.bloodmagic.item.sigil;
|
|
|
|
|
2018-08-07 22:27:12 +00:00
|
|
|
import WayofTime.bloodmagic.core.data.SoulTicket;
|
2018-02-16 02:49:01 +00:00
|
|
|
import WayofTime.bloodmagic.iface.ISigil;
|
|
|
|
import WayofTime.bloodmagic.util.helper.NetworkHelper;
|
|
|
|
import WayofTime.bloodmagic.util.helper.PlayerHelper;
|
2015-11-08 02:37:12 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2018-08-26 19:59:41 +00:00
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.EnumActionResult;
|
|
|
|
import net.minecraft.util.EnumHand;
|
2016-03-18 19:38:26 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2015-11-08 02:37:12 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.fluids.FluidRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2017-01-02 05:43:34 +00:00
|
|
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
2015-11-08 02:37:12 +00:00
|
|
|
|
2018-08-26 19:59:41 +00:00
|
|
|
|
|
|
|
public class ItemSigilLava extends ItemSigilFluidBase {
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public ItemSigilLava() {
|
2018-08-26 19:59:41 +00:00
|
|
|
super("lava", 1000, new FluidStack(FluidRegistry.LAVA, 1000));
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
2017-01-02 05:43:34 +00:00
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2017-03-15 02:33:13 +00:00
|
|
|
if (stack.getItem() instanceof ISigil.Holding)
|
|
|
|
stack = ((Holding) stack.getItem()).getHeldItem(stack, player);
|
2016-11-12 00:57:50 +00:00
|
|
|
if (PlayerHelper.isFakePlayer(player))
|
|
|
|
return ActionResult.newResult(EnumActionResult.FAIL, stack);
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (!world.isRemote && !isUnusable(stack)) {
|
2016-04-24 17:06:28 +00:00
|
|
|
RayTraceResult rayTrace = this.rayTrace(world, player, false);
|
2015-11-08 02:37:12 +00:00
|
|
|
|
2018-08-26 19:59:41 +00:00
|
|
|
if (rayTrace == null || rayTrace.typeOfHit != RayTraceResult.Type.BLOCK) {
|
|
|
|
return ActionResult.newResult(EnumActionResult.PASS, stack);
|
|
|
|
}
|
2015-11-08 02:37:12 +00:00
|
|
|
|
2018-08-26 19:59:41 +00:00
|
|
|
BlockPos blockPos = rayTrace.getBlockPos();
|
2015-11-08 02:37:12 +00:00
|
|
|
|
2018-08-26 19:59:41 +00:00
|
|
|
if (world.isBlockModifiable(player, blockPos) && player.canPlayerEdit(blockPos, rayTrace.sideHit, stack)) {
|
|
|
|
//Case for if block at blockPos is a fluid handler like a tank
|
|
|
|
//Try to put fluid into tank
|
|
|
|
IFluidHandler destination = getFluidHandler(world, blockPos, null);
|
|
|
|
if (destination != null && tryInsertSigilFluid(destination, false) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, SoulTicket.item(stack, world, player, getLpUsed())).isSuccess()) {
|
|
|
|
boolean result = tryInsertSigilFluid(destination, true);
|
|
|
|
if (result)
|
|
|
|
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
|
|
|
|
}
|
|
|
|
//Do the same as above, but use sidedness to interact with the fluid handler.
|
|
|
|
IFluidHandler destinationSide = getFluidHandler(world, blockPos, rayTrace.sideHit);
|
|
|
|
if (destinationSide != null && tryInsertSigilFluid(destinationSide, false) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, SoulTicket.item(stack, world, player, getLpUsed())).isSuccess()) {
|
|
|
|
boolean result = tryInsertSigilFluid(destinationSide, true);
|
|
|
|
if (result)
|
|
|
|
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
|
|
|
|
}
|
|
|
|
//Case for if block at blockPos is not a tank
|
|
|
|
//Place fluid in world
|
|
|
|
if (destination == null && destinationSide == null) {
|
|
|
|
BlockPos targetPos = blockPos.offset(rayTrace.sideHit);
|
|
|
|
if (tryPlaceSigilFluid(player, world, targetPos) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, SoulTicket.item(stack, world, player, getLpUsed())).isSuccess()) {
|
|
|
|
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-02 05:43:34 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
}
|