Improved previous commit and some cleanup.

This commit is contained in:
Amnet 2013-08-11 18:11:13 +02:00
parent 14515d3e76
commit efebe1e58f

View file

@ -21,9 +21,6 @@ public class ItemBOPFood extends ItemFood
private static final String[] foodTypes = new String[] {"berries", "shroompowder", "wildcarrots", "sunflowerseeds", "saladfruit", "saladveggie", "saladshroom", "earth"}; private static final String[] foodTypes = new String[] {"berries", "shroompowder", "wildcarrots", "sunflowerseeds", "saladfruit", "saladveggie", "saladshroom", "earth"};
private Icon[] textures; private Icon[] textures;
private int healAmount;
private float saturationModifier;
public ItemBOPFood(int par1) public ItemBOPFood(int par1)
{ {
super(par1, 0, 0.0F, false); super(par1, 0, 0.0F, false);
@ -55,51 +52,42 @@ public class ItemBOPFood extends ItemFood
@Override @Override
public ItemStack onEaten(ItemStack itemstack, World world, EntityPlayer player) public ItemStack onEaten(ItemStack itemstack, World world, EntityPlayer player)
{ {
--itemstack.stackSize;
switch (itemstack.getItemDamage()) switch (itemstack.getItemDamage())
{ {
case 0: case 0:
this.healAmount = 2; player.getFoodStats().addStats(2, 0.2F);
this.saturationModifier = 0.2F;
break; break;
case 1: case 1:
this.healAmount = 1; player.getFoodStats().addStats(1, 0.1F);
this.saturationModifier = 0.1F;
break; break;
case 2: case 2:
this.healAmount = 3; player.getFoodStats().addStats(3, 0.5F);
this.saturationModifier = 0.5F;
break; break;
case 3: case 3:
this.healAmount = 2; player.getFoodStats().addStats(2, 0.5F);
this.saturationModifier = 0.5F;
break; break;
case 4: case 4:
this.healAmount = 6; player.getFoodStats().addStats(6, 0.8F);
this.saturationModifier = 0.8F;
break; break;
case 5: case 5:
this.healAmount = 6; player.getFoodStats().addStats(6, 1.2F);
this.saturationModifier = 1.2F;
break; break;
case 6: case 6:
this.healAmount = 6; player.getFoodStats().addStats(6, 1.6F);
this.saturationModifier = 1.6F;
break; break;
default: default:
this.healAmount = 0; player.getFoodStats().addStats(0, 0.0F);
this.saturationModifier = 0.0F;
break; break;
} }
--itemstack.stackSize;
player.getFoodStats().addStats(this);
world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F); world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
this.onFoodEaten(itemstack, world, player); this.onFoodEaten(itemstack, world, player);
@ -109,9 +97,8 @@ public class ItemBOPFood extends ItemFood
case 5: case 5:
case 6: case 6:
if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bowlEmpty))) if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bowlEmpty)))
{
player.dropPlayerItem(new ItemStack(Item.bowlEmpty.itemID, 1, 0)); player.dropPlayerItem(new ItemStack(Item.bowlEmpty.itemID, 1, 0));
} break;
} }
return itemstack; return itemstack;
@ -152,94 +139,6 @@ public class ItemBOPFood extends ItemFood
} }
} }
@Override
public int getHealAmount()
{
return this.healAmount;
}
@Override
public float getSaturationModifier()
{
return this.saturationModifier;
}
private ItemStack addFoodAndSaturation(World world, ItemStack itemstack, EntityPlayer player, int food, float saturation)
{
--itemstack.stackSize;
FoodStats foodstats = player.getFoodStats();
Field flfield = null;
Field[] fields = foodstats.getClass().getDeclaredFields();
for (Field f : fields)
{
if (f.getName().equals("foodLevel") || f.getName().equals("a"))
{
flfield = f;
break;
}
}
try
{
flfield.setAccessible(true);
flfield.setInt(foodstats, flfield.getInt(foodstats) + food);
}
catch (Exception e)
{
e.printStackTrace();
}
Field slfield = null;
for (Field f : fields)
{
if (f.getName().equals("foodSaturationLevel") || f.getName().equals("b"))
{
slfield = f;
break;
}
}
try
{
slfield.setAccessible(true);
slfield.setFloat(foodstats, slfield.getFloat(foodstats) + saturation);
}
catch (Exception e)
{
e.printStackTrace();
}
world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
super.onFoodEaten(itemstack, world, player);
if (itemstack.getItemDamage() == 4)
{
if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bowlEmpty)))
{
player.dropPlayerItem(new ItemStack(Item.bowlEmpty.itemID, 1, 0));
}
}
if (itemstack.getItemDamage() == 5)
{
if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bowlEmpty)))
{
player.dropPlayerItem(new ItemStack(Item.bowlEmpty.itemID, 1, 0));
}
}
if (itemstack.getItemDamage() == 6)
{
if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bowlEmpty)))
{
player.dropPlayerItem(new ItemStack(Item.bowlEmpty.itemID, 1, 0));
}
}
return itemstack;
}
@Override @Override
public void getSubItems(int itemID, CreativeTabs par2CreativeTabs, List list) public void getSubItems(int itemID, CreativeTabs par2CreativeTabs, List list)
{ {