2015-11-07 21:37:12 -05:00
|
|
|
package WayofTime.bloodmagic.item.sigil;
|
|
|
|
|
2018-02-15 18:49:01 -08:00
|
|
|
import WayofTime.bloodmagic.iface.ISigil;
|
|
|
|
import WayofTime.bloodmagic.util.helper.NetworkHelper;
|
|
|
|
import WayofTime.bloodmagic.util.helper.PlayerHelper;
|
2015-11-07 21:37:12 -05:00
|
|
|
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;
|
2015-11-07 21:37:12 -05:00
|
|
|
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;
|
2015-11-07 21:37:12 -05:00
|
|
|
import net.minecraft.world.World;
|
2016-01-09 17:30:10 -08:00
|
|
|
import net.minecraftforge.event.ForgeEventFactory;
|
2015-11-07 21:37:12 -05:00
|
|
|
import net.minecraftforge.fluids.FluidRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2017-01-01 21:43:34 -08:00
|
|
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
|
|
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
2015-11-07 21:37:12 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public class ItemSigilLava extends ItemSigilBase {
|
|
|
|
public ItemSigilLava() {
|
2015-11-07 21:37:12 -05:00
|
|
|
super("lava", 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
2017-01-01 21:43:34 -08:00
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2017-03-14 19:33:13 -07:00
|
|
|
if (stack.getItem() instanceof ISigil.Holding)
|
|
|
|
stack = ((Holding) stack.getItem()).getHeldItem(stack, player);
|
2016-11-11 16:57:50 -08:00
|
|
|
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, false);
|
2015-11-07 21:37:12 -05:00
|
|
|
|
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;
|
2015-11-07 21:37:12 -05:00
|
|
|
|
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();
|
2015-11-07 21:37:12 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (!world.isBlockModifiable(player, blockpos)) {
|
2017-01-01 21:43:34 -08:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (!player.canPlayerEdit(blockpos.offset(rayTrace.sideHit), rayTrace.sideHit, stack)) {
|
2017-01-01 21:43:34 -08:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
|
2016-04-24 10:06:28 -07:00
|
|
|
BlockPos blockpos1 = blockpos.offset(rayTrace.sideHit);
|
2015-11-07 21:37:12 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (!player.canPlayerEdit(blockpos1, rayTrace.sideHit, stack)) {
|
2017-01-01 21:43:34 -08:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (this.canPlaceLava(world, blockpos1) && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceLava(world, blockpos1)) {
|
2017-01-01 21:43:34 -08:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-01 21:43:34 -08:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@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-01 21:43:34 -08:00
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
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;
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
2017-08-15 21:30:48 -07:00
|
|
|
if (!world.canMineBlockBody(player, blockPos)) {
|
2016-03-18 15:38:26 -04:00
|
|
|
return EnumActionResult.FAIL;
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TileEntity tile = world.getTileEntity(blockPos);
|
2018-02-19 14:06:05 -08:00
|
|
|
if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
|
2017-01-01 21:43:34 -08:00
|
|
|
IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
|
2015-11-07 21:37:12 -05:00
|
|
|
FluidStack fluid = new FluidStack(FluidRegistry.LAVA, 1000);
|
2017-01-01 21:43:34 -08:00
|
|
|
int amount = handler.fill(fluid, false);
|
2015-11-07 21:37:12 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (amount > 0 && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())) {
|
2017-01-01 21:43:34 -08:00
|
|
|
handler.fill(fluid, true);
|
2016-04-05 16:13:49 -04:00
|
|
|
return EnumActionResult.SUCCESS;
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
|
2016-03-18 15:38:26 -04:00
|
|
|
return EnumActionResult.FAIL;
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
|
2016-03-18 15:38:26 -04:00
|
|
|
return EnumActionResult.FAIL;
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean canPlaceLava(World world, BlockPos blockPos) {
|
|
|
|
if (!world.isAirBlock(blockPos) && world.getBlockState(blockPos).getBlock().getMaterial(world.getBlockState(blockPos)).isSolid()) {
|
2015-11-07 21:37:12 -05:00
|
|
|
return false;
|
2017-08-15 21:30:48 -07: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;
|
2017-08-15 21:30:48 -07:00
|
|
|
} else {
|
2016-04-24 10:06:28 -07:00
|
|
|
world.setBlockState(blockPos, Blocks.FLOWING_LAVA.getBlockState().getBaseState(), 3);
|
2015-11-07 21:37:12 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07: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));
|
2015-11-07 21:37:12 -05:00
|
|
|
|
2016-03-18 15:38:26 -04:00
|
|
|
return world.isAirBlock(pos) && !material.isSolid();
|
2015-11-07 21:37:12 -05:00
|
|
|
}
|
|
|
|
}
|