BloodMagic/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilVoid.java

115 lines
4.7 KiB
Java
Raw Normal View History

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