2013-07-10 10:58:21 +00:00
|
|
|
package biomesoplenty.items;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.client.renderer.texture.IconRegister;
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-07-11 23:24:04 +00:00
|
|
|
import net.minecraft.item.Item;
|
2013-07-10 10:58:21 +00:00
|
|
|
import net.minecraft.item.ItemFood;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.potion.Potion;
|
|
|
|
import net.minecraft.potion.PotionEffect;
|
|
|
|
import net.minecraft.util.Icon;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import biomesoplenty.BiomesOPlenty;
|
2013-07-19 22:42:53 +00:00
|
|
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
2013-07-10 10:58:21 +00:00
|
|
|
|
|
|
|
public class ItemBOPFood extends ItemFood
|
|
|
|
{
|
2013-07-13 08:53:58 +00:00
|
|
|
private static final String[] foodTypes = new String[] {"berries", "shroomPowder", "wildcarrots", "sunflowerseeds", "saladfruit", "saladveggie", "saladshroom", "earth"};
|
2013-07-10 10:58:21 +00:00
|
|
|
private Icon[] textures;
|
|
|
|
|
|
|
|
public ItemBOPFood(int par1)
|
|
|
|
{
|
|
|
|
super(par1, 0, 0.0F, false);
|
|
|
|
setCreativeTab(BiomesOPlenty.tabBiomesOPlenty);
|
|
|
|
setHasSubtypes(true);
|
|
|
|
}
|
|
|
|
|
2013-07-13 22:47:39 +00:00
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
|
|
|
|
{
|
|
|
|
boolean alwaysEdible = ReflectionHelper.getPrivateValue(ItemFood.class, (ItemFood)Item.itemsList[itemstack.itemID], "alwaysEdible");
|
|
|
|
|
|
|
|
if (itemstack.getItemDamage() == 0)
|
|
|
|
{
|
|
|
|
if (player.canEat(true))
|
|
|
|
{
|
|
|
|
player.setItemInUse(itemstack, this.getMaxItemUseDuration(itemstack));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (itemstack.getItemDamage() == 1)
|
|
|
|
{
|
|
|
|
if (player.canEat(true))
|
|
|
|
{
|
|
|
|
player.setItemInUse(itemstack, this.getMaxItemUseDuration(itemstack));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (player.canEat(alwaysEdible))
|
|
|
|
{
|
|
|
|
player.setItemInUse(itemstack, this.getMaxItemUseDuration(itemstack));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
2013-07-10 10:58:21 +00:00
|
|
|
@Override
|
|
|
|
public ItemStack onEaten(ItemStack itemstack, World world, EntityPlayer player)
|
|
|
|
{
|
|
|
|
if (itemstack.getItemDamage() == 0)
|
|
|
|
{
|
2013-07-10 12:51:30 +00:00
|
|
|
return addFoodAndSaturation(world, itemstack, player, 2, 0.2F);
|
2013-07-10 10:58:21 +00:00
|
|
|
}
|
|
|
|
else if (itemstack.getItemDamage() == 1)
|
|
|
|
{
|
|
|
|
if (world.rand.nextFloat() < 0.6F)
|
|
|
|
{
|
2013-07-11 05:15:07 +00:00
|
|
|
player.addPotionEffect(new PotionEffect(Potion.confusion.id, 225, 0));
|
2013-07-10 10:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return addFoodAndSaturation(world, itemstack, player, 1, 0.1F);
|
|
|
|
}
|
2013-07-10 12:51:30 +00:00
|
|
|
else if (itemstack.getItemDamage() == 2)
|
|
|
|
{
|
2013-07-11 05:15:07 +00:00
|
|
|
if (world.rand.nextFloat() < 0.6F)
|
|
|
|
{
|
|
|
|
player.addPotionEffect(new PotionEffect(Potion.weakness.id, 225, 1));
|
|
|
|
}
|
|
|
|
|
2013-07-10 12:51:30 +00:00
|
|
|
return addFoodAndSaturation(world, itemstack, player, 3, 0.5F);
|
|
|
|
}
|
|
|
|
else if (itemstack.getItemDamage() == 3)
|
|
|
|
{
|
|
|
|
return addFoodAndSaturation(world, itemstack, player, 2, 0.5F);
|
|
|
|
}
|
|
|
|
else if (itemstack.getItemDamage() == 4)
|
|
|
|
{
|
|
|
|
if (world.rand.nextFloat() < 0.05F)
|
|
|
|
{
|
2013-07-11 05:15:07 +00:00
|
|
|
player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 775, 1));
|
2013-07-10 12:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return addFoodAndSaturation(world, itemstack, player, 6, 0.8F);
|
|
|
|
}
|
|
|
|
else if (itemstack.getItemDamage() == 5)
|
|
|
|
{
|
|
|
|
if (world.rand.nextFloat() < 0.05F)
|
|
|
|
{
|
|
|
|
player.addPotionEffect(new PotionEffect(Potion.field_76434_w.id, 1100, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return addFoodAndSaturation(world, itemstack, player, 6, 1.2F);
|
|
|
|
}
|
|
|
|
else if (itemstack.getItemDamage() == 6)
|
|
|
|
{
|
|
|
|
if (world.rand.nextFloat() < 0.05F)
|
|
|
|
{
|
|
|
|
player.addPotionEffect(new PotionEffect(Potion.jump.id, 550, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return addFoodAndSaturation(world, itemstack, player, 6, 1.6F);
|
|
|
|
}
|
2013-07-10 10:58:21 +00:00
|
|
|
|
|
|
|
return addFoodAndSaturation(world, itemstack, player, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private ItemStack addFoodAndSaturation(World world, ItemStack itemstack, EntityPlayer player, int food, float saturation)
|
|
|
|
{
|
|
|
|
--itemstack.stackSize;
|
|
|
|
player.getFoodStats().setFoodLevel(player.getFoodStats().getFoodLevel() + food);
|
|
|
|
player.getFoodStats().setFoodSaturationLevel(player.getFoodStats().getSaturationLevel() + saturation);
|
|
|
|
world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
|
2013-07-13 22:47:39 +00:00
|
|
|
super.onFoodEaten(itemstack, world, player);
|
2013-07-11 23:24:04 +00:00
|
|
|
if (itemstack.getItemDamage() == 4)
|
|
|
|
{
|
2013-07-13 22:47:39 +00:00
|
|
|
if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bowlEmpty)))
|
|
|
|
{
|
|
|
|
player.dropPlayerItem(new ItemStack(Item.bowlEmpty.itemID, 1, 0));
|
|
|
|
}
|
2013-07-11 23:24:04 +00:00
|
|
|
}
|
|
|
|
if (itemstack.getItemDamage() == 5)
|
|
|
|
{
|
2013-07-13 22:47:39 +00:00
|
|
|
if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bowlEmpty)))
|
|
|
|
{
|
|
|
|
player.dropPlayerItem(new ItemStack(Item.bowlEmpty.itemID, 1, 0));
|
|
|
|
}
|
2013-07-11 23:24:04 +00:00
|
|
|
}
|
|
|
|
if (itemstack.getItemDamage() == 6)
|
|
|
|
{
|
2013-07-13 22:47:39 +00:00
|
|
|
if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bowlEmpty)))
|
|
|
|
{
|
|
|
|
player.dropPlayerItem(new ItemStack(Item.bowlEmpty.itemID, 1, 0));
|
|
|
|
}
|
2013-07-11 23:24:04 +00:00
|
|
|
}
|
2013-07-13 22:47:39 +00:00
|
|
|
|
2013-07-10 10:58:21 +00:00
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void getSubItems(int itemID, CreativeTabs par2CreativeTabs, List list)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < foodTypes.length; ++i)
|
|
|
|
{
|
2013-07-13 08:53:58 +00:00
|
|
|
if (i != 7)
|
|
|
|
{
|
|
|
|
list.add(new ItemStack(itemID, 1, i));
|
|
|
|
}
|
2013-07-10 10:58:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerIcons(IconRegister iconRegister)
|
|
|
|
{
|
|
|
|
textures = new Icon[foodTypes.length];
|
|
|
|
|
|
|
|
for (int i = 0; i < foodTypes.length; ++i) {
|
|
|
|
textures[i] = iconRegister.registerIcon("biomesoplenty:"+ foodTypes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Icon getIconFromDamage(int meta)
|
|
|
|
{
|
|
|
|
if (meta < 0 || meta >= textures.length) {
|
|
|
|
meta = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return textures[meta];
|
|
|
|
}
|
2013-07-11 05:15:07 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
int meta = itemStack.getItemDamage();
|
|
|
|
if (meta < 0 || meta >= foodTypes.length) {
|
|
|
|
meta = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.getUnlocalizedName() + "." + foodTypes[meta];
|
|
|
|
}
|
2013-07-10 10:58:21 +00:00
|
|
|
}
|