2014-06-27 19:43:09 -04:00
|
|
|
package WayofTime.alchemicalWizardry.common.items.sigil;
|
|
|
|
|
2015-04-24 07:41:08 -04:00
|
|
|
import java.util.List;
|
|
|
|
|
2015-05-18 18:33:23 -04:00
|
|
|
import WayofTime.alchemicalWizardry.api.items.interfaces.ISigil;
|
2015-06-14 10:33:01 -04:00
|
|
|
import WayofTime.alchemicalWizardry.common.tileEntity.TESocket;
|
2014-06-27 19:43:09 -04:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
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;
|
2015-07-31 11:35:05 -04:00
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
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.fluids.FluidRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.IFluidHandler;
|
2015-04-24 07:41:08 -04:00
|
|
|
import WayofTime.alchemicalWizardry.api.items.interfaces.ArmourUpgrade;
|
2015-07-30 17:24:20 -04:00
|
|
|
import WayofTime.alchemicalWizardry.common.items.Orb;
|
|
|
|
import WayofTime.alchemicalWizardry.common.items.BindableItems;
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2015-05-18 18:33:23 -04:00
|
|
|
public class SigilLava extends ItemBucket implements ArmourUpgrade, ISigil
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* field for checking if the bucket has been filled.
|
|
|
|
*/
|
|
|
|
private Block isFull = Blocks.lava;
|
|
|
|
private int energyUsed;
|
|
|
|
|
2015-05-18 18:33:23 -04:00
|
|
|
public SigilLava()
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
super(Blocks.lava);
|
|
|
|
setEnergyUsed(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
|
*/
|
2015-04-24 07:41:08 -04:00
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-04-24 07:41:08 -04:00
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-31 11:35:05 -04:00
|
|
|
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ)
|
2015-04-24 07:41:08 -04:00
|
|
|
{
|
2015-07-30 17:24:20 -04:00
|
|
|
if (world.isRemote || !BindableItems.checkAndSetItemOwner(stack, player) || player.isSneaking())
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-04-24 07:41:08 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if (!world.canMineBlockBody(player, blockPos))
|
2015-04-24 07:41:08 -04:00
|
|
|
{
|
|
|
|
return false;
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
TileEntity tile = world.getTileEntity(blockPos);
|
2015-04-24 07:41:08 -04:00
|
|
|
if (tile instanceof IFluidHandler)
|
|
|
|
{
|
|
|
|
FluidStack fluid = new FluidStack(FluidRegistry.LAVA, 1000);
|
2015-07-31 11:35:05 -04:00
|
|
|
int amount = ((IFluidHandler) tile).fill(side, fluid, false);
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2015-07-30 17:24:20 -04:00
|
|
|
if (amount > 0 && BindableItems.syphonBatteries(stack, player, getEnergyUsed()))
|
2015-04-24 07:41:08 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
((IFluidHandler) tile).fill(side, fluid, true);
|
2015-04-24 07:41:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-14 10:33:01 -04:00
|
|
|
else if (tile instanceof TESocket)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
|
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
int x = blockPos.getX();
|
|
|
|
int y = blockPos.getY();
|
|
|
|
int z = blockPos.getZ();
|
|
|
|
|
|
|
|
if (side.getIndex() == 0)
|
2015-04-24 07:41:08 -04:00
|
|
|
{
|
|
|
|
--y;
|
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if (side.getIndex() == 1)
|
2015-04-24 07:41:08 -04:00
|
|
|
{
|
|
|
|
++y;
|
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if (side.getIndex() == 2)
|
2015-04-24 07:41:08 -04:00
|
|
|
{
|
|
|
|
--z;
|
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if (side.getIndex() == 3)
|
2015-04-24 07:41:08 -04:00
|
|
|
{
|
|
|
|
++z;
|
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if (side.getIndex() == 4)
|
2015-04-24 07:41:08 -04:00
|
|
|
{
|
|
|
|
--x;
|
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if (side.getIndex() == 5)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-04-24 07:41:08 -04:00
|
|
|
++x;
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if (!player.func_175151_a(new BlockPos(x, y, z), side, stack))
|
2015-04-24 07:41:08 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if(this.canPlaceContainedLiquid(world, new BlockPos(x, y, z)) && BindableItems.syphonBatteries(stack, player, getEnergyUsed()))
|
2015-04-24 07:41:08 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
return this.func_180616_a(world, new BlockPos(x, y, z));
|
2015-04-24 07:41:08 -04:00
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
2015-04-24 07:41:08 -04:00
|
|
|
|
|
|
|
return false;
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
@Override
|
2014-06-27 19:43:09 -04:00
|
|
|
/**
|
|
|
|
* Attempts to place the liquid contained inside the bucket.
|
|
|
|
*/
|
2015-07-31 11:35:05 -04:00
|
|
|
public boolean func_180616_a(World par1World, BlockPos blockPos)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
if (!par1World.isAirBlock(blockPos) && par1World.getBlockState(blockPos).getBlock().getMaterial().isSolid())
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
return false;
|
2015-07-31 11:35:05 -04:00
|
|
|
} else if ((par1World.getBlockState(blockPos).getBlock() == Blocks.lava || par1World.getBlockState(blockPos).getBlock() == Blocks.flowing_lava) && par1World.getBlockState(blockPos).getBlock().getMetaFromState(par1World.getBlockState(blockPos)) == 0)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
par1World.setBlockState(blockPos, this.isFull.getBlockState().getBaseState());
|
2014-06-27 19:43:09 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-11-07 13:45:02 -05:00
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
public boolean canPlaceContainedLiquid(World par1World, BlockPos blockPos)
|
2014-11-07 13:45:02 -05:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
if (!par1World.isAirBlock(blockPos) && par1World.getBlockState(blockPos).getBlock().getMaterial().isSolid())
|
2014-11-07 13:45:02 -05:00
|
|
|
{
|
|
|
|
return false;
|
2015-07-31 11:35:05 -04:00
|
|
|
} else if ((par1World.getBlockState(blockPos).getBlock() == Blocks.lava || par1World.getBlockState(blockPos).getBlock() == Blocks.flowing_lava) && par1World.getBlockState(blockPos).getBlock().getMetaFromState(par1World.getBlockState(blockPos)) == 0)
|
2014-11-07 13:45:02 -05:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2015-07-30 17:24:20 -04:00
|
|
|
if (stack.getItem() instanceof Orb && !usedBattery)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
if (stack.getItemDamage() <= stack.getMaxDamage() - damageToBeDone)
|
|
|
|
{
|
|
|
|
stack.setItemDamage(stack.getItemDamage() + damageToBeDone);
|
|
|
|
usedBattery = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-02 11:05:07 -04:00
|
|
|
return usedBattery;
|
2014-06-27 19:43:09 -04:00
|
|
|
} 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
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
player.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 2, 9, true, false));
|
2014-06-27 19:43:09 -04:00
|
|
|
player.extinguish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isUpgrade()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergyForTenSeconds()
|
|
|
|
{
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
}
|