diff options
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/item/ItemBaseJewelry.java')
| -rwxr-xr-x | src/main/java/darkknight/jewelrycraft/item/ItemBaseJewelry.java | 146 |
1 files changed, 122 insertions, 24 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/item/ItemBaseJewelry.java b/src/main/java/darkknight/jewelrycraft/item/ItemBaseJewelry.java index 13e8546..b14a365 100755 --- a/src/main/java/darkknight/jewelrycraft/item/ItemBaseJewelry.java +++ b/src/main/java/darkknight/jewelrycraft/item/ItemBaseJewelry.java @@ -7,8 +7,9 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly;
import darkknight.jewelrycraft.JewelrycraftMod;
import darkknight.jewelrycraft.api.IJewelryItem;
-import darkknight.jewelrycraft.api.ModifierEffects;
+import darkknight.jewelrycraft.api.ModifierEffect;
import darkknight.jewelrycraft.config.ConfigHandler;
+import darkknight.jewelrycraft.effects.AffixMods;
import darkknight.jewelrycraft.util.JewelryNBT;
import darkknight.jewelrycraft.util.JewelrycraftUtil;
import darkknight.jewelrycraft.util.Variables;
@@ -61,13 +62,29 @@ public abstract class ItemBaseJewelry extends Item { String itemName = ("" + StatCollector.translateToLocal(getUnlocalizedNameInefficiently(stack) + ".name"))
.trim();
- if (JewelryNBT.ingot(stack) != null && Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) > 0) {
- String ingotName = JewelryNBT.ingot(stack).getDisplayName().replace("Ingot", " ").trim();
-
- return ingotName + " " + itemName;
+ 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;
+ }
}
- return itemName;
+ String prefix = JewelryNBT.prefix(stack);
+ String suffix = JewelryNBT.suffix(stack);
+
+ if (prefix != null && !prefix.equals("")) {
+ baseName = prefix + " " + baseName;
+ }
+
+ if (suffix != null && !suffix.equals("")) {
+ baseName = baseName + " of " + suffix;
+ }
+
+ return baseName;
}
/**
@@ -83,7 +100,7 @@ public abstract class ItemBaseJewelry extends Item { if (stack.hasTagCompound() && ConfigHandler.JEWELRY_INFO) {
ItemStack ingot = JewelryNBT.ingot(stack);
- if (ingot != null && Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) > 0) {
+ if (ingot != null && Item.getIdFromItem(ingot.getItem()) > 0) {
String metalInfo = StatCollector.translateToLocal("info." + Variables.MODID + ".metal");
String ingotInfo = StatCollector.translateToLocal("info." + Variables.MODID + ".ingot");
@@ -103,9 +120,8 @@ public abstract class ItemBaseJewelry extends Item { list.add(StatCollector.translateToLocal("info." + Variables.MODID + ".modifiers") + ": ");
}
- for (int i = 0; i < modifier.size(); i++) {
- list.add(EnumChatFormatting.DARK_PURPLE + modifier.get(i).getDisplayName() + " x"
- + modifier.get(i).stackSize);
+ for (ItemStack is : modifier) {
+ list.add(EnumChatFormatting.DARK_PURPLE + is.getDisplayName() + " x" + is.stackSize);
}
}
}
@@ -115,11 +131,17 @@ public abstract class ItemBaseJewelry extends Item { * @param player
*/
public void action(ItemStack item, EntityPlayer player) {
- for (ModifierEffects mod : ModifierEffects.getEffects()) {
+ 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);
}
/**
@@ -129,13 +151,32 @@ public abstract class ItemBaseJewelry extends Item { * @return
*/
public boolean onPlayerAttackedCacellable(ItemStack item, EntityPlayer player, DamageSource source, float amount) {
- for (ModifierEffects mod : ModifierEffects.getEffects()) {
+ boolean cancelEvent = false;
+
+ for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
- return mod.onPlayerAttackedCancellable(item, player, source, this, amount);
+ cancelEvent = mod.onPlayerAttackedCancellable(item, player, source, this, amount);
+
+ if (cancelEvent) return true;
}
}
- return false;
+ 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;
}
/**
@@ -145,13 +186,32 @@ public abstract class ItemBaseJewelry extends Item { * @return
*/
public boolean onEntityAttackedCacellable(ItemStack item, EntityPlayer player, Entity target, float amount) {
- for (ModifierEffects mod : ModifierEffects.getEffects()) {
+ boolean cancelEvent = false;
+
+ for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
- return mod.onEntityAttackedCancellable(item, player, target, this, amount);
+ cancelEvent = mod.onEntityAttackedCancellable(item, player, target, this, amount);
+
+ if (cancelEvent) return true;
}
}
- return false;
+ ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
+ ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
+
+ if (prefix != null) {
+ cancelEvent = prefix.onEntityAttackedCancellable(item, player, target, this, amount);
+
+ if (cancelEvent) return true;
+ }
+
+ if (suffix != null) {
+ cancelEvent = suffix.onEntityAttackedCancellable(item, player, target, this, amount);
+
+ if (cancelEvent) return true;
+ }
+
+ return cancelEvent;
}
/**
@@ -161,9 +221,17 @@ public abstract class ItemBaseJewelry extends Item { * @return
*/
public void onPlayerAttacked(ItemStack item, EntityPlayer player, DamageSource source, float amount) {
- for (ModifierEffects mod : ModifierEffects.getEffects())
- if (JewelryNBT.doesModifierExist(item, mod.getModifier()))
+ 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);
}
/**
@@ -173,42 +241,72 @@ public abstract class ItemBaseJewelry extends Item { * @return
*/
public void onEntityAttacked(ItemStack item, EntityPlayer player, Entity target, float amount) {
- for (ModifierEffects mod : ModifierEffects.getEffects()) {
+ for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
mod.onEntityAttacked(item, player, target, this, amount);
}
}
+
+ ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
+ ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
+
+ if (prefix != null) prefix.onEntityAttacked(item, player, target, this, amount);
+ if (suffix != null) suffix.onEntityAttacked(item, player, target, this, amount);
}
public void onPlayerDead(ItemStack item, EntityPlayer player, DamageSource source) {
- for (ModifierEffects mod : ModifierEffects.getEffects()) {
+ 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 (ModifierEffects mod : ModifierEffects.getEffects()) {
+ 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) {
- for (ModifierEffects mod : ModifierEffects.getEffects()) {
+ for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
mod.onJewelryEquipped(item, this);
}
}
+
+ ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
+ ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
+
+ if (prefix != null) prefix.onJewelryEquipped(item, this);
+ if (suffix != null) suffix.onJewelryEquipped(item, this);
}
public void onJewelryUnequipped(ItemStack item) {
- for (ModifierEffects mod : ModifierEffects.getEffects()) {
+ for (ModifierEffect mod : ModifierEffect.getEffects()) {
if (JewelryNBT.doesModifierExist(item, mod.getModifier())) {
mod.onJewelryUnequipped(item, this);
}
}
+
+ ModifierEffect prefix = AffixMods.getPrefix(JewelryNBT.prefix(item));
+ ModifierEffect suffix = AffixMods.getSuffix(JewelryNBT.suffix(item));
+
+ if (prefix != null) prefix.onJewelryUnequipped(item, this);
+ if (suffix != null) suffix.onJewelryUnequipped(item, this);
}
}
\ No newline at end of file |
