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

118 lines
3.8 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.item.sigil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fluids.IFluidHandler;
import WayofTime.bloodmagic.api.Constants;
public class ItemSigilVoid extends ItemSigilBase
{
public ItemSigilVoid()
{
super("void", 50);
setRegistryName(Constants.BloodMagicItem.SIGIL_VOID.getRegName());
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
if (!world.isRemote && !isUnusable(stack))
{
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, true);
if (movingobjectposition != null)
{
ItemStack ret = net.minecraftforge.event.ForgeEventFactory.onBucketUse(player, world, stack, movingobjectposition);
2015-12-31 13:50:38 -05:00
if (ret != null)
return ret;
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
{
BlockPos blockpos = movingobjectposition.getBlockPos();
if (!world.isBlockModifiable(player, blockpos))
{
return stack;
}
if (!player.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, stack))
{
return stack;
}
if (!player.canPlayerEdit(blockpos, movingobjectposition.sideHit, stack))
{
return stack;
}
2015-12-30 17:24:40 -05:00
if (world.getBlockState(blockpos).getBlock().getMaterial().isLiquid() && syphonNetwork(stack, player, getLPUsed()))
{
world.setBlockToAir(blockpos);
return stack;
}
}
2015-12-31 13:50:38 -05:00
} else
{
return stack;
}
if (!player.capabilities.isCreativeMode)
2015-12-30 17:24:40 -05:00
this.setUnusable(stack, !syphonNetwork(stack, player, getLPUsed()));
}
return stack;
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ)
{
super.onItemUse(stack, player, world, blockPos, side, hitX, hitY, hitZ);
if (world.isRemote || player.isSneaking() || isUnusable(stack))
{
return false;
}
if (!world.canMineBlockBody(player, blockPos))
{
return false;
}
TileEntity tile = world.getTileEntity(blockPos);
if (tile instanceof IFluidHandler)
{
FluidStack amount = ((IFluidHandler) tile).drain(side, 1000, false);
2015-12-30 17:24:40 -05:00
if (amount != null && amount.amount > 0 && syphonNetwork(stack, player, getLPUsed()))
{
((IFluidHandler) tile).drain(side, 1000, true);
return true;
}
return false;
}
2015-12-27 19:38:12 -05:00
BlockPos newPos = blockPos.offset(side);
if (!player.canPlayerEdit(newPos, side, stack))
{
2015-12-27 19:38:12 -05:00
return false;
}
2015-12-30 17:24:40 -05:00
if (world.getBlockState(newPos).getBlock() instanceof IFluidBlock && syphonNetwork(stack, player, getLPUsed()))
{
2015-12-27 19:38:12 -05:00
world.setBlockToAir(newPos);
return true;
}
return false;
}
}