/
BowlStew.java
142 lines (123 loc) · 4.42 KB
/
BowlStew.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
package mods.natura.items;
import java.util.List;
import mods.natura.common.NContent;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BowlStew extends ItemFood
{
IIcon[] icons;
public static String[] textureNames = new String[] { "mushroom", "glowshroom" };
public BowlStew()
{
super(6, false);
}
@SideOnly(Side.CLIENT)
@Override
public boolean requiresMultipleRenderPasses ()
{
return true;
}
@Override
public IIcon getIcon (ItemStack stack, int renderPass)
{
if (renderPass == 0)
{
int stackDamage = stack.getItemDamage() % 14;
if (stackDamage == 0)
return Items.bowl.getIconFromDamage(0);
return NContent.bowlEmpty.getIconFromDamage(stack.getItemDamage() % 14 - 1);
}
else
return icons[stack.getItemDamage() / 14];
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons (IIconRegister iconRegister)
{
this.icons = new IIcon[textureNames.length];
for (int i = 0; i < BowlStew.textureNames.length; ++i)
{
if (!textureNames[i].equals(""))
this.icons[i] = iconRegister.registerIcon("natura:stew_" + textureNames[i]);
}
}
@Override
public ItemStack onEaten (ItemStack stack, World world, EntityPlayer player)
{
// TODO 1.7 check this
player.getFoodStats().addStats(6, 0.6f);
world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
this.onFoodEaten(stack, world, player);
if (!player.capabilities.isCreativeMode)
{
--stack.stackSize;
if (stack.stackSize <= 0)
{
int stackDamage = stack.getItemDamage() % 14;
if (stackDamage == 0)
return new ItemStack(Items.bowl);
return new ItemStack(NContent.bowlEmpty, 1, stackDamage - 1);
}
ItemStack returnStack = new ItemStack(Items.bowl);
int stackDamage = stack.getItemDamage() % 14;
if (stackDamage != 0)
returnStack = new ItemStack(NContent.bowlEmpty, 1, stackDamage - 1);
player.inventory.addItemStackToInventory(returnStack);
}
return stack;
}
@Override
protected void onFoodEaten (ItemStack stack, World world, EntityPlayer player)
{
if (!world.isRemote && stack.getItemDamage() / 14 == 1)
{
int duration = 0;
PotionEffect potion;
potion = player.getActivePotionEffect(Potion.nightVision);
if (potion != null)
duration = potion.getDuration();
else
duration = 0;
player.addPotionEffect(new PotionEffect(Potion.nightVision.id, duration + 45 * 25, 0));
potion = player.getActivePotionEffect(Potion.weakness);
if (potion != null)
duration = potion.getDuration();
else
duration = 0;
player.addPotionEffect(new PotionEffect(Potion.weakness.id, duration + 16 * 25, 0));
potion = player.getActivePotionEffect(Potion.weakness);
if (potion != null)
duration = potion.getDuration();
else
duration = 0;
player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, duration + 8 * 25, 0));
}
}
@Override
public String getUnlocalizedName (ItemStack stack)
{
int arr = MathHelper.clamp_int(stack.getItemDamage() / 14, 0, textureNames.length);
return "item.bowl." + textureNames[arr];
}
@SideOnly(Side.CLIENT)
@Override
public void getSubItems (Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int iter = 1; iter < textureNames.length; iter++)
{
par3List.add(new ItemStack(par1, 1, iter * 14));
}
}
}