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

140 lines
5.1 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.item.sigil;
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;
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.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
2016-03-18 15:38:26 -04:00
import WayofTime.bloodmagic.api.Constants;
public class ItemSigilLava extends ItemSigilBase
{
public ItemSigilLava()
{
super("lava", 1000);
setRegistryName(Constants.BloodMagicItem.SIGIL_LAVA.getRegName());
}
@Override
2016-03-18 15:38:26 -04:00
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
{
if (!world.isRemote && !isUnusable(stack))
{
2016-03-18 15:38:26 -04:00
RayTraceResult movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, false);
if (movingobjectposition != null)
{
2016-03-18 15:38:26 -04:00
ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, stack, movingobjectposition);
2015-12-31 13:50:38 -05:00
if (ret != null)
return ret;
2016-03-18 15:38:26 -04:00
if (movingobjectposition.typeOfHit == RayTraceResult.Type.BLOCK)
{
BlockPos blockpos = movingobjectposition.getBlockPos();
if (!world.isBlockModifiable(player, blockpos))
{
2016-03-18 15:38:26 -04:00
return super.onItemRightClick(stack, world, player, hand);
}
if (!player.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, stack))
{
2016-03-18 15:38:26 -04:00
return super.onItemRightClick(stack, world, player, hand);
}
BlockPos blockpos1 = blockpos.offset(movingobjectposition.sideHit);
if (!player.canPlayerEdit(blockpos1, movingobjectposition.sideHit, stack))
{
2016-03-18 15:38:26 -04:00
return super.onItemRightClick(stack, world, player, hand);
}
2015-12-30 17:24:40 -05:00
if (this.canPlaceLava(world, blockpos1) && syphonNetwork(stack, player, getLPUsed()) && this.tryPlaceLava(world, blockpos1))
{
2016-03-18 15:38:26 -04:00
return super.onItemRightClick(stack, world, player, hand);
}
}
}
}
2016-03-18 15:38:26 -04:00
return super.onItemRightClick(stack, world, player, hand);
}
@Override
2016-03-18 15:38:26 -04:00
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos blockPos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (world.isRemote || player.isSneaking() || isUnusable(stack))
{
2016-03-18 15:38:26 -04:00
return EnumActionResult.FAIL;
}
if (!world.canMineBlockBody(player, blockPos))
{
2016-03-18 15:38:26 -04:00
return EnumActionResult.FAIL;
}
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-30 17:24:40 -05:00
if (amount > 0 && syphonNetwork(stack, player, getLPUsed()))
{
((IFluidHandler) tile).fill(side, fluid, true);
}
2016-03-18 15:38:26 -04:00
return EnumActionResult.FAIL;
}
// else if (tile instanceof TESocket) {
// return false;
// }
2015-12-27 19:38:12 -05:00
BlockPos newPos = blockPos.offset(side);
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
}
2015-12-30 17:24:40 -05:00
if (this.canPlaceLava(world, newPos) && syphonNetwork(stack, player, getLPUsed()))
{
2016-03-18 15:38:26 -04:00
return this.tryPlaceLava(world, newPos) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
}
2016-03-18 15:38:26 -04:00
return EnumActionResult.FAIL;
}
public boolean canPlaceLava(World world, BlockPos blockPos)
{
2016-03-18 15:38:26 -04:00
if (!world.isAirBlock(blockPos) && world.getBlockState(blockPos).getBlock().getMaterial(world.getBlockState(blockPos)).isSolid())
{
return false;
2015-12-31 13:50:38 -05: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)
{
return false;
2015-12-31 13:50:38 -05:00
} else
{
world.setBlockState(blockPos, Blocks.flowing_lava.getBlockState().getBaseState(), 3);
return true;
}
}
2016-03-18 15:38:26 -04:00
public boolean tryPlaceLava(World world, BlockPos pos)
{
2016-03-18 15:38:26 -04:00
Material material = world.getBlockState(pos).getBlock().getMaterial(world.getBlockState(pos));
2016-03-18 15:38:26 -04:00
return world.isAirBlock(pos) && !material.isSolid();
}
}