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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
package darkknight.jewelrycraft.item;
import java.util.ArrayList;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import darkknight.jewelrycraft.JewelrycraftMod;
import darkknight.jewelrycraft.affixes.AffixMods;
import darkknight.jewelrycraft.api.IJewelryItem;
import darkknight.jewelrycraft.api.ModifierEffect;
import darkknight.jewelrycraft.config.ConfigHandler;
import darkknight.jewelrycraft.util.JewelryNBT;
import darkknight.jewelrycraft.util.JewelrycraftUtil;
import darkknight.jewelrycraft.util.Variables;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
@SuppressWarnings({ "rawtypes", "unchecked" })
public abstract class ItemBaseJewelry extends Item {
public ItemBaseJewelry() {
super();
setMaxStackSize(1);
setCreativeTab(JewelrycraftMod.jewelrycraft);
}
@Override
public boolean requiresMultipleRenderPasses() {
return true;
}
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack stack, int pass) {
if (pass == 0 && JewelryNBT.ingot(stack) != null) {
return JewelrycraftUtil.getColor(JewelryNBT.ingot(stack));
}
if (pass == 1 && JewelryNBT.gem(stack) != null) {
return JewelrycraftUtil.getColor(JewelryNBT.gem(stack));
} else if (JewelryNBT.ingot(stack) != null) {
return JewelrycraftUtil.getColor(JewelryNBT.ingot(stack));
}
return 16777215;
}
/**
* @param stack
* @return
*/
@Override
public String getItemStackDisplayName(ItemStack stack) {
String itemName = ("" + StatCollector.translateToLocal(getUnlocalizedNameInefficiently(stack) + ".name"))
.trim();
String baseName = itemName;
ItemStack ingot = JewelryNBT.ingot(stack);
if (ingot != null) {
if (Item.getIdFromItem(ingot.getItem()) > 0) {
String ingotName = ingot.getDisplayName().replace("Ingot", " ").trim();
baseName = ingotName + " " + itemName;
}
}
String prefix = JewelryNBT.prefix(stack);
String suffix = JewelryNBT.suffix(stack);
if (prefix != null && !prefix.equals("")) {
String translatedPrefix = StatCollector.translateToLocal("prefix." + Variables.MODID + "." + prefix);
baseName = translatedPrefix + " " + baseName;
}
if (suffix != null && !suffix.equals("")) {
String translatedSuffix = StatCollector.translateToLocal("suffix." + Variables.MODID + "." + suffix);
baseName = baseName + " " + translatedSuffix;
}
return baseName;
}
/**
* allows items to add custom lines of information to the mouseover description.
*
* @param stack
* @param player
* @param list
* @param par4
*/
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
if (stack.hasTagCompound() && ConfigHandler.JEWELRY_INFO) {
ItemStack ingot = JewelryNBT.ingot(stack);
if (ingot != null && Item.getIdFromItem(ingot.getItem()) > 0) {
String metalInfo = StatCollector.translateToLocal("info." + Variables.MODID + ".metal");
String ingotInfo = StatCollector.translateToLocal("info." + Variables.MODID + ".ingot");
list.add(metalInfo + ": " + EnumChatFormatting.YELLOW + ingot.getDisplayName().replace(ingotInfo, " "));
}
ItemStack gem = JewelryNBT.gem(stack);
if (gem != null) {
list.add(StatCollector.translateToLocal("info." + Variables.MODID + ".gem") + ": "
+ EnumChatFormatting.BLUE + gem.getDisplayName());
}
if (player.isSneaking()) {
ArrayList<ItemStack> modifier = JewelryNBT.modifier(stack);
if (!modifier.isEmpty()) {
list.add(StatCollector.translateToLocal("info." + Variables.MODID + ".modifiers") + ": ");
}
for (ItemStack is : modifier) {
list.add(EnumChatFormatting.DARK_PURPLE + is.getDisplayName() + " x" + is.stackSize);
}
String prefix = JewelryNBT.prefix(stack);
String suffix = JewelryNBT.suffix(stack);
if (prefix != null && !prefix.equals("")) {
String translatedPrefix = StatCollector
.translateToLocal("prefix." + Variables.MODID + "." + prefix);
String translatedDesc = StatCollector
.translateToLocal("prefix." + Variables.MODID + "." + prefix + ".desc");
list.add(translatedPrefix + ": " + translatedDesc);
}
if (suffix != null && !suffix.equals("")) {
String translatedSuffix = StatCollector
.translateToLocal("suffix." + Variables.MODID + "." + prefix);
String translatedDesc = StatCollector
.translateToLocal("suffix." + Variables.MODID + "." + prefix + ".desc");
list.add(translatedSuffix + ": " + translatedDesc);
}
} else {
list.add("<Sneak to see modifier info>");
}
}
}
/**
* @param stack
* @param player
*/
public void action(ItemStack item, EntityPlayer player) {
for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
mod.action(item, player, this);
}
}
ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
if (prefix != null)
prefix.action(item, player, this);
if (suffix != null)
suffix.action(item, player, this);
}
/**
* @param item
* @param player
* @param source
* @return
*/
public boolean onPlayerAttackedCacellable(ItemStack item, EntityPlayer player, DamageSource source, float amount) {
boolean cancelEvent = false;
for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
cancelEvent = mod.onPlayerAttackedCancellable(item, player, source, this, amount);
if (cancelEvent)
return true;
}
}
ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
if (prefix != null) {
cancelEvent = prefix.onPlayerAttackedCancellable(item, player, source, this, amount);
if (cancelEvent)
return true;
}
if (suffix != null) {
cancelEvent = suffix.onPlayerAttackedCancellable(item, player, source, this, amount);
if (cancelEvent)
return true;
}
return cancelEvent;
}
/**
* @param item
* @param player
* @param target
* @return
*/
public boolean onEntityAttackedCancellable(ItemStack item, EntityPlayer player, Entity target,
LivingAttackEvent event) {
boolean cancelEvent = false;
for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
cancelEvent = mod.onEntityAttackedCancellable(item, player, target, this, event);
if (cancelEvent)
return true;
}
}
ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
if (prefix != null) {
cancelEvent = prefix.onEntityAttackedCancellable(item, player, target, this, event);
if (cancelEvent)
return true;
}
if (suffix != null) {
cancelEvent = suffix.onEntityAttackedCancellable(item, player, target, this, event);
if (cancelEvent)
return true;
}
return cancelEvent;
}
/**
* @param item
* @param player
* @param source
* @return
*/
public void onPlayerAttacked(ItemStack item, EntityPlayer player, DamageSource source, float amount) {
for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
mod.onPlayerAttacked(item, player, source, this, amount);
}
}
ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
if (prefix != null)
prefix.onPlayerAttacked(item, player, source, this, amount);
if (suffix != null)
suffix.onPlayerAttacked(item, player, source, this, amount);
}
/**
* @param item
* @param player
* @param target
* @return
*/
public void onEntityAttacked(ItemStack item, EntityPlayer player, Entity target, LivingAttackEvent event) {
for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
mod.onEntityAttacked(item, player, target, this, event);
}
}
ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
if (prefix != null)
prefix.onEntityAttacked(item, player, target, this, event);
if (suffix != null)
suffix.onEntityAttacked(item, player, target, this, event);
}
public void onPlayerDead(ItemStack item, EntityPlayer player, DamageSource source) {
for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
mod.onPlayerDead(item, player, source, this);
}
}
ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
if (prefix != null)
prefix.onPlayerDead(item, player, source, this);
if (suffix != null)
suffix.onPlayerDead(item, player, source, this);
}
public void onPlayerRespawn(ItemStack item, PlayerEvent.Clone event) {
for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
mod.onPlayerRespawn(item, event, this);
}
}
ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
if (prefix != null)
prefix.onPlayerRespawn(item, event, this);
if (suffix != null)
suffix.onPlayerRespawn(item, event, this);
}
public void onJewelryEquipped(ItemStack item, EntityPlayer player) {
for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
mod.onJewelryEquipped(item, this, player);
}
}
ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
if (prefix != null)
prefix.onJewelryEquipped(item, this, player);
if (suffix != null)
suffix.onJewelryEquipped(item, this, player);
}
public void onJewelryUnequipped(ItemStack item, EntityPlayer player) {
for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
mod.onJewelryUnequipped(item, this, player);
}
}
ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
if (prefix != null)
prefix.onJewelryUnequipped(item, this, player);
if (suffix != null)
suffix.onJewelryUnequipped(item, this, player);
}
public void onLivingDropItems(ItemStack item, EntityPlayer player, LivingDropsEvent event) {
for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
mod.onLivingDropItems(item, player, event, this);
}
}
ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
if (prefix != null)
prefix.onLivingDropItems(item, player, event, this);
if (suffix != null)
suffix.onLivingDropItems(item, player, event, this);
}
}
|