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-31 10:34:02 +00:00
|
|
|
public class ItemBOPBucket extends Item
|
2013-05-25 04:08:06 +00:00
|
|
|
{
|
2013-05-31 10:34:02 +00:00
|
|
|
private int isFull;
|
|
|
|
|
2013-05-25 13:22:37 +00:00
|
|
|
private static final String[] bucketTypes = new String[] {"spring_water", "liquid_poison"};
|
2013-05-31 10:34:02 +00:00
|
|
|
|
2013-05-25 13:22:37 +00:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
private Icon[] textures;
|
2013-05-31 10:34:02 +00:00
|
|
|
|
|
|
|
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-31 10:34:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
|
|
|
{
|
|
|
|
float f = 1.0F;
|
|
|
|
double d0 = par3EntityPlayer.prevPosX + (par3EntityPlayer.posX - par3EntityPlayer.prevPosX) * f;
|
|
|
|
double d1 = par3EntityPlayer.prevPosY + (par3EntityPlayer.posY - par3EntityPlayer.prevPosY) * f + 1.62D - par3EntityPlayer.yOffset;
|
|
|
|
double d2 = par3EntityPlayer.prevPosZ + (par3EntityPlayer.posZ - par3EntityPlayer.prevPosZ) * f;
|
|
|
|
isFull = getLiquidIDFromMeta(par1ItemStack.getItemDamage());
|
|
|
|
boolean flag = 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 (isFull == 0)
|
|
|
|
{
|
|
|
|
if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack))
|
|
|
|
return par1ItemStack;
|
|
|
|
|
|
|
|
if (par2World.getBlockMaterial(i, j, k) == Material.water && (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.bucketWater);
|
|
|
|
|
|
|
|
if (!par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketWater)))
|
|
|
|
{
|
|
|
|
par3EntityPlayer.dropPlayerItem(new ItemStack(Item.bucketWater.itemID, 1, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack))
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 (isFull <= 0)
|
|
|
|
return false;
|
|
|
|
else if (!par1World.isAirBlock(par8, par9, par10) && par1World.getBlockMaterial(par8, par9, par10).isSolid())
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (par1World.provider.isHellWorld && isFull == Liquids.springWater.get().blockID)
|
|
|
|
{
|
|
|
|
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", par8 + Math.random(), par9 + Math.random(), par10 + Math.random(), 0.0D, 0.0D, 0.0D);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
par1World.setBlock(par8, par9, par10, isFull, 0, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int getLiquidIDFromMeta(int meta)
|
|
|
|
{
|
|
|
|
switch (meta)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return Liquids.springWater.get().blockID;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
return Liquids.liquidPoison.get().blockID;
|
|
|
|
|
|
|
|
default:
|
|
|
|
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)
|
|
|
|
{
|
2013-05-31 10:34:02 +00:00
|
|
|
int meta = itemStack.getItemDamage();
|
|
|
|
if (meta < 0 || meta >= bucketTypes.length) {
|
|
|
|
meta = 0;
|
|
|
|
}
|
|
|
|
|
2013-06-09 20:48:05 +00:00
|
|
|
return super.getUnlocalizedName() + "." + bucketTypes[meta];
|
2013-05-25 13:22:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 10:34:02 +00:00
|
|
|
@Override
|
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];
|
|
|
|
|
2013-05-31 10:34:02 +00:00
|
|
|
for (int i = 0; i < bucketTypes.length; ++i) {
|
2013-07-03 06:01:28 +00:00
|
|
|
textures[i] = iconRegister.registerIcon("biomesoplenty:" + "bucket_" + bucketTypes[i]);
|
2013-05-31 10:34:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Icon getIconFromDamage(int meta)
|
|
|
|
{
|
|
|
|
return textures[meta];
|
2013-05-25 04:08:06 +00:00
|
|
|
}
|
|
|
|
}
|