2014-06-27 19:43:09 -04:00
|
|
|
package WayofTime.alchemicalWizardry.common.items.sigil;
|
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
|
|
|
import WayofTime.alchemicalWizardry.api.items.interfaces.ArmourUpgrade;
|
|
|
|
import WayofTime.alchemicalWizardry.common.items.EnergyBattery;
|
|
|
|
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2014-06-27 19:43:09 -04:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemBucket;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.potion.Potion;
|
|
|
|
import net.minecraft.potion.PotionEffect;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
2015-01-22 20:13:57 +03:00
|
|
|
import net.minecraft.util.StatCollector;
|
2014-06-27 19:43:09 -04:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
import net.minecraftforge.fluids.FluidRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.IFluidHandler;
|
2014-10-13 22:33:20 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
2014-06-27 19:43:09 -04:00
|
|
|
|
|
|
|
public class LavaSigil extends ItemBucket implements ArmourUpgrade
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* field for checking if the bucket has been filled.
|
|
|
|
*/
|
|
|
|
private Block isFull = Blocks.lava;
|
|
|
|
private int energyUsed;
|
|
|
|
|
|
|
|
public LavaSigil()
|
|
|
|
{
|
|
|
|
super(Blocks.lava);
|
|
|
|
this.maxStackSize = 1;
|
|
|
|
setEnergyUsed(1000);
|
|
|
|
setCreativeTab(AlchemicalWizardry.tabBloodMagic);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerIcons(IIconRegister iconRegister)
|
|
|
|
{
|
|
|
|
this.itemIcon = iconRegister.registerIcon("AlchemicalWizardry:LavaSigil");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getContainerItem(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
ItemStack copiedStack = itemStack.copy();
|
|
|
|
copiedStack.setItemDamage(copiedStack.getItemDamage() + getEnergyUsed());
|
|
|
|
copiedStack.stackSize = 1;
|
|
|
|
return copiedStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
|
|
|
|
{
|
2015-01-22 20:13:57 +03:00
|
|
|
par3List.add(StatCollector.translateToLocal("tooltip.lavasigil.desc1"));
|
|
|
|
par3List.add(StatCollector.translateToLocal("tooltip.lavasigil.desc2"));
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2015-01-16 10:00:50 -05:00
|
|
|
if (!(par1ItemStack.getTagCompound() == null))
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-01-22 20:13:57 +03:00
|
|
|
par3List.add(StatCollector.translateToLocal("tooltip.owner.currentowner") + " " + par1ItemStack.getTagCompound().getString("ownerName"));
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
|
|
|
*/
|
|
|
|
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
|
|
|
{
|
2015-01-31 23:37:17 +00:00
|
|
|
if (!EnergyItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer) || par3EntityPlayer.isSneaking())
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
float f = 1.0F;
|
|
|
|
double d0 = par3EntityPlayer.prevPosX + (par3EntityPlayer.posX - par3EntityPlayer.prevPosX) * (double) f;
|
|
|
|
double d1 = par3EntityPlayer.prevPosY + (par3EntityPlayer.posY - par3EntityPlayer.prevPosY) * (double) f + 1.62D - (double) par3EntityPlayer.yOffset;
|
|
|
|
double d2 = par3EntityPlayer.prevPosZ + (par3EntityPlayer.posZ - par3EntityPlayer.prevPosZ) * (double) f;
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-06-27 19:43:09 -04:00
|
|
|
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, false);
|
|
|
|
|
|
|
|
if (movingobjectposition == null)
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
|
|
|
{
|
|
|
|
int i = movingobjectposition.blockX;
|
|
|
|
int j = movingobjectposition.blockY;
|
|
|
|
int k = movingobjectposition.blockZ;
|
|
|
|
|
|
|
|
if (!par2World.canMineBlock(par3EntityPlayer, i, j, k))
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-06-27 19:43:09 -04:00
|
|
|
TileEntity tile = par2World.getTileEntity(i, j, k);
|
2014-10-13 22:33:20 +02:00
|
|
|
if (tile instanceof IFluidHandler)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
FluidStack fluid = new FluidStack(FluidRegistry.LAVA, 1000);
|
|
|
|
int amount = ((IFluidHandler) tile).fill(ForgeDirection.getOrientation(movingobjectposition.sideHit), fluid, false);
|
|
|
|
|
2014-11-07 13:45:02 -05:00
|
|
|
if (amount > 0 && EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
|
2014-10-13 22:33:20 +02:00
|
|
|
{
|
|
|
|
((IFluidHandler) tile).fill(ForgeDirection.getOrientation(movingobjectposition.sideHit), fluid, true);
|
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
if (movingobjectposition.sideHit == 0)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
--j;
|
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
if (movingobjectposition.sideHit == 1)
|
|
|
|
{
|
|
|
|
++j;
|
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
if (movingobjectposition.sideHit == 2)
|
|
|
|
{
|
|
|
|
--k;
|
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
if (movingobjectposition.sideHit == 3)
|
|
|
|
{
|
|
|
|
++k;
|
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
if (movingobjectposition.sideHit == 4)
|
|
|
|
{
|
|
|
|
--i;
|
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
if (movingobjectposition.sideHit == 5)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack))
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2014-11-18 15:29:31 -05:00
|
|
|
if(this.canPlaceContainedLiquid(par2World, d0, d1, d2, i, j, k) && EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
|
2014-10-13 22:33:20 +02:00
|
|
|
{
|
2014-11-07 13:45:02 -05:00
|
|
|
this.tryPlaceContainedLiquid(par2World, d0, d1, d2, i, j, k);
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempts to place the liquid contained inside the bucket.
|
|
|
|
*/
|
|
|
|
public boolean tryPlaceContainedLiquid(World par1World, double par2, double par4, double par6, int par8, int par9, int par10)
|
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
if (!par1World.isAirBlock(par8, par9, par10) && par1World.getBlock(par8, par9, par10).getMaterial().isSolid())
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
} else if ((par1World.getBlock(par8, par9, par10) == Blocks.lava || par1World.getBlock(par8, par9, par10) == Blocks.flowing_lava) && par1World.getBlockMetadata(par8, par9, par10) == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
par1World.setBlock(par8, par9, par10, this.isFull, 0, 3);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-11-07 13:45:02 -05:00
|
|
|
|
|
|
|
public boolean canPlaceContainedLiquid(World par1World, double par2, double par4, double par6, int par8, int par9, int par10)
|
|
|
|
{
|
|
|
|
if (!par1World.isAirBlock(par8, par9, par10) && par1World.getBlock(par8, par9, par10).getMaterial().isSolid())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
} else if ((par1World.getBlock(par8, par9, par10) == Blocks.lava || par1World.getBlock(par8, par9, par10) == Blocks.flowing_lava) && par1World.getBlockMetadata(par8, par9, par10) == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
|
|
|
|
protected void setEnergyUsed(int par1int)
|
|
|
|
{
|
|
|
|
this.energyUsed = par1int;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int getEnergyUsed()
|
|
|
|
{
|
|
|
|
return this.energyUsed;
|
|
|
|
}
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-06-27 19:43:09 -04:00
|
|
|
protected boolean syphonBatteries(ItemStack ist, EntityPlayer player, int damageToBeDone)
|
|
|
|
{
|
|
|
|
if (!player.capabilities.isCreativeMode)
|
|
|
|
{
|
|
|
|
boolean usedBattery = false;
|
|
|
|
IInventory inventory = player.inventory;
|
|
|
|
|
|
|
|
for (int slot = 0; slot < inventory.getSizeInventory(); slot++)
|
|
|
|
{
|
|
|
|
ItemStack stack = inventory.getStackInSlot(slot);
|
|
|
|
|
|
|
|
if (stack == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (stack.getItem() instanceof EnergyBattery && !usedBattery)
|
|
|
|
{
|
|
|
|
if (stack.getItemDamage() <= stack.getMaxDamage() - damageToBeDone)
|
|
|
|
{
|
|
|
|
stack.setItemDamage(stack.getItemDamage() + damageToBeDone);
|
|
|
|
usedBattery = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!usedBattery)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-10-13 22:33:20 +02:00
|
|
|
public void onArmourUpdate(World world, EntityPlayer player, ItemStack thisItemStack)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
player.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 2, 9, true));
|
2014-06-27 19:43:09 -04:00
|
|
|
player.extinguish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isUpgrade()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergyForTenSeconds()
|
|
|
|
{
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
}
|