From 857d548f591b8f3770befd2535985959fd870474 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 22 Aug 2019 21:14:31 -0400 Subject: Begin implementing affix mods --- .../jewelrycraft/api/ModifierEffect.java | 197 +++++++++++++++++++++ .../jewelrycraft/api/ModifierEffects.java | 197 --------------------- .../darkknight/jewelrycraft/effects/AffixMods.java | 13 ++ .../jewelrycraft/effects/EffectBlazePowder.java | 4 +- .../jewelrycraft/effects/EffectEnderEye.java | 4 +- .../jewelrycraft/effects/EffectEnderPearl.java | 4 +- .../jewelrycraft/effects/EffectFeather.java | 4 +- .../jewelrycraft/effects/EffectObsidian.java | 4 +- .../jewelrycraft/effects/EffectsList.java | 4 +- .../jewelrycraft/item/ItemBaseJewelry.java | 146 ++++++++++++--- .../darkknight/jewelrycraft/util/JewelryNBT.java | 66 +++++++ 11 files changed, 410 insertions(+), 233 deletions(-) create mode 100755 src/main/java/darkknight/jewelrycraft/api/ModifierEffect.java delete mode 100755 src/main/java/darkknight/jewelrycraft/api/ModifierEffects.java create mode 100644 src/main/java/darkknight/jewelrycraft/effects/AffixMods.java (limited to 'src/main/java') diff --git a/src/main/java/darkknight/jewelrycraft/api/ModifierEffect.java b/src/main/java/darkknight/jewelrycraft/api/ModifierEffect.java new file mode 100755 index 0000000..8e58f72 --- /dev/null +++ b/src/main/java/darkknight/jewelrycraft/api/ModifierEffect.java @@ -0,0 +1,197 @@ +package darkknight.jewelrycraft.api; + +import java.util.ArrayList; +import java.util.Random; + +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.minecraftforge.event.entity.player.PlayerEvent; + +public class ModifierEffect { + protected ItemStack modifier; + protected Random rand = new Random(); + + protected static ArrayList effects = new ArrayList<>(); + + /** + * @param modifier + * The item to use as modifier + */ + public ModifierEffect(ItemStack modifier) { + this.modifier = modifier; + + if (modifier != null) { + effects.add(this); + } + } + + /** + * @return The list of all effects registered + */ + public static ArrayList getEffects() { + return effects; + } + + /** + * @return The ItemStack set as the modifier + */ + public ItemStack getModifier() { + return modifier; + } + + /** + * This runs every tick + * + * @param item + * The ItemStack representing the jewelry that runs the effect + * @param player + * The player wearing the jewelry wearing a jewelry with this + * modifier on it + * @param jewelry + * The actual jewelry item (used by me to determine the type of + * jewelry so I don't have to call item.getItem() blah blah blah) + */ + public void action(ItemStack item, EntityPlayer player, Item jewelry) { + // Do nothing + }; + + /** + * This runs when an entity is attacked. This event can be canceled. + * + * @param item + * The ItemStack representing the jewelry that runs the effect + * @param player + * The player wearing the jewelry wearing a jewelry with this + * modifier on it + * @param target + * The attacked entity + * @param jewelry + * The actual jewelry item (aka item.getItem(), almost) + * @param amount + * The amount of damage the entity took + * @return The state of the event (true to cancel it, false to not) + */ + public boolean onEntityAttackedCancellable(ItemStack item, EntityPlayer player, Entity target, Item jewelry, + float amount) { + return false; + } + + /** + * This runs when a player gets damaged. This event can be canceled. + * + * @param item + * The ItemStack representing the jewelry that runs the effect + * @param player + * The attacked player wearing a jewelry with this modifier on it + * @param source + * The source of the damage + * @param jewelry + * The actual jewelry item (aka item.getItem(), almost) + * @param amount + * The amount of damage the player took + * @return The state of the event (true to cancel it, false to not) + */ + public boolean onPlayerAttackedCancellable(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry, + float amount) { + return false; + } + + /** + * This is the same as onEntityAttackedCacellable, but this can not be canceled. + * I recommend using this over onEntityAttackedCacellable, as it is more + * reliable. + * + * @param item + * The ItemStack representing the jewelry that runs the effect + * @param player + * The player wearing the jewelry wearing a jewelry with this + * modifier on it + * @param target + * The attacked entity + * @param jewelry + * The actual jewelry item (aka item.getItem(), almost) + * @param amount + * The amount of damage the entity took + */ + public void onEntityAttacked(ItemStack item, EntityPlayer player, Entity target, Item jewelry, float amount) { + // Do nothing + } + + /** + * This is just like onPlayerAttackedCacellable, only that this can not be + * canceled. I recommend using this over onPlayerAttackedCacellable, as it is + * more reliable. + * + * @param item + * The ItemStack representing the jewelry that runs the effect + * @param player + * The attacked player wearing a jewelry with this modifier on it + * @param source + * The source of the damage + * @param jewelry + * The actual jewelry item (aka item.getItem(), almost) + * @param amount + * The amount of damage the player took + */ + public void onPlayerAttacked(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry, float amount) { + // Do nothing + } + + /** + * This runs when the player dies + * + * @param item + * The ItemStack representing the jewelry that runs the effect + * @param player + * The player that died wearing a jewelry with this modifier on it + * @param source + * The source of the killing blow + * @param jewelry + * The actual jewelry item (aka item.getItem(), almost) + */ + public void onPlayerDead(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry) { + // Do nothing + } + + /** + * This runs when the player respawns + * + * @param item + * The ItemStack representing the jewelry that runs the effect + * @param event + * The PlayerEvent that runs when the player respawns (this is also + * called when a player moves between dimensions) + * @param jewelry + * The actual jewelry item (aka item.getItem(), almost) + */ + public void onPlayerRespawn(ItemStack item, PlayerEvent.Clone event, Item jewelry) { + // Do nothing + } + + /** + * This runs when the item containing this modifier is equipped + * + * @param item + * The ItemStack representing the jewelry that runs the effect + * @param jewelry + * The actual jewelry item (aka item.getItem(), almost) + */ + public void onJewelryEquipped(ItemStack item, Item jewelry) { + // Do nothing + } + + /** + * This runs when the item containing this modifier is unquipped + * + * @param item + * The ItemStack representing the jewelry that runs the effect + * @param jewelry + * The actual jewelry item (aka item.getItem(), almost) + */ + public void onJewelryUnequipped(ItemStack item, Item jewelry) { + // Do nothing + } +} diff --git a/src/main/java/darkknight/jewelrycraft/api/ModifierEffects.java b/src/main/java/darkknight/jewelrycraft/api/ModifierEffects.java deleted file mode 100755 index b3c832c..0000000 --- a/src/main/java/darkknight/jewelrycraft/api/ModifierEffects.java +++ /dev/null @@ -1,197 +0,0 @@ -package darkknight.jewelrycraft.api; - -import java.util.ArrayList; -import java.util.Random; - -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.minecraftforge.event.entity.player.PlayerEvent; - -public class ModifierEffects { - protected ItemStack modifier; - protected Random rand = new Random(); - - protected static ArrayList effects = new ArrayList<>(); - - /** - * @param modifier - * The item to use as modifier - */ - public ModifierEffects(ItemStack modifier) { - this.modifier = modifier; - - if (modifier != null) { - effects.add(this); - } - } - - /** - * @return The list of all effects registered - */ - public static ArrayList getEffects() { - return effects; - } - - /** - * @return The ItemStack set as the modifier - */ - public ItemStack getModifier() { - return modifier; - } - - /** - * This runs every tick - * - * @param item - * The ItemStack representing the jewelry that runs the effect - * @param player - * The player wearing the jewelry wearing a jewelry with this - * modifier on it - * @param jewelry - * The actual jewelry item (used by me to determine the type of - * jewelry so I don't have to call item.getItem() blah blah blah) - */ - public void action(ItemStack item, EntityPlayer player, Item jewelry) { - // Do nothing - }; - - /** - * This runs when an entity is attacked. This event can be canceled. - * - * @param item - * The ItemStack representing the jewelry that runs the effect - * @param player - * The player wearing the jewelry wearing a jewelry with this - * modifier on it - * @param target - * The attacked entity - * @param jewelry - * The actual jewelry item (aka item.getItem(), almost) - * @param amount - * The amount of damage the entity took - * @return The state of the event (true to cancel it, false to not) - */ - public boolean onEntityAttackedCancellable(ItemStack item, EntityPlayer player, Entity target, Item jewelry, - float amount) { - return false; - } - - /** - * This runs when a player gets damaged. This event can be canceled. - * - * @param item - * The ItemStack representing the jewelry that runs the effect - * @param player - * The attacked player wearing a jewelry with this modifier on it - * @param source - * The source of the damage - * @param jewelry - * The actual jewelry item (aka item.getItem(), almost) - * @param amount - * The amount of damage the player took - * @return The state of the event (true to cancel it, false to not) - */ - public boolean onPlayerAttackedCancellable(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry, - float amount) { - return false; - } - - /** - * This is the same as onEntityAttackedCacellable, but this can not be canceled. - * I recommend using this over onEntityAttackedCacellable, as it is more - * reliable. - * - * @param item - * The ItemStack representing the jewelry that runs the effect - * @param player - * The player wearing the jewelry wearing a jewelry with this - * modifier on it - * @param target - * The attacked entity - * @param jewelry - * The actual jewelry item (aka item.getItem(), almost) - * @param amount - * The amount of damage the entity took - */ - public void onEntityAttacked(ItemStack item, EntityPlayer player, Entity target, Item jewelry, float amount) { - // Do nothing - } - - /** - * This is just like onPlayerAttackedCacellable, only that this can not be - * canceled. I recommend using this over onPlayerAttackedCacellable, as it is - * more reliable. - * - * @param item - * The ItemStack representing the jewelry that runs the effect - * @param player - * The attacked player wearing a jewelry with this modifier on it - * @param source - * The source of the damage - * @param jewelry - * The actual jewelry item (aka item.getItem(), almost) - * @param amount - * The amount of damage the player took - */ - public void onPlayerAttacked(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry, float amount) { - // Do nothing - } - - /** - * This runs when the player dies - * - * @param item - * The ItemStack representing the jewelry that runs the effect - * @param player - * The player that died wearing a jewelry with this modifier on it - * @param source - * The source of the killing blow - * @param jewelry - * The actual jewelry item (aka item.getItem(), almost) - */ - public void onPlayerDead(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry) { - // Do nothing - } - - /** - * This runs when the player respawns - * - * @param item - * The ItemStack representing the jewelry that runs the effect - * @param event - * The PlayerEvent that runs when the player respawns (this is also - * called when a player moves between dimensions) - * @param jewelry - * The actual jewelry item (aka item.getItem(), almost) - */ - public void onPlayerRespawn(ItemStack item, PlayerEvent.Clone event, Item jewelry) { - // Do nothing - } - - /** - * This runs when the item containing this modifier is equipped - * - * @param item - * The ItemStack representing the jewelry that runs the effect - * @param jewelry - * The actual jewelry item (aka item.getItem(), almost) - */ - public void onJewelryEquipped(ItemStack item, Item jewelry) { - // Do nothing - } - - /** - * This runs when the item containing this modifier is unquipped - * - * @param item - * The ItemStack representing the jewelry that runs the effect - * @param jewelry - * The actual jewelry item (aka item.getItem(), almost) - */ - public void onJewelryUnequipped(ItemStack item, Item jewelry) { - // Do nothing - } -} diff --git a/src/main/java/darkknight/jewelrycraft/effects/AffixMods.java b/src/main/java/darkknight/jewelrycraft/effects/AffixMods.java new file mode 100644 index 0000000..b9ec06a --- /dev/null +++ b/src/main/java/darkknight/jewelrycraft/effects/AffixMods.java @@ -0,0 +1,13 @@ +package darkknight.jewelrycraft.effects; + +import darkknight.jewelrycraft.api.ModifierEffect; + +public class AffixMods { + public static ModifierEffect getPrefix(String prefix) { + return null; + } + + public static ModifierEffect getSuffix(String suffix) { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/darkknight/jewelrycraft/effects/EffectBlazePowder.java b/src/main/java/darkknight/jewelrycraft/effects/EffectBlazePowder.java index f65d135..ca35754 100755 --- a/src/main/java/darkknight/jewelrycraft/effects/EffectBlazePowder.java +++ b/src/main/java/darkknight/jewelrycraft/effects/EffectBlazePowder.java @@ -1,6 +1,6 @@ package darkknight.jewelrycraft.effects; -import darkknight.jewelrycraft.api.ModifierEffects; +import darkknight.jewelrycraft.api.ModifierEffect; import darkknight.jewelrycraft.item.ItemBracelet; import darkknight.jewelrycraft.item.ItemEarrings; import darkknight.jewelrycraft.item.ItemNecklace; @@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.DamageSource; -public class EffectBlazePowder extends ModifierEffects { +public class EffectBlazePowder extends ModifierEffect { public EffectBlazePowder() { super(new ItemStack(Items.blaze_powder)); } diff --git a/src/main/java/darkknight/jewelrycraft/effects/EffectEnderEye.java b/src/main/java/darkknight/jewelrycraft/effects/EffectEnderEye.java index 1f0c325..01c045a 100755 --- a/src/main/java/darkknight/jewelrycraft/effects/EffectEnderEye.java +++ b/src/main/java/darkknight/jewelrycraft/effects/EffectEnderEye.java @@ -1,7 +1,7 @@ package darkknight.jewelrycraft.effects; import cpw.mods.fml.relauncher.ReflectionHelper; -import darkknight.jewelrycraft.api.ModifierEffects; +import darkknight.jewelrycraft.api.ModifierEffect; import darkknight.jewelrycraft.item.ItemBracelet; import darkknight.jewelrycraft.item.ItemEarrings; import darkknight.jewelrycraft.item.ItemNecklace; @@ -23,7 +23,7 @@ import net.minecraft.util.*; import net.minecraft.world.ChunkPosition; import net.minecraft.world.biome.BiomeGenBase; -public class EffectEnderEye extends ModifierEffects { +public class EffectEnderEye extends ModifierEffect { public EffectEnderEye() { super(new ItemStack(Items.ender_eye)); } diff --git a/src/main/java/darkknight/jewelrycraft/effects/EffectEnderPearl.java b/src/main/java/darkknight/jewelrycraft/effects/EffectEnderPearl.java index 7722484..fca9fe0 100755 --- a/src/main/java/darkknight/jewelrycraft/effects/EffectEnderPearl.java +++ b/src/main/java/darkknight/jewelrycraft/effects/EffectEnderPearl.java @@ -3,7 +3,7 @@ package darkknight.jewelrycraft.effects; import java.util.Iterator; import java.util.List; -import darkknight.jewelrycraft.api.ModifierEffects; +import darkknight.jewelrycraft.api.ModifierEffect; import darkknight.jewelrycraft.item.ItemBracelet; import darkknight.jewelrycraft.item.ItemEarrings; import darkknight.jewelrycraft.item.ItemNecklace; @@ -21,7 +21,7 @@ import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.DamageSource; -public class EffectEnderPearl extends ModifierEffects { +public class EffectEnderPearl extends ModifierEffect { public EffectEnderPearl() { super(new ItemStack(Items.ender_pearl)); } diff --git a/src/main/java/darkknight/jewelrycraft/effects/EffectFeather.java b/src/main/java/darkknight/jewelrycraft/effects/EffectFeather.java index 42df76f..14953e6 100755 --- a/src/main/java/darkknight/jewelrycraft/effects/EffectFeather.java +++ b/src/main/java/darkknight/jewelrycraft/effects/EffectFeather.java @@ -3,7 +3,7 @@ package darkknight.jewelrycraft.effects; import java.util.Iterator; import java.util.List; -import darkknight.jewelrycraft.api.ModifierEffects; +import darkknight.jewelrycraft.api.ModifierEffect; import darkknight.jewelrycraft.damage.DamageSourceList; import darkknight.jewelrycraft.item.ItemBracelet; import darkknight.jewelrycraft.item.ItemEarrings; @@ -24,7 +24,7 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.*; -public class EffectFeather extends ModifierEffects { +public class EffectFeather extends ModifierEffect { public EffectFeather() { super(new ItemStack(Items.feather)); } diff --git a/src/main/java/darkknight/jewelrycraft/effects/EffectObsidian.java b/src/main/java/darkknight/jewelrycraft/effects/EffectObsidian.java index 95f52b5..0d561e0 100755 --- a/src/main/java/darkknight/jewelrycraft/effects/EffectObsidian.java +++ b/src/main/java/darkknight/jewelrycraft/effects/EffectObsidian.java @@ -1,6 +1,6 @@ package darkknight.jewelrycraft.effects; -import darkknight.jewelrycraft.api.ModifierEffects; +import darkknight.jewelrycraft.api.ModifierEffect; import darkknight.jewelrycraft.damage.DamageSourceList; import darkknight.jewelrycraft.item.ItemBracelet; import darkknight.jewelrycraft.item.ItemEarrings; @@ -19,7 +19,7 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.DamageSource; -public class EffectObsidian extends ModifierEffects { +public class EffectObsidian extends ModifierEffect { public EffectObsidian() { super(new ItemStack(Blocks.obsidian)); } diff --git a/src/main/java/darkknight/jewelrycraft/effects/EffectsList.java b/src/main/java/darkknight/jewelrycraft/effects/EffectsList.java index 06498f4..186a3bf 100755 --- a/src/main/java/darkknight/jewelrycraft/effects/EffectsList.java +++ b/src/main/java/darkknight/jewelrycraft/effects/EffectsList.java @@ -1,10 +1,10 @@ package darkknight.jewelrycraft.effects; import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import darkknight.jewelrycraft.api.ModifierEffects; +import darkknight.jewelrycraft.api.ModifierEffect; public class EffectsList { - public static ModifierEffects blazePowder, enderEye, feather, enderPearl, obsidian; + public static ModifierEffect blazePowder, enderEye, feather, enderPearl, obsidian; public static void postInit(FMLPostInitializationEvent e) { blazePowder = new EffectBlazePowder(); 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 diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java b/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java index 17090ab..d7eff3a 100755 --- a/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java +++ b/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java @@ -70,6 +70,48 @@ public class JewelryNBT { itemStackData.setTag("gem", gemNBT); } } + + /** + * @param item + * The item you want to add the NBT data on + * @param prefix + * The prefix you want to add on the item + */ + public static void addPrefix(ItemStack item, String prefix) { + if (prefix != null) { + NBTTagCompound itemStackData; + + if (item.hasTagCompound()) { + itemStackData = item.getTagCompound(); + } else { + itemStackData = new NBTTagCompound(); + item.setTagCompound(itemStackData); + } + + itemStackData.setString("prefix", prefix); + } + } + + /** + * @param item + * The item you want to add the NBT data on + * @param suffix + * The suffix you want to add on the item + */ + public static void addSuffix(ItemStack item, String suffix) { + if (suffix != null) { + NBTTagCompound itemStackData; + + if (item.hasTagCompound()) { + itemStackData = item.getTagCompound(); + } else { + itemStackData = new NBTTagCompound(); + item.setTagCompound(itemStackData); + } + + itemStackData.setString("suffix", suffix); + } + } /** * @param item @@ -276,6 +318,30 @@ public class JewelryNBT { return null; } + + public static String prefix(ItemStack stack) { + if (stack != null) { + if (stack != new ItemStack(Item.getItemById(0), 0, 0)) { + if (stack.hasTagCompound() && stack.getTagCompound().hasKey("prefix")) { + return stack.getTagCompound().getString("prefix"); + } + } + } + + return null; + } + + public static String suffix(ItemStack stack) { + if (stack != null) { + if (stack != new ItemStack(Item.getItemById(0), 0, 0)) { + if (stack.hasTagCompound() && stack.getTagCompound().hasKey("suffix")) { + return stack.getTagCompound().getString("suffix"); + } + } + } + + return null; + } /** * @param stack -- cgit v1.2.3