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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
package fyresmodjam.items;
import java.util.List;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import fyresmodjam.ModjamMod;
import fyresmodjam.blessings.BlessingUtils;
import fyresmodjam.entities.EntityMysteryPotion;
import fyresmodjam.handlers.CommonTickHandler;
import fyresmodjam.handlers.NewPacketHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
public class ItemMysteryPotion extends Item {
public IIcon[] icons = null;
public ItemMysteryPotion() {
super();
setHasSubtypes(true);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister) {
icons = new IIcon[26];
for (int i = 0; i < 13; i++) {
icons[i] = par1IconRegister.registerIcon(
"fyresmodjam:mysteryPotion_"
+ (i + 1));
icons[i + 13] = par1IconRegister.registerIcon(
"fyresmodjam:mysteryPotionThrowable_"
+ (i + 1));
}
itemIcon = icons[0];
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int par1) {
return icons[par1 % 26];
}
@Override
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs,
List par3List) {
for (int i = 0; i < 13; i++) {
par3List.add(new ItemStack(par1, 1, i));
}
for (int i = 0; i < 13; i++) {
par3List.add(new ItemStack(par1, 1, i + 13));
}
}
@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(ItemStack par1ItemStack) {
int damage = par1ItemStack.getItemDamage() % 13;
String name = "Mystery Potion #" + (damage + 1);
if (damage < 12) {
if (Minecraft.getMinecraft().thePlayer != null
&& Minecraft.getMinecraft().thePlayer
.getEntityData()
.hasKey("PotionKnowledge")) {
if (Minecraft.getMinecraft().thePlayer
.getEntityData()
.getIntArray("PotionKnowledge")[damage] != -1) {
Potion potion = Potion.potionTypes[NewPacketHandler.potionValues[damage]];
name = StatCollector
.translateToLocal(
potion.getName())
+ " Potion";
if (!potion.isInstant()) {
int time = NewPacketHandler.potionDurations[damage];
name += " (" + time
+ " seconds)";
}
}
}
} else if (damage >= 12) {
name = "Wildcard Potion";
}
if (FMLCommonHandler.instance().getSide() == Side.CLIENT
&& hasBlessing("Alchemist")) {
name = "\u00A7k" + name;
}
return name;
}
@Override
public EnumAction getItemUseAction(ItemStack par1ItemStack) {
return par1ItemStack.getItemDamage() < 13
? EnumAction.drink
: super.getItemUseAction(par1ItemStack);
}
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack,
World par2World, EntityPlayer par3EntityPlayer) {
if (par1ItemStack.getItemDamage() < 13) {
par3EntityPlayer.setItemInUse(par1ItemStack,
getMaxItemUseDuration(
par1ItemStack));
} else {
if (!par3EntityPlayer.capabilities.isCreativeMode) {
par1ItemStack.stackSize--;
}
par2World.playSoundAtEntity(par3EntityPlayer,
"random.bow", 0.5F,
0.4F / (itemRand.nextFloat() * 0.4F
+ 0.8F));
if (!par2World.isRemote) {
int value = 0;
if (par1ItemStack.getItemDamage()
% 13 >= 12) {
value = ModjamMod.r.nextInt(
Potion.potionTypes.length);
while (Potion.potionTypes[value] == null) {
value = ModjamMod.r
.nextInt(Potion.potionTypes.length);
}
} else {
value = CommonTickHandler.worldData.potionValues[par1ItemStack
.getItemDamage()
% 13];
}
par2World.spawnEntityInWorld(
new EntityMysteryPotion(
par2World,
par3EntityPlayer,
par1ItemStack));
}
}
return par1ItemStack;
}
@Override
public int getMaxItemUseDuration(ItemStack par1ItemStack) {
return par1ItemStack.getItemDamage() < 13 ? 32
: super.getMaxItemUseDuration(
par1ItemStack);
}
@Override
public ItemStack onEaten(ItemStack par1ItemStack, World par2World,
EntityPlayer par3EntityPlayer) {
if (!par3EntityPlayer.capabilities.isCreativeMode) {
--par1ItemStack.stackSize;
}
int damage = par1ItemStack.getItemDamage() % 13;
if (!BlessingUtils.hasBlessing(par3EntityPlayer,
"BlessingAlchemist") && damage < 12) {
if (!par2World.isRemote) {
int value = CommonTickHandler.worldData.potionValues[damage];
if (!Potion.potionTypes[value]
.isInstant()) {
par3EntityPlayer.addPotionEffect(
new PotionEffect(
value,
CommonTickHandler.worldData.potionDurations[damage]
* 20,
1,
false));
} else {
Potion.potionTypes[value]
.affectEntity(par3EntityPlayer,
par3EntityPlayer,
1,
1);
}
if (!par3EntityPlayer.getEntityData()
.hasKey("PotionKnowledge")) {
par3EntityPlayer.getEntityData()
.setIntArray("PotionKnowledge",
new int[] {
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
});
}
if (par3EntityPlayer.getEntityData()
.getIntArray("PotionKnowledge")[damage] == -1) {
par3EntityPlayer.getEntityData()
.getIntArray("PotionKnowledge")[damage] = 1;
NewPacketHandler.UPDATE_POTION_KNOWLEDGE
.sendToPlayer(par3EntityPlayer,
par3EntityPlayer.getEntityData()
.getIntArray("PotionKnowledge"));
Potion potion = Potion.potionTypes[CommonTickHandler.worldData.potionValues[damage]];
String name = StatCollector
.translateToLocal(
potion.getName())
+ " Potion";
if (!potion.isInstant()) {
int time = CommonTickHandler.worldData.potionDurations[damage];
name += " (" + time
+ " seconds)";
}
NewPacketHandler.SEND_MESSAGE
.sendToPlayer(par3EntityPlayer,
"\u00A7oYou learnt Mystery Potion #"
+ (damage + 1)
+ " was a "
+ name
+ "!");
}
}
} else if (!par2World.isRemote) {
int value = ModjamMod.r.nextInt(
Potion.potionTypes.length);
while (Potion.potionTypes[value] == null) {
value = ModjamMod.r.nextInt(
Potion.potionTypes.length);
}
int time = 5 + ModjamMod.r.nextInt(26);
if (!Potion.potionTypes[value].isInstant()) {
par3EntityPlayer.addPotionEffect(
new PotionEffect(value,
time * 20,
1, false));
} else {
Potion.potionTypes[value].affectEntity(
par3EntityPlayer,
par3EntityPlayer, 1, 1);
}
Potion potion = Potion.potionTypes[value];
String name = StatCollector.translateToLocal(
potion.getName()) + " Potion";
if (!potion.isInstant()) {
name += " (" + time + " seconds)";
}
NewPacketHandler.SEND_MESSAGE.sendToPlayer(
par3EntityPlayer,
"\u00A7oYou drank a " + name
+ ".");
}
return par1ItemStack;
}
@SideOnly(Side.CLIENT)
public boolean hasBlessing(String bless) {
return (Minecraft.getMinecraft().thePlayer != null
&& BlessingUtils.hasBlessing(Minecraft
.getMinecraft().thePlayer,
bless));
}
@Override
public boolean onItemUse(ItemStack par1ItemStack,
EntityPlayer par2EntityPlayer, World par3World,
int par4, int par5, int par6, int par7, float par8,
float par9, float par10) {
return false;
}
}
|