2015-11-08 02:37:12 +00:00
|
|
|
package WayofTime.bloodmagic.item.sigil;
|
|
|
|
|
2018-02-28 00:59:51 +00:00
|
|
|
import WayofTime.bloodmagic.core.data.SoulNetwork;
|
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;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2018-08-07 22:27:12 +00:00
|
|
|
import net.minecraft.util.*;
|
2016-03-17 20:00:44 +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;
|
2016-03-17 20:00:44 +00:00
|
|
|
import net.minecraftforge.event.ForgeEventFactory;
|
2015-11-08 02:37:12 +00:00
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.IFluidBlock;
|
2017-01-02 08:10:28 +00:00
|
|
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
|
|
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
2015-11-08 02:37:12 +00:00
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public class ItemSigilVoid extends ItemSigilBase {
|
|
|
|
public ItemSigilVoid() {
|
2015-11-08 02:37:12 +00:00
|
|
|
super("void", 50);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
2017-01-02 08:10:28 +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, true);
|
2015-11-08 02:37:12 +00:00
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (rayTrace != null) {
|
2016-04-24 17:06:28 +00:00
|
|
|
ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, stack, rayTrace);
|
2015-12-31 18:50:38 +00:00
|
|
|
if (ret != null)
|
|
|
|
return ret;
|
2015-11-08 02:37:12 +00:00
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (rayTrace.typeOfHit == RayTraceResult.Type.BLOCK) {
|
2016-04-24 17:06:28 +00:00
|
|
|
BlockPos blockpos = rayTrace.getBlockPos();
|
2015-11-08 02:37:12 +00:00
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (!world.isBlockModifiable(player, blockpos)) {
|
2017-01-02 08:10:28 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (!player.canPlayerEdit(blockpos.offset(rayTrace.sideHit), rayTrace.sideHit, stack)) {
|
2017-01-02 08:10:28 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (!player.canPlayerEdit(blockpos, rayTrace.sideHit, stack)) {
|
2017-01-02 08:10:28 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 22:27:12 +00:00
|
|
|
if (world.getBlockState(blockpos).getBlock().getMaterial(world.getBlockState(blockpos)).isLiquid() && NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, SoulTicket.item(stack, world, player, getLpUsed())).isSuccess()) {
|
2015-11-08 02:37:12 +00:00
|
|
|
world.setBlockToAir(blockpos);
|
2017-01-02 08:10:28 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-16 04:30:48 +00:00
|
|
|
} else {
|
2017-01-02 08:10:28 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!player.capabilities.isCreativeMode)
|
2018-08-07 22:27:12 +00:00
|
|
|
setUnusable(stack, !NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, SoulTicket.item(stack, world, player, getLpUsed())).isSuccess());
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-02 08:10:28 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos blockPos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
2017-01-02 08:10:28 +00:00
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2016-11-12 00:57:50 +00:00
|
|
|
if (PlayerHelper.isFakePlayer(player))
|
|
|
|
return EnumActionResult.FAIL;
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (world.isRemote || player.isSneaking() || isUnusable(stack)) {
|
2016-03-18 19:38:26 +00:00
|
|
|
return EnumActionResult.FAIL;
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (!world.canMineBlockBody(player, blockPos)) {
|
2016-03-18 19:38:26 +00:00
|
|
|
return EnumActionResult.FAIL;
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 00:59:51 +00:00
|
|
|
SoulNetwork network = NetworkHelper.getSoulNetwork(getBinding(stack));
|
2015-11-08 02:37:12 +00:00
|
|
|
TileEntity tile = world.getTileEntity(blockPos);
|
2018-02-19 22:06:05 +00:00
|
|
|
if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
|
2017-01-02 08:10:28 +00:00
|
|
|
IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
|
|
|
|
FluidStack amount = handler.drain(1000, false);
|
2015-11-08 02:37:12 +00:00
|
|
|
|
2018-08-07 22:27:12 +00:00
|
|
|
if (amount != null && amount.amount > 0 && network.syphonAndDamage(player, SoulTicket.item(stack, world, player, getLpUsed())).isSuccess()) {
|
2017-01-02 08:10:28 +00:00
|
|
|
handler.drain(1000, true);
|
2016-03-18 19:38:26 +00:00
|
|
|
return EnumActionResult.SUCCESS;
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 19:38:26 +00:00
|
|
|
return EnumActionResult.FAIL;
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
2015-12-28 00:38:12 +00:00
|
|
|
BlockPos newPos = blockPos.offset(side);
|
2015-11-08 02:37:12 +00:00
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
if (!player.canPlayerEdit(newPos, side, stack)) {
|
2016-03-18 19:38:26 +00:00
|
|
|
return EnumActionResult.FAIL;
|
2015-12-28 00:38:12 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 22:27:12 +00:00
|
|
|
if (world.getBlockState(newPos).getBlock() instanceof IFluidBlock && network.syphonAndDamage(player, SoulTicket.item(stack, world, player, getLpUsed())).isSuccess()) {
|
2015-12-28 00:38:12 +00:00
|
|
|
world.setBlockToAir(newPos);
|
2016-03-18 19:38:26 +00:00
|
|
|
return EnumActionResult.SUCCESS;
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 19:38:26 +00:00
|
|
|
return EnumActionResult.FAIL;
|
2015-11-08 02:37:12 +00:00
|
|
|
}
|
|
|
|
}
|