From 7a141bd959857462949cf6496d50592518897218 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sun, 14 Jul 2013 08:47:39 +1000 Subject: [PATCH] Cleanup and fixed some bugs with foods --- .../biomesoplenty/items/ItemBOPFood.java | 50 +++++++++++++++++-- .../biomesoplenty/worldgen/WorldGenFir1.java | 8 ++- .../biomesoplenty/worldgen/WorldGenFir2.java | 7 ++- .../biomesoplenty/worldgen/WorldGenFir3.java | 7 ++- .../worldgen/WorldGenRealMagic.java | 5 +- .../worldgen/WorldGenRealPineTree.java | 3 +- .../worldgen/WorldGenRealPineTree2.java | 3 +- .../worldgen/WorldGenRealRedwood.java | 8 ++- .../worldgen/WorldGenRealRedwood2.java | 7 ++- 9 files changed, 67 insertions(+), 31 deletions(-) diff --git a/src/minecraft/biomesoplenty/items/ItemBOPFood.java b/src/minecraft/biomesoplenty/items/ItemBOPFood.java index 20de3aebf..bfd4e2735 100644 --- a/src/minecraft/biomesoplenty/items/ItemBOPFood.java +++ b/src/minecraft/biomesoplenty/items/ItemBOPFood.java @@ -2,6 +2,7 @@ package biomesoplenty.items; import java.util.List; +import cpw.mods.fml.relauncher.ReflectionHelper; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; @@ -22,11 +23,40 @@ public class ItemBOPFood extends ItemFood public ItemBOPFood(int par1) { super(par1, 0, 0.0F, false); - setAlwaysEdible(); setCreativeTab(BiomesOPlenty.tabBiomesOPlenty); setHasSubtypes(true); } + @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; + } + @Override public ItemStack onEaten(ItemStack itemstack, World world, EntityPlayer player) { @@ -93,19 +123,29 @@ public class ItemBOPFood extends ItemFood 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); - this.onFoodEaten(itemstack, world, player); + super.onFoodEaten(itemstack, world, player); if (itemstack.getItemDamage() == 4) { - return new ItemStack(Item.bowlEmpty); + if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bowlEmpty))) + { + player.dropPlayerItem(new ItemStack(Item.bowlEmpty.itemID, 1, 0)); + } } if (itemstack.getItemDamage() == 5) { - return new ItemStack(Item.bowlEmpty); + if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bowlEmpty))) + { + player.dropPlayerItem(new ItemStack(Item.bowlEmpty.itemID, 1, 0)); + } } if (itemstack.getItemDamage() == 6) { - return new ItemStack(Item.bowlEmpty); + if (!player.inventory.addItemStackToInventory(new ItemStack(Item.bowlEmpty))) + { + player.dropPlayerItem(new ItemStack(Item.bowlEmpty.itemID, 1, 0)); + } } + return itemstack; } diff --git a/src/minecraft/biomesoplenty/worldgen/WorldGenFir1.java b/src/minecraft/biomesoplenty/worldgen/WorldGenFir1.java index a3c3cb032..896c3b5db 100644 --- a/src/minecraft/biomesoplenty/worldgen/WorldGenFir1.java +++ b/src/minecraft/biomesoplenty/worldgen/WorldGenFir1.java @@ -2,17 +2,15 @@ package biomesoplenty.worldgen; import java.util.Random; -import biomesoplenty.api.Blocks; -import biomesoplenty.configuration.BOPBlocks; - import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; +import biomesoplenty.api.Blocks; public class WorldGenFir1 extends WorldGenerator { - public boolean generate(World var1, Random var2, int var3, int var4, int var5) + @Override + public boolean generate(World var1, Random var2, int var3, int var4, int var5) { while (var1.isAirBlock(var3 + 11, var4, var5 + 9) && var4 > 2) { diff --git a/src/minecraft/biomesoplenty/worldgen/WorldGenFir2.java b/src/minecraft/biomesoplenty/worldgen/WorldGenFir2.java index 38d5d9090..3263ca9db 100644 --- a/src/minecraft/biomesoplenty/worldgen/WorldGenFir2.java +++ b/src/minecraft/biomesoplenty/worldgen/WorldGenFir2.java @@ -2,16 +2,15 @@ package biomesoplenty.worldgen; import java.util.Random; -import biomesoplenty.api.Blocks; -import biomesoplenty.configuration.BOPBlocks; - import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; +import biomesoplenty.api.Blocks; public class WorldGenFir2 extends WorldGenerator { - public boolean generate(World var1, Random var2, int var3, int var4, int var5) + @Override + public boolean generate(World var1, Random var2, int var3, int var4, int var5) { while (var1.isAirBlock(var3 + 9, var4, var5 + 8) && var4 > 2) { diff --git a/src/minecraft/biomesoplenty/worldgen/WorldGenFir3.java b/src/minecraft/biomesoplenty/worldgen/WorldGenFir3.java index f3942c985..5c23579f7 100644 --- a/src/minecraft/biomesoplenty/worldgen/WorldGenFir3.java +++ b/src/minecraft/biomesoplenty/worldgen/WorldGenFir3.java @@ -2,16 +2,15 @@ package biomesoplenty.worldgen; import java.util.Random; -import biomesoplenty.api.Blocks; -import biomesoplenty.configuration.BOPBlocks; - import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; +import biomesoplenty.api.Blocks; public class WorldGenFir3 extends WorldGenerator { - public boolean generate(World var1, Random var2, int var3, int var4, int var5) + @Override + public boolean generate(World var1, Random var2, int var3, int var4, int var5) { while (var1.isAirBlock(var3 + 4, var4, var5 + 4) && var4 > 2) { diff --git a/src/minecraft/biomesoplenty/worldgen/WorldGenRealMagic.java b/src/minecraft/biomesoplenty/worldgen/WorldGenRealMagic.java index 4fc77e02e..396d4d936 100644 --- a/src/minecraft/biomesoplenty/worldgen/WorldGenRealMagic.java +++ b/src/minecraft/biomesoplenty/worldgen/WorldGenRealMagic.java @@ -9,8 +9,9 @@ import net.minecraft.world.gen.feature.WorldGenerator; public class WorldGenRealMagic extends WorldGenerator { - public boolean generate(World world, Random rand, int i, int j, int k) { - + @Override + public boolean generate(World world, Random rand, int i, int j, int k) + { world.setBlock(i + 4, j + 22, k + 47, Block.leaves.blockID, 12, 2); world.setBlock(i + 5, j + 20, k + 45, Block.leaves.blockID, 12, 2); world.setBlock(i + 5, j + 21, k + 46, Block.leaves.blockID, 12, 2); diff --git a/src/minecraft/biomesoplenty/worldgen/WorldGenRealPineTree.java b/src/minecraft/biomesoplenty/worldgen/WorldGenRealPineTree.java index 8e4559f94..dee5857f9 100644 --- a/src/minecraft/biomesoplenty/worldgen/WorldGenRealPineTree.java +++ b/src/minecraft/biomesoplenty/worldgen/WorldGenRealPineTree.java @@ -9,7 +9,8 @@ import biomesoplenty.api.Blocks; public class WorldGenRealPineTree extends WorldGenerator { - public boolean generate(World var1, Random var2, int var3, int var4, int var5) + @Override + public boolean generate(World var1, Random var2, int var3, int var4, int var5) { while (var1.isAirBlock(var3 + 10, var4, var5 + 8) && var4 > 2) { diff --git a/src/minecraft/biomesoplenty/worldgen/WorldGenRealPineTree2.java b/src/minecraft/biomesoplenty/worldgen/WorldGenRealPineTree2.java index 94d5aa9f4..7b4bf8ac4 100644 --- a/src/minecraft/biomesoplenty/worldgen/WorldGenRealPineTree2.java +++ b/src/minecraft/biomesoplenty/worldgen/WorldGenRealPineTree2.java @@ -8,7 +8,8 @@ import net.minecraft.world.gen.feature.WorldGenerator; public class WorldGenRealPineTree2 extends WorldGenerator { - public boolean generate(World var1, Random var2, int var3, int var4, int var5) + @Override + public boolean generate(World var1, Random var2, int var3, int var4, int var5) { while (var1.isAirBlock(var3 + 5, var4, var5 + 9) && var4 > 2) { diff --git a/src/minecraft/biomesoplenty/worldgen/WorldGenRealRedwood.java b/src/minecraft/biomesoplenty/worldgen/WorldGenRealRedwood.java index b3d04971b..8482a7e38 100644 --- a/src/minecraft/biomesoplenty/worldgen/WorldGenRealRedwood.java +++ b/src/minecraft/biomesoplenty/worldgen/WorldGenRealRedwood.java @@ -2,17 +2,15 @@ package biomesoplenty.worldgen; import java.util.Random; -import biomesoplenty.api.Blocks; -import biomesoplenty.configuration.BOPBlocks; - import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; +import biomesoplenty.api.Blocks; public class WorldGenRealRedwood extends WorldGenerator { - public boolean generate(World var1, Random var2, int var3, int var4, int var5) + @Override + public boolean generate(World var1, Random var2, int var3, int var4, int var5) { while (var1.isAirBlock(var3 + 8, var4, var5 + 7) && var4 > 2) { diff --git a/src/minecraft/biomesoplenty/worldgen/WorldGenRealRedwood2.java b/src/minecraft/biomesoplenty/worldgen/WorldGenRealRedwood2.java index af434c84a..2a83b1f3f 100644 --- a/src/minecraft/biomesoplenty/worldgen/WorldGenRealRedwood2.java +++ b/src/minecraft/biomesoplenty/worldgen/WorldGenRealRedwood2.java @@ -2,16 +2,15 @@ package biomesoplenty.worldgen; import java.util.Random; -import biomesoplenty.api.Blocks; -import biomesoplenty.configuration.BOPBlocks; - import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; +import biomesoplenty.api.Blocks; public class WorldGenRealRedwood2 extends WorldGenerator { - public boolean generate(World var1, Random var2, int var3, int var4, int var5) + @Override + public boolean generate(World var1, Random var2, int var3, int var4, int var5) { while (var1.isAirBlock(var3 + 5, var4, var5 + 5) && var4 > 2) {