mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 03:49:29 +00:00
158 lines
4.6 KiB
Java
158 lines
4.6 KiB
Java
package tconstruct.items.blocks;
|
|
|
|
import java.util.List;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.item.EnumAction;
|
|
import net.minecraft.item.ItemBlock;
|
|
import net.minecraft.item.ItemFood;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.potion.PotionEffect;
|
|
import net.minecraft.util.MathHelper;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.util.StatCollector;
|
|
import cpw.mods.fml.common.Loader;
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
public class HamboneItemBlock extends ItemBlock
|
|
{
|
|
public HamboneItemBlock(Block b)
|
|
{
|
|
super(b);
|
|
itemUseDuration = 32;
|
|
if (Loader.isModLoaded("HungerOverhaul"))
|
|
{
|
|
healAmount = 8;
|
|
saturationModifier = 0.8f;
|
|
}
|
|
else
|
|
{
|
|
healAmount = 20;
|
|
saturationModifier = 3.0f;
|
|
}
|
|
isWolfsFavoriteMeat = true;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public void addInformation (ItemStack stack, EntityPlayer player, List list, boolean par4)
|
|
{
|
|
list.add("\u00A74"+StatCollector.translateToLocal("hambone1.tooltip"));
|
|
list.add(StatCollector.translateToLocal("hambone2.tooltip"));
|
|
}
|
|
|
|
/** Number of ticks to run while 'EnumAction'ing until result. */
|
|
public final int itemUseDuration;
|
|
|
|
/** The amount this food item heals the player. */
|
|
private final int healAmount;
|
|
private final float saturationModifier;
|
|
|
|
/** Whether wolves like this food (true for raw and cooked porkchop). */
|
|
private final boolean isWolfsFavoriteMeat;
|
|
|
|
/**
|
|
* If this field is true, the food can be consumed even if the player don't need to eat.
|
|
*/
|
|
private boolean alwaysEdible;
|
|
|
|
/**
|
|
* represents the potion effect that will occurr upon eating this food. Set by setPotionEffect
|
|
*/
|
|
private int potionId;
|
|
|
|
/** set by setPotionEffect */
|
|
private int potionDuration;
|
|
|
|
/** set by setPotionEffect */
|
|
private int potionAmplifier;
|
|
|
|
/** probably of the set potion effect occurring */
|
|
private float potionEffectProbability;
|
|
|
|
/*public ItemFood(int par1, int par2, float par3, boolean par4)
|
|
{
|
|
super(par1);
|
|
this.itemUseDuration = 32;
|
|
this.healAmount = par2;
|
|
this.isWolfsFavoriteMeat = par4;
|
|
this.saturationModifier = par3;
|
|
this.setCreativeTab(CreativeTabs.tabFood);
|
|
}
|
|
|
|
public ItemFood(int par1, int par2, boolean par3)
|
|
{
|
|
this(par1, par2, 0.6F, par3);
|
|
}*/
|
|
|
|
public ItemStack onEaten (ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
|
{
|
|
--par1ItemStack.stackSize;
|
|
par3EntityPlayer.getFoodStats().addStats(getHealAmount(), getSaturationModifier());
|
|
par2World.playSoundAtEntity(par3EntityPlayer, "random.burp", 0.5F, par2World.rand.nextFloat() * 0.1F + 0.9F);
|
|
this.onFoodEaten(par1ItemStack, par2World, par3EntityPlayer);
|
|
return par1ItemStack;
|
|
}
|
|
|
|
protected void onFoodEaten (ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
|
{
|
|
if (!par2World.isRemote && this.potionId > 0 && par2World.rand.nextFloat() < this.potionEffectProbability)
|
|
{
|
|
par3EntityPlayer.addPotionEffect(new PotionEffect(this.potionId, this.potionDuration * 20, this.potionAmplifier));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* How long it takes to use or consume an item
|
|
*/
|
|
public int getMaxItemUseDuration (ItemStack par1ItemStack)
|
|
{
|
|
return 32;
|
|
}
|
|
|
|
/**
|
|
* returns the action that specifies what animation to play when the items is being used
|
|
*/
|
|
public EnumAction getItemUseAction (ItemStack par1ItemStack)
|
|
{
|
|
return EnumAction.eat;
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
if (par3EntityPlayer.canEat(this.alwaysEdible))
|
|
{
|
|
par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
|
|
}
|
|
|
|
return par1ItemStack;
|
|
}
|
|
|
|
public int getHealAmount ()
|
|
{
|
|
return this.healAmount;
|
|
}
|
|
|
|
/**
|
|
* gets the saturationModifier of the ItemFood
|
|
*/
|
|
public float getSaturationModifier ()
|
|
{
|
|
return this.saturationModifier;
|
|
}
|
|
|
|
/**
|
|
* Whether wolves like this food (true for raw and cooked porkchop).
|
|
*/
|
|
public boolean isWolfsFavoriteMeat ()
|
|
{
|
|
return this.isWolfsFavoriteMeat;
|
|
}
|
|
}
|