From 35ab9d67f2cd48db2a364f56bfcd83332d035a15 Mon Sep 17 00:00:00 2001 From: Jeremy Diamond Date: Mon, 17 Nov 2014 04:39:11 -0800 Subject: [PATCH] API stuffs --- .../api/ColourAndCoords.java | 45 + .../AlchemicalPotionCreationHandler.java | 4 +- .../api/alchemy/AlchemyRecipe.java | 6 +- .../api/alchemy/AlchemyRecipeRegistry.java | 6 +- .../api/alchemy/energy/IAlchemyGoggles.java | 10 + .../api/alchemy/energy/IReagentContainer.java | 16 + .../api/alchemy/energy/IReagentHandler.java | 18 + .../energy/ISegmentedReagentHandler.java | 14 + .../api/alchemy/energy/Reagent.java | 52 ++ .../api/alchemy/energy/ReagentContainer.java | 153 ++++ .../alchemy/energy/ReagentContainerInfo.java | 19 + .../api/alchemy/energy/ReagentRegistry.java | 174 ++++ .../api/alchemy/energy/ReagentStack.java | 63 ++ .../alchemy/energy/TileReagentHandler.java | 66 ++ .../energy/TileSegmentedReagentHandler.java | 283 ++++++ .../api/altarRecipeRegistry/AltarRecipe.java | 194 +++-- .../AltarRecipeRegistry.java | 111 +-- .../api/bindingRegistry/BindingRecipe.java | 53 +- .../api/bindingRegistry/BindingRegistry.java | 118 +-- .../api/event/AddToNetworkEvent.java | 38 + .../api/event/ItemBindEvent.java | 20 + .../api/event/ItemDrainNetworkEvent.java | 29 + .../api/event/PlayerAddToNetworkEvent.java | 18 + .../api/event/PlayerDrainNetworkEvent.java | 20 + .../api/event/RitualActivatedEvent.java | 23 + .../api/event/RitualEvent.java | 18 + .../api/event/RitualRunEvent.java | 16 + .../api/event/RitualStopEvent.java | 15 + .../api/event/SoulNetworkEvent.java | 26 + .../api/harvest/HarvestRegistry.java | 53 +- .../api/harvest/IHarvestHandler.java | 29 +- .../api/items/IAltarManipulator.java | 6 + .../api/items/ItemSpellMultiTool.java | 806 ++++++++++++++++++ .../api/items/ShapedBloodOrbRecipe.java | 418 +++++---- .../api/items/ShapelessBloodOrbRecipe.java | 254 +++--- .../api/items/interfaces/IBloodOrb.java | 8 +- .../api/items/interfaces/IHolding.java | 2 +- .../items/interfaces/IReagentManipulator.java | 9 + .../api/renderer/MRSRenderer.java | 21 + .../api/rituals/IMasterRitualStone.java | 20 +- .../api/rituals/IRitualStone.java | 6 +- .../api/rituals/RitualBreakMethod.java | 11 + .../api/rituals/RitualComponent.java | 30 +- .../api/rituals/RitualEffect.java | 41 +- .../api/rituals/Rituals.java | 377 +++++--- .../api/soulNetwork/SoulNetworkHandler.java | 378 +++++--- .../api/spell/APISpellHelper.java | 101 +++ .../api/spell/ComplexSpellEffect.java | 92 ++ .../api/spell/ComplexSpellModifier.java | 9 + .../api/spell/ComplexSpellType.java | 9 + .../api/spell/EntitySpellProjectile.java | 650 ++++++++++++++ .../spell/ExtrapolatedMeleeEntityEffect.java | 72 ++ .../api/spell/IDigAreaEffect.java | 12 + .../api/spell/IItemManipulator.java | 10 + .../api/spell/ILeftClickEffect.java | 9 + .../api/spell/IMeleeSpellEntityEffect.java | 9 + .../api/spell/IMeleeSpellWorldEffect.java | 9 + .../api/spell/IOnBanishTool.java | 10 + .../api/spell/IOnBreakBlock.java | 12 + .../api/spell/IOnSummonTool.java | 10 + .../api/spell/IProjectileImpactEffect.java | 12 + .../api/spell/IProjectileUpdateEffect.java | 8 + .../api/spell/IRightClickEffect.java | 15 + .../api/spell/ISelfSpellEffect.java | 9 + .../api/spell/ISpecialDamageEffect.java | 10 + .../api/spell/IToolUpdateEffect.java | 10 + .../spell/MeleeSpellCenteredWorldEffect.java | 33 + .../api/spell/MeleeSpellWorldEffect.java | 21 + .../api/spell/ProjectileImpactEffect.java | 15 + .../api/spell/ProjectileUpdateEffect.java | 15 + .../api/spell/SelfSpellEffect.java | 15 + .../api/spell/SpellEffect.java | 500 +++++++++++ .../api/spell/SpellEffectRegistry.java | 159 ++++ .../api/spell/SpellEnhancement.java | 20 + .../api/spell/SpellEnhancementCost.java | 10 + .../api/spell/SpellEnhancementPotency.java | 10 + .../api/spell/SpellEnhancementPower.java | 10 + .../api/spell/SpellParadigm.java | 131 +++ .../api/spell/SpellParadigmMelee.java | 70 ++ .../api/spell/SpellParadigmProjectile.java | 101 +++ .../api/spell/SpellParadigmSelf.java | 58 ++ .../api/spell/SpellParadigmTool.java | 485 +++++++++++ .../summoningRegistry/SummoningHelper.java | 6 +- .../summoningRegistry/SummoningRegistry.java | 4 +- .../SummoningRegistryComponent.java | 2 +- .../api/tile/ISpellParadigmTile.java | 10 + .../api/tile/ISpellTile.java | 11 + 87 files changed, 6047 insertions(+), 814 deletions(-) create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/ColourAndCoords.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IAlchemyGoggles.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentContainer.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentHandler.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ISegmentedReagentHandler.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainer.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainerInfo.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentRegistry.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentStack.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileReagentHandler.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileSegmentedReagentHandler.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/event/AddToNetworkEvent.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/event/ItemBindEvent.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/event/ItemDrainNetworkEvent.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerAddToNetworkEvent.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerDrainNetworkEvent.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/event/RitualActivatedEvent.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/event/RitualEvent.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/event/RitualRunEvent.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/event/RitualStopEvent.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/event/SoulNetworkEvent.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/items/IAltarManipulator.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/items/ItemSpellMultiTool.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IReagentManipulator.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/renderer/MRSRenderer.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualBreakMethod.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellModifier.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellType.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/EntitySpellProjectile.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/ExtrapolatedMeleeEntityEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/IDigAreaEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/IItemManipulator.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/ILeftClickEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellEntityEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellWorldEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBanishTool.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBreakBlock.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnSummonTool.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileImpactEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileUpdateEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/IRightClickEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/ISelfSpellEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/ISpecialDamageEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/IToolUpdateEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellCenteredWorldEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellWorldEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileImpactEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileUpdateEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SelfSpellEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffect.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffectRegistry.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancement.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementCost.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPotency.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPower.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigm.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmMelee.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmProjectile.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmSelf.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmTool.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellParadigmTile.java create mode 100644 src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellTile.java diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/ColourAndCoords.java b/src/api/java/WayofTime/alchemicalWizardry/api/ColourAndCoords.java new file mode 100644 index 0000000..d34dd41 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/ColourAndCoords.java @@ -0,0 +1,45 @@ +package WayofTime.alchemicalWizardry.api; + +import net.minecraft.nbt.NBTTagCompound; + +public class ColourAndCoords +{ + public int colourRed; + public int colourGreen; + public int colourBlue; + public int colourIntensity; + + public int xCoord; + public int yCoord; + public int zCoord; + + public ColourAndCoords(int red, int green, int blue, int intensity, int x, int y, int z) + { + this.colourRed = red; + this.colourGreen = green; + this.colourBlue = blue; + this.colourIntensity = intensity; + + this.xCoord = x; + this.yCoord = y; + this.zCoord = z; + } + + public static ColourAndCoords readFromNBT(NBTTagCompound tag) + { + return new ColourAndCoords(tag.getInteger("colourRed"), tag.getInteger("colourGreen"), tag.getInteger("colourBlue"), tag.getInteger("colourIntensity"), tag.getInteger("xCoord"), tag.getInteger("yCoord"), tag.getInteger("zCoord")); + } + + public NBTTagCompound writeToNBT(NBTTagCompound tag) + { + tag.setInteger("colourRed", colourRed); + tag.setInteger("colourGreen", colourGreen); + tag.setInteger("colourBlue", colourBlue); + tag.setInteger("colourIntensity", colourIntensity); + tag.setInteger("xCoord", xCoord); + tag.setInteger("yCoord", yCoord); + tag.setInteger("zCoord", zCoord); + + return tag; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemicalPotionCreationHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemicalPotionCreationHandler.java index 4a4b40e..6af0491 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemicalPotionCreationHandler.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemicalPotionCreationHandler.java @@ -1,9 +1,9 @@ package WayofTime.alchemicalWizardry.api.alchemy; -import java.util.ArrayList; - import net.minecraft.item.ItemStack; +import java.util.ArrayList; + public class AlchemicalPotionCreationHandler { public static ArrayList registeredPotionEffects = new ArrayList(); diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipe.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipe.java index f773d06..aad27ee 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipe.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipe.java @@ -104,7 +104,7 @@ public class AlchemyRecipe continue; } - if ((checkedItemStack.getItemDamage() == recipeItemStack.getItemDamage() || OreDictionary.WILDCARD_VALUE == recipeItemStack.getItemDamage()) && checkedItemStack.getItem()==recipeItemStack.getItem()) + if ((checkedItemStack.getItemDamage() == recipeItemStack.getItemDamage() || OreDictionary.WILDCARD_VALUE == recipeItemStack.getItemDamage()) && checkedItemStack.getItem() == recipeItemStack.getItem()) { test = true; checkList[j] = true; @@ -135,9 +135,9 @@ public class AlchemyRecipe { return this.recipe; } - + public int getOrbLevel() { - return this.bloodOrbLevel; + return this.bloodOrbLevel; } } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipeRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipeRegistry.java index 5753cff..dfb2459 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipeRegistry.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipeRegistry.java @@ -1,11 +1,11 @@ package WayofTime.alchemicalWizardry.api.alchemy; +import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb; +import net.minecraft.item.ItemStack; + import java.util.ArrayList; import java.util.List; -import net.minecraft.item.ItemStack; -import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb; - public class AlchemyRecipeRegistry { public static List recipes = new ArrayList(); diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IAlchemyGoggles.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IAlchemyGoggles.java new file mode 100644 index 0000000..8b3e227 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IAlchemyGoggles.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IAlchemyGoggles +{ + public boolean showIngameHUD(World world, ItemStack stack, EntityPlayer player); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentContainer.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentContainer.java new file mode 100644 index 0000000..804fa72 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentContainer.java @@ -0,0 +1,16 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +public interface IReagentContainer +{ + public ReagentStack getReagent(); + + public int getReagentStackAmount(); + + public int getCapacity(); + + public int fill(ReagentStack resource, boolean doFill); + + public ReagentStack drain(int maxDrain, boolean doDrain); + + public ReagentContainerInfo getInfo(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentHandler.java new file mode 100644 index 0000000..165e9ab --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentHandler.java @@ -0,0 +1,18 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IReagentHandler +{ + int fill(ForgeDirection from, ReagentStack resource, boolean doFill); + + ReagentStack drain(ForgeDirection from, ReagentStack resource, boolean doDrain); + + ReagentStack drain(ForgeDirection from, int maxDrain, boolean doDrain); + + boolean canFill(ForgeDirection from, Reagent reagent); + + boolean canDrain(ForgeDirection from, Reagent reagent); + + ReagentContainerInfo[] getContainerInfo(ForgeDirection from); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ISegmentedReagentHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ISegmentedReagentHandler.java new file mode 100644 index 0000000..14cb51c --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ISegmentedReagentHandler.java @@ -0,0 +1,14 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import java.util.Map; + +public interface ISegmentedReagentHandler extends IReagentHandler +{ + public int getNumberOfTanks(); + + public int getTanksTunedToReagent(Reagent reagent); + + public void setTanksTunedToReagent(Reagent reagent, int total); + + public Map getAttunedTankMap(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java new file mode 100644 index 0000000..1abbc0b --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java @@ -0,0 +1,52 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +public class Reagent +{ + public final String name; + + public static final int REAGENT_SIZE = 1000; + + private int colourRed = 0; + private int colourGreen = 0; + private int colourBlue = 0; + private int colourIntensity = 255; + + public Reagent(String name) + { + this.name = name; + } + + public void setColour(int red, int green, int blue, int intensity) + { + this.colourRed = red; + this.colourGreen = green; + this.colourBlue = blue; + this.colourIntensity = intensity; + } + + public int getColourRed() + { + return colourRed; + } + + public int getColourGreen() + { + return colourGreen; + } + + public int getColourBlue() + { + return colourBlue; + } + + public int getColourIntensity() + { + return colourIntensity; + } + + @Override + public boolean equals(Object o) + { + return o instanceof Reagent ? this == o && name.equals(((Reagent) o).name) : false; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainer.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainer.java new file mode 100644 index 0000000..c135274 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainer.java @@ -0,0 +1,153 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraft.nbt.NBTTagCompound; + +public class ReagentContainer implements IReagentContainer +{ + protected ReagentStack reagentStack; + protected int capacity; + + public ReagentContainer(int capacity) + { + this(null, capacity); + } + + public ReagentContainer(ReagentStack stack, int capacity) + { + this.reagentStack = stack; + this.capacity = capacity; + } + + public ReagentContainer(Reagent reagent, int amount, int capacity) + { + this(new ReagentStack(reagent, amount), capacity); + } + + public static ReagentContainer readFromNBT(NBTTagCompound nbt) + { + ReagentStack reagent = ReagentStack.loadReagentStackFromNBT(nbt); + int capacity = nbt.getInteger("capacity"); + + if (reagent != null) + { + return new ReagentContainer(reagent, capacity); + } else + { + return new ReagentContainer(null, capacity); + } + } + + public NBTTagCompound writeToNBT(NBTTagCompound nbt) + { + if (reagentStack != null) + { + reagentStack.writeToNBT(nbt); + } + + nbt.setInteger("capacity", capacity); + + return nbt; + } + + @Override + public ReagentStack getReagent() + { + return reagentStack; + } + + @Override + public int getReagentStackAmount() + { + if (reagentStack == null) + { + return 0; + } + return reagentStack.amount; + } + + @Override + public int getCapacity() + { + return capacity; + } + + @Override + public int fill(ReagentStack resource, boolean doFill) + { + if (resource == null) + { + return 0; + } + + if (!doFill) + { + if (reagentStack == null) + { + return Math.min(capacity, resource.amount); + } + + if (!reagentStack.isReagentEqual(resource)) + { + return 0; + } + + return Math.min(capacity - reagentStack.amount, resource.amount); + } + + if (reagentStack == null) + { + reagentStack = new ReagentStack(resource, Math.min(capacity, resource.amount)); + + return reagentStack.amount; + } + + if (!reagentStack.isReagentEqual(resource)) + { + return 0; + } + int filled = capacity - reagentStack.amount; + + if (resource.amount < filled) + { + reagentStack.amount += resource.amount; + filled = resource.amount; + } else + { + reagentStack.amount = capacity; + } + + return filled; + } + + @Override + public ReagentStack drain(int maxDrain, boolean doDrain) + { + if (reagentStack == null) + { + return null; + } + + int drained = maxDrain; + if (reagentStack.amount < drained) + { + drained = reagentStack.amount; + } + + ReagentStack stack = new ReagentStack(reagentStack, drained); + if (doDrain) + { + reagentStack.amount -= drained; + if (reagentStack.amount <= 0) + { + reagentStack = null; + } + } + return stack; + } + + @Override + public ReagentContainerInfo getInfo() + { + return new ReagentContainerInfo(this); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainerInfo.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainerInfo.java new file mode 100644 index 0000000..99521dc --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainerInfo.java @@ -0,0 +1,19 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +public final class ReagentContainerInfo +{ + public final ReagentStack reagent; + public final int capacity; + + public ReagentContainerInfo(ReagentStack reagent, int capacity) + { + this.reagent = reagent; + this.capacity = capacity; + } + + public ReagentContainerInfo(IReagentContainer tank) + { + this.reagent = tank.getReagent(); + this.capacity = tank.getCapacity(); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentRegistry.java new file mode 100644 index 0000000..16306ef --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentRegistry.java @@ -0,0 +1,174 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import net.minecraft.item.ItemStack; + +public class ReagentRegistry +{ + public static Map reagentList = new HashMap(); + public static Map itemToReagentMap = new HashMap(); + + public static Reagent sanctusReagent; + public static Reagent incendiumReagent; + public static Reagent aquasalusReagent; + public static Reagent magicalesReagent; + public static Reagent aetherReagent; + public static Reagent crepitousReagent; + public static Reagent crystallosReagent; + public static Reagent terraeReagent; + public static Reagent tenebraeReagent; + + public static Reagent offensaReagent; + public static Reagent praesidiumReagent; + public static Reagent orbisTerraeReagent; + public static Reagent virtusReagent; + public static Reagent reductusReagent; + public static Reagent potentiaReagent; + + public static void initReagents() + { + sanctusReagent = new Reagent("sanctus"); + incendiumReagent = new Reagent("incendium"); + aquasalusReagent = new Reagent("aquasalus"); + magicalesReagent = new Reagent("magicales"); + aetherReagent = new Reagent("aether"); + crepitousReagent = new Reagent("crepitous"); + crystallosReagent = new Reagent("crystallos"); + terraeReagent = new Reagent("terrae"); + tenebraeReagent = new Reagent("tenebrae"); + offensaReagent = new Reagent("offensa"); + praesidiumReagent = new Reagent("praesidium"); + orbisTerraeReagent = new Reagent("orbisTerrae"); + virtusReagent = new Reagent("virtus"); + reductusReagent = new Reagent("reductus"); + potentiaReagent = new Reagent("potentia"); + + sanctusReagent.setColour(255, 255, 0, 255); + incendiumReagent.setColour(255, 0, 0, 255); + aquasalusReagent.setColour(47, 0, 196, 255); + magicalesReagent.setColour(150, 0, 146, 255); + aetherReagent.setColour(105, 223, 86, 255); + crepitousReagent.setColour(145, 145, 145, 255); + crystallosReagent.setColour(135, 255, 231, 255); + terraeReagent.setColour(147, 48, 13, 255); + tenebraeReagent.setColour(86, 86, 86, 255); + offensaReagent.setColour(126, 0, 0, 255); + praesidiumReagent.setColour(135, 135, 135, 255); + orbisTerraeReagent.setColour(32, 94, 14, 255); + virtusReagent.setColour(180, 0, 0, 255); + reductusReagent.setColour(20, 93, 2, 255); + potentiaReagent.setColour(64, 81, 208, 255); + + registerReagent("sanctus", sanctusReagent); + registerReagent("incendium", incendiumReagent); + registerReagent("aquasalus", aquasalusReagent); + registerReagent("magicales", magicalesReagent); + registerReagent("aether", aetherReagent); + registerReagent("crepitous", crepitousReagent); + registerReagent("crystallos", crystallosReagent); + registerReagent("terrae", terraeReagent); + registerReagent("tenebrae", tenebraeReagent); + registerReagent("offensa", offensaReagent); + registerReagent("praesidium", praesidiumReagent); + registerReagent("orbisTerrae", orbisTerraeReagent); + registerReagent("virtus", virtusReagent); + registerReagent("reductus", reductusReagent); + registerReagent("potentia", potentiaReagent); + } + + public static boolean registerReagent(String key, Reagent reagent) + { + if (reagentList.containsKey(key) || reagent == null) + { + return false; + } + + reagentList.put(key, reagent); + + return true; + } + + public static Reagent getReagentForKey(String key) + { + if (reagentList.containsKey(key)) + { + return reagentList.get(key); + } + + return null; + } + + public static String getKeyForReagent(Reagent reagent) + { + if (reagentList.containsValue(reagent)) + { + Set> set = reagentList.entrySet(); + for (Entry entry : set) + { + if (entry.getValue().equals(reagent)) + { + return entry.getKey(); + } + } + } + + return ""; + } + + public static void registerItemAndReagent(ItemStack stack, ReagentStack reagentStack) + { + itemToReagentMap.put(stack, reagentStack); + } + + public static ReagentStack getReagentStackForItem(ItemStack stack) + { + if (stack == null) + { + return null; + } + + for (Entry entry : itemToReagentMap.entrySet()) + { + if (entry.getKey() != null && entry.getKey().isItemEqual(stack)) + { + if (entry.getValue() == null) + { + return null; + } else + { + return entry.getValue().copy(); + } + } + } + + return null; + } + + public static ItemStack getItemForReagent(Reagent reagent) + { + if (reagent == null) + { + return null; + } + + for (Entry entry : itemToReagentMap.entrySet()) + { + if (entry.getValue() != null && entry.getValue().reagent == reagent) + { + if (entry.getKey() == null) + { + return null; + } else + { + return entry.getKey().copy(); + } + } + } + + return null; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentStack.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentStack.java new file mode 100644 index 0000000..f858397 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentStack.java @@ -0,0 +1,63 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraft.nbt.NBTTagCompound; + +public class ReagentStack +{ + public Reagent reagent; + public int amount; + + public ReagentStack(Reagent reagent, int amount) + { + this.reagent = reagent; + this.amount = amount; + } + + public ReagentStack(ReagentStack reagentStack, int amount) + { + this(reagentStack.reagent, amount); + } + + public static ReagentStack loadReagentStackFromNBT(NBTTagCompound tag) + { + Reagent reagent = ReagentRegistry.getReagentForKey(tag.getString("Reagent")); + + if (reagent == null) + { + return null; + } + + int amount = tag.getInteger("amount"); + ReagentStack stack = new ReagentStack(reagent, amount); + + return stack; + } + + public NBTTagCompound writeToNBT(NBTTagCompound tag) + { + tag.setString("Reagent", ReagentRegistry.getKeyForReagent(this.reagent)); + tag.setInteger("amount", this.amount); + + return tag; + } + + public ReagentStack splitStack(int amount) + { + ReagentStack copyStack = this.copy(); + int splitAmount = Math.min(amount, this.amount); + copyStack.amount = splitAmount; + this.amount -= splitAmount; + + return copyStack; + } + + public ReagentStack copy() + { + return new ReagentStack(this.reagent, this.amount); + } + + public boolean isReagentEqual(ReagentStack other) + { + return other != null && this.reagent == other.reagent; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileReagentHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileReagentHandler.java new file mode 100644 index 0000000..3e75464 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileReagentHandler.java @@ -0,0 +1,66 @@ + +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +public class TileReagentHandler extends TileEntity implements IReagentHandler +{ + protected ReagentContainer tank = new ReagentContainer(4000); + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT(tag); + tank.readFromNBT(tag); + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT(tag); + tank.writeToNBT(tag); + } + + /* IReagentHandler */ + @Override + public int fill(ForgeDirection from, ReagentStack resource, boolean doFill) + { + return tank.fill(resource, doFill); + } + + @Override + public ReagentStack drain(ForgeDirection from, ReagentStack resource, boolean doDrain) + { + if (resource == null || !resource.isReagentEqual(tank.getReagent())) + { + return null; + } + return tank.drain(resource.amount, doDrain); + } + + @Override + public ReagentStack drain(ForgeDirection from, int maxDrain, boolean doDrain) + { + return tank.drain(maxDrain, doDrain); + } + + @Override + public boolean canFill(ForgeDirection from, Reagent reagent) + { + return true; + } + + @Override + public boolean canDrain(ForgeDirection from, Reagent reagent) + { + return true; + } + + @Override + public ReagentContainerInfo[] getContainerInfo(ForgeDirection from) + { + return new ReagentContainerInfo[]{tank.getInfo()}; + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileSegmentedReagentHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileSegmentedReagentHandler.java new file mode 100644 index 0000000..a088b8a --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileSegmentedReagentHandler.java @@ -0,0 +1,283 @@ + +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.Constants; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +public class TileSegmentedReagentHandler extends TileEntity implements ISegmentedReagentHandler +{ + protected ReagentContainer[] tanks; + protected Map attunedTankMap; + + public TileSegmentedReagentHandler() + { + this(1); + } + + public TileSegmentedReagentHandler(int numberOfTanks) + { + this(numberOfTanks, 1000); + } + + public TileSegmentedReagentHandler(int numberOfTanks, int tankSize) + { + super(); + + this.attunedTankMap = new HashMap(); + this.tanks = new ReagentContainer[numberOfTanks]; + for (int i = 0; i < numberOfTanks; i++) + { + this.tanks[i] = new ReagentContainer(tankSize); + } + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT(tag); + + NBTTagList tagList = tag.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND); + + int size = tagList.tagCount(); + this.tanks = new ReagentContainer[size]; + + for (int i = 0; i < size; i++) + { + NBTTagCompound savedTag = tagList.getCompoundTagAt(i); + this.tanks[i] = ReagentContainer.readFromNBT(savedTag); + } + + NBTTagList attunedTagList = tag.getTagList("attunedTankMap", Constants.NBT.TAG_COMPOUND); + + for (int i = 0; i < attunedTagList.tagCount(); i++) + { + NBTTagCompound savedTag = attunedTagList.getCompoundTagAt(i); + Reagent reagent = ReagentRegistry.getReagentForKey(savedTag.getString("reagent")); + this.attunedTankMap.put(reagent, savedTag.getInteger("amount")); + } + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT(tag); + + NBTTagList tagList = new NBTTagList(); + + for (int i = 0; i < this.tanks.length; i++) + { + NBTTagCompound savedTag = new NBTTagCompound(); + if (this.tanks[i] != null) + { + this.tanks[i].writeToNBT(savedTag); + } + tagList.appendTag(savedTag); + } + + tag.setTag("reagentTanks", tagList); + + NBTTagList attunedTagList = new NBTTagList(); + + for (Entry entry : this.attunedTankMap.entrySet()) + { + NBTTagCompound savedTag = new NBTTagCompound(); + savedTag.setString("reagent", ReagentRegistry.getKeyForReagent(entry.getKey())); + savedTag.setInteger("amount", entry.getValue()); + attunedTagList.appendTag(savedTag); + } + + tag.setTag("attunedTankMap", attunedTagList); + } + + /* ISegmentedReagentHandler */ + @Override + public int fill(ForgeDirection from, ReagentStack resource, boolean doFill) + { + int totalFill = 0; + + boolean useTankLimit = !this.attunedTankMap.isEmpty(); + + if (resource != null) + { + int totalTanksFillable = useTankLimit ? this.getTanksTunedToReagent(resource.reagent) : this.tanks.length; + int tanksFilled = 0; + + int maxFill = resource.amount; + + for (int i = this.tanks.length - 1; i >= 0; i--) + { + ReagentStack remainingStack = resource.copy(); + remainingStack.amount = maxFill - totalFill; + + boolean doesReagentMatch = tanks[i].getReagent() == null ? false : tanks[i].getReagent().isReagentEqual(remainingStack); + + if (doesReagentMatch) + { + totalFill += tanks[i].fill(remainingStack, doFill); + tanksFilled++; + } else + { + continue; + } + + if (totalFill >= maxFill || tanksFilled >= totalTanksFillable) + { + return totalFill; + } + } + + if (tanksFilled >= totalTanksFillable) + { + return totalFill; + } + + for (int i = this.tanks.length - 1; i >= 0; i--) + { + ReagentStack remainingStack = resource.copy(); + remainingStack.amount = maxFill - totalFill; + + boolean isTankEmpty = tanks[i].getReagent() == null; + + if (isTankEmpty) + { + totalFill += tanks[i].fill(remainingStack, doFill); + tanksFilled++; + } else + { + continue; + } + + if (totalFill >= maxFill || tanksFilled >= totalTanksFillable) + { + return totalFill; + } + } + } + return totalFill; + } + + @Override + public ReagentStack drain(ForgeDirection from, ReagentStack resource, boolean doDrain) + { + if (resource == null) + { + return null; + } + + int maxDrain = resource.amount; + Reagent reagent = resource.reagent; + int drained = 0; + + for (int i = 0; i < tanks.length; i++) + { + if (drained >= maxDrain) + { + break; + } + + if (resource.isReagentEqual(tanks[i].getReagent())) + { + ReagentStack drainStack = tanks[i].drain(maxDrain - drained, doDrain); + if (drainStack != null) + { + drained += drainStack.amount; + } + } + } + + return new ReagentStack(reagent, drained); + } + + /* Only returns the amount from the first available tank */ + @Override + public ReagentStack drain(ForgeDirection from, int maxDrain, boolean doDrain) + { + for (int i = 0; i < tanks.length; i++) + { + ReagentStack stack = tanks[i].drain(maxDrain, doDrain); + if (stack != null) + { + return stack; + } + } + + return null; + } + + @Override + public boolean canFill(ForgeDirection from, Reagent reagent) + { + return true; + } + + @Override + public boolean canDrain(ForgeDirection from, Reagent reagent) + { + return true; + } + + @Override + public ReagentContainerInfo[] getContainerInfo(ForgeDirection from) + { + ReagentContainerInfo[] info = new ReagentContainerInfo[this.getNumberOfTanks()]; + for (int i = 0; i < this.getNumberOfTanks(); i++) + { + info[i] = tanks[i].getInfo(); + } + return info; + } + + @Override + public int getNumberOfTanks() + { + return tanks.length; + } + + @Override + public int getTanksTunedToReagent(Reagent reagent) + { + if (this.attunedTankMap.containsKey(reagent) && this.attunedTankMap.get(reagent) != null) + { + return this.attunedTankMap.get(reagent); + } + return 0; + } + + @Override + public void setTanksTunedToReagent(Reagent reagent, int total) + { + if (total == 0 && this.attunedTankMap.containsKey(reagent)) + { + this.attunedTankMap.remove(reagent); + return; + } + + this.attunedTankMap.put(reagent, new Integer(total)); + } + + @Override + public Map getAttunedTankMap() + { + return this.attunedTankMap; + } + + public boolean areTanksEmpty() + { + for (int i = 0; i < this.tanks.length; i++) + { + if (tanks[i] != null && tanks[i].reagentStack != null) + { + return false; + } + } + + return true; + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipe.java b/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipe.java index 624f219..fab96be 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipe.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipe.java @@ -1,70 +1,134 @@ package WayofTime.alchemicalWizardry.api.altarRecipeRegistry; -import net.minecraft.item.ItemStack; +import java.util.Set; -public class AltarRecipe +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; + +public class AltarRecipe { - public int minTier; - public int liquidRequired; - public boolean canBeFilled; //Tells the system that the item is an orb - public int consumptionRate; - public int drainRate; - public ItemStack requiredItem; - public ItemStack result; - - public AltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled) - { - this.result = result; - this.requiredItem = requiredItem; - this.minTier = minTier; - this.liquidRequired = liquidRequired; - this.consumptionRate = consumptionRate; - this.drainRate = drainRate; - this.canBeFilled = canBeFilled; - } - - public ItemStack getResult() - { - return this.result; - } - - public ItemStack getRequiredItem() - { - return this.requiredItem; - } - - public boolean doesRequiredItemMatch(ItemStack comparedStack, int tierCheck) - { - if(comparedStack == null || this.requiredItem == null) - { - return false; - } - - return tierCheck>=minTier && this.requiredItem.isItemEqual(comparedStack); - } - - public int getMinTier() - { - return this.minTier; - } - - public int getLiquidRequired() - { - return this.liquidRequired; - } - - public int getConsumptionRate() - { - return this.consumptionRate; - } - - public int getDrainRate() - { - return this.drainRate; - } - - public boolean getCanBeFilled() - { - return this.canBeFilled; - } + public int minTier; + public int liquidRequired; + public boolean canBeFilled; //Tells the system that the item is an orb + public int consumptionRate; + public int drainRate; + public ItemStack requiredItem; + public ItemStack result; + public boolean useTag; + + public AltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled) + { + this(result, requiredItem, minTier, liquidRequired, consumptionRate, drainRate, canBeFilled, false); + } + + public AltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled, boolean useTag) + { + this.result = result; + this.requiredItem = requiredItem; + this.minTier = minTier; + this.liquidRequired = liquidRequired; + this.consumptionRate = consumptionRate; + this.drainRate = drainRate; + this.canBeFilled = canBeFilled; + this.useTag = useTag; + } + + public ItemStack getResult() + { + return this.result; + } + + public ItemStack getRequiredItem() + { + return this.requiredItem; + } + + public boolean doesRequiredItemMatch(ItemStack comparedStack, int tierCheck) + { + if (comparedStack == null || this.requiredItem == null) + { + return false; + } + + return tierCheck >= minTier && this.requiredItem.isItemEqual(comparedStack) && (this.useTag ? this.areRequiredTagsEqual(comparedStack) : true); + } + + public boolean areRequiredTagsEqual(ItemStack comparedStack) + { + if(requiredItem.hasTagCompound()) + { + NBTTagCompound tag = requiredItem.getTagCompound(); + if(!comparedStack.hasTagCompound()) + { + return false; + } + + NBTTagCompound comparedTag = comparedStack.getTagCompound(); + + return this.areTagsEqual(tag, comparedTag); + } + + return true; + } + + protected boolean areTagsEqual(NBTTagCompound tag, NBTTagCompound comparedTag) + { + Set set = tag.func_150296_c(); + + for(Object obj : set) + { + if(obj instanceof String) + { + String str = (String)obj; + + NBTBase baseTag = comparedTag.getTag(str); + + if(baseTag instanceof NBTTagCompound) + { + NBTBase comparedBaseTag = comparedTag.getTag(str); + if(comparedBaseTag instanceof NBTTagCompound) + { + if(!this.areTagsEqual((NBTTagCompound) tag, comparedTag)) + { + return false; + } + } + }else + { + if(baseTag != null && !baseTag.equals(comparedTag.getTag(str))) + { + return false; + } + } + } + } + + return true; + } + + public int getMinTier() + { + return this.minTier; + } + + public int getLiquidRequired() + { + return this.liquidRequired; + } + + public int getConsumptionRate() + { + return this.consumptionRate; + } + + public int getDrainRate() + { + return this.drainRate; + } + + public boolean getCanBeFilled() + { + return this.canBeFilled; + } } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipeRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipeRegistry.java index 89c0be4..d8077f3 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipeRegistry.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipeRegistry.java @@ -1,60 +1,65 @@ package WayofTime.alchemicalWizardry.api.altarRecipeRegistry; +import net.minecraft.item.ItemStack; + import java.util.LinkedList; import java.util.List; -import net.minecraft.item.ItemStack; - -public class AltarRecipeRegistry +public class AltarRecipeRegistry { - public static List altarRecipes = new LinkedList(); - - public static void registerAltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled) - { - altarRecipes.add(new AltarRecipe(result, requiredItem, minTier, liquidRequired, consumptionRate, drainRate, canBeFilled)); - } - - public static void registerAltarOrbRecipe(ItemStack orbStack, int minTier, int consumptionRate) - { - registerAltarRecipe(null, orbStack, minTier, 0, consumptionRate, 0, true); - } - - public static boolean isRequiredItemValid(ItemStack testItem, int currentTierAltar) - { - for(AltarRecipe recipe : altarRecipes) - { - if(recipe.doesRequiredItemMatch(testItem, currentTierAltar)) - { - return true; - } - } - - return false; - } - - public static ItemStack getItemForItemAndTier(ItemStack testItem, int currentTierAltar) - { - for(AltarRecipe recipe : altarRecipes) - { - if(recipe.doesRequiredItemMatch(testItem, currentTierAltar)) - { - return ItemStack.copyItemStack(recipe.getResult()); - } - } - - return null; - } - - public static AltarRecipe getAltarRecipeForItemAndTier(ItemStack testItem, int currentTierAltar) - { - for(AltarRecipe recipe : altarRecipes) - { - if(recipe.doesRequiredItemMatch(testItem, currentTierAltar)) - { - return recipe; - } - } - - return null; - } + public static List altarRecipes = new LinkedList(); + + public static void registerAltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled) + { + altarRecipes.add(new AltarRecipe(result, requiredItem, minTier, liquidRequired, consumptionRate, drainRate, canBeFilled)); + } + + public static void registerNBTAltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled) + { + altarRecipes.add(new AltarRecipe(result, requiredItem, minTier, liquidRequired, consumptionRate, drainRate, canBeFilled, true)); + } + + public static void registerAltarOrbRecipe(ItemStack orbStack, int minTier, int consumptionRate) + { + registerAltarRecipe(null, orbStack, minTier, 0, consumptionRate, 0, true); + } + + public static boolean isRequiredItemValid(ItemStack testItem, int currentTierAltar) + { + for (AltarRecipe recipe : altarRecipes) + { + if (recipe.doesRequiredItemMatch(testItem, currentTierAltar)) + { + return true; + } + } + + return false; + } + + public static ItemStack getItemForItemAndTier(ItemStack testItem, int currentTierAltar) + { + for (AltarRecipe recipe : altarRecipes) + { + if (recipe.doesRequiredItemMatch(testItem, currentTierAltar)) + { + return ItemStack.copyItemStack(recipe.getResult()); + } + } + + return null; + } + + public static AltarRecipe getAltarRecipeForItemAndTier(ItemStack testItem, int currentTierAltar) + { + for (AltarRecipe recipe : altarRecipes) + { + if (recipe.doesRequiredItemMatch(testItem, currentTierAltar)) + { + return recipe; + } + } + + return null; + } } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRecipe.java b/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRecipe.java index f8d6385..fc0ba2d 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRecipe.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRecipe.java @@ -2,29 +2,34 @@ package WayofTime.alchemicalWizardry.api.bindingRegistry; import net.minecraft.item.ItemStack; -public class BindingRecipe +public class BindingRecipe { - public ItemStack requiredItem; - public ItemStack outputItem; - - public BindingRecipe(ItemStack outputItem, ItemStack requiredItem) - { - this.requiredItem = requiredItem; - this.outputItem = outputItem; - } - - public boolean doesRequiredItemMatch(ItemStack testStack) - { - if(testStack == null || this.requiredItem == null) - { - return false; - } - - return this.requiredItem.isItemEqual(testStack); - } - - public ItemStack getResult() - { - return this.outputItem; - } + public ItemStack requiredItem; + public ItemStack outputItem; + + public BindingRecipe(ItemStack outputItem, ItemStack requiredItem) + { + this.requiredItem = requiredItem; + this.outputItem = outputItem; + } + + public boolean doesRequiredItemMatch(ItemStack testStack) + { + if (testStack == null || this.requiredItem == null) + { + return false; + } + + return this.requiredItem.isItemEqual(testStack); + } + + public ItemStack getResult(ItemStack inputItem) + { + return this.getResult(); + } + + public ItemStack getResult() + { + return this.outputItem; + } } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRegistry.java index 68f34e4..ba06911 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRegistry.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRegistry.java @@ -1,67 +1,67 @@ package WayofTime.alchemicalWizardry.api.bindingRegistry; +import net.minecraft.item.ItemStack; + import java.util.LinkedList; import java.util.List; -import net.minecraft.item.ItemStack; - -public class BindingRegistry +public class BindingRegistry { - public static List bindingRecipes = new LinkedList(); + public static List bindingRecipes = new LinkedList(); - public static void registerRecipe(ItemStack output, ItemStack input) - { - bindingRecipes.add(new BindingRecipe(output, input)); - } - - public static boolean isRequiredItemValid(ItemStack testItem) - { - for(BindingRecipe recipe : bindingRecipes) - { - if(recipe.doesRequiredItemMatch(testItem)) - { - return true; - } - } - - return false; - } - - public static ItemStack getItemForItemAndTier(ItemStack testItem) - { - for(BindingRecipe recipe : bindingRecipes) - { - if(recipe.doesRequiredItemMatch(testItem)) - { - return recipe.getResult().copy(); - } - } - - return null; - } - - public static int getIndexForItem(ItemStack testItem) - { - int i=0; - for(BindingRecipe recipe : bindingRecipes) - { - if(recipe.doesRequiredItemMatch(testItem)) - { - return i; - } - i++; - } - - return -1; - } - - public static ItemStack getOutputForIndex(int index) - { - if(bindingRecipes.size()<=index) - { - return null; - } - - return bindingRecipes.get(index).getResult(); - } + public static void registerRecipe(ItemStack output, ItemStack input) + { + bindingRecipes.add(new BindingRecipe(output, input)); + } + + public static boolean isRequiredItemValid(ItemStack testItem) + { + for (BindingRecipe recipe : bindingRecipes) + { + if (recipe.doesRequiredItemMatch(testItem)) + { + return true; + } + } + + return false; + } + + public static ItemStack getItemForItemAndTier(ItemStack testItem) + { + for (BindingRecipe recipe : bindingRecipes) + { + if (recipe.doesRequiredItemMatch(testItem)) + { + return recipe.getResult(testItem).copy(); + } + } + + return null; + } + + public static int getIndexForItem(ItemStack testItem) + { + int i = 0; + for (BindingRecipe recipe : bindingRecipes) + { + if (recipe.doesRequiredItemMatch(testItem)) + { + return i; + } + i++; + } + + return -1; + } + + public static ItemStack getOutputForIndex(int index) + { + if (bindingRecipes.size() <= index) + { + return null; + } + + return bindingRecipes.get(index).getResult(); + } } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/AddToNetworkEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/AddToNetworkEvent.java new file mode 100644 index 0000000..ddcc3b0 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/AddToNetworkEvent.java @@ -0,0 +1,38 @@ +package WayofTime.alchemicalWizardry.api.event; + +import cpw.mods.fml.common.eventhandler.Cancelable; +import cpw.mods.fml.common.eventhandler.Event; + +@Cancelable +public class AddToNetworkEvent extends Event +{ + public String ownerNetwork; + public int addedAmount; + public int maximum; + + /** + * This event is called whenever the network is added to. If cancelled, no LP will be drained from the source. If result is set to Result.DENY, + * the LP will still be drained but the soul network will not be added to. + * + * @param ownerNetwork Key used for the soul network + * @param addedAmount Amount added + * @param maximum Ceiling that the network can add to + */ + public AddToNetworkEvent(String ownerNetwork, int addedAmount, int maximum) + { + super(); + this.ownerNetwork = ownerNetwork; + this.addedAmount = addedAmount; + this.maximum = maximum; + } + + public String getOwnerNetwork() + { + return this.ownerNetwork; + } + + public int getAddedAmount() + { + return this.addedAmount; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemBindEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemBindEvent.java new file mode 100644 index 0000000..a0a9273 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemBindEvent.java @@ -0,0 +1,20 @@ +package WayofTime.alchemicalWizardry.api.event; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import cpw.mods.fml.common.eventhandler.Event; + +public class ItemBindEvent extends Event +{ + public final EntityPlayer player; + public String key; + public ItemStack itemStack; + + public ItemBindEvent(EntityPlayer player, String key, ItemStack itemStack) + { + super(); + this.player = player; + this.key = key; + this.itemStack = itemStack; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemDrainNetworkEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemDrainNetworkEvent.java new file mode 100644 index 0000000..d75fd7d --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemDrainNetworkEvent.java @@ -0,0 +1,29 @@ +package WayofTime.alchemicalWizardry.api.event; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import cpw.mods.fml.common.eventhandler.Cancelable; + +@Cancelable +public class ItemDrainNetworkEvent extends PlayerDrainNetworkEvent +{ + public final ItemStack itemStack; + public boolean shouldDamage; //If true, will damage regardless of if the network had enough inside it + public float damageAmount; //Amount of damage that would incur if the network could not drain properly + + /** + * Set result to deny the action i.e. damage/drain anyways. Cancelling event prevents action without penalties + * + * @param player Player using the item + * @param ownerNetwork Network that the item is tied to + * @param itemStack Item used + * @param drainAmount Original drain amount - change to alter cost + */ + public ItemDrainNetworkEvent(EntityPlayer player, String ownerNetwork, ItemStack itemStack, int drainAmount) + { + super(player, ownerNetwork, drainAmount); + this.itemStack = itemStack; + this.shouldDamage = false; + this.damageAmount = (float)(drainAmount) / 100.0f; + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerAddToNetworkEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerAddToNetworkEvent.java new file mode 100644 index 0000000..f752255 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerAddToNetworkEvent.java @@ -0,0 +1,18 @@ +package WayofTime.alchemicalWizardry.api.event; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import cpw.mods.fml.common.eventhandler.Cancelable; + +@Cancelable +public class PlayerAddToNetworkEvent extends AddToNetworkEvent +{ + public final EntityPlayer player; + public ItemStack itemStack; + public PlayerAddToNetworkEvent(EntityPlayer player, ItemStack itemStack, String ownerNetwork, int addedAmount, int maximum) + { + super(ownerNetwork, addedAmount, maximum); + this.player = player; + this.itemStack = itemStack; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerDrainNetworkEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerDrainNetworkEvent.java new file mode 100644 index 0000000..dacb26d --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerDrainNetworkEvent.java @@ -0,0 +1,20 @@ +package WayofTime.alchemicalWizardry.api.event; + +import net.minecraft.entity.player.EntityPlayer; +import cpw.mods.fml.common.eventhandler.Cancelable; + +@Cancelable +public class PlayerDrainNetworkEvent extends SoulNetworkEvent +{ + public final EntityPlayer player; //Player that activated the event + public PlayerDrainNetworkEvent(EntityPlayer player, String ownerNetwork, int drainAmount) + { + super(ownerNetwork, drainAmount); + this.player = player; + } + + public EntityPlayer getPlayer() + { + return player; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualActivatedEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualActivatedEvent.java new file mode 100644 index 0000000..83c10c0 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualActivatedEvent.java @@ -0,0 +1,23 @@ +package WayofTime.alchemicalWizardry.api.event; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone; +import cpw.mods.fml.common.eventhandler.Cancelable; + +@Cancelable +public class RitualActivatedEvent extends RitualEvent +{ + public final EntityPlayer player; + public final ItemStack crystalStack; + public int crystalTier; + + public RitualActivatedEvent(IMasterRitualStone mrs, String ownerKey, String ritualKey, EntityPlayer player, ItemStack activationCrystal, int crystalTier) + { + super(mrs, ownerKey, ritualKey); + + this.player = player; + this.crystalStack = activationCrystal; + this.crystalTier = crystalTier; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualEvent.java new file mode 100644 index 0000000..fbe1649 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualEvent.java @@ -0,0 +1,18 @@ +package WayofTime.alchemicalWizardry.api.event; + +import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone; +import cpw.mods.fml.common.eventhandler.Event; + +public class RitualEvent extends Event +{ + public final IMasterRitualStone mrs; + public String ownerKey; + public final String ritualKey; + + public RitualEvent(IMasterRitualStone mrs, String ownerKey, String ritualKey) + { + this.mrs = mrs; + this.ownerKey = ownerKey; + this.ritualKey = ritualKey; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualRunEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualRunEvent.java new file mode 100644 index 0000000..4bcf075 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualRunEvent.java @@ -0,0 +1,16 @@ +package WayofTime.alchemicalWizardry.api.event; + +import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone; +import cpw.mods.fml.common.eventhandler.Cancelable; + +@Cancelable +public class RitualRunEvent extends RitualEvent +{ + + + public RitualRunEvent(IMasterRitualStone mrs, String ownerKey, String ritualKey) + { + super(mrs, ownerKey, ritualKey); + } + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualStopEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualStopEvent.java new file mode 100644 index 0000000..4fc998f --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualStopEvent.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.event; + +import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone; +import WayofTime.alchemicalWizardry.api.rituals.RitualBreakMethod; + +public class RitualStopEvent extends RitualEvent +{ + public final RitualBreakMethod method; + public RitualStopEvent(IMasterRitualStone mrs, String ownerKey, String ritualKey, RitualBreakMethod method) + { + super(mrs, ownerKey, ritualKey); + + this.method = method; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/SoulNetworkEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/SoulNetworkEvent.java new file mode 100644 index 0000000..bf47a13 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/SoulNetworkEvent.java @@ -0,0 +1,26 @@ +package WayofTime.alchemicalWizardry.api.event; + +import cpw.mods.fml.common.eventhandler.Event; + +public class SoulNetworkEvent extends Event +{ + public String ownerNetwork; + public int drainAmount; + + public SoulNetworkEvent(String ownerNetwork, int drainAmount) + { + super(); + this.ownerNetwork = ownerNetwork; + this.drainAmount = drainAmount; + } + + public String getOwnerNetwork() + { + return this.ownerNetwork; + } + + public int getDrainAmount() + { + return this.drainAmount; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/harvest/HarvestRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/harvest/HarvestRegistry.java index 0d91715..aac57f5 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/harvest/HarvestRegistry.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/harvest/HarvestRegistry.java @@ -1,34 +1,33 @@ package WayofTime.alchemicalWizardry.api.harvest; -import java.util.ArrayList; -import java.util.List; - import net.minecraft.block.Block; import net.minecraft.world.World; -public class HarvestRegistry +import java.util.ArrayList; +import java.util.List; + +public class HarvestRegistry { - public static List handlerList = new ArrayList(); - - public static void registerHarvestHandler(IHarvestHandler handler) - { - System.out.println("Heeeeelllooooo"); - handlerList.add(handler); - } - - public static boolean harvestBlock(World world, int xCoord, int yCoord, int zCoord) - { - Block block = world.getBlock(xCoord, yCoord, zCoord); - int meta = world.getBlockMetadata(xCoord, yCoord, zCoord); - - for(IHarvestHandler handler : handlerList) - { - if(handler.harvestAndPlant(world, xCoord, yCoord, zCoord, block, meta)) - { - return true; - } - } - - return false; - } + public static List handlerList = new ArrayList(); + + public static void registerHarvestHandler(IHarvestHandler handler) + { + handlerList.add(handler); + } + + public static boolean harvestBlock(World world, int xCoord, int yCoord, int zCoord) + { + Block block = world.getBlock(xCoord, yCoord, zCoord); + int meta = world.getBlockMetadata(xCoord, yCoord, zCoord); + + for (IHarvestHandler handler : handlerList) + { + if (handler.harvestAndPlant(world, xCoord, yCoord, zCoord, block, meta)) + { + return true; + } + } + + return false; + } } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/harvest/IHarvestHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/harvest/IHarvestHandler.java index 888dff5..d5e479d 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/harvest/IHarvestHandler.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/harvest/IHarvestHandler.java @@ -2,20 +2,19 @@ package WayofTime.alchemicalWizardry.api.harvest; import net.minecraft.block.Block; import net.minecraft.world.World; -import net.minecraftforge.common.IPlantable; -public interface IHarvestHandler -{ - /** - * A handler that is used to harvest and replant the block at the specified location - * - * @param world - * @param xCoord - * @param yCoord - * @param zCoord - * @param block block at this given location - * @param meta meta at this given location - * @return true if successfully harvested, false if not - */ - public boolean harvestAndPlant(World world, int xCoord, int yCoord, int zCoord, Block block, int meta); +public interface IHarvestHandler +{ + /** + * A handler that is used to harvest and replant the block at the specified location + * + * @param world + * @param xCoord + * @param yCoord + * @param zCoord + * @param block block at this given location + * @param meta meta at this given location + * @return true if successfully harvested, false if not + */ + public boolean harvestAndPlant(World world, int xCoord, int yCoord, int zCoord, Block block, int meta); } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/IAltarManipulator.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/IAltarManipulator.java new file mode 100644 index 0000000..b84f95c --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/IAltarManipulator.java @@ -0,0 +1,6 @@ +package WayofTime.alchemicalWizardry.api.items; + +public interface IAltarManipulator +{ + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/ItemSpellMultiTool.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/ItemSpellMultiTool.java new file mode 100644 index 0000000..72f0c83 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/ItemSpellMultiTool.java @@ -0,0 +1,806 @@ +package WayofTime.alchemicalWizardry.api.items; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.common.util.Constants; +import net.minecraftforge.common.util.ForgeDirection; +import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; +import WayofTime.alchemicalWizardry.api.spell.APISpellHelper; +import WayofTime.alchemicalWizardry.api.spell.SpellEffect; +import WayofTime.alchemicalWizardry.api.spell.SpellParadigmTool; + +public class ItemSpellMultiTool extends Item +{ + private static final String harvestLevelSuffix = "harvestLvl"; + private static final String digLevelSuffix = "digLvl"; + private static final String tagName = "BloodMagicTool"; + private Random rand = new Random(); + + public ItemSpellMultiTool() + { + super(); + this.setMaxDamage(0); + this.setMaxStackSize(1); + this.setFull3D(); + } + + @Override + public void registerIcons(IIconRegister iconRegister) + { + this.itemIcon = iconRegister.registerIcon("AlchemicalWizardry:BoundTool"); + } + + @Override + public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase) + { + float damage = this.getCustomItemAttack(par1ItemStack); + + SpellParadigmTool parad = this.loadParadigmFromStack(par1ItemStack); + + if (parad != null) + { + parad.onLeftClickEntity(par1ItemStack, par2EntityLivingBase, par3EntityLivingBase); + } + + damage += parad.getAddedDamageForEntity(par2EntityLivingBase); + + if (rand.nextFloat() < this.getCritChance(par1ItemStack)) + { + damage *= 1.75f; + } + + if (par3EntityLivingBase instanceof EntityPlayer) + { + par2EntityLivingBase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) par3EntityLivingBase), damage); + } else + { + par2EntityLivingBase.attackEntityFrom(DamageSource.causeMobDamage(par3EntityLivingBase), damage); + } + + return true; + } + + @Override + public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) + { + SpellParadigmTool parad = this.loadParadigmFromStack(stack); + + if (parad != null && entity instanceof EntityLivingBase) + { + parad.onLeftClickEntity(stack, (EntityLivingBase) entity, player); + } + + return false; + } + + @Override + public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) + { + if (player.worldObj.isRemote) + { + return false; + } + + if (!stack.hasTagCompound()) + return false; + + World world = player.worldObj; + Block block = player.worldObj.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + if (block == null || block == Blocks.air) + return false; + int hlvl = -1; + float blockHardness = block.getBlockHardness(world, x, y, z); + + MovingObjectPosition mop = APISpellHelper.raytraceFromEntity(world, player, true, 5.0D); + + Block localBlock = world.getBlock(x, y, z); + int localMeta = world.getBlockMetadata(x, y, z); + String toolClass = block.getHarvestTool(meta); + if (toolClass != null && this.getHarvestLevel(stack, toolClass) != -1) + hlvl = block.getHarvestLevel(meta); + int toolLevel = this.getHarvestLevel(stack, toolClass); + + float localHardness = localBlock == null ? Float.MAX_VALUE : localBlock.getBlockHardness(world, x, y, z); + + if (hlvl <= toolLevel && localHardness - 1.5 <= blockHardness) + { + boolean cancelHarvest = false; + + if (!cancelHarvest) + { + if (localBlock != null && !(localHardness < 0)) + { + boolean isEffective = false; + + String localToolClass = this.getToolClassForMaterial(localBlock.getMaterial()); + + if (localToolClass != null && this.getHarvestLevel(stack, toolClass) >= localBlock.getHarvestLevel(localMeta)) + { + isEffective = true; + } + + + if (localBlock.getMaterial().isToolNotRequired()) + { + isEffective = true; + } + + if (!player.capabilities.isCreativeMode) + { + if (isEffective) + { + if (localBlock.removedByPlayer(world, player, x, y, z)) + { + localBlock.onBlockDestroyedByPlayer(world, x, y, z, localMeta); + } + localBlock.onBlockHarvested(world, x, y, z, localMeta, player); + if (blockHardness > 0f) + onBlockDestroyed(stack, world, localBlock, x, y, z, player); + + List items = APISpellHelper.getItemsFromBlock(world, localBlock, x, y, z, localMeta, this.getSilkTouch(stack), this.getFortuneLevel(stack)); + + SpellParadigmTool parad = this.loadParadigmFromStack(stack); + List newItems = parad.handleItemList(stack, items); + + if (!world.isRemote) + { + APISpellHelper.spawnItemListInWorld(newItems, world, x + 0.5f, y + 0.5f, z + 0.5f); + } + + world.func_147479_m(x, y, z); + + int cost = 0; + + cost += parad.digSurroundingArea(stack, world, player, mop, localToolClass, localHardness, toolLevel, this); + + cost += parad.onBreakBlock(stack, world, player, localBlock, localMeta, x, y, z, ForgeDirection.getOrientation(mop.sideHit)); + + if (cost > 0) + { + SoulNetworkHandler.syphonAndDamageFromNetwork(stack, player, cost); + } + } else + { + world.setBlockToAir(x, y, z); + world.func_147479_m(x, y, z); + } + + } else + { + world.setBlockToAir(x, y, z); + world.func_147479_m(x, y, z); + } + } + } + } + + if (!world.isRemote) + world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); + return true; + + } + + public Material[] getMaterialsForToolclass(String toolClass) + { + if ("pickaxe".equals(toolClass)) + { + return new Material[]{Material.rock, Material.iron, Material.ice, Material.glass, Material.piston, Material.anvil, Material.circuits}; + } else if ("shovel".equals(toolClass)) + { + return new Material[]{Material.grass, Material.ground, Material.sand, Material.snow, Material.craftedSnow, Material.clay}; + } else if ("axe".equals(toolClass)) + { + return new Material[]{Material.wood, Material.vine, Material.circuits, Material.cactus}; + } + return new Material[0]; + } + + public String getToolClassForMaterial(Material mat) + { + String testString = "pickaxe"; + + Material[] matList = this.getMaterialsForToolclass(testString); + for (int i = 0; i < matList.length; i++) + { + if (matList[i] == mat) + { + return testString; + } + } + + testString = "shovel"; + matList = this.getMaterialsForToolclass(testString); + for (int i = 0; i < matList.length; i++) + { + if (matList[i] == mat) + { + return testString; + } + } + + testString = "axe"; + matList = this.getMaterialsForToolclass(testString); + for (int i = 0; i < matList.length; i++) + { + if (matList[i] == mat) + { + return testString; + } + } + + return null; + } + + public Set getToolClasses(ItemStack stack) + { + Set set = new HashSet(); + + if (this.getHarvestLevel(stack, "pickaxe") > -1) + { + set.add("pickaxe"); + } + + if (this.getHarvestLevel(stack, "axe") > -1) + { + set.add("axe"); + } + + if (this.getHarvestLevel(stack, "shovel") > -1) + { + set.add("shovel"); + } + + return set; + } + + @Override + public float getDigSpeed(ItemStack stack, Block block, int meta) + { + String toolClass = block.getHarvestTool(meta); + + if (toolClass == null || toolClass.equals("")) + { + return 1.0f; + } + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + return tag.getFloat(digLevelSuffix + toolClass); + } else + { + stack.setTagCompound(new NBTTagCompound()); + } + } + + return 1.0f; + } + + @Override + public int getHarvestLevel(ItemStack stack, String toolClass) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + if (tag.hasKey(harvestLevelSuffix + toolClass)) + { + return tag.getInteger(harvestLevelSuffix + toolClass); + } else + { + return -1; + } + } else + { + stack.setTagCompound(new NBTTagCompound()); + } + + return -1; + } + + @Override + public boolean canHarvestBlock(Block par1Block, ItemStack itemStack) + { + + return true; + } + + @Override + public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) + { + return false; + } + + @Override + public void onUpdate(ItemStack toolStack, World world, Entity par3Entity, int par4, boolean par5) + { + if (world.isRemote) + { + return; + } + + SpellParadigmTool parad = this.loadParadigmFromStack(toolStack); + int cost = parad.onUpdate(toolStack, world, par3Entity, par4, par5); + + if (par3Entity instanceof EntityPlayer && cost > 0) + SoulNetworkHandler.syphonAndDamageFromNetwork(toolStack, (EntityPlayer) par3Entity, cost); + + int duration = Math.max(this.getDuration(toolStack, world), 0); + + if (duration <= 0 && par3Entity instanceof EntityPlayer) + { + int banishCost = parad.onBanishTool(toolStack, world, par3Entity, par4, par5); + SoulNetworkHandler.syphonAndDamageFromNetwork(toolStack, (EntityPlayer) par3Entity, banishCost); + ((EntityPlayer) par3Entity).inventory.mainInventory[par4] = this.getContainedCrystal(toolStack); + } + } + + @Override + public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) + { + if (par3EntityPlayer.isSneaking()) + { + par3EntityPlayer.setCurrentItemOrArmor(0, this.getContainedCrystal(par1ItemStack)); + return par1ItemStack; + } + + SpellParadigmTool parad = this.loadParadigmFromStack(par1ItemStack); + + MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, false); + + int cost = 0; + + if (mop != null && mop.typeOfHit.equals(MovingObjectPosition.MovingObjectType.BLOCK)) + { + cost = parad.onRightClickBlock(par1ItemStack, par3EntityPlayer, par2World, mop); + } else + { + cost = parad.onRightClickAir(par1ItemStack, par2World, par3EntityPlayer); + } + + if (cost > 0) + { + SoulNetworkHandler.syphonAndDamageFromNetwork(par1ItemStack, par3EntityPlayer, cost); + } + + return par1ItemStack; + } + + @Override + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + { + par3List.add("A mace filled with ancient alchemy"); + + if (!(par1ItemStack.stackTagCompound == null)) + { + if (!par1ItemStack.stackTagCompound.getString("ownerName").equals("")) + { + par3List.add("Current owner: " + par1ItemStack.stackTagCompound.getString("ownerName")); + } + + for (String str : this.getToolListString(par1ItemStack)) + { + par3List.add(str); + } + + par3List.add(""); + float damage = this.getCustomItemAttack(par1ItemStack); + par3List.add("\u00A79+" + ((int) (damage * 10)) / 10.0f + " " + "Attack Damage"); + float critChance = ((int) (this.getCritChance(par1ItemStack) * 1000)) / 10.0f; + par3List.add("\u00A79+" + critChance + "% " + "Crit Chance"); + } + } + + //--------------Custom methods--------------// + + public void setHarvestLevel(ItemStack stack, String toolClass, int harvestLevel) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setInteger(harvestLevelSuffix + toolClass, Math.max(-1, harvestLevel)); + + stack.getTagCompound().setTag(tagName, tag); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setInteger(harvestLevelSuffix + toolClass, Math.max(-1, harvestLevel)); + + stack.getTagCompound().setTag(tagName, tag); + } + } + + public void setDigSpeed(ItemStack stack, String toolClass, float digSpeed) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setFloat(digLevelSuffix + toolClass, digSpeed); + + stack.getTagCompound().setTag(tagName, tag); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setFloat(digLevelSuffix + toolClass, digSpeed); + + stack.getTagCompound().setTag(tagName, tag); + } + } + + public float getDigSpeed(ItemStack stack, String toolClass) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + return tag.getFloat(digLevelSuffix + toolClass); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + return 0.0f; + } + } + + public void setItemAttack(ItemStack stack, float damage) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setFloat("itemAttack", Math.max(damage, 0.0f)); + + stack.stackTagCompound.setTag(tagName, tag); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setFloat("itemAttack", Math.max(damage, 0.0f)); + + stack.stackTagCompound.setTag(tagName, tag); + } + } + + public float getCustomItemAttack(ItemStack stack) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + return tag.getFloat("itemAttack"); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + return 0.0f; + } + } + + public ItemStack getContainedCrystal(ItemStack container) + { + if (container.hasTagCompound()) + { + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName).getCompoundTag("heldItem"); + + return ItemStack.loadItemStackFromNBT(tag); + } else + { + container.setTagCompound(new NBTTagCompound()); + + return null; + } + } + + public void setContainedCrystal(ItemStack container, ItemStack crystal) + { + if (container.hasTagCompound()) + { + NBTTagCompound compTag = container.getTagCompound().getCompoundTag(tagName); + NBTTagCompound tag = compTag.getCompoundTag("heldItem"); + + crystal.writeToNBT(tag); + + compTag.setTag("heldItem", tag); + container.getTagCompound().setTag(tagName, compTag); + } else + { + container.setTagCompound(new NBTTagCompound()); + + NBTTagCompound compTag = container.getTagCompound().getCompoundTag(tagName); + NBTTagCompound tag = compTag.getCompoundTag("heldItem"); + + crystal.writeToNBT(tag); + + compTag.setTag("heldItem", tag); + container.getTagCompound().setTag(tagName, compTag); + } + } + + public void setDuration(ItemStack container, World world, int duration) + { + if (world.isRemote) + { + return; + } else + { + World overWorld = DimensionManager.getWorld(0); + long worldtime = overWorld.getTotalWorldTime(); + + if (container.hasTagCompound()) + { + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + tag.setLong("duration", Math.max(duration + worldtime, worldtime)); + + container.getTagCompound().setTag(tagName, tag); + } else + { + container.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + tag.setLong("duration", Math.max(duration + worldtime, worldtime)); + + container.getTagCompound().setTag(tagName, tag); + } + } + } + + public int getDuration(ItemStack container, World world) + { + if (world.isRemote) + { + return 0; + } else + { + World overWorld = DimensionManager.getWorld(0); + long worldtime = overWorld.getTotalWorldTime(); + + if (container.hasTagCompound()) + { + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + return (int) (tag.getLong("duration") - worldtime); + } else + { + container.setTagCompound(new NBTTagCompound()); + + return 0; + } + } + } + + public void loadParadigmIntoStack(ItemStack container, List list) + { + if (!container.hasTagCompound()) + { + container.setTagCompound(new NBTTagCompound()); + } + + NBTTagCompound tagiest = container.getTagCompound().getCompoundTag(tagName); + + NBTTagList effectList = new NBTTagList(); + + for (SpellEffect eff : list) + { + effectList.appendTag(eff.getTag()); + } + + tagiest.setTag("Effects", effectList); + + container.getTagCompound().setTag(tagName, tagiest); + } + + public SpellParadigmTool loadParadigmFromStack(ItemStack container) + { + if (!container.hasTagCompound()) + { + container.setTagCompound(new NBTTagCompound()); + } + NBTTagCompound tagiest = container.getTagCompound().getCompoundTag(tagName); + + NBTTagList tagList = tagiest.getTagList("Effects", Constants.NBT.TAG_COMPOUND); + + List spellEffectList = new LinkedList(); + for (int i = 0; i < tagList.tagCount(); i++) + { + NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); + + SpellEffect eff = SpellEffect.getEffectFromTag(tag); + if (eff != null) + { + spellEffectList.add(eff); + } + } + + return SpellParadigmTool.getParadigmForEffectArray(spellEffectList); + } + + public void setSilkTouch(ItemStack stack, boolean silkTouch) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setBoolean("silkTouch", silkTouch); + + stack.stackTagCompound.setTag(tagName, tag); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setBoolean("silkTouch", silkTouch); + + stack.stackTagCompound.setTag(tagName, tag); + } + } + + public boolean getSilkTouch(ItemStack stack) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + return tag.getBoolean("silkTouch"); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + return false; + } + } + + public void setFortuneLevel(ItemStack stack, int fortune) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setInteger("fortuneLevel", Math.max(fortune, 0)); + + stack.stackTagCompound.setTag(tagName, tag); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setInteger("fortuneLevel", Math.max(fortune, 0)); + + stack.stackTagCompound.setTag(tagName, tag); + } + } + + public int getFortuneLevel(ItemStack stack) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + return tag.getInteger("fortuneLevel"); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + return 0; + } + } + + public List getToolListString(ItemStack container) + { + if (!container.hasTagCompound()) + { + container.setTagCompound(new NBTTagCompound()); + } + NBTTagCompound tagiest = container.getTagCompound().getCompoundTag(tagName); + + NBTTagList tagList = tagiest.getTagList("ToolTips", Constants.NBT.TAG_COMPOUND); + + List toolTipList = new LinkedList(); + for (int i = 0; i < tagList.tagCount(); i++) + { + NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); + + String str = tag.getString("tip"); + if (str != null) + { + toolTipList.add(str); + } + } + + return toolTipList; + } + + public void setToolListString(ItemStack container, List toolTipString) + { + if (!container.hasTagCompound()) + { + container.setTagCompound(new NBTTagCompound()); + } + + NBTTagCompound tagiest = container.getTagCompound().getCompoundTag(tagName); + + NBTTagList stringList = new NBTTagList(); + + for (String str : toolTipString) + { + NBTTagCompound tag = new NBTTagCompound(); + tag.setString("tip", str); + + stringList.appendTag(tag); + } + + tagiest.setTag("ToolTips", stringList); + + container.getTagCompound().setTag(tagName, tagiest); + } + + public void setCritChance(ItemStack container, float chance) + { + if (container.hasTagCompound()) + { + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + tag.setFloat("critChance", Math.max(chance, 0)); + + container.stackTagCompound.setTag(tagName, tag); + } else + { + container.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + tag.setFloat("critChance", Math.max(chance, 0)); + + container.stackTagCompound.setTag(tagName, tag); + } + } + + public float getCritChance(ItemStack container) + { + if (container.hasTagCompound()) + { + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + return tag.getFloat("critChance"); + } else + { + container.setTagCompound(new NBTTagCompound()); + + return 0; + } + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapedBloodOrbRecipe.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapedBloodOrbRecipe.java index cdf82e6..6e5b0f9 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapedBloodOrbRecipe.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapedBloodOrbRecipe.java @@ -1,11 +1,6 @@ package WayofTime.alchemicalWizardry.api.items; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - +import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb; import net.minecraft.block.Block; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; @@ -14,214 +9,273 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.world.World; import net.minecraftforge.oredict.OreDictionary; -import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb; -/** Shaped Blood Orb Recipe Handler by joshie **/ -public class ShapedBloodOrbRecipe implements IRecipe { - private static final int MAX_CRAFT_GRID_WIDTH = 3; - private static final int MAX_CRAFT_GRID_HEIGHT = 3; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; - private ItemStack output = null; - private Object[] input = null; - public int width = 0; - public int height = 0; - private boolean mirrored = true; +/** + * Shaped Blood Orb Recipe Handler by joshie * + */ +public class ShapedBloodOrbRecipe implements IRecipe +{ + private static final int MAX_CRAFT_GRID_WIDTH = 3; + private static final int MAX_CRAFT_GRID_HEIGHT = 3; - public ShapedBloodOrbRecipe(Block result, Object... recipe) { - this(new ItemStack(result), recipe); - } + private ItemStack output = null; + private Object[] input = null; + public int width = 0; + public int height = 0; + private boolean mirrored = true; - public ShapedBloodOrbRecipe(Item result, Object... recipe) { - this(new ItemStack(result), recipe); - } + public ShapedBloodOrbRecipe(Block result, Object... recipe) + { + this(new ItemStack(result), recipe); + } - public ShapedBloodOrbRecipe(ItemStack result, Object... recipe) { - output = result.copy(); + public ShapedBloodOrbRecipe(Item result, Object... recipe) + { + this(new ItemStack(result), recipe); + } - String shape = ""; - int idx = 0; + public ShapedBloodOrbRecipe(ItemStack result, Object... recipe) + { + output = result.copy(); - if (recipe[idx] instanceof Boolean) { - mirrored = (Boolean) recipe[idx]; - if (recipe[idx + 1] instanceof Object[]) { - recipe = (Object[]) recipe[idx + 1]; - } else { - idx = 1; - } - } + String shape = ""; + int idx = 0; - if (recipe[idx] instanceof String[]) { - String[] parts = ((String[]) recipe[idx++]); + if (recipe[idx] instanceof Boolean) + { + mirrored = (Boolean) recipe[idx]; + if (recipe[idx + 1] instanceof Object[]) + { + recipe = (Object[]) recipe[idx + 1]; + } else + { + idx = 1; + } + } - for (String s : parts) { - width = s.length(); - shape += s; - } + if (recipe[idx] instanceof String[]) + { + String[] parts = ((String[]) recipe[idx++]); - height = parts.length; - } else { - while (recipe[idx] instanceof String) { - String s = (String) recipe[idx++]; - shape += s; - width = s.length(); - height++; - } - } + for (String s : parts) + { + width = s.length(); + shape += s; + } - if (width * height != shape.length()) { - String ret = "Invalid shaped ore recipe: "; - for (Object tmp : recipe) { - ret += tmp + ", "; - } - ret += output; - throw new RuntimeException(ret); - } + height = parts.length; + } else + { + while (recipe[idx] instanceof String) + { + String s = (String) recipe[idx++]; + shape += s; + width = s.length(); + height++; + } + } - HashMap itemMap = new HashMap(); + if (width * height != shape.length()) + { + String ret = "Invalid shaped ore recipe: "; + for (Object tmp : recipe) + { + ret += tmp + ", "; + } + ret += output; + throw new RuntimeException(ret); + } - for (; idx < recipe.length; idx += 2) { - Character chr = (Character) recipe[idx]; - Object in = recipe[idx + 1]; + HashMap itemMap = new HashMap(); - if (in instanceof IBloodOrb || (in instanceof ItemStack && ((ItemStack)in).getItem() instanceof IBloodOrb)) { //If the item is an instanceof IBloodOrb then save the level of the orb - if(in instanceof ItemStack) itemMap.put(chr, (Integer)(((IBloodOrb)((ItemStack)in).getItem()).getOrbLevel())); - else itemMap.put(chr, (Integer)(((IBloodOrb)in).getOrbLevel())); - } else if (in instanceof ItemStack) { - itemMap.put(chr, ((ItemStack) in).copy()); - } else if (in instanceof Item) { - itemMap.put(chr, new ItemStack((Item) in)); - } else if (in instanceof Block) { - itemMap.put(chr, new ItemStack((Block) in, 1, OreDictionary.WILDCARD_VALUE)); - } else if (in instanceof String) { - itemMap.put(chr, OreDictionary.getOres((String) in)); - } else { - String ret = "Invalid shaped ore recipe: "; - for (Object tmp : recipe) { - ret += tmp + ", "; - } - ret += output; - throw new RuntimeException(ret); - } - } + for (; idx < recipe.length; idx += 2) + { + Character chr = (Character) recipe[idx]; + Object in = recipe[idx + 1]; - input = new Object[width * height]; - int x = 0; - for (char chr : shape.toCharArray()) { - input[x++] = itemMap.get(chr); - } - } + if (in instanceof IBloodOrb || (in instanceof ItemStack && ((ItemStack) in).getItem() instanceof IBloodOrb)) + { //If the item is an instanceof IBloodOrb then save the level of the orb + if (in instanceof ItemStack) + itemMap.put(chr, (Integer) (((IBloodOrb) ((ItemStack) in).getItem()).getOrbLevel())); + else itemMap.put(chr, (Integer) (((IBloodOrb) in).getOrbLevel())); + } else if (in instanceof ItemStack) + { + itemMap.put(chr, ((ItemStack) in).copy()); + } else if (in instanceof Item) + { + itemMap.put(chr, new ItemStack((Item) in)); + } else if (in instanceof Block) + { + itemMap.put(chr, new ItemStack((Block) in, 1, OreDictionary.WILDCARD_VALUE)); + } else if (in instanceof String) + { + itemMap.put(chr, OreDictionary.getOres((String) in)); + } else + { + String ret = "Invalid shaped ore recipe: "; + for (Object tmp : recipe) + { + ret += tmp + ", "; + } + ret += output; + throw new RuntimeException(ret); + } + } - ShapedBloodOrbRecipe(ShapedRecipes recipe, Map replacements) { - output = recipe.getRecipeOutput(); - width = recipe.recipeWidth; - height = recipe.recipeHeight; + input = new Object[width * height]; + int x = 0; + for (char chr : shape.toCharArray()) + { + input[x++] = itemMap.get(chr); + } + } - input = new Object[recipe.recipeItems.length]; + ShapedBloodOrbRecipe(ShapedRecipes recipe, Map replacements) + { + output = recipe.getRecipeOutput(); + width = recipe.recipeWidth; + height = recipe.recipeHeight; - for (int i = 0; i < input.length; i++) { - ItemStack ingred = recipe.recipeItems[i]; + input = new Object[recipe.recipeItems.length]; - if (ingred == null) - continue; + for (int i = 0; i < input.length; i++) + { + ItemStack ingred = recipe.recipeItems[i]; - input[i] = recipe.recipeItems[i]; + if (ingred == null) + continue; - for (Entry replace : replacements.entrySet()) { - if (OreDictionary.itemMatches(replace.getKey(), ingred, true)) { - input[i] = OreDictionary.getOres(replace.getValue()); - break; - } - } - } - } + input[i] = recipe.recipeItems[i]; - @Override - public ItemStack getCraftingResult(InventoryCrafting var1) { - return output.copy(); - } + for (Entry replace : replacements.entrySet()) + { + if (OreDictionary.itemMatches(replace.getKey(), ingred, true)) + { + input[i] = OreDictionary.getOres(replace.getValue()); + break; + } + } + } + } - @Override - public int getRecipeSize() { - return input.length; - } + @Override + public ItemStack getCraftingResult(InventoryCrafting var1) + { + return output.copy(); + } - @Override - public ItemStack getRecipeOutput() { - return output; - } + @Override + public int getRecipeSize() + { + return input.length; + } - @Override - public boolean matches(InventoryCrafting inv, World world) { - for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - width; x++) { - for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - height; ++y) { - if (checkMatch(inv, x, y, false)) { - return true; - } + @Override + public ItemStack getRecipeOutput() + { + return output; + } - if (mirrored && checkMatch(inv, x, y, true)) { - return true; - } - } - } + @Override + public boolean matches(InventoryCrafting inv, World world) + { + for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - width; x++) + { + for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - height; ++y) + { + if (checkMatch(inv, x, y, false)) + { + return true; + } - return false; - } + if (mirrored && checkMatch(inv, x, y, true)) + { + return true; + } + } + } - @SuppressWarnings("unchecked") - private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror) { - for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++) { - for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++) { - int subX = x - startX; - int subY = y - startY; - Object target = null; + return false; + } - if (subX >= 0 && subY >= 0 && subX < width && subY < height) { - if (mirror) { - target = input[width - subX - 1 + subY * width]; - } else { - target = input[subX + subY * width]; - } - } - - ItemStack slot = inv.getStackInRowAndColumn(x, y); - //If target is integer, then we should be check the blood orb value of the item instead - if(target instanceof Integer) { - if(slot != null && slot.getItem() instanceof IBloodOrb) { - IBloodOrb orb = (IBloodOrb) slot.getItem(); - if(orb.getOrbLevel() < (Integer)target) { - return false; - } - } else return false; - } else if (target instanceof ItemStack) { - if (!OreDictionary.itemMatches((ItemStack) target, slot, false)) { - return false; - } - } else if (target instanceof ArrayList) { - boolean matched = false; + @SuppressWarnings("unchecked") + private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror) + { + for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++) + { + for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++) + { + int subX = x - startX; + int subY = y - startY; + Object target = null; - Iterator itr = ((ArrayList) target).iterator(); - while (itr.hasNext() && !matched) { - matched = OreDictionary.itemMatches(itr.next(), slot, false); - } + if (subX >= 0 && subY >= 0 && subX < width && subY < height) + { + if (mirror) + { + target = input[width - subX - 1 + subY * width]; + } else + { + target = input[subX + subY * width]; + } + } - if (!matched) { - return false; - } - } else if (target == null && slot != null) { - return false; - } - } - } + ItemStack slot = inv.getStackInRowAndColumn(x, y); + //If target is integer, then we should be check the blood orb value of the item instead + if (target instanceof Integer) + { + if (slot != null && slot.getItem() instanceof IBloodOrb) + { + IBloodOrb orb = (IBloodOrb) slot.getItem(); + if (orb.getOrbLevel() < (Integer) target) + { + return false; + } + } else return false; + } else if (target instanceof ItemStack) + { + if (!OreDictionary.itemMatches((ItemStack) target, slot, false)) + { + return false; + } + } else if (target instanceof ArrayList) + { + boolean matched = false; - return true; - } + Iterator itr = ((ArrayList) target).iterator(); + while (itr.hasNext() && !matched) + { + matched = OreDictionary.itemMatches(itr.next(), slot, false); + } - public ShapedBloodOrbRecipe setMirrored(boolean mirror) { - mirrored = mirror; - return this; - } + if (!matched) + { + return false; + } + } else if (target == null && slot != null) + { + return false; + } + } + } - public Object[] getInput() { - return this.input; - } + return true; + } + + public ShapedBloodOrbRecipe setMirrored(boolean mirror) + { + mirrored = mirror; + return this; + } + + public Object[] getInput() + { + return this.input; + } } \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapelessBloodOrbRecipe.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapelessBloodOrbRecipe.java index fbf28a4..3b22ded 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapelessBloodOrbRecipe.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapelessBloodOrbRecipe.java @@ -1,11 +1,6 @@ package WayofTime.alchemicalWizardry.api.items; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - +import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb; import net.minecraft.block.Block; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; @@ -14,127 +9,166 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.ShapelessRecipes; import net.minecraft.world.World; import net.minecraftforge.oredict.OreDictionary; -import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb; -/** Shapeless Blood Orb Recipe Handler by joshie **/ -public class ShapelessBloodOrbRecipe implements IRecipe { - private ItemStack output = null; - private ArrayList input = new ArrayList(); +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; - public ShapelessBloodOrbRecipe(Block result, Object... recipe) { - this(new ItemStack(result), recipe); - } +/** + * Shapeless Blood Orb Recipe Handler by joshie * + */ +public class ShapelessBloodOrbRecipe implements IRecipe +{ + private ItemStack output = null; + private ArrayList input = new ArrayList(); - public ShapelessBloodOrbRecipe(Item result, Object... recipe) { - this(new ItemStack(result), recipe); - } + public ShapelessBloodOrbRecipe(Block result, Object... recipe) + { + this(new ItemStack(result), recipe); + } - public ShapelessBloodOrbRecipe(ItemStack result, Object... recipe) { - output = result.copy(); - for (Object in : recipe) { - if (in instanceof ItemStack) { - input.add(((ItemStack) in).copy()); - } else if (in instanceof IBloodOrb) { //If the item is an instanceof IBloodOrb then save the level of the orb - input.add((Integer)(((IBloodOrb)in).getOrbLevel())); - } else if (in instanceof Item) { - input.add(new ItemStack((Item) in)); - } else if (in instanceof Block) { - input.add(new ItemStack((Block) in)); - } else if (in instanceof String) { - input.add(OreDictionary.getOres((String) in)); - } else { - String ret = "Invalid shapeless ore recipe: "; - for (Object tmp : recipe) { - ret += tmp + ", "; - } - ret += output; - throw new RuntimeException(ret); - } - } - } + public ShapelessBloodOrbRecipe(Item result, Object... recipe) + { + this(new ItemStack(result), recipe); + } - @SuppressWarnings("unchecked") - ShapelessBloodOrbRecipe(ShapelessRecipes recipe, Map replacements) { - output = recipe.getRecipeOutput(); + public ShapelessBloodOrbRecipe(ItemStack result, Object... recipe) + { + output = result.copy(); + for (Object in : recipe) + { + if (in instanceof ItemStack) + { + input.add(((ItemStack) in).copy()); + } else if (in instanceof IBloodOrb) + { //If the item is an instanceof IBloodOrb then save the level of the orb + input.add((Integer) (((IBloodOrb) in).getOrbLevel())); + } else if (in instanceof Item) + { + input.add(new ItemStack((Item) in)); + } else if (in instanceof Block) + { + input.add(new ItemStack((Block) in)); + } else if (in instanceof String) + { + input.add(OreDictionary.getOres((String) in)); + } else + { + String ret = "Invalid shapeless ore recipe: "; + for (Object tmp : recipe) + { + ret += tmp + ", "; + } + ret += output; + throw new RuntimeException(ret); + } + } + } - for (ItemStack ingred : ((List) recipe.recipeItems)) { - Object finalObj = ingred; - for (Entry replace : replacements.entrySet()) { - if (OreDictionary.itemMatches(replace.getKey(), ingred, false)) { - finalObj = OreDictionary.getOres(replace.getValue()); - break; - } - } - input.add(finalObj); - } - } + @SuppressWarnings("unchecked") + ShapelessBloodOrbRecipe(ShapelessRecipes recipe, Map replacements) + { + output = recipe.getRecipeOutput(); - @Override - public int getRecipeSize() { - return input.size(); - } + for (ItemStack ingred : ((List) recipe.recipeItems)) + { + Object finalObj = ingred; + for (Entry replace : replacements.entrySet()) + { + if (OreDictionary.itemMatches(replace.getKey(), ingred, false)) + { + finalObj = OreDictionary.getOres(replace.getValue()); + break; + } + } + input.add(finalObj); + } + } - @Override - public ItemStack getRecipeOutput() { - return output; - } + @Override + public int getRecipeSize() + { + return input.size(); + } - @Override - public ItemStack getCraftingResult(InventoryCrafting var1) { - return output.copy(); - } + @Override + public ItemStack getRecipeOutput() + { + return output; + } - @SuppressWarnings("unchecked") - @Override - public boolean matches(InventoryCrafting var1, World world) { - ArrayList required = new ArrayList(input); + @Override + public ItemStack getCraftingResult(InventoryCrafting var1) + { + return output.copy(); + } - for (int x = 0; x < var1.getSizeInventory(); x++) { - ItemStack slot = var1.getStackInSlot(x); + @SuppressWarnings("unchecked") + @Override + public boolean matches(InventoryCrafting var1, World world) + { + ArrayList required = new ArrayList(input); - if (slot != null) { - boolean inRecipe = false; - Iterator req = required.iterator(); + for (int x = 0; x < var1.getSizeInventory(); x++) + { + ItemStack slot = var1.getStackInSlot(x); - while (req.hasNext()) { - boolean match = false; + if (slot != null) + { + boolean inRecipe = false; + Iterator req = required.iterator(); - Object next = req.next(); + while (req.hasNext()) + { + boolean match = false; - //If target is integer, then we should be check the blood orb value of the item instead - if(next instanceof Integer) { - if(slot != null && slot.getItem() instanceof IBloodOrb) { - IBloodOrb orb = (IBloodOrb) slot.getItem(); - if(orb.getOrbLevel() < (Integer)next) { - return false; - } - } else return false; - } else if (next instanceof ItemStack) { - match = OreDictionary.itemMatches((ItemStack) next, slot, false); - } else if (next instanceof ArrayList) { - Iterator itr = ((ArrayList) next).iterator(); - while (itr.hasNext() && !match) { - match = OreDictionary.itemMatches(itr.next(), slot, false); - } - } + Object next = req.next(); - if (match) { - inRecipe = true; - required.remove(next); - break; - } - } + //If target is integer, then we should be check the blood orb value of the item instead + if (next instanceof Integer) + { + if (slot != null && slot.getItem() instanceof IBloodOrb) + { + IBloodOrb orb = (IBloodOrb) slot.getItem(); + if (orb.getOrbLevel() < (Integer) next) + { + return false; + } + } else return false; + } else if (next instanceof ItemStack) + { + match = OreDictionary.itemMatches((ItemStack) next, slot, false); + } else if (next instanceof ArrayList) + { + Iterator itr = ((ArrayList) next).iterator(); + while (itr.hasNext() && !match) + { + match = OreDictionary.itemMatches(itr.next(), slot, false); + } + } - if (!inRecipe) { - return false; - } - } - } + if (match) + { + inRecipe = true; + required.remove(next); + break; + } + } - return required.isEmpty(); - } + if (!inRecipe) + { + return false; + } + } + } - public ArrayList getInput() { - return this.input; - } + return required.isEmpty(); + } + + public ArrayList getInput() + { + return this.input; + } } \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IBloodOrb.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IBloodOrb.java index 794172c..e88e9cc 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IBloodOrb.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IBloodOrb.java @@ -1,8 +1,8 @@ package WayofTime.alchemicalWizardry.api.items.interfaces; -public interface IBloodOrb +public interface IBloodOrb { - public int getMaxEssence(); - - public int getOrbLevel(); + public int getMaxEssence(); + + public int getOrbLevel(); } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IHolding.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IHolding.java index cb07b99..4150abe 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IHolding.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IHolding.java @@ -1,6 +1,6 @@ package WayofTime.alchemicalWizardry.api.items.interfaces; -public interface IHolding +public interface IHolding { } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IReagentManipulator.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IReagentManipulator.java new file mode 100644 index 0000000..23ac780 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IReagentManipulator.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.items.interfaces; + +/** + * Implement this interface to have reagent blocks return false on activating them, to allow manipulation of said block + */ +public interface IReagentManipulator +{ + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/renderer/MRSRenderer.java b/src/api/java/WayofTime/alchemicalWizardry/api/renderer/MRSRenderer.java new file mode 100644 index 0000000..f898fc6 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/renderer/MRSRenderer.java @@ -0,0 +1,21 @@ +package WayofTime.alchemicalWizardry.api.renderer; + +//import WayofTime.alchemicalWizardry.common.tileEntity.TEMasterStone; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.util.ResourceLocation; + +public abstract class MRSRenderer +{ + //public abstract void renderAt(TEMasterStone tile, double x, double y, double z); + + protected void bindTexture(ResourceLocation p_147499_1_) + { + TextureManager texturemanager = TileEntityRendererDispatcher.instance.field_147553_e; + + if (texturemanager != null) + { + texturemanager.bindTexture(p_147499_1_); + } + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IMasterRitualStone.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IMasterRitualStone.java index 9777093..e00ed79 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IMasterRitualStone.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IMasterRitualStone.java @@ -1,11 +1,13 @@ package WayofTime.alchemicalWizardry.api.rituals; +import WayofTime.alchemicalWizardry.api.alchemy.energy.ISegmentedReagentHandler; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -public interface IMasterRitualStone +public interface IMasterRitualStone extends ISegmentedReagentHandler { - public void performRitual(World world, int x, int y, int z, String ritualID); - + public void performRitual(World world, int x, int y, int z, String ritualID); + public String getOwner(); public void setCooldown(int newCooldown); @@ -19,12 +21,16 @@ public interface IMasterRitualStone public void setActive(boolean active); public int getDirection(); - + public World getWorld(); - + public int getXCoord(); - + public int getYCoord(); - + public int getZCoord(); + + public NBTTagCompound getCustomRitualTag(); + + public void setCustomRitualTag(NBTTagCompound tag); } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IRitualStone.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IRitualStone.java index 078cfd4..efe32e0 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IRitualStone.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IRitualStone.java @@ -1,6 +1,8 @@ package WayofTime.alchemicalWizardry.api.rituals; -public interface IRitualStone -{ +import net.minecraft.world.World; +public interface IRitualStone +{ + public int getRuneType(World world, int x, int y, int z, int meta); } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualBreakMethod.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualBreakMethod.java new file mode 100644 index 0000000..a705056 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualBreakMethod.java @@ -0,0 +1,11 @@ +package WayofTime.alchemicalWizardry.api.rituals; + +public enum RitualBreakMethod +{ + REDSTONE, + BREAK_MRS, + BREAK_STONE, + ACTIVATE, //When an activation crystal activates the MRS, overwriting the current ritual + DEACTIVATE, + EXPLOSION, //When the MRS is destroyed by an explosion +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualComponent.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualComponent.java index b714985..6e896e0 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualComponent.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualComponent.java @@ -35,9 +35,37 @@ public class RitualComponent { return this.z; } + + public int getX(int direction) + { + switch(direction) + { + case 2: + return -this.getZ(); + case 3: + return -this.getX(); + case 4: + return this.getZ(); + default: return this.getX(); + } + } + + public int getZ(int direction) + { + switch(direction) + { + case 2: + return this.getX(); + case 3: + return -this.getZ(); + case 4: + return -this.getX(); + default: return this.getZ(); + } + } public int getStoneType() { return this.stoneType; } -} +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualEffect.java index 70f89f5..498c803 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualEffect.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualEffect.java @@ -2,16 +2,55 @@ package WayofTime.alchemicalWizardry.api.rituals; import java.util.List; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.util.ForgeDirection; +import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent; +import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack; + public abstract class RitualEffect { public abstract void performEffect(IMasterRitualStone ritualStone); + public boolean startRitual(IMasterRitualStone ritualStone, EntityPlayer player) + { + return true; + } + + public void onRitualBroken(IMasterRitualStone ritualStone, RitualBreakMethod method) + { + + } + public abstract int getCostPerRefresh(); public int getInitialCooldown() { return 0; } - + public abstract List getRitualComponentList(); + + public boolean canDrainReagent(IMasterRitualStone ritualStone, Reagent reagent, int amount, boolean doDrain) + { + if (ritualStone == null || reagent == null || amount == 0) + { + return false; + } + + ReagentStack reagentStack = new ReagentStack(reagent, amount); + + ReagentStack stack = ritualStone.drain(ForgeDirection.UNKNOWN, reagentStack, false); + + if (stack != null && stack.amount >= amount) + { + if (doDrain) + { + ritualStone.drain(ForgeDirection.UNKNOWN, reagentStack, true); + } + + return true; + } + + return false; + } } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/Rituals.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/Rituals.java index 7eca627..b3bd97f 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/Rituals.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/Rituals.java @@ -5,9 +5,14 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import scala.reflect.internal.Trees.This; import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import WayofTime.alchemicalWizardry.api.event.RitualRunEvent; +import WayofTime.alchemicalWizardry.api.event.RitualStopEvent; +import WayofTime.alchemicalWizardry.api.renderer.MRSRenderer; +import cpw.mods.fml.common.eventhandler.Event; public class Rituals { @@ -16,83 +21,104 @@ public class Rituals private RitualEffect effect; private String name; - public static Map ritualMap = new HashMap(); - @Deprecated - public static List ritualList = new LinkedList(); - public static List keyList = new LinkedList(); + private MRSRenderer customRenderer; - public Rituals(int crystalLevel, int actCost, RitualEffect effect, String name) + public static Map ritualMap = new HashMap(); + public static List keyList = new LinkedList(); + + public Rituals(int crystalLevel, int actCost, RitualEffect effect, String name, MRSRenderer renderer) { - this.crystalLevel = crystalLevel; //For a test commit + this.crystalLevel = crystalLevel; this.actCost = actCost; this.effect = effect; this.name = name; keyList.add(name); ritualMap.put(name, this); + this.customRenderer = renderer; } - + + public Rituals(int crystalLevel, int actCost, RitualEffect effect, String name) + { + this(crystalLevel, actCost, effect, name, null); + } + /** * Static method to register a ritual to the Ritual Registry - * @param key Unique identification key - must be different from all others to properly register - * @param crystalLevel Crystal level required to activate - * @param actCost LP amount required to activate - * @param effect The effect that will be ticked - * @param name The name of the ritual - * @return Returns true if properly registered, or false if the key is already used + * + * @param key Unique identification key - must be different from all others to properly register + * @param crystalLevel Crystal level required to activate + * @param actCost LP amount required to activate + * @param effect The effect that will be ticked + * @param name The name of the ritual + * @return Returns true if properly registered, or false if the key is already used */ + public static boolean registerRitual(String key, int crystalLevel, int actCost, RitualEffect effect, String name, MRSRenderer renderer) + { + if (ritualMap.containsKey(key)) + { + return false; + } else + { + Rituals ritual = new Rituals(crystalLevel, actCost, effect, name, renderer); + ritual.removeRitualFromList(); + ritualMap.put(key, ritual); + keyList.add(key); + return true; + } + } + public static boolean registerRitual(String key, int crystalLevel, int actCost, RitualEffect effect, String name) { - if(ritualMap.containsKey(key)) - { - return false; - } - else - { - Rituals ritual = new Rituals(crystalLevel, actCost, effect, name); - ritual.removeRitualFromList(); - ritualMap.put(key, ritual); - keyList.add(key); - return true; - } + if (ritualMap.containsKey(key)) + { + return false; + } else + { + Rituals ritual = new Rituals(crystalLevel, actCost, effect, name); + ritual.removeRitualFromList(); + ritualMap.put(key, ritual); + keyList.add(key); + return true; + } } - + public void removeRitualFromList() { - if(ritualMap.containsValue(this)) - { - ritualMap.remove(ritualMap.remove(this.name)); - } - if(keyList.contains(this.name)) - { - keyList.remove(this.name); - } + if (ritualMap.containsValue(this)) + { + ritualMap.remove(ritualMap.remove(this.name)); + } + if (keyList.contains(this.name)) + { + keyList.remove(this.name); + } } public static String checkValidRitual(World world, int x, int y, int z) { - for(String key : ritualMap.keySet()) - { - if(checkRitualIsValid(world,x,y,z,key)) - { - return key; - } - } - - return ""; + for (String key : ritualMap.keySet()) + { + if (checkRitualIsValid(world, x, y, z, key)) + { + return key; + } + } + + return ""; } public static boolean canCrystalActivate(String ritualID, int crystalLevel) { - if(ritualMap.containsKey(ritualID)) - { - Rituals ritual = ritualMap.get(ritualID); - if(ritual != null) - { - return ritual.getCrystalLevel() <= crystalLevel; - } - } - - return false; + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null) + { + return ritual.getCrystalLevel() <= crystalLevel; + } + } + + return false; } public static boolean checkRitualIsValid(World world, int x, int y, int z, String ritualID) @@ -136,7 +162,7 @@ public class Rituals return false; } - if (world.getBlockMetadata(x + rc.getX(), y + rc.getY(), z + rc.getZ()) != rc.getStoneType()) + if (((IRitualStone)test).getRuneType(world, x, y, z, world.getBlockMetadata(x + rc.getX(), y + rc.getY(), z + rc.getZ())) != rc.getStoneType()) { return false; } @@ -147,14 +173,14 @@ public class Rituals case 2: for (RitualComponent rc : ritual) { - test = world.getBlock(x - rc.getZ(), y + rc.getY(), z + rc.getX()); - + test = world.getBlock(x - rc.getZ(), y + rc.getY(), z + rc.getX()); + if (!(test instanceof IRitualStone)) { return false; } - if (world.getBlockMetadata(x - rc.getZ(), y + rc.getY(), z + rc.getX()) != rc.getStoneType()) + if (((IRitualStone)test).getRuneType(world, x, y, z, world.getBlockMetadata(x - rc.getZ(), y + rc.getY(), z + rc.getX())) != rc.getStoneType()) { return false; } @@ -165,14 +191,14 @@ public class Rituals case 3: for (RitualComponent rc : ritual) { - test = world.getBlock(x - rc.getX(), y + rc.getY(), z - rc.getZ()); - + test = world.getBlock(x - rc.getX(), y + rc.getY(), z - rc.getZ()); + if (!(test instanceof IRitualStone)) { return false; } - if (world.getBlockMetadata(x - rc.getX(), y + rc.getY(), z - rc.getZ()) != rc.getStoneType()) + if (((IRitualStone)test).getRuneType(world, x, y, z, world.getBlockMetadata(x - rc.getX(), y + rc.getY(), z - rc.getZ())) != rc.getStoneType()) { return false; } @@ -183,14 +209,14 @@ public class Rituals case 4: for (RitualComponent rc : ritual) { - test = world.getBlock(x + rc.getZ(), y + rc.getY(), z - rc.getX()); - - if (!(test instanceof IRitualStone)) + test = world.getBlock(x + rc.getZ(), y + rc.getY(), z - rc.getX()); + + if (!(test instanceof IRitualStone)) { return false; } - if (world.getBlockMetadata(x + rc.getZ(), y + rc.getY(), z - rc.getX()) != rc.getStoneType()) + if (((IRitualStone)test).getRuneType(world, x, y, z, world.getBlockMetadata(x + rc.getZ(), y + rc.getY(), z - rc.getX())) != rc.getStoneType()) { return false; } @@ -217,48 +243,48 @@ public class Rituals public static int getCostForActivation(String ritualID) { - if(ritualMap.containsKey(ritualID)) - { - Rituals ritual = ritualMap.get(ritualID); - if(ritual != null) - { - return ritual.actCost; - } - } - - return 0; + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null) + { + return ritual.actCost; + } + } + + return 0; } public static int getInitialCooldown(String ritualID) { - if(ritualMap.containsKey(ritualID)) - { - Rituals ritual = ritualMap.get(ritualID); - if(ritual != null && ritual.effect != null) - { - return ritual.effect.getInitialCooldown(); - } - } - - return 0; + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null && ritual.effect != null) + { + return ritual.effect.getInitialCooldown(); + } + } + + return 0; } public static List getRitualList(String ritualID) { - if(ritualMap.containsKey(ritualID)) - { - Rituals ritual = ritualMap.get(ritualID); - if(ritual != null) - { - return ritual.obtainComponents(); - }else - { - return null; - } - }else - { - return null; - } + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null) + { + return ritual.obtainComponents(); + } else + { + return null; + } + } else + { + return null; + } } private List obtainComponents() @@ -271,21 +297,67 @@ public class Rituals return this.crystalLevel; } + private MRSRenderer getRenderer() + { + return this.customRenderer; + } + public static void performEffect(IMasterRitualStone ritualStone, String ritualID) { - if(ritualMap.containsKey(ritualID)) + String ownerName = ritualStone.getOwner(); + + RitualRunEvent event = new RitualRunEvent(ritualStone, ownerName, ritualID); + + if(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) { - Rituals ritual = ritualMap.get(ritualID); - if(ritual != null && ritual.effect != null) - { - ritual.effect.performEffect(ritualStone); - } + return; } + + if (ritualMap.containsKey(event.ritualKey)) + { + Rituals ritual = ritualMap.get(event.ritualKey); + if (ritual != null && ritual.effect != null) + { + ritual.effect.performEffect(ritualStone); + } + } + } + + public static boolean startRitual(IMasterRitualStone ritualStone, String ritualID, EntityPlayer player) + { + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null && ritual.effect != null) + { + return ritual.effect.startRitual(ritualStone, player); + } + } + + return false; + } + + public static void onRitualBroken(IMasterRitualStone ritualStone, String ritualID, RitualBreakMethod method) + { + String ownerName = ritualStone.getOwner(); + RitualStopEvent event = new RitualStopEvent(ritualStone, ownerName, ritualID, method); + MinecraftForge.EVENT_BUS.post(event); + + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null && ritual.effect != null) + { + ritual.effect.onRitualBroken(ritualStone, method); + } + } + + System.out.println(method); } public static int getNumberOfRituals() { - return ritualMap.size(); + return ritualMap.size(); } public String getRitualName() @@ -295,39 +367,74 @@ public class Rituals public static String getNameOfRitual(String id) { - if(ritualMap.containsKey(id)) - { - Rituals ritual = ritualMap.get(id); - if(ritual != null) - { - return ritual.getRitualName(); - } - } - - return ""; + if (ritualMap.containsKey(id)) + { + Rituals ritual = ritualMap.get(id); + if (ritual != null) + { + return ritual.getRitualName(); + } + } + + return ""; } - + public static String getNextRitualKey(String key) { - boolean hasSpotted = false; - String firstKey = ""; + boolean hasSpotted = false; + String firstKey = ""; - for(String str : keyList) - { - if(firstKey.equals("")) - { - firstKey = str; - } - if(hasSpotted) - { - return str; - } - if(str.equals(key)) - { - hasSpotted = true; - } - } + for (String str : keyList) + { + if (firstKey.equals("")) + { + firstKey = str; + } + if (hasSpotted) + { + return str; + } + if (str.equals(key)) + { + hasSpotted = true; + } + } - return firstKey; + return firstKey; + } + + public static String getPreviousRitualKey(String key) + { + boolean hasSpotted = false; + String lastKey = keyList.get(keyList.size() - 1); + + for (String str : keyList) + { + if (str.equals(key)) + { + hasSpotted = true; + } + if (hasSpotted) + { + return lastKey; + } + lastKey = str; + } + + return lastKey; + } + + public static MRSRenderer getRendererForKey(String ritualID) + { + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null) + { + return ritual.getRenderer(); + } + } + + return null; } } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/SoulNetworkHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/SoulNetworkHandler.java index a4d6858..ce900aa 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/SoulNetworkHandler.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/SoulNetworkHandler.java @@ -1,96 +1,53 @@ package WayofTime.alchemicalWizardry.api.soulNetwork; +import java.util.UUID; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; import net.minecraft.server.MinecraftServer; import net.minecraft.util.DamageSource; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import WayofTime.alchemicalWizardry.api.event.AddToNetworkEvent; +import WayofTime.alchemicalWizardry.api.event.ItemBindEvent; +import WayofTime.alchemicalWizardry.api.event.ItemDrainNetworkEvent; -public class SoulNetworkHandler +import com.mojang.authlib.GameProfile; + +import cpw.mods.fml.common.eventhandler.Event; + +public class SoulNetworkHandler { - public static int syphonFromNetwork(ItemStack ist, int damageToBeDone) - { - if (ist.getTagCompound() != null && !(ist.getTagCompound().getString("ownerName").equals(""))) - { - String ownerName = ist.getTagCompound().getString("ownerName"); - - if (MinecraftServer.getServer() == null) - { - return 0; - } - - World world = MinecraftServer.getServer().worldServers[0]; - LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName); - - if (data == null) - { - data = new LifeEssenceNetwork(ownerName); - world.setItemData(ownerName, data); - } - - if (data.currentEssence >= damageToBeDone) - { - data.currentEssence -= damageToBeDone; - data.markDirty(); - return damageToBeDone; - } - } - return 0; - } - - /** - * Master method used to syphon from the player's network, and will damage them accordingly if they do not have enough LP. - * Does not drain on the client side. - * - * @param ist Owned itemStack - * @param player Player using the item - * @param damageToBeDone - * @return True if server-sided, false if client-sided - */ - public static boolean syphonAndDamageFromNetwork(ItemStack ist, EntityPlayer player, int damageToBeDone) + public static UUID getUUIDFromPlayer(EntityPlayer player) { - if(player.worldObj.isRemote) - { - return false; - } - - int amount = SoulNetworkHandler.syphonFromNetwork(ist, damageToBeDone); - - hurtPlayer(player, damageToBeDone-amount); - - return true; + return player.getPersistentID(); } - - public static boolean canSyphonFromOnlyNetwork(ItemStack ist, int damageToBeDone) + + public static EntityPlayer getPlayerFromUUID(UUID uuid) + { + MinecraftServer server = MinecraftServer.getServer(); + GameProfile gameProfile; + gameProfile = server.func_152358_ax().func_152652_a(uuid); + return null; + } + + public static int syphonFromNetwork(ItemStack ist, int damageToBeDone) { if (ist.getTagCompound() != null && !(ist.getTagCompound().getString("ownerName").equals(""))) { String ownerName = ist.getTagCompound().getString("ownerName"); - if (MinecraftServer.getServer() == null) - { - return false; - } - - World world = MinecraftServer.getServer().worldServers[0]; - LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName); - - if (data == null) - { - data = new LifeEssenceNetwork(ownerName); - world.setItemData(ownerName, data); - } - - return data.currentEssence >= damageToBeDone; + return syphonFromNetwork(ownerName, damageToBeDone); } - - return false; + return 0; } - - public static int getCurrentEssence(String ownerName) - { - if (MinecraftServer.getServer() == null) + + public static int syphonFromNetwork(String ownerName, int damageToBeDone) + { + if (MinecraftServer.getServer() == null) { return 0; } @@ -103,13 +60,137 @@ public class SoulNetworkHandler data = new LifeEssenceNetwork(ownerName); world.setItemData(ownerName, data); } + + if (data.currentEssence >= damageToBeDone) + { + data.currentEssence -= damageToBeDone; + data.markDirty(); + return damageToBeDone; + } + + return 0; + } + + /** + * Master method used to syphon from the player's network, and will damage them accordingly if they do not have enough LP. + * Does not drain on the client side. + * + * @param ist Owned itemStack + * @param player Player using the item + * @param damageToBeDone + * @return True if the action should be executed and false if it should not. Always returns false if client-sided. + */ + public static boolean syphonAndDamageFromNetwork(ItemStack ist, EntityPlayer player, int drain) + { + if (player.worldObj.isRemote) + { + return false; + } + if (ist.getTagCompound() != null && !(ist.getTagCompound().getString("ownerName").equals(""))) + { + String ownerName = ist.getTagCompound().getString("ownerName"); + + ItemDrainNetworkEvent event = new ItemDrainNetworkEvent(player, ownerName, ist, drain); + + if(MinecraftForge.EVENT_BUS.post(event)) + { + return false; + } + + int drainAmount = syphonFromNetwork(event.ownerNetwork, event.drainAmount); + if(drainAmount == 0 || event.shouldDamage) + { + hurtPlayer(player, event.damageAmount); + } + + return (event.getResult() != Event.Result.DENY); //The event has been told to prevent the action but allow all repercussions of using the item. + } + + int amount = SoulNetworkHandler.syphonFromNetwork(ist, drain); + + hurtPlayer(player, drain - amount); + + return true; + } + + public static boolean syphonAndDamageFromNetwork(String ownerName, EntityPlayer player, int damageToBeDone) + { + if (player.worldObj.isRemote) + { + return false; + } + + World world = player.worldObj; + if (world != null) + { + double posX = player.posX; + double posY = player.posY; + double posZ = player.posZ; + + world.playSoundEffect((double) ((float) player.posX + 0.5F), (double) ((float) player.posY + 0.5F), (double) ((float) player.posZ + 0.5F), "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F); + } + + int amount = SoulNetworkHandler.syphonFromNetwork(ownerName, damageToBeDone); + + hurtPlayer(player, damageToBeDone - amount); + + return true; + } + + public static boolean canSyphonFromOnlyNetwork(ItemStack ist, int damageToBeDone) + { + if (ist.getTagCompound() != null && !(ist.getTagCompound().getString("ownerName").equals(""))) + { + String ownerName = ist.getTagCompound().getString("ownerName"); + + return canSyphonFromOnlyNetwork(ownerName, damageToBeDone); + } + + return false; + } + + public static boolean canSyphonFromOnlyNetwork(String ownerName, int damageToBeDone) + { + if (MinecraftServer.getServer() == null) + { + return false; + } + + World world = MinecraftServer.getServer().worldServers[0]; + LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName); + + if (data == null) + { + data = new LifeEssenceNetwork(ownerName); + world.setItemData(ownerName, data); + } + + return data.currentEssence >= damageToBeDone; + } + + public static int getCurrentEssence(String ownerName) + { + if (MinecraftServer.getServer() == null) + { + return 0; + } + + World world = MinecraftServer.getServer().worldServers[0]; + LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName); + + if (data == null) + { + data = new LifeEssenceNetwork(ownerName); + world.setItemData(ownerName, data); + } + return data.currentEssence; - } - - public static void setCurrentEssence(String ownerName, int essence) - { - if (MinecraftServer.getServer() == null) + } + + public static void setCurrentEssence(String ownerName, int essence) + { + if (MinecraftServer.getServer() == null) { return; } @@ -122,49 +203,59 @@ public class SoulNetworkHandler data = new LifeEssenceNetwork(ownerName); world.setItemData(ownerName, data); } - + data.currentEssence = essence; data.markDirty(); - } - - /** - * A method to add to an owner's network up to a maximum value. - * - * @param ownerName - * @param addedEssence - * @param maximum - * @return amount added to the network - */ - public static int addCurrentEssenceToMaximum(String ownerName, int addedEssence, int maximum) - { - if (MinecraftServer.getServer() == null) + } + + /** + * A method to add to an owner's network up to a maximum value. + * + * @param ownerName + * @param addedEssence + * @param maximum + * @return amount added to the network + */ + public static int addCurrentEssenceToMaximum(String ownerName, int addedEssence, int maximum) + { + AddToNetworkEvent event = new AddToNetworkEvent(ownerName, addedEssence, maximum); + + if(MinecraftForge.EVENT_BUS.post(event)) + { + return 0; + } + + if (MinecraftServer.getServer() == null) { return 0; } World world = MinecraftServer.getServer().worldServers[0]; - LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName); + LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, event.ownerNetwork); if (data == null) { - data = new LifeEssenceNetwork(ownerName); - world.setItemData(ownerName, data); + data = new LifeEssenceNetwork(event.ownerNetwork); + world.setItemData(event.ownerNetwork, data); } - + int currEss = data.currentEssence; - - if(currEss>=maximum) + + if (currEss >= event.maximum) { - return 0; + return 0; } - - int newEss = Math.min(maximum, currEss+addedEssence); - data.currentEssence = newEss; - - return newEss-currEss; - } - - public static void hurtPlayer(EntityPlayer user, int energySyphoned) + + int newEss = Math.min(event.maximum, currEss + event.addedAmount); + if(event.getResult() != Event.Result.DENY) + { + data.currentEssence = newEss; + } + + return newEss - currEss; + } + + public static void hurtPlayer(EntityPlayer user, int energySyphoned) { if (energySyphoned < 100 && energySyphoned > 0) { @@ -194,8 +285,21 @@ public class SoulNetworkHandler } } } + + public static void hurtPlayer(EntityPlayer user, float damage) + { + if (!user.capabilities.isCreativeMode) + { + user.setHealth((user.getHealth() - damage)); - public static void checkAndSetItemOwner(ItemStack item, EntityPlayer player) + if (user.getHealth() <= 0.0005f) + { + user.onDeath(DamageSource.generic); + } + } + } + + public static void checkAndSetItemOwner(ItemStack item, EntityPlayer player) { if (item.stackTagCompound == null) { @@ -204,7 +308,12 @@ public class SoulNetworkHandler if (item.stackTagCompound.getString("ownerName").equals("")) { - item.stackTagCompound.setString("ownerName", SoulNetworkHandler.getUsername(player)); + ItemBindEvent event = new ItemBindEvent(player, SoulNetworkHandler.getUsername(player), item); + + if(!MinecraftForge.EVENT_BUS.post(event)) + { + item.stackTagCompound.setString("ownerName", event.key); + } } } @@ -220,9 +329,50 @@ public class SoulNetworkHandler item.stackTagCompound.setString("ownerName", ownerName); } } - + public static String getUsername(EntityPlayer player) - { - return player.getDisplayName(); - } + { + return player.getDisplayName(); + } + + public static EntityPlayer getPlayerForUsername(String str) + { + if (MinecraftServer.getServer() == null) + { + return null; + } + return MinecraftServer.getServer().getConfigurationManager().func_152612_a(str); + } + + public static void causeNauseaToPlayer(ItemStack stack) + { + if (stack.getTagCompound() != null && !(stack.getTagCompound().getString("ownerName").equals(""))) + { + String ownerName = stack.getTagCompound().getString("ownerName"); + + SoulNetworkHandler.causeNauseaToPlayer(ownerName); + } + } + + public static void causeNauseaToPlayer(String ownerName) + { + EntityPlayer entityOwner = SoulNetworkHandler.getPlayerForUsername(ownerName); + + if (entityOwner == null) + { + return; + } + + entityOwner.addPotionEffect(new PotionEffect(Potion.confusion.id, 80)); + } + + public static String getOwnerName(ItemStack item) + { + if (item.stackTagCompound == null) + { + item.setTagCompound(new NBTTagCompound()); + } + + return item.stackTagCompound.getString("ownerName"); + } } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java new file mode 100644 index 0000000..a0cc0a5 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java @@ -0,0 +1,101 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +public class APISpellHelper +{ + public static MovingObjectPosition raytraceFromEntity(World world, Entity player, boolean par3, double range) + { + float f = 1.0F; + float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f; + float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f; + double d0 = player.prevPosX + (player.posX - player.prevPosX) * (double) f; + double d1 = player.prevPosY + (player.posY - player.prevPosY) * (double) f; + if (!world.isRemote && player instanceof EntityPlayer) + d1 += 1.62D; + double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * (double) f; + Vec3 vec3 = Vec3.createVectorHelper(d0, d1, d2); + float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI); + float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI); + float f5 = -MathHelper.cos(-f1 * 0.017453292F); + float f6 = MathHelper.sin(-f1 * 0.017453292F); + float f7 = f4 * f5; + float f8 = f3 * f5; + double d3 = range; + if (player instanceof EntityPlayerMP) + { + d3 = ((EntityPlayerMP) player).theItemInWorldManager.getBlockReachDistance(); + } + Vec3 vec31 = vec3.addVector((double) f7 * d3, (double) f6 * d3, (double) f8 * d3); + return world.func_147447_a(vec3, vec31, par3, !par3, par3); + } + + public static List getItemsFromBlock(World world, Block block, int x, int y, int z, int meta, boolean silkTouch, int fortune) + { + boolean canSilk = block.canSilkHarvest(world, null, x, y, z, meta); + + if (canSilk && silkTouch) + { + ArrayList items = new ArrayList(); + ItemStack item = new ItemStack(block, 1, meta); + + items.add(item); + + return items; + } else + { + return block.getDrops(world, x, y, z, meta, fortune); + } + } + + public static void spawnItemListInWorld(List items, World world, float x, float y, float z) + { + for (ItemStack stack : items) + { + EntityItem itemEntity = new EntityItem(world, x, y, z, stack); + itemEntity.delayBeforeCanPickup = 10; + world.spawnEntityInWorld(itemEntity); + } + } + + public static String getNumeralForInt(int num) + { + switch (num) + { + case 1: + return "I"; + case 2: + return "II"; + case 3: + return "III"; + case 4: + return "IV"; + case 5: + return "V"; + case 6: + return "VI"; + case 7: + return "VII"; + case 8: + return "VIII"; + case 9: + return "IX"; + case 10: + return "X"; + default: + return ""; + } + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellEffect.java new file mode 100644 index 0000000..26bcfc2 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellEffect.java @@ -0,0 +1,92 @@ +package WayofTime.alchemicalWizardry.api.spell; + + +public abstract class ComplexSpellEffect +{ + public final ComplexSpellType type; + public final ComplexSpellModifier modifier; + + protected int powerEnhancement; + protected int costEnhancement; + protected int potencyEnhancement; + + public ComplexSpellEffect(ComplexSpellType type, ComplexSpellModifier modifier) + { + this.type = type; + this.modifier = modifier; + } + + public ComplexSpellEffect(ComplexSpellType type, ComplexSpellModifier modifier, int power, int cost, int potency) + { + this(type, modifier); + + this.powerEnhancement = power; + this.costEnhancement = cost; + this.potencyEnhancement = potency; + } + + public abstract void modifyParadigm(SpellParadigm parad); + + public ComplexSpellType getType() + { + return this.type; + } + + public ComplexSpellModifier getModifier() + { + return this.modifier; + } + + public abstract ComplexSpellEffect copy(int power, int cost, int potency); + + public abstract int getCostOfEffect(); + +// public NBTTagCompound getTag() +// { +// NBTTagCompound tag = new NBTTagCompound(); +// +// tag.setString("Class", this.getClass().getName()); +// tag.setInteger("modifier", modifierState); +// tag.setInteger("power", powerEnhancement); +// tag.setInteger("cost", costEnhancement); +// tag.setInteger("potency", potencyEnhancement); +// +// return tag; +// } +// +// public static SpellEffect getEffectFromTag(NBTTagCompound tag) +// { +// try +// { +// Class clazz = Class.forName(tag.getString("Class")); +// if (clazz != null) +// { +// try +// { +// Object obj = clazz.newInstance(); +// if (obj instanceof SpellEffect) +// { +// SpellEffect eff = (SpellEffect) obj; +// +// eff.modifierState = tag.getInteger("modifier"); +// eff.powerEnhancement = tag.getInteger("power"); +// eff.costEnhancement = tag.getInteger("cost"); +// eff.potencyEnhancement = tag.getInteger("potency"); +// +// return eff; +// } +// } catch (InstantiationException e) +// { +// e.printStackTrace(); +// } catch (IllegalAccessException e) +// { +// e.printStackTrace(); +// } +// } +// } catch (ClassNotFoundException e) +// { +// e.printStackTrace(); +// } +// return null; +// } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellModifier.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellModifier.java new file mode 100644 index 0000000..537a5e2 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellModifier.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class ComplexSpellModifier +{ + public static ComplexSpellModifier DEFAULT = new ComplexSpellModifier(); + public static ComplexSpellModifier OFFENSIVE = new ComplexSpellModifier(); + public static ComplexSpellModifier DEFENSIVE = new ComplexSpellModifier(); + public static ComplexSpellModifier ENVIRONMENTAL = new ComplexSpellModifier(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellType.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellType.java new file mode 100644 index 0000000..1c308a8 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellType.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class ComplexSpellType +{ + public static ComplexSpellType FIRE = new ComplexSpellType(); + public static ComplexSpellType ICE = new ComplexSpellType(); + public static ComplexSpellType EARTH = new ComplexSpellType(); + public static ComplexSpellType WIND = new ComplexSpellType(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/EntitySpellProjectile.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/EntitySpellProjectile.java new file mode 100644 index 0000000..becdb32 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/EntitySpellProjectile.java @@ -0,0 +1,650 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.IProjectile; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.*; +import net.minecraft.world.World; +import net.minecraftforge.common.util.Constants; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +public class EntitySpellProjectile extends Entity implements IProjectile +{ + private int xTile = -1; + private int yTile = -1; + private int zTile = -1; + private int inTile = 0; + private int inData = 0; + private boolean inGround = false; + /** + * The owner of this arrow. + */ + public EntityPlayer shootingEntity; + private int ticksInAir = 0; + private int ricochetCounter = 0; + private boolean scheduledForDeath = false; + private boolean isSilkTouch = false; + + //Custom variables + private int maxRicochet = 0; + private float damage = 1; + public List impactList = new ArrayList(); + private boolean penetration = false; + public List updateEffectList = new ArrayList(); + public List spellEffectList = new LinkedList(); + private int blocksBroken = 0; + + public EntitySpellProjectile(World par1World) + { + super(par1World); + this.setSize(0.5F, 0.5F); + } + + public EntitySpellProjectile(World par1World, double par2, double par4, double par6) + { + super(par1World); + this.setSize(0.5F, 0.5F); + this.setPosition(par2, par4, par6); + yOffset = 0.0F; + } + + public EntitySpellProjectile(World par1World, EntityPlayer par2EntityPlayer) + { + super(par1World); + shootingEntity = par2EntityPlayer; + float par3 = 0.8F; + this.setSize(0.1F, 0.1F); + this.setLocationAndAngles(par2EntityPlayer.posX, par2EntityPlayer.posY + par2EntityPlayer.getEyeHeight(), par2EntityPlayer.posZ, par2EntityPlayer.rotationYaw, par2EntityPlayer.rotationPitch); + posX -= MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * 0.16F; + posY -= 0.2D; + posZ -= MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * 0.16F; + this.setPosition(posX, posY, posZ); + yOffset = 0.0F; + motionX = -MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI); + motionZ = MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI); + motionY = -MathHelper.sin(rotationPitch / 180.0F * (float) Math.PI); + this.setThrowableHeading(motionX, motionY, motionZ, par3 * 1.5F, 1.0F); + + } + + @Override + protected void entityInit() + { + dataWatcher.addObject(16, Byte.valueOf((byte) 0)); + } + + /** + * Similar to setArrowHeading, it's point the throwable entity to a x, y, z + * direction. + */ + @Override + public void setThrowableHeading(double var1, double var3, double var5, float var7, float var8) + { + float var9 = MathHelper.sqrt_double(var1 * var1 + var3 * var3 + var5 * var5); + var1 /= var9; + var3 /= var9; + var5 /= var9; + var1 += rand.nextGaussian() * 0.007499999832361937D * var8; + var3 += rand.nextGaussian() * 0.007499999832361937D * var8; + var5 += rand.nextGaussian() * 0.007499999832361937D * var8; + var1 *= var7; + var3 *= var7; + var5 *= var7; + motionX = var1; + motionY = var3; + motionZ = var5; + float var10 = MathHelper.sqrt_double(var1 * var1 + var5 * var5); + prevRotationYaw = rotationYaw = (float) (Math.atan2(var1, var5) * 180.0D / Math.PI); + prevRotationPitch = rotationPitch = (float) (Math.atan2(var3, var10) * 180.0D / Math.PI); + } + + @Override + @SideOnly(Side.CLIENT) + /** + * Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX, + * posY, posZ, yaw, pitch + */ + public void setPositionAndRotation2(double par1, double par3, double par5, float par7, float par8, int par9) + { + this.setPosition(par1, par3, par5); + this.setRotation(par7, par8); + } + + @Override + @SideOnly(Side.CLIENT) + /** + * Sets the velocity to the args. Args: x, y, z + */ + public void setVelocity(double par1, double par3, double par5) + { + motionX = par1; + motionY = par3; + motionZ = par5; + if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) + { + float var7 = MathHelper.sqrt_double(par1 * par1 + par5 * par5); + prevRotationYaw = rotationYaw = (float) (Math.atan2(par1, par5) * 180.0D / Math.PI); + prevRotationPitch = rotationPitch = (float) (Math.atan2(par3, var7) * 180.0D / Math.PI); + prevRotationPitch = rotationPitch; + prevRotationYaw = rotationYaw; + this.setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch); + } + } + + /** + * Called to update the entity's position/logic. + */ + @Override + public void onUpdate() + { + super.onUpdate(); + this.performUpdateEffects(); + if (ticksInAir > 600) + { + this.setDead(); + } + if (shootingEntity == null) + { + List players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(posX - 1, posY - 1, posZ - 1, posX + 1, posY + 1, posZ + 1)); + Iterator i = players.iterator(); + double closestDistance = Double.MAX_VALUE; + EntityPlayer closestPlayer = null; + while (i.hasNext()) + { + EntityPlayer e = (EntityPlayer) i.next(); + double distance = e.getDistanceToEntity(this); + if (distance < closestDistance) + { + closestPlayer = e; + } + } + if (closestPlayer != null) + { + shootingEntity = closestPlayer; + } + } + if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) + { + float var1 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); + prevRotationYaw = rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI); + prevRotationPitch = rotationPitch = (float) (Math.atan2(motionY, var1) * 180.0D / Math.PI); + } + Block var16 = worldObj.getBlock(xTile, yTile, zTile); + + if (var16 != null) + { + var16.setBlockBoundsBasedOnState(worldObj, xTile, yTile, zTile); + AxisAlignedBB var2 = var16.getCollisionBoundingBoxFromPool(worldObj, xTile, yTile, zTile); + + if (var2 != null && var2.isVecInside(Vec3.createVectorHelper(posX, posY, posZ))) + { + inGround = true; + } + } + + if (inGround) + { + Block var18 = worldObj.getBlock(xTile, yTile, zTile); + int var19 = worldObj.getBlockMetadata(xTile, yTile, zTile); + + if (var18.equals(Block.getBlockById(inTile)) && var19 == inData) + { + // this.groundImpact(); + // this.setDead(); + } + } else + { + ++ticksInAir; + + if (ticksInAir > 1 && ticksInAir < 3) + { + //worldObj.spawnParticle("flame", posX + smallGauss(0.1D), posY + smallGauss(0.1D), posZ + smallGauss(0.1D), 0D, 0D, 0D); + for (int particles = 0; particles < 3; particles++) + { + this.doFiringParticles(); + } + } + + Vec3 var17 = Vec3.createVectorHelper(posX, posY, posZ); + Vec3 var3 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ); + MovingObjectPosition var4 = worldObj.func_147447_a(var17, var3, true, false, false); + var17 = Vec3.createVectorHelper(posX, posY, posZ); + var3 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ); + + if (var4 != null) + { + var3 = Vec3.createVectorHelper(var4.hitVec.xCoord, var4.hitVec.yCoord, var4.hitVec.zCoord); + } + + Entity var5 = null; + List var6 = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D)); + double var7 = 0.0D; + Iterator var9 = var6.iterator(); + float var11; + + while (var9.hasNext()) + { + Entity var10 = (Entity) var9.next(); + + if (var10.canBeCollidedWith() && (var10 != shootingEntity || ticksInAir >= 5)) + { + var11 = 0.3F; + AxisAlignedBB var12 = var10.boundingBox.expand(var11, var11, var11); + MovingObjectPosition var13 = var12.calculateIntercept(var17, var3); + + if (var13 != null) + { + double var14 = var17.distanceTo(var13.hitVec); + + if (var14 < var7 || var7 == 0.0D) + { + var5 = var10; + var7 = var14; + } + } + } + } + + if (var5 != null) + { + var4 = new MovingObjectPosition(var5); + } + + if (var4 != null) + { + this.onImpact(var4); + + if (scheduledForDeath) + { + this.setDead(); + } + } + + posX += motionX; + posY += motionY; + posZ += motionZ; + MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); + this.setPosition(posX, posY, posZ); + //this.doBlockCollisions(); + } + } + + private void doFlightParticles() + { + if (ticksInAir % 3 == 0) + { + double gauss = gaussian(1.0F); + worldObj.spawnParticle("mobSpell", posX, posY, posZ, gauss, gauss, 0.0F); + } + } + + private void doFiringParticles() + { + worldObj.spawnParticle("mobSpellAmbient", posX + smallGauss(0.1D), posY + smallGauss(0.1D), posZ + smallGauss(0.1D), 0.5D, 0.5D, 0.5D); + worldObj.spawnParticle("flame", posX, posY, posZ, gaussian(motionX), gaussian(motionY), gaussian(motionZ)); + } + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + @Override + public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) + { + par1NBTTagCompound.setShort("xTile", (short) xTile); + par1NBTTagCompound.setShort("yTile", (short) yTile); + par1NBTTagCompound.setShort("zTile", (short) zTile); + par1NBTTagCompound.setByte("inTile", (byte) inTile); + par1NBTTagCompound.setByte("inData", (byte) inData); + par1NBTTagCompound.setByte("inGround", (byte) (inGround ? 1 : 0)); + + NBTTagList effectList = new NBTTagList(); + + for (SpellEffect eff : spellEffectList) + { + effectList.appendTag(eff.getTag()); + } + +// for (String str : this.effectList) +// { +// if (str != null) +// { +// NBTTagCompound tag = new NBTTagCompound(); +// +// tag.setString("Class", str); +// effectList.appendTag(tag); +// } +// } + + par1NBTTagCompound.setTag("Effects", effectList); + par1NBTTagCompound.setInteger("blocksBroken", blocksBroken); + par1NBTTagCompound.setBoolean("isSilkTouch", isSilkTouch); + } + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + @Override + public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) + { + xTile = par1NBTTagCompound.getShort("xTile"); + yTile = par1NBTTagCompound.getShort("yTile"); + zTile = par1NBTTagCompound.getShort("zTile"); + inTile = par1NBTTagCompound.getByte("inTile") & 255; + inData = par1NBTTagCompound.getByte("inData") & 255; + inGround = par1NBTTagCompound.getByte("inGround") == 1; + blocksBroken = par1NBTTagCompound.getInteger("blocksBroken"); + isSilkTouch = par1NBTTagCompound.getBoolean("isSilkTouch"); + + NBTTagList tagList = par1NBTTagCompound.getTagList("Effects", Constants.NBT.TAG_COMPOUND); + + List spellEffectList = new LinkedList(); + for (int i = 0; i < tagList.tagCount(); i++) + { + NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); + + SpellEffect eff = SpellEffect.getEffectFromTag(tag); + if (eff != null) + { + spellEffectList.add(eff); + } + } + this.spellEffectList = spellEffectList; + + +// this.effectList = new LinkedList(); +// for (int i = 0; i < tagList.tagCount(); i++) +// { +// NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i); +// +// this.effectList.add(tag.getString("Class")); +// } + + //SpellParadigmProjectile parad = SpellParadigmProjectile.getParadigmForStringArray(effectList); + SpellParadigmProjectile parad = SpellParadigmProjectile.getParadigmForEffectArray(spellEffectList); + parad.applyAllSpellEffects(); + parad.prepareProjectile(this); + } + + /** + * returns if this entity triggers Block.onEntityWalking on the blocks they + * walk on. used for spiders and wolves to prevent them from trampling crops + */ + @Override + protected boolean canTriggerWalking() + { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public float getShadowSize() + { + return 0.0F; + } + + /** + * Sets the amount of knockback the arrow applies when it hits a mob. + */ + public void setKnockbackStrength(int par1) + { + } + + /** + * If returns false, the item will not inflict any damage against entities. + */ + @Override + public boolean canAttackWithItem() + { + return false; + } + + /** + * Whether the arrow has a stream of critical hit particles flying behind + * it. + */ + public void setIsCritical(boolean par1) + { + byte var2 = dataWatcher.getWatchableObjectByte(16); + if (par1) + { + dataWatcher.updateObject(16, Byte.valueOf((byte) (var2 | 1))); + } else + { + dataWatcher.updateObject(16, Byte.valueOf((byte) (var2 & -2))); + } + } + + /** + * Whether the arrow has a stream of critical hit particles flying behind + * it. + */ + public boolean getIsCritical() + { + byte var1 = dataWatcher.getWatchableObjectByte(16); + return (var1 & 1) != 0; + } + + private void onImpact(MovingObjectPosition mop) + { + if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY && mop.entityHit != null) + { + if (mop.entityHit == shootingEntity) return; + this.onImpact(mop.entityHit); + this.performEntityImpactEffects(mop.entityHit); + } else if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) + { + if (!this.penetration) + { + this.groundImpact(mop.sideHit); + this.performTileImpactEffects(mop); + } + } + } + + private void onImpact(Entity mop) //TODO + { + if (mop == shootingEntity && ticksInAir > 3) + { + shootingEntity.attackEntityFrom(DamageSource.causePlayerDamage(shootingEntity), 1); + this.setDead(); + } else + { + doDamage(this.damage, mop); + } + spawnHitParticles("exorcism", 8); + this.setDead(); + } + + + private void spawnHitParticles(String string, int i) + { + for (int particles = 0; particles < i; particles++) + { + worldObj.spawnParticle("mobSpellAmbient", posX + smallGauss(0.1D), posY + smallGauss(0.1D), posZ + smallGauss(0.1D), posGauss(1.0F), posGauss(1.0F), 0.0F); + } + } + + private void doDamage(float f, Entity mop) + { + mop.attackEntityFrom(this.getDamageSource(), f); + } + + private DamageSource getDamageSource() + { + return DamageSource.causePlayerDamage(shootingEntity); + } + + private void groundImpact(int sideHit) + { + this.ricochet(sideHit); + } + + private double smallGauss(double d) + { + return (worldObj.rand.nextFloat() - 0.5D) * d; + } + + private double posGauss(double d) + { + return rand.nextFloat() * 0.5D * d; + } + + private double gaussian(double d) + { + return d + d * ((rand.nextFloat() - 0.5D) / 4); + } + + private void ricochet(int sideHit) + { + switch (sideHit) + { + case 0: + case 1: + // topHit, bottomHit, reflect Y + motionY = motionY * -1; + break; + case 2: + case 3: + // westHit, eastHit, reflect Z + motionZ = motionZ * -1; + break; + case 4: + case 5: + // southHit, northHit, reflect X + motionX = motionX * -1; + break; + } + ricochetCounter++; + if (ricochetCounter > this.getRicochetMax()) + { + scheduledForDeath = true; + for (int particles = 0; particles < 4; particles++) + { + switch (sideHit) + { + case 0: + worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), -gaussian(0.1D), gaussian(0.1D)); + break; + case 1: + worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), gaussian(0.1D)); + break; + case 2: + worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), -gaussian(0.1D)); + break; + case 3: + worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), gaussian(0.1D)); + break; + case 4: + worldObj.spawnParticle("smoke", posX, posY, posZ, -gaussian(0.1D), gaussian(0.1D), gaussian(0.1D)); + break; + case 5: + worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), gaussian(0.1D)); + break; + } + } + } + } + + //Custom stuff + public int getRicochetMax() + { + return this.maxRicochet; + } + + public void setRicochetMax(int ricochet) + { + this.maxRicochet = ricochet; + } + + public void setImpactList(List list) + { + this.impactList = list; + } + + public void setUpdateEffectList(List list) + { + this.updateEffectList = list; + } + + private void performEntityImpactEffects(Entity mop) + { + if (impactList != null) + { + for (IProjectileImpactEffect impactEffect : impactList) + { + impactEffect.onEntityImpact(mop, this); + } + } + } + + private void performTileImpactEffects(MovingObjectPosition mop) + { + if (impactList != null) + { + for (IProjectileImpactEffect impactEffect : impactList) + { + impactEffect.onTileImpact(worldObj, mop); + } + } + } + + private void performUpdateEffects() + { + if (updateEffectList != null) + { + for (IProjectileUpdateEffect updateEffect : updateEffectList) + { + updateEffect.onUpdateEffect(this); + } + } + } + + public void setPenetration(boolean penetration) + { + this.penetration = penetration; + } + + public float getDamage() + { + return this.damage; + } + + public void setDamage(float damage) + { + this.damage = damage; + } + + public void setSpellEffectList(List list) + { + this.spellEffectList = list; + } + + public int getBlocksBroken() + { + return this.blocksBroken; + } + + public void setBlocksBroken(int blocksBroken) + { + this.blocksBroken = blocksBroken; + } + + public boolean getIsSilkTouch() + { + return this.isSilkTouch; + } + + public void setIsSilkTouch(boolean bool) + { + this.isSilkTouch = bool; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ExtrapolatedMeleeEntityEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ExtrapolatedMeleeEntityEffect.java new file mode 100644 index 0000000..0392937 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ExtrapolatedMeleeEntityEffect.java @@ -0,0 +1,72 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +import java.util.List; + +public abstract class ExtrapolatedMeleeEntityEffect implements IMeleeSpellEntityEffect +{ + protected float range; + protected float radius; + protected int powerUpgrades; + protected int potencyUpgrades; + protected int costUpgrades; + protected int maxHit; + + public ExtrapolatedMeleeEntityEffect(int power, int potency, int cost) + { + this.powerUpgrades = power; + this.potencyUpgrades = potency; + this.costUpgrades = cost; + this.range = 0; + this.radius = 0; + this.maxHit = 1; + } + + @Override + public void onEntityImpact(World world, EntityPlayer entityPlayer) + { + Vec3 lookVec = entityPlayer.getLook(range); + double x = entityPlayer.posX + lookVec.xCoord; + double y = entityPlayer.posY + entityPlayer.getEyeHeight() + lookVec.yCoord; + double z = entityPlayer.posZ + lookVec.zCoord; + + List entities = world.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(x - 0.5f, y - 0.5f, z - 0.5f, x + 0.5f, y + 0.5f, z + 0.5f).expand(radius, radius, radius)); + int hit = 0; + + if (entities != null) + { + for (Entity entity : entities) + { + if (hit < maxHit && !entity.equals(entityPlayer)) + { + if (this.entityEffect(world, entity, entityPlayer)) + { + hit++; + } + } + } + } + } + + protected abstract boolean entityEffect(World world, Entity entity, EntityPlayer player); + + public void setRange(float range) + { + this.range = range; + } + + public void setRadius(float radius) + { + this.radius = radius; + } + + public void setMaxNumberHit(int maxHit) + { + this.maxHit = maxHit; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IDigAreaEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IDigAreaEffect.java new file mode 100644 index 0000000..2355ed7 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IDigAreaEffect.java @@ -0,0 +1,12 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import WayofTime.alchemicalWizardry.api.items.ItemSpellMultiTool; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +public interface IDigAreaEffect +{ + public abstract int digSurroundingArea(ItemStack container, World world, EntityPlayer player, MovingObjectPosition blockPos, String usedToolClass, float blockHardness, int harvestLvl, ItemSpellMultiTool itemTool); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IItemManipulator.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IItemManipulator.java new file mode 100644 index 0000000..eb9b766 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IItemManipulator.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.item.ItemStack; + +import java.util.List; + +public interface IItemManipulator +{ + public List handleItemsOnBlockBroken(ItemStack toolStack, List itemList); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ILeftClickEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ILeftClickEffect.java new file mode 100644 index 0000000..65f53f8 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ILeftClickEffect.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; + +public interface ILeftClickEffect +{ + public abstract int onLeftClickEntity(ItemStack stack, EntityLivingBase attacked, EntityLivingBase weilder); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellEntityEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellEntityEffect.java new file mode 100644 index 0000000..6b5d7ef --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellEntityEffect.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public interface IMeleeSpellEntityEffect +{ + public void onEntityImpact(World world, EntityPlayer entityPlayer); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellWorldEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellWorldEffect.java new file mode 100644 index 0000000..b0560cf --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellWorldEffect.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public interface IMeleeSpellWorldEffect +{ + public void onWorldEffect(World world, EntityPlayer entityPlayer); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBanishTool.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBanishTool.java new file mode 100644 index 0000000..4e12fdd --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBanishTool.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IOnBanishTool +{ + public abstract int onBanishTool(ItemStack toolStack, World world, Entity entity, int invSlot, boolean inHand); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBreakBlock.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBreakBlock.java new file mode 100644 index 0000000..12f844c --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBreakBlock.java @@ -0,0 +1,12 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public interface IOnBreakBlock +{ + public abstract int onBlockBroken(ItemStack container, World world, EntityPlayer player, Block block, int meta, int x, int y, int z, ForgeDirection sideBroken); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnSummonTool.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnSummonTool.java new file mode 100644 index 0000000..6a5ea4d --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnSummonTool.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IOnSummonTool +{ + public abstract int onSummonTool(ItemStack toolStack, World world, Entity entity); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileImpactEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileImpactEffect.java new file mode 100644 index 0000000..c534823 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileImpactEffect.java @@ -0,0 +1,12 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +public interface IProjectileImpactEffect +{ + public void onEntityImpact(Entity mop, Entity projectile); + + public void onTileImpact(World world, MovingObjectPosition mop); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileUpdateEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileUpdateEffect.java new file mode 100644 index 0000000..e973538 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileUpdateEffect.java @@ -0,0 +1,8 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; + +public interface IProjectileUpdateEffect +{ + public void onUpdateEffect(Entity projectile); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IRightClickEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IRightClickEffect.java new file mode 100644 index 0000000..dd9f7d2 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IRightClickEffect.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +public interface IRightClickEffect +{ + //public abstract int onRightClickEntity(ItemStack stack, EntityLivingBase attacked, EntityLivingBase weilder); + + public abstract int onRightClickBlock(ItemStack stack, EntityLivingBase weilder, World world, MovingObjectPosition mop); + + public abstract int onRightClickAir(ItemStack stack, EntityLivingBase weilder); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISelfSpellEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISelfSpellEffect.java new file mode 100644 index 0000000..c49edaf --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISelfSpellEffect.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public interface ISelfSpellEffect +{ + public void onSelfUse(World world, EntityPlayer player); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISpecialDamageEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISpecialDamageEffect.java new file mode 100644 index 0000000..323ccf3 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISpecialDamageEffect.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; + +public interface ISpecialDamageEffect +{ + public float getDamageForEntity(Entity entity); + + public String getKey(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IToolUpdateEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IToolUpdateEffect.java new file mode 100644 index 0000000..c3bacfc --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IToolUpdateEffect.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IToolUpdateEffect +{ + public abstract int onUpdate(ItemStack toolStack, World world, Entity par3Entity, int invSlot, boolean inHand); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellCenteredWorldEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellCenteredWorldEffect.java new file mode 100644 index 0000000..68ec013 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellCenteredWorldEffect.java @@ -0,0 +1,33 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +public abstract class MeleeSpellCenteredWorldEffect extends MeleeSpellWorldEffect +{ + protected float range; + + public MeleeSpellCenteredWorldEffect(int power, int potency, int cost) + { + super(power, potency, cost); + } + + @Override + public void onWorldEffect(World world, EntityPlayer entityPlayer) + { + Vec3 lookVec = entityPlayer.getLook(range).normalize(); + int x = (int) (entityPlayer.posX + lookVec.xCoord * range); + int y = (int) (entityPlayer.posY + entityPlayer.getEyeHeight() + lookVec.yCoord * range); + int z = (int) (entityPlayer.posZ + lookVec.zCoord * range); + + this.onCenteredWorldEffect(entityPlayer, world, x, y, z); + } + + public void setRange(float range) + { + this.range = range; + } + + public abstract void onCenteredWorldEffect(EntityPlayer player, World world, int posX, int posY, int posZ); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellWorldEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellWorldEffect.java new file mode 100644 index 0000000..844b540 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellWorldEffect.java @@ -0,0 +1,21 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public abstract class MeleeSpellWorldEffect implements IMeleeSpellWorldEffect +{ + protected int powerUpgrades; + protected int potencyUpgrades; + protected int costUpgrades; + + public MeleeSpellWorldEffect(int power, int potency, int cost) + { + this.powerUpgrades = power; + this.potencyUpgrades = potency; + this.costUpgrades = cost; + } + + @Override + public abstract void onWorldEffect(World world, EntityPlayer entityPlayer); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileImpactEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileImpactEffect.java new file mode 100644 index 0000000..22ef5db --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileImpactEffect.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public abstract class ProjectileImpactEffect implements IProjectileImpactEffect +{ + protected int powerUpgrades; + protected int potencyUpgrades; + protected int costUpgrades; + + public ProjectileImpactEffect(int power, int potency, int cost) + { + this.powerUpgrades = power; + this.potencyUpgrades = potency; + this.costUpgrades = cost; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileUpdateEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileUpdateEffect.java new file mode 100644 index 0000000..500e7cf --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileUpdateEffect.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public abstract class ProjectileUpdateEffect implements IProjectileUpdateEffect +{ + protected int powerUpgrades; + protected int potencyUpgrades; + protected int costUpgrades; + + public ProjectileUpdateEffect(int power, int potency, int cost) + { + this.powerUpgrades = power; + this.potencyUpgrades = potency; + this.costUpgrades = cost; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SelfSpellEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SelfSpellEffect.java new file mode 100644 index 0000000..5e9e356 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SelfSpellEffect.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public abstract class SelfSpellEffect implements ISelfSpellEffect +{ + protected int powerUpgrades; + protected int potencyUpgrades; + protected int costUpgrades; + + public SelfSpellEffect(int power, int potency, int cost) + { + this.powerUpgrades = power; + this.potencyUpgrades = potency; + this.costUpgrades = cost; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffect.java new file mode 100644 index 0000000..1ae52ba --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffect.java @@ -0,0 +1,500 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.nbt.NBTTagCompound; + +/** + * New wrapper class to enclose the ComplexSpellEffect + */ +public class SpellEffect +{ + public ComplexSpellType type; + public ComplexSpellModifier modifier; + + protected int powerEnhancement; + protected int costEnhancement; + protected int potencyEnhancement; + + public SpellEffect() + { + this(ComplexSpellType.FIRE); + } + + public SpellEffect(ComplexSpellType type) + { + this(type, ComplexSpellModifier.DEFAULT); + } + + public SpellEffect(ComplexSpellType type, ComplexSpellModifier modifier) + { + this.type = type; + this.modifier = modifier; + + this.powerEnhancement = 0; + this.potencyEnhancement = 0; + this.costEnhancement = 0; + } + + public void enhanceEffect(SpellEnhancement enh) + { + if (enh != null) + { + switch (enh.getState()) + { + case SpellEnhancement.POWER: + this.powerEnhancement++; + break; + case SpellEnhancement.EFFICIENCY: + this.costEnhancement++; + break; + case SpellEnhancement.POTENCY: + this.potencyEnhancement++; + break; + } + } + } + + public void modifyEffect(ComplexSpellModifier mod) + { + if(mod != null) + { + this.modifier = mod; + } + } + + public void modifyParadigm(SpellParadigm parad) //When modifying the paradigm it will instead get the class name and ask the registry + { + if(parad == null) + { + return; + } + + Class paraClass = parad.getClass(); + + ComplexSpellEffect effect = SpellEffectRegistry.getSpellEffect(paraClass, type, modifier, powerEnhancement, potencyEnhancement, costEnhancement); + + if(effect != null) + { + effect.modifyParadigm(parad); + } + } + + public int getCostOfEffect(SpellParadigm parad) + { + if(parad == null) + { + return 0; + } + + Class paraClass = parad.getClass(); + + ComplexSpellEffect effect = SpellEffectRegistry.getSpellEffect(paraClass, type, modifier, powerEnhancement, potencyEnhancement, costEnhancement); + + if(effect == null) + { + return 0; + } + + return effect.getCostOfEffect(); + } + + public NBTTagCompound getTag() + { + NBTTagCompound tag = new NBTTagCompound(); + + tag.setString("Class", this.getClass().getName()); + tag.setString("type", SpellEffectRegistry.getKeyForType(type)); + tag.setString("modifier", SpellEffectRegistry.getKeyForModifier(modifier)); + tag.setInteger("power", powerEnhancement); + tag.setInteger("cost", costEnhancement); + tag.setInteger("potency", potencyEnhancement); + + return tag; + } + + public static SpellEffect getEffectFromTag(NBTTagCompound tag) + { + try + { + Class clazz = Class.forName(tag.getString("Class")); + if (clazz != null) + { + try + { + Object obj = clazz.newInstance(); + if (obj instanceof SpellEffect) + { + SpellEffect eff = (SpellEffect) obj; + + eff.type = SpellEffectRegistry.getTypeForKey(tag.getString("type")); + eff.modifier = SpellEffectRegistry.getModifierForKey(tag.getString("modifier")); + eff.powerEnhancement = tag.getInteger("power"); + eff.costEnhancement = tag.getInteger("cost"); + eff.potencyEnhancement = tag.getInteger("potency"); + + return eff; + } + } catch (InstantiationException e) + { + e.printStackTrace(); + } catch (IllegalAccessException e) + { + e.printStackTrace(); + } + } + } catch (ClassNotFoundException e) + { + e.printStackTrace(); + } + return null; + } + + public int getPowerEnhancements() + { + return this.powerEnhancement; + } + + public int getPotencyEnhancements() + { + return this.potencyEnhancement; + } + + public int getCostEnhancements() + { + return this.costEnhancement; + } +} + +//package WayofTime.alchemicalWizardry.common.spell.complex.effect; +// +//import WayofTime.alchemicalWizardry.common.spell.complex.*; +//import WayofTime.alchemicalWizardry.common.spell.complex.enhancement.SpellEnhancement; +//import net.minecraft.nbt.NBTTagCompound; +// +//public abstract class SpellEffect +//{ +// protected int modifierState; +// protected int powerEnhancement; +// protected int costEnhancement; +// protected int potencyEnhancement; +// +// public SpellEffect() +// { +// this.modifierState = SpellModifier.DEFAULT; +// this.powerEnhancement = 0; +// this.costEnhancement = 0; +// this.potencyEnhancement = 0; +// } +// +// public void enhanceEffect(SpellEnhancement enh) +// { +// if (enh != null) +// { +// switch (enh.getState()) +// { +// case SpellEnhancement.POWER: +// this.powerEnhancement++; +// break; +// case SpellEnhancement.EFFICIENCY: +// this.costEnhancement++; +// break; +// case SpellEnhancement.POTENCY: +// this.potencyEnhancement++; +// break; +// } +// } +// } +// +// public void modifyEffect(SpellModifier mod) +// { +// if (mod != null) +// modifierState = mod.getModifier(); +// } +// +// public void modifyParadigm(SpellParadigm parad) //When modifying the paradigm it will instead get the class name and ask the registry +// { +// if (parad instanceof SpellParadigmProjectile) +// { +// this.modifyProjectileParadigm((SpellParadigmProjectile) parad); +// } +// if (parad instanceof SpellParadigmSelf) +// { +// this.modifySelfParadigm((SpellParadigmSelf) parad); +// } +// if (parad instanceof SpellParadigmMelee) +// { +// this.modifyMeleeParadigm((SpellParadigmMelee) parad); +// } +// if (parad instanceof SpellParadigmTool) +// { +// this.modifyToolParadigm((SpellParadigmTool) parad); +// } +// } +// +// public void modifyProjectileParadigm(SpellParadigmProjectile parad) +// { +// switch (modifierState) +// { +// case SpellModifier.DEFAULT: +// this.defaultModificationProjectile(parad); +// break; +// case SpellModifier.OFFENSIVE: +// this.offensiveModificationProjectile(parad); +// break; +// case SpellModifier.DEFENSIVE: +// this.defensiveModificationProjectile(parad); +// break; +// case SpellModifier.ENVIRONMENTAL: +// this.environmentalModificationProjectile(parad); +// break; +// } +// } +// +// public abstract void defaultModificationProjectile(SpellParadigmProjectile parad); +// +// public abstract void offensiveModificationProjectile(SpellParadigmProjectile parad); +// +// public abstract void defensiveModificationProjectile(SpellParadigmProjectile parad); +// +// public abstract void environmentalModificationProjectile(SpellParadigmProjectile parad); +// +// public void modifySelfParadigm(SpellParadigmSelf parad) +// { +// switch (modifierState) +// { +// case SpellModifier.DEFAULT: +// this.defaultModificationSelf(parad); +// break; +// case SpellModifier.OFFENSIVE: +// this.offensiveModificationSelf(parad); +// break; +// case SpellModifier.DEFENSIVE: +// this.defensiveModificationSelf(parad); +// break; +// case SpellModifier.ENVIRONMENTAL: +// this.environmentalModificationSelf(parad); +// break; +// } +// } +// +// public abstract void defaultModificationSelf(SpellParadigmSelf parad); +// +// public abstract void offensiveModificationSelf(SpellParadigmSelf parad); +// +// public abstract void defensiveModificationSelf(SpellParadigmSelf parad); +// +// public abstract void environmentalModificationSelf(SpellParadigmSelf parad); +// +// public void modifyMeleeParadigm(SpellParadigmMelee parad) +// { +// switch (modifierState) +// { +// case SpellModifier.DEFAULT: +// this.defaultModificationMelee(parad); +// break; +// case SpellModifier.OFFENSIVE: +// this.offensiveModificationMelee(parad); +// break; +// case SpellModifier.DEFENSIVE: +// this.defensiveModificationMelee(parad); +// break; +// case SpellModifier.ENVIRONMENTAL: +// this.environmentalModificationMelee(parad); +// break; +// } +// } +// +// public abstract void defaultModificationMelee(SpellParadigmMelee parad); +// +// public abstract void offensiveModificationMelee(SpellParadigmMelee parad); +// +// public abstract void defensiveModificationMelee(SpellParadigmMelee parad); +// +// public abstract void environmentalModificationMelee(SpellParadigmMelee parad); +// +// public void modifyToolParadigm(SpellParadigmTool parad) +// { +// switch (modifierState) +// { +// case SpellModifier.DEFAULT: +// this.defaultModificationTool(parad); +// break; +// case SpellModifier.OFFENSIVE: +// this.offensiveModificationTool(parad); +// break; +// case SpellModifier.DEFENSIVE: +// this.defensiveModificationTool(parad); +// break; +// case SpellModifier.ENVIRONMENTAL: +// this.environmentalModificationTool(parad); +// break; +// } +// } +// +// public abstract void defaultModificationTool(SpellParadigmTool parad); +// +// public abstract void offensiveModificationTool(SpellParadigmTool parad); +// +// public abstract void defensiveModificationTool(SpellParadigmTool parad); +// +// public abstract void environmentalModificationTool(SpellParadigmTool parad); +// +// public int getCostForProjectile() +// { +// switch (this.modifierState) +// { +// case SpellModifier.DEFAULT: +// return this.getCostForDefaultProjectile(); +// case SpellModifier.OFFENSIVE: +// return this.getCostForOffenseProjectile(); +// case SpellModifier.DEFENSIVE: +// return this.getCostForDefenseProjectile(); +// case SpellModifier.ENVIRONMENTAL: +// return this.getCostForEnvironmentProjectile(); +// } +// return 0; +// } +// +// protected abstract int getCostForDefaultProjectile(); +// +// protected abstract int getCostForOffenseProjectile(); +// +// protected abstract int getCostForDefenseProjectile(); +// +// protected abstract int getCostForEnvironmentProjectile(); +// +// public int getCostForSelf() +// { +// switch (this.modifierState) +// { +// case SpellModifier.DEFAULT: +// return this.getCostForDefaultSelf(); +// case SpellModifier.OFFENSIVE: +// return this.getCostForOffenseSelf(); +// case SpellModifier.DEFENSIVE: +// return this.getCostForDefenseSelf(); +// case SpellModifier.ENVIRONMENTAL: +// return this.getCostForEnvironmentSelf(); +// } +// return 0; +// } +// +// protected abstract int getCostForDefaultSelf(); +// +// protected abstract int getCostForOffenseSelf(); +// +// protected abstract int getCostForDefenseSelf(); +// +// protected abstract int getCostForEnvironmentSelf(); +// +// public int getCostForMelee() +// { +// switch (this.modifierState) +// { +// case SpellModifier.DEFAULT: +// return this.getCostForDefaultMelee(); +// case SpellModifier.OFFENSIVE: +// return this.getCostForOffenseMelee(); +// case SpellModifier.DEFENSIVE: +// return this.getCostForDefenseMelee(); +// case SpellModifier.ENVIRONMENTAL: +// return this.getCostForEnvironmentMelee(); +// } +// return 0; +// } +// +// protected abstract int getCostForDefaultMelee(); +// +// protected abstract int getCostForOffenseMelee(); +// +// protected abstract int getCostForDefenseMelee(); +// +// protected abstract int getCostForEnvironmentMelee(); +// +// public int getCostForTool() +// { +// switch (this.modifierState) +// { +// case SpellModifier.DEFAULT: +// return this.getCostForDefaultTool(); +// case SpellModifier.OFFENSIVE: +// return this.getCostForOffenseTool(); +// case SpellModifier.DEFENSIVE: +// return this.getCostForDefenseTool(); +// case SpellModifier.ENVIRONMENTAL: +// return this.getCostForEnvironmentTool(); +// } +// return 0; +// } +// +// protected abstract int getCostForDefaultTool(); +// +// protected abstract int getCostForOffenseTool(); +// +// protected abstract int getCostForDefenseTool(); +// +// protected abstract int getCostForEnvironmentTool(); +// +// public int getPowerEnhancements() +// { +// return this.powerEnhancement; +// } +// +// public int getCostEnhancements() +// { +// return this.costEnhancement; +// } +// +// public int getPotencyEnhancements() +// { +// return this.potencyEnhancement; +// } +// +// public NBTTagCompound getTag() +// { +// NBTTagCompound tag = new NBTTagCompound(); +// +// tag.setString("Class", this.getClass().getName()); +// tag.setInteger("modifier", modifierState); +// tag.setInteger("power", powerEnhancement); +// tag.setInteger("cost", costEnhancement); +// tag.setInteger("potency", potencyEnhancement); +// +// return tag; +// } +// +// public static SpellEffect getEffectFromTag(NBTTagCompound tag) +// { +// try +// { +// Class clazz = Class.forName(tag.getString("Class")); +// if (clazz != null) +// { +// try +// { +// Object obj = clazz.newInstance(); +// if (obj instanceof SpellEffect) +// { +// SpellEffect eff = (SpellEffect) obj; +// +// eff.modifierState = tag.getInteger("modifier"); +// eff.powerEnhancement = tag.getInteger("power"); +// eff.costEnhancement = tag.getInteger("cost"); +// eff.potencyEnhancement = tag.getInteger("potency"); +// +// return eff; +// } +// } catch (InstantiationException e) +// { +// e.printStackTrace(); +// } catch (IllegalAccessException e) +// { +// e.printStackTrace(); +// } +// } +// } catch (ClassNotFoundException e) +// { +// e.printStackTrace(); +// } +// return null; +// } +//} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffectRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffectRegistry.java new file mode 100644 index 0000000..9d60722 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffectRegistry.java @@ -0,0 +1,159 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class SpellEffectRegistry +{ + public static Map, List> effectRegistry = new HashMap(); + public static Map typeRegistry = new HashMap(); + public static Map modifierRegistry = new HashMap(); + + public static void registerSpellEffect(Class paraClass, ComplexSpellEffect effect) + { + if(paraClass == null || effect == null) + { + return; + } + + if(effectRegistry.containsKey(paraClass)) + { + List effectList = effectRegistry.get(paraClass); + ComplexSpellType type = effect.getType(); + ComplexSpellModifier modifier = effect.getModifier(); + + if(type == null || modifier == null) + { + return; + } + + for(ComplexSpellEffect eff : effectList) + { + if(type.equals(eff.getType()) && modifier.equals(eff.getModifier())) + { + effectList.remove(eff); + effectList.add(effect); + return; + } + } + + effectList.add(effect); + }else + { + List effectList = new LinkedList(); + effectList.add(effect); + effectRegistry.put(paraClass, effectList); + } + } + + /** + * + * @param paraClass + * @param type + * @param mod + * @return A copy of the spell effect + */ + public static ComplexSpellEffect getSpellEffect(Class paraClass, ComplexSpellType type, ComplexSpellModifier mod) + { + return SpellEffectRegistry.getSpellEffect(paraClass, type, mod, 0, 0, 0); + } + + public static ComplexSpellEffect getSpellEffect(Class paraClass, ComplexSpellType type, ComplexSpellModifier mod, int power, int potency, int cost) + { + System.out.println("Debuging"); + + if(paraClass == null || type == null || mod == null) + { + return null; + } + + List list = effectRegistry.get(paraClass); + + if(list == null || list.isEmpty()) + { + return null; + } + + for(ComplexSpellEffect effect : list) + { + if(effect != null && type.equals(effect.type) && mod.equals(effect.modifier)) + { + return effect.copy(power, cost, potency); + } + } + + return null; + } + + public static void registerSpellType(String key, ComplexSpellType type) + { + typeRegistry.put(key, type); + } + + public static void registerSpellModifier(String key, ComplexSpellModifier modifier) + { + modifierRegistry.put(key, modifier); + } + + public static ComplexSpellType getTypeForKey(String key) + { + return typeRegistry.get(key); + } + + public static String getKeyForType(ComplexSpellType type) + { + if(type == null) + { + return ""; + } + + for(Entry entry : typeRegistry.entrySet()) + { + if(type.equals(entry.getValue())) + { + return entry.getKey(); + } + } + + return ""; + } + + public static ComplexSpellModifier getModifierForKey(String key) + { + return modifierRegistry.get(key); + } + + public static String getKeyForModifier(ComplexSpellModifier modifier) + { + if(modifier == null) + { + return ""; + } + + for(Entry entry : modifierRegistry.entrySet()) + { + if(modifier.equals(entry.getValue())) + { + return entry.getKey(); + } + } + + return ""; + } + + public static void initiateRegistry() + { + SpellEffectRegistry.registerSpellType("FIRE", ComplexSpellType.FIRE); + SpellEffectRegistry.registerSpellType("WATER", ComplexSpellType.ICE); + SpellEffectRegistry.registerSpellType("EARTH", ComplexSpellType.EARTH); + SpellEffectRegistry.registerSpellType("AIR", ComplexSpellType.WIND); + + SpellEffectRegistry.registerSpellModifier("DEFAULT", ComplexSpellModifier.DEFAULT); + SpellEffectRegistry.registerSpellModifier("OFFENSIVE", ComplexSpellModifier.OFFENSIVE); + SpellEffectRegistry.registerSpellModifier("DEFENSIVE", ComplexSpellModifier.DEFENSIVE); + SpellEffectRegistry.registerSpellModifier("ENVIRONMENTAL", ComplexSpellModifier.ENVIRONMENTAL); + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancement.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancement.java new file mode 100644 index 0000000..acbbdcc --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancement.java @@ -0,0 +1,20 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class SpellEnhancement +{ + public static final int POWER = 0; + public static final int EFFICIENCY = 1; + public static final int POTENCY = 2; + + private int state = this.POWER; + + protected SpellEnhancement(int state) + { + this.state = state; + } + + public int getState() + { + return this.state; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementCost.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementCost.java new file mode 100644 index 0000000..8078ce6 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementCost.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class SpellEnhancementCost extends SpellEnhancement +{ + + public SpellEnhancementCost() + { + super(SpellEnhancement.EFFICIENCY); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPotency.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPotency.java new file mode 100644 index 0000000..a540f89 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPotency.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class SpellEnhancementPotency extends SpellEnhancement +{ + public SpellEnhancementPotency() + { + super(SpellEnhancement.POTENCY); + } + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPower.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPower.java new file mode 100644 index 0000000..044ef10 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPower.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class SpellEnhancementPower extends SpellEnhancement +{ + + public SpellEnhancementPower() + { + super(SpellEnhancement.POWER); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigm.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigm.java new file mode 100644 index 0000000..5423cb4 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigm.java @@ -0,0 +1,131 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public abstract class SpellParadigm +{ + protected List bufferedEffectList = new LinkedList(); + + public void addBufferedEffect(SpellEffect effect) + { + if (effect != null) + { + this.bufferedEffectList.add(effect); + } + } + + public void modifyBufferedEffect(ComplexSpellModifier modifier) + { + SpellEffect effect = this.getBufferedEffect(); + if (effect != null) + { + effect.modifyEffect(modifier); + } + } + + public void applyEnhancement(SpellEnhancement enh) + { + if (enh != null) + { + if (bufferedEffectList.isEmpty()) + { + this.enhanceParadigm(enh); + } else + { + SpellEffect effect = this.getBufferedEffect(); + if (effect != null) + { + effect.enhanceEffect(enh); + } + } + } + + } + + public abstract void enhanceParadigm(SpellEnhancement enh); + + public abstract void castSpell(World world, EntityPlayer entityPlayer, ItemStack itemStack); + + public void applySpellEffect(SpellEffect effect) + { + effect.modifyParadigm(this); + } + + public void applyAllSpellEffects() + { + for (SpellEffect effect : bufferedEffectList) + { + this.applySpellEffect(effect); + } + } + + public SpellEffect getBufferedEffect() + { + if (bufferedEffectList.isEmpty()) + { + return null; + } else + { + return bufferedEffectList.get(bufferedEffectList.size() - 1); + } + } + + public int getTotalCost() + { + int cost = 0; + if (this.bufferedEffectList != null && !this.bufferedEffectList.isEmpty()) + { + for(SpellEffect effect : bufferedEffectList) + { + cost += effect.getCostOfEffect(this); + } + + return (int) (cost * Math.sqrt(this.bufferedEffectList.size())); + } + + return getDefaultCost(); + } + + public abstract int getDefaultCost(); + + public int getBufferedEffectPower() + { + SpellEffect eff = this.getBufferedEffect(); + + if (eff != null) + { + return eff.getPowerEnhancements(); + } + + return 0; + } + + public int getBufferedEffectCost() + { + SpellEffect eff = this.getBufferedEffect(); + + if (eff != null) + { + return eff.getCostEnhancements(); + } + + return 0; + } + + public int getBufferedEffectPotency() + { + SpellEffect eff = this.getBufferedEffect(); + + if (eff != null) + { + return eff.getPotencyEnhancements(); + } + + return 0; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmMelee.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmMelee.java new file mode 100644 index 0000000..629f7db --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmMelee.java @@ -0,0 +1,70 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; + +public class SpellParadigmMelee extends SpellParadigm +{ + private List entityEffectList; + private List worldEffectList; + + public SpellParadigmMelee() + { + this.entityEffectList = new ArrayList(); + this.worldEffectList = new ArrayList(); + } + + @Override + public void enhanceParadigm(SpellEnhancement enh) + { + + } + + @Override + public void castSpell(World world, EntityPlayer entityPlayer, ItemStack itemStack) + { + int cost = this.getTotalCost(); + + if(!SoulNetworkHandler.syphonAndDamageFromNetwork(itemStack, entityPlayer, cost)) + { + return; + } + + for (IMeleeSpellEntityEffect effect : entityEffectList) + { + effect.onEntityImpact(world, entityPlayer); + } + + for (IMeleeSpellWorldEffect effect : worldEffectList) + { + effect.onWorldEffect(world, entityPlayer); + } + } + + public void addEntityEffect(IMeleeSpellEntityEffect eff) + { + if (eff != null) + { + this.entityEffectList.add(eff); + } + } + + public void addWorldEffect(IMeleeSpellWorldEffect eff) + { + if (eff != null) + { + this.worldEffectList.add(eff); + } + } + + @Override + public int getDefaultCost() + { + return 0; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmProjectile.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmProjectile.java new file mode 100644 index 0000000..8b6f6a3 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmProjectile.java @@ -0,0 +1,101 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; + +public class SpellParadigmProjectile extends SpellParadigm +{ + public DamageSource damageSource; + public float damage; + public int cost; + public List impactList; + public List updateEffectList; + public boolean penetration; + public int ricochetMax; + public boolean isSilkTouch; + + public SpellParadigmProjectile() + { + this.damageSource = DamageSource.generic; + this.damage = 1; + this.cost = 0; + this.impactList = new ArrayList(); + this.updateEffectList = new ArrayList(); + this.penetration = false; + this.ricochetMax = 0; + this.isSilkTouch = false; + } + + @Override + public void enhanceParadigm(SpellEnhancement enh) + { + + } + + @Override + public void castSpell(World world, EntityPlayer entityPlayer, ItemStack itemStack) + { + int cost = this.getTotalCost(); + + if(!SoulNetworkHandler.syphonAndDamageFromNetwork(itemStack, entityPlayer, cost)) + { + return; + } + + EntitySpellProjectile proj = new EntitySpellProjectile(world, entityPlayer); + this.prepareProjectile(proj); + world.spawnEntityInWorld(proj); + } + + public static SpellParadigmProjectile getParadigmForEffectArray(List effectList) + { + SpellParadigmProjectile parad = new SpellParadigmProjectile(); + + for (SpellEffect eff : effectList) + { + parad.addBufferedEffect(eff); + } + + return parad; + } + + public void prepareProjectile(EntitySpellProjectile proj) + { + proj.setDamage(damage); + proj.setImpactList(impactList); + proj.setUpdateEffectList(updateEffectList); + proj.setPenetration(penetration); + proj.setRicochetMax(ricochetMax); + proj.setIsSilkTouch(isSilkTouch); + proj.setSpellEffectList(bufferedEffectList); + } + + public void addImpactEffect(IProjectileImpactEffect eff) + { + if (eff != null) + { + this.impactList.add(eff); + } + } + + public void addUpdateEffect(IProjectileUpdateEffect eff) + { + if (eff != null) + { + this.updateEffectList.add(eff); + } + } + + @Override + public int getDefaultCost() + { + return 50; + } + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmSelf.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmSelf.java new file mode 100644 index 0000000..89cffe0 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmSelf.java @@ -0,0 +1,58 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; + +public class SpellParadigmSelf extends SpellParadigm +{ + public List selfSpellEffectList; + + public SpellParadigmSelf() + { + selfSpellEffectList = new ArrayList(); + } + + @Override + public void enhanceParadigm(SpellEnhancement enh) + { + + } + + @Override + public void castSpell(World world, EntityPlayer entityPlayer, ItemStack itemStack) + { + this.applyAllSpellEffects(); + + int cost = this.getTotalCost(); + + if(!SoulNetworkHandler.syphonAndDamageFromNetwork(itemStack, entityPlayer, cost)) + { + return; + } + + for (ISelfSpellEffect eff : selfSpellEffectList) + { + eff.onSelfUse(world, entityPlayer); + } + } + + public void addSelfSpellEffect(ISelfSpellEffect eff) + { + if (eff != null) + { + this.selfSpellEffectList.add(eff); + } + } + + @Override + public int getDefaultCost() + { + return 100; + } + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmTool.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmTool.java new file mode 100644 index 0000000..f6cc001 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmTool.java @@ -0,0 +1,485 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import WayofTime.alchemicalWizardry.api.items.ItemSpellMultiTool; +import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; + +public class SpellParadigmTool extends SpellParadigm +{ + private List leftClickEffectList; + private List rightClickEffectList; + private List toolUpdateEffectList; + private List toolSummonEffectList; + private List toolBanishEffectList; + private List breakBlockEffectList; + private List itemManipulatorEffectList; + private List digAreaEffectList; + private List specialDamageEffectList; + + private float maxDamage; + private HashMap harvestLevel; + private HashMap digSpeed; + private HashMap maxDamageHash; + private HashMap critChanceHash; + private HashMap durationHash; + + private HashMap toolInfoString; + + private int fortuneLevel; + private boolean silkTouch; + + private int duration; + + public static Item customTool; + + public SpellParadigmTool() + { + this.leftClickEffectList = new LinkedList(); + this.rightClickEffectList = new LinkedList(); + this.toolUpdateEffectList = new LinkedList(); + this.toolSummonEffectList = new LinkedList(); + this.toolBanishEffectList = new LinkedList(); + this.breakBlockEffectList = new LinkedList(); + this.itemManipulatorEffectList = new LinkedList(); + this.digAreaEffectList = new LinkedList(); + this.specialDamageEffectList = new LinkedList(); + this.durationHash = new HashMap(); + + this.toolInfoString = new HashMap(); + this.critChanceHash = new HashMap(); + + this.maxDamage = 5; + + this.harvestLevel = new HashMap(); + this.harvestLevel.put("pickaxe", -1); + this.harvestLevel.put("shovel", -1); + this.harvestLevel.put("axe", -1); + + this.digSpeed = new HashMap(); + this.digSpeed.put("pickaxe", 1.0f); + this.digSpeed.put("shovel", 1.0f); + this.digSpeed.put("axe", 1.0f); + + this.maxDamageHash = new HashMap(); + this.maxDamageHash.put("default", 5.0f); + + this.fortuneLevel = 0; + this.silkTouch = false; + this.duration = 0; + this.durationHash.put("default", 2400); + } + + @Override + public void enhanceParadigm(SpellEnhancement enh) + { + + } + + @Override + public void castSpell(World world, EntityPlayer entityPlayer, ItemStack crystal) + { + if (entityPlayer.worldObj.isRemote) + { + return; + } + + int cost = this.getTotalCost(); + + if(!SoulNetworkHandler.syphonAndDamageFromNetwork(crystal, entityPlayer, cost)) + { + return; + } + + ItemStack toolStack = this.prepareTool(crystal, world); + + entityPlayer.setCurrentItemOrArmor(0, toolStack); + + this.onSummonTool(toolStack, world, entityPlayer); + } + + /** + * @param crystalStack + * @return stack containing the new multitool + */ + public ItemStack prepareTool(ItemStack crystalStack, World world) + { + ItemStack toolStack = new ItemStack(customTool, 1); + + ItemSpellMultiTool itemTool = (ItemSpellMultiTool) customTool; + + itemTool.setItemAttack(toolStack, this.composeMaxDamageFromHash()); + + Set> harvestLevelSet = this.harvestLevel.entrySet(); + + for (Entry testMap : harvestLevelSet) + { + String tool = testMap.getKey(); + int level = testMap.getValue(); + + itemTool.setHarvestLevel(toolStack, tool, level); + } + + Set> digSpeedSet = this.digSpeed.entrySet(); + + for (Entry testMap : digSpeedSet) + { + String tool = testMap.getKey(); + float speed = testMap.getValue(); + + itemTool.setDigSpeed(toolStack, tool, speed); + } + + itemTool.setFortuneLevel(toolStack, getFortuneLevel()); + itemTool.setSilkTouch(toolStack, this.getSilkTouch()); + + if (this.getSilkTouch()) + { + this.addToolString("SilkTouch", "Silk Touch" + " " + APISpellHelper.getNumeralForInt(1)); + } + + if (this.getFortuneLevel() > 0) + { + this.addToolString("Fortune", "Fortune" + " " + APISpellHelper.getNumeralForInt(this.getFortuneLevel())); + } + + itemTool.setCritChance(toolStack, this.getCritChance() / 100f); + + List toolStringList = new LinkedList(); + + for (String str : this.toolInfoString.values()) + { + toolStringList.add(str); + } + + itemTool.setToolListString(toolStack, toolStringList); + + for (Integer integ : this.durationHash.values()) + { + this.duration += integ; + } + + itemTool.setDuration(toolStack, world, this.duration); + itemTool.loadParadigmIntoStack(toolStack, this.bufferedEffectList); + + SoulNetworkHandler.checkAndSetItemOwner(toolStack, SoulNetworkHandler.getOwnerName(crystalStack)); + + itemTool.setContainedCrystal(toolStack, crystalStack); + + return toolStack; + } + + @Override + public int getDefaultCost() + { + return 100; + } + + public static SpellParadigmTool getParadigmForEffectArray(List effectList) + { + SpellParadigmTool parad = new SpellParadigmTool(); + + for (SpellEffect eff : effectList) + { + parad.addBufferedEffect(eff); + } + + parad.applyAllSpellEffects(); + + return parad; + } + + public void addLeftClickEffect(ILeftClickEffect eff) + { + if (eff != null) + { + this.leftClickEffectList.add(eff); + } + } + + public void addRightClickEffect(IRightClickEffect eff) + { + if (eff != null) + { + this.rightClickEffectList.add(eff); + } + } + + public void addUpdateEffect(IToolUpdateEffect eff) + { + if (eff != null) + { + this.toolUpdateEffectList.add(eff); + } + } + + public void addToolSummonEffect(IOnSummonTool eff) + { + if (eff != null) + { + this.toolSummonEffectList.add(eff); + } + } + + public void addToolBanishEffect(IOnBanishTool eff) + { + if (eff != null) + { + this.toolBanishEffectList.add(eff); + } + } + + public void addBlockBreakEffect(IOnBreakBlock eff) + { + if (eff != null) + { + this.breakBlockEffectList.add(eff); + } + } + + public void addItemManipulatorEffect(IItemManipulator eff) + { + if (eff != null) + { + this.itemManipulatorEffectList.add(eff); + } + } + + public void addDigAreaEffect(IDigAreaEffect eff) + { + if (eff != null) + { + this.digAreaEffectList.add(eff); + } + } + + public void addSpecialDamageEffect(ISpecialDamageEffect eff) + { + if (eff != null) + { + this.specialDamageEffectList.add(eff); + } + } + + public int onLeftClickEntity(ItemStack stack, EntityLivingBase attacked, EntityLivingBase weilder) + { + int total = 0; + for (ILeftClickEffect effect : this.leftClickEffectList) + { + total += effect.onLeftClickEntity(stack, attacked, weilder); + } + + return total; + } + + public int onRightClickBlock(ItemStack toolStack, EntityLivingBase weilder, World world, MovingObjectPosition mop) + { + int total = 0; + for (IRightClickEffect effect : this.rightClickEffectList) + { + total += effect.onRightClickBlock(toolStack, weilder, world, mop); + } + + return total; + } + + public int onRightClickAir(ItemStack toolStack, World world, EntityPlayer player) + { + int total = 0; + for (IRightClickEffect effect : this.rightClickEffectList) + { + total += effect.onRightClickAir(toolStack, player); + } + + return total; + } + + public int onUpdate(ItemStack toolStack, World world, Entity par3Entity, int invSlot, boolean inHand) + { + int total = 0; + for (IToolUpdateEffect effect : this.toolUpdateEffectList) + { + total += effect.onUpdate(toolStack, world, par3Entity, invSlot, inHand); + } + + return total; + } + + public int onSummonTool(ItemStack toolStack, World world, Entity entity) + { + int total = 0; + for (IOnSummonTool effect : this.toolSummonEffectList) + { + total += effect.onSummonTool(toolStack, world, entity); + } + + return total; + } + + public int onBanishTool(ItemStack toolStack, World world, Entity entity, int invSlot, boolean inHand) + { + int total = 0; + for (IOnBanishTool effect : this.toolBanishEffectList) + { + total += effect.onBanishTool(toolStack, world, entity, invSlot, inHand); + } + + return total; + } + + public int onBreakBlock(ItemStack container, World world, EntityPlayer player, Block block, int meta, int x, int y, int z, ForgeDirection sideBroken) + { + int total = 0; + for (IOnBreakBlock effect : this.breakBlockEffectList) + { + total += effect.onBlockBroken(container, world, player, block, meta, x, y, z, sideBroken); + } + + return total; + } + + public List handleItemList(ItemStack toolStack, List items) + { + List heldList = items; + + for (IItemManipulator eff : this.itemManipulatorEffectList) + { + List newHeldList = eff.handleItemsOnBlockBroken(toolStack, heldList); + heldList = newHeldList; + } + + return heldList; + } + + public int digSurroundingArea(ItemStack container, World world, EntityPlayer player, MovingObjectPosition blockPos, String usedToolClass, float blockHardness, int harvestLvl, ItemSpellMultiTool itemTool) + { + int cost = 0; + + for (IDigAreaEffect effect : this.digAreaEffectList) + { + cost += effect.digSurroundingArea(container, world, player, blockPos, usedToolClass, blockHardness, harvestLvl, itemTool); + } + + return cost; + } + + public int getFortuneLevel() + { + return this.fortuneLevel; + } + + public void setFortuneLevel(int fortuneLevel) + { + this.fortuneLevel = fortuneLevel; + } + + public boolean getSilkTouch() + { + return this.silkTouch; + } + + public void setSilkTouch(boolean silkTouch) + { + this.silkTouch = silkTouch; + } + + public int getDuration() + { + return this.duration; + } + + public void setDuration(int duration) + { + this.duration = duration; + } + + public void setDigSpeed(String toolClass, float digSpeed) + { + this.digSpeed.put(toolClass, digSpeed); + } + + public void setHarvestLevel(String toolClass, int hlvl) + { + this.harvestLevel.put(toolClass, hlvl); + } + + public float composeMaxDamageFromHash() + { + float damage = 0.0f; + + for (float f : this.maxDamageHash.values()) + { + damage += f; + } + + return damage; + } + + public void addDamageToHash(String key, float dmg) + { + this.maxDamageHash.put(key, dmg); + } + + public void addToolString(String key, String str) + { + if (str != null && key != null) + { + this.toolInfoString.put(key, str); + } + } + + public void addCritChance(String key, float chance) + { + //Chance is in percentage chance i.e. chance = 1.0 means 1.0% + this.critChanceHash.put(key, chance); + } + + public void addDuration(String key, int dur) + { + this.durationHash.put(key, dur); + } + + public float getCritChance() + { + float chance = 0.0f; + + for (float fl : this.critChanceHash.values()) + { + chance += fl; + } + + return chance; + } + + public float getAddedDamageForEntity(Entity entity) + { + HashMap hash = new HashMap(); + + for (ISpecialDamageEffect effect : this.specialDamageEffectList) + { + hash.put(effect.getKey(), effect.getDamageForEntity(entity)); + } + + float addedDmg = 0.0f; + + for (float fl : hash.values()) + { + addedDmg += fl; + } + + return addedDmg; + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningHelper.java b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningHelper.java index cccfe3f..84c4d3a 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningHelper.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningHelper.java @@ -5,16 +5,16 @@ import net.minecraft.world.World; public abstract class SummoningHelper { - protected int id; + protected String id; - public SummoningHelper(int id) + public SummoningHelper(String id) { this.id = id; } public abstract EntityLivingBase getEntity(World worldObj); - public int getSummoningHelperID() + public String getSummoningHelperID() { return id; } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistry.java index 9fda582..18180d8 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistry.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistry.java @@ -55,11 +55,11 @@ public class SummoningRegistry return null; } - public static EntityLivingBase getEntityWithID(World worldObj, int id) + public static EntityLivingBase getEntityWithID(World worldObj, String id) { for (SummoningRegistryComponent src : summoningList) { - if (src.getSummoningHelperID() == id) + if (src.getSummoningHelperID().equals(id)) { return src.getEntity(worldObj); } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistryComponent.java b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistryComponent.java index 8496b0f..72dbd83 100644 --- a/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistryComponent.java +++ b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistryComponent.java @@ -224,7 +224,7 @@ public class SummoningRegistryComponent } } - public int getSummoningHelperID() + public String getSummoningHelperID() { return this.summoningHelper.getSummoningHelperID(); } diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellParadigmTile.java b/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellParadigmTile.java new file mode 100644 index 0000000..de9994b --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellParadigmTile.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.tile; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface ISpellParadigmTile extends ISpellTile +{ + public void castSpell(World world, EntityPlayer entity, ItemStack spellCasterStack); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellTile.java b/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellTile.java new file mode 100644 index 0000000..143a0ea --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellTile.java @@ -0,0 +1,11 @@ +package WayofTime.alchemicalWizardry.api.tile; + +import net.minecraftforge.common.util.ForgeDirection; +import WayofTime.alchemicalWizardry.api.spell.SpellParadigm; + +public interface ISpellTile +{ + public void modifySpellParadigm(SpellParadigm parad); + + public boolean canInputRecieveOutput(ForgeDirection output); +}