2013-05-25 04:08:06 +00:00
|
|
|
package biomesoplenty.items;
|
|
|
|
|
2013-05-25 13:22:37 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.block.material.Material;
|
2013-05-25 04:08:06 +00:00
|
|
|
import net.minecraft.client.renderer.texture.IconRegister;
|
2013-05-25 13:22:37 +00:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.Item;
|
2013-05-25 04:08:06 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
2013-05-25 13:22:37 +00:00
|
|
|
import net.minecraft.util.EnumMovingObjectType;
|
|
|
|
import net.minecraft.util.Icon;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.Event;
|
|
|
|
import net.minecraftforge.event.entity.player.FillBucketEvent;
|
2013-05-29 01:05:27 +00:00
|
|
|
import biomesoplenty.BiomesOPlenty;
|
|
|
|
import biomesoplenty.api.Liquids;
|
2013-05-25 04:08:06 +00:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2013-05-25 13:22:37 +00:00
|
|
|
public class ItemBOPBucket extends Item
|
2013-05-25 04:08:06 +00:00
|
|
|
{
|
2013-05-25 13:22:37 +00:00
|
|
|
private int isFull;
|
|
|
|
|
|
|
|
private static final String[] bucketTypes = new String[] {"spring_water", "liquid_poison"};
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
private Icon[] textures;
|
|
|
|
|
|
|
|
public ItemBOPBucket(int i)
|
2013-05-25 04:08:06 +00:00
|
|
|
{
|
2013-05-25 13:22:37 +00:00
|
|
|
super(i);
|
|
|
|
this.setHasSubtypes(true);
|
2013-05-25 04:08:06 +00:00
|
|
|
this.setCreativeTab(BiomesOPlenty.tabBiomesOPlenty);
|
|
|
|
}
|
2013-05-25 13:22:37 +00: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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
this.isFull = getLiquidIDFromMeta(par1ItemStack.getItemDamage());
|
|
|
|
boolean flag = this.isFull == 0;
|
|
|
|
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, flag);
|
|
|
|
|
|
|
|
if (movingobjectposition == null)
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FillBucketEvent event = new FillBucketEvent(par3EntityPlayer, par1ItemStack, par2World, movingobjectposition);
|
|
|
|
if (MinecraftForge.EVENT_BUS.post(event))
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.getResult() == Event.Result.ALLOW)
|
|
|
|
{
|
|
|
|
if (par3EntityPlayer.capabilities.isCreativeMode)
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (--par1ItemStack.stackSize <= 0)
|
|
|
|
{
|
|
|
|
return event.result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!par3EntityPlayer.inventory.addItemStackToInventory(event.result))
|
|
|
|
{
|
|
|
|
par3EntityPlayer.dropPlayerItem(event.result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
|
|
|
|
{
|
|
|
|
int i = movingobjectposition.blockX;
|
|
|
|
int j = movingobjectposition.blockY;
|
|
|
|
int k = movingobjectposition.blockZ;
|
|
|
|
|
|
|
|
if (!par2World.canMineBlock(par3EntityPlayer, i, j, k))
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isFull == 0)
|
|
|
|
{
|
|
|
|
if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack))
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
2013-05-29 01:05:27 +00:00
|
|
|
if (par2World.getBlockMaterial(i, j, k) == Material.water && (par2World.getBlockMetadata(i, j, k) == 0))
|
2013-05-25 13:22:37 +00:00
|
|
|
{
|
|
|
|
par2World.setBlockToAir(i, j, k);
|
|
|
|
|
|
|
|
if (par3EntityPlayer.capabilities.isCreativeMode)
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (--par1ItemStack.stackSize <= 0)
|
|
|
|
{
|
|
|
|
return new ItemStack(Item.bucketWater);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketWater)))
|
|
|
|
{
|
|
|
|
par3EntityPlayer.dropPlayerItem(new ItemStack(Item.bucketWater.itemID, 1, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
2013-05-29 01:05:27 +00:00
|
|
|
|
|
|
|
if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack))
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
2013-05-25 13:22:37 +00:00
|
|
|
|
|
|
|
if (par2World.getBlockMaterial(i, j, k) == Material.lava && par2World.getBlockMetadata(i, j, k) == 0)
|
|
|
|
{
|
|
|
|
par2World.setBlockToAir(i, j, k);
|
|
|
|
|
|
|
|
if (par3EntityPlayer.capabilities.isCreativeMode)
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (--par1ItemStack.stackSize <= 0)
|
|
|
|
{
|
|
|
|
return new ItemStack(Item.bucketLava);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketLava)))
|
|
|
|
{
|
|
|
|
par3EntityPlayer.dropPlayerItem(new ItemStack(Item.bucketLava.itemID, 1, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this.isFull < 0)
|
|
|
|
{
|
|
|
|
return new ItemStack(Item.bucketEmpty);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (movingobjectposition.sideHit == 0)
|
|
|
|
{
|
|
|
|
--j;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (movingobjectposition.sideHit == 1)
|
|
|
|
{
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (movingobjectposition.sideHit == 2)
|
|
|
|
{
|
|
|
|
--k;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (movingobjectposition.sideHit == 3)
|
|
|
|
{
|
|
|
|
++k;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (movingobjectposition.sideHit == 4)
|
|
|
|
{
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (movingobjectposition.sideHit == 5)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack))
|
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.tryPlaceContainedLiquid(par2World, d0, d1, d2, i, j, k) && !par3EntityPlayer.capabilities.isCreativeMode)
|
|
|
|
{
|
|
|
|
return new ItemStack(Item.bucketEmpty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-29 01:05:27 +00:00
|
|
|
|
2013-05-25 13:22:37 +00: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)
|
|
|
|
{
|
|
|
|
if (this.isFull <= 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (!par1World.isAirBlock(par8, par9, par10) && par1World.getBlockMaterial(par8, par9, par10).isSolid())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-29 01:05:27 +00:00
|
|
|
if (par1World.provider.isHellWorld && this.isFull == Liquids.springWater.get().blockID)
|
2013-05-25 13:22:37 +00:00
|
|
|
{
|
|
|
|
par1World.playSoundEffect(par2 + 0.5D, par4 + 0.5D, par6 + 0.5D, "random.fizz", 0.5F, 2.6F + (par1World.rand.nextFloat() - par1World.rand.nextFloat()) * 0.8F);
|
|
|
|
|
|
|
|
for (int l = 0; l < 8; ++l)
|
|
|
|
{
|
|
|
|
par1World.spawnParticle("largesmoke", (double)par8 + Math.random(), (double)par9 + Math.random(), (double)par10 + Math.random(), 0.0D, 0.0D, 0.0D);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-29 01:05:27 +00:00
|
|
|
par1World.setBlock(par8, par9, par10, this.isFull, 0, 3);
|
2013-05-25 13:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int getLiquidIDFromMeta(int meta)
|
|
|
|
{
|
|
|
|
switch (meta)
|
|
|
|
{
|
|
|
|
case 0:
|
2013-05-28 11:22:54 +00:00
|
|
|
return Liquids.springWater.get().blockID;
|
2013-05-25 13:22:37 +00:00
|
|
|
|
|
|
|
case 1:
|
2013-05-28 11:22:54 +00:00
|
|
|
return Liquids.liquidPoison.get().blockID;
|
2013-05-25 13:22:37 +00:00
|
|
|
|
|
|
|
default:
|
2013-05-28 11:22:54 +00:00
|
|
|
return Liquids.springWater.get().blockID;
|
2013-05-25 13:22:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
|
|
@Override
|
|
|
|
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < bucketTypes.length; ++i)
|
|
|
|
{
|
|
|
|
par3List.add(new ItemStack(par1, 1, i));
|
|
|
|
}
|
|
|
|
}
|
2013-05-25 04:08:06 +00:00
|
|
|
|
|
|
|
@Override
|
2013-05-25 13:22:37 +00:00
|
|
|
public String getUnlocalizedName(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
int meta = itemStack.getItemDamage();
|
|
|
|
if (meta < 0 || meta >= bucketTypes.length)
|
|
|
|
meta = 0;
|
|
|
|
|
|
|
|
return bucketTypes[meta];
|
|
|
|
}
|
|
|
|
|
2013-05-25 04:08:06 +00:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-05-25 13:22:37 +00:00
|
|
|
public void registerIcons(IconRegister iconRegister)
|
2013-05-25 04:08:06 +00:00
|
|
|
{
|
2013-05-25 13:22:37 +00:00
|
|
|
textures = new Icon[bucketTypes.length];
|
|
|
|
|
|
|
|
for (int i = 0; i < bucketTypes.length; ++i)
|
|
|
|
textures[i] = iconRegister.registerIcon("BiomesOPlenty:" + "bucket_" + bucketTypes[i]);
|
2013-05-25 04:08:06 +00:00
|
|
|
}
|
2013-05-25 13:22:37 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Icon getIconFromDamage(int meta)
|
|
|
|
{
|
|
|
|
return textures[meta];
|
|
|
|
}
|
2013-05-25 04:08:06 +00:00
|
|
|
}
|