2015-11-07 21:37:12 -05:00
|
|
|
package WayofTime.bloodmagic.item.sigil;
|
|
|
|
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.BindableHelper;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
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.FluidRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.IFluidHandler;
|
|
|
|
|
2015-11-07 21:44:44 -05:00
|
|
|
public class ItemSigilLava extends ItemSigilBase {
|
2015-11-07 21:37:12 -05:00
|
|
|
|
|
|
|
public ItemSigilLava() {
|
|
|
|
super("lava", 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
|
|
|
if (!world.isRemote && !isUnusable(stack)) {
|
2015-12-27 19:38:12 -05:00
|
|
|
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, false);
|
2015-11-07 21:37:12 -05:00
|
|
|
|
|
|
|
if (movingobjectposition != null) {
|
|
|
|
ItemStack ret = net.minecraftforge.event.ForgeEventFactory.onBucketUse(player, world, stack, movingobjectposition);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BlockPos blockpos1 = blockpos.offset(movingobjectposition.sideHit);
|
|
|
|
|
|
|
|
if (!player.canPlayerEdit(blockpos1, movingobjectposition.sideHit, stack)) {
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
2015-12-29 14:32:35 -05:00
|
|
|
if (this.canPlaceLava(world, blockpos1) && syphonBatteries(stack, player, getLPUsed()) && this.tryPlaceLava(world, blockpos1)) {
|
2015-12-27 19:38:12 -05:00
|
|
|
return stack;
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!player.capabilities.isCreativeMode)
|
2015-12-29 14:32:35 -05:00
|
|
|
this.setUnusable(stack, !syphonBatteries(stack, player, getLPUsed()));
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ) {
|
|
|
|
if (world.isRemote || !BindableHelper.checkAndSetItemOwner(stack, player) || player.isSneaking() || isUnusable(stack)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!world.canMineBlockBody(player, blockPos)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TileEntity tile = world.getTileEntity(blockPos);
|
|
|
|
if (tile instanceof IFluidHandler) {
|
|
|
|
FluidStack fluid = new FluidStack(FluidRegistry.LAVA, 1000);
|
|
|
|
int amount = ((IFluidHandler) tile).fill(side, fluid, false);
|
|
|
|
|
2015-12-29 14:32:35 -05:00
|
|
|
if (amount > 0 && syphonBatteries(stack, player, getLPUsed())) {
|
2015-11-07 21:37:12 -05:00
|
|
|
((IFluidHandler) tile).fill(side, fluid, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// else if (tile instanceof TESocket) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
|
2015-12-27 19:38:12 -05:00
|
|
|
BlockPos newPos = blockPos.offset(side);
|
2015-11-07 21:37:12 -05:00
|
|
|
|
2015-12-27 19:38:12 -05:00
|
|
|
if (!player.canPlayerEdit(newPos, side, stack)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-07 21:37:12 -05:00
|
|
|
|
2015-12-29 14:32:35 -05:00
|
|
|
if (this.canPlaceLava(world, newPos) && syphonBatteries(stack, player, getLPUsed())) {
|
2015-12-27 19:38:12 -05:00
|
|
|
return this.tryPlaceLava(world, newPos);
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canPlaceLava(World world, BlockPos blockPos) {
|
|
|
|
if (!world.isAirBlock(blockPos) && world.getBlockState(blockPos).getBlock().getMaterial().isSolid()) {
|
|
|
|
return false;
|
2015-11-28 18:25:46 -08:00
|
|
|
} else if ((world.getBlockState(blockPos).getBlock() == Blocks.lava || world.getBlockState(blockPos).getBlock() == Blocks.flowing_lava) && world.getBlockState(blockPos).getBlock().getMetaFromState(world.getBlockState(blockPos)) == 0) {
|
2015-11-07 21:37:12 -05:00
|
|
|
return false;
|
2015-11-28 18:25:46 -08:00
|
|
|
} else {
|
2015-12-27 19:38:12 -05:00
|
|
|
world.setBlockState(blockPos, Blocks.lava.getBlockState().getBaseState(), 3);
|
2015-11-07 21:37:12 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean tryPlaceLava(World worldIn, BlockPos pos) {
|
|
|
|
Material material = worldIn.getBlockState(pos).getBlock().getMaterial();
|
|
|
|
|
|
|
|
return worldIn.isAirBlock(pos) && !material.isSolid();
|
|
|
|
}
|
|
|
|
}
|