-
Notifications
You must be signed in to change notification settings - Fork 755
/
HamboneItemBlock.java
153 lines (132 loc) · 4.45 KB
/
HamboneItemBlock.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package tconstruct.world.itemblocks;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.relauncher.*;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.*;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
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); }
*/
@Override
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
*/
@Override
public int getMaxItemUseDuration (ItemStack par1ItemStack)
{
return 32;
}
/**
* returns the action that specifies what animation to play when the items
* is being used
*/
@Override
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
*/
@Override
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;
}
}