From ed8427c04e538b37943ebde5520113385856b808 Mon Sep 17 00:00:00 2001 From: WayofTime Date: Sat, 8 Oct 2016 21:23:16 -0400 Subject: [PATCH] Added the framework for a ritual that grants downgrades (instead of the potion method) --- changelog.txt | 1 + .../WayofTime/bloodmagic/ConfigHandler.java | 7 +- .../api/livingArmour/ILivingArmour.java | 3 + .../recipe/LivingArmourDowngradeRecipe.java | 135 ++++++++++ .../LivingArmourDowngradeRecipeRegistry.java | 72 +++++ .../bloodmagic/livingArmour/LivingArmour.java | 32 ++- .../LivingArmourUpgradeStormTrooper.java | 64 +++++ .../registry/ModArmourTrackers.java | 2 + .../bloodmagic/registry/ModRecipes.java | 39 +++ .../bloodmagic/registry/ModRituals.java | 8 +- .../ritual/RitualLivingArmourDowngrade.java | 253 ++++++++++++++++++ .../handler/event/LivingArmourHandler.java | 42 +++ .../assets/bloodmagic/lang/en_US.lang | 7 +- 13 files changed, 661 insertions(+), 4 deletions(-) create mode 100644 src/main/java/WayofTime/bloodmagic/api/recipe/LivingArmourDowngradeRecipe.java create mode 100644 src/main/java/WayofTime/bloodmagic/api/registry/LivingArmourDowngradeRecipeRegistry.java create mode 100644 src/main/java/WayofTime/bloodmagic/livingArmour/downgrade/LivingArmourUpgradeStormTrooper.java create mode 100644 src/main/java/WayofTime/bloodmagic/ritual/RitualLivingArmourDowngrade.java diff --git a/changelog.txt b/changelog.txt index cd7b2039..93a8836d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -8,6 +8,7 @@ Version 2.1.0-66 - Added a Repairing Living Armour Upgrade (trained by damaging the chestplate of the Living Armour while you have a full set on - it repairs all of your armour pieces over time) - Modified the Dwarven Might skill to better change the mining speed when mining. - Added a Dig Slowdown armour downgrade called "Weakened Pick", trained by having weakness on while mining. +- Added the framework for a ritual that grants downgrades (instead of the potion method). ------------------------------------------------------ Version 2.1.0-65 diff --git a/src/main/java/WayofTime/bloodmagic/ConfigHandler.java b/src/main/java/WayofTime/bloodmagic/ConfigHandler.java index c80350be..d986471c 100644 --- a/src/main/java/WayofTime/bloodmagic/ConfigHandler.java +++ b/src/main/java/WayofTime/bloodmagic/ConfigHandler.java @@ -79,6 +79,8 @@ public class ConfigHandler public static boolean pumpRitual; public static boolean altarBuilderRitual; public static boolean portalRitual; + public static boolean meteorRitual; + public static boolean downgradeRitual; // Imperfect Rituals public static boolean imperfectRitualNight; @@ -293,6 +295,8 @@ public class ConfigHandler pumpRitual = config.get(category, "ritualPump", true).getBoolean(); altarBuilderRitual = config.get(category, "ritualAltarBuilder", true).getBoolean(); portalRitual = config.get(category, "ritualPortal", true).getBoolean(); + meteorRitual = config.get(category, "ritualMeteor", true).getBoolean(); + downgradeRitual = config.get(category, "ritualDowngrade", true).getBoolean(); category = "Rituals.Imperfect"; imperfectRitualNight = config.get(category, "imperfectRitualNight", true).getBoolean(); @@ -372,7 +376,8 @@ public class ConfigHandler @SubscribeEvent public void onConfigChanged(ConfigChangedEvent event) { - if (event.getModID().equals(Constants.Mod.MODID)) { + if (event.getModID().equals(Constants.Mod.MODID)) + { syncConfig(); MeteorConfigHandler.handleMeteors(false); } diff --git a/src/main/java/WayofTime/bloodmagic/api/livingArmour/ILivingArmour.java b/src/main/java/WayofTime/bloodmagic/api/livingArmour/ILivingArmour.java index 04024943..c47b310d 100644 --- a/src/main/java/WayofTime/bloodmagic/api/livingArmour/ILivingArmour.java +++ b/src/main/java/WayofTime/bloodmagic/api/livingArmour/ILivingArmour.java @@ -1,6 +1,7 @@ package WayofTime.bloodmagic.api.livingArmour; import com.google.common.collect.Multimap; + import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; @@ -16,6 +17,8 @@ public interface ILivingArmour { Multimap getAttributeModifiers(); + boolean canApplyUpgrade(EntityPlayer user, LivingArmourUpgrade upgrade); + boolean upgradeArmour(EntityPlayer user, LivingArmourUpgrade upgrade); boolean removeUpgrade(EntityPlayer user, LivingArmourUpgrade upgrade); diff --git a/src/main/java/WayofTime/bloodmagic/api/recipe/LivingArmourDowngradeRecipe.java b/src/main/java/WayofTime/bloodmagic/api/recipe/LivingArmourDowngradeRecipe.java new file mode 100644 index 00000000..92838a7f --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/api/recipe/LivingArmourDowngradeRecipe.java @@ -0,0 +1,135 @@ +package WayofTime.bloodmagic.api.recipe; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; +import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; + +public class LivingArmourDowngradeRecipe +{ + protected LivingArmourUpgrade upgrade = null; + protected ItemStack keyStack = null; + protected ArrayList input = new ArrayList(); + + public LivingArmourDowngradeRecipe(LivingArmourUpgrade upgrade, ItemStack keyStack, Object... recipe) + { + this.upgrade = upgrade; + this.keyStack = keyStack; + for (Object in : recipe) + { + if (in instanceof ItemStack) + { + input.add(((ItemStack) in).copy()); + } 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 living armour downgrade recipe: "; + for (Object tmp : recipe) + { + ret += tmp + ", "; + } + ret += upgrade.toString(); + throw new RuntimeException(ret); + } + } + } + + /** + * Returns the size of the recipe area + */ + public int getRecipeSize() + { + return input.size(); + } + + public LivingArmourUpgrade getRecipeOutput() + { + return upgrade; + } + + /** + * Used to check if a recipe matches current crafting inventory. World and + * BlockPos are for future-proofing + */ + @SuppressWarnings("unchecked") + public boolean matches(ItemStack key, List checkedList, World world, BlockPos pos) + { + if (!OreDictionary.itemMatches(keyStack, key, false)) + { + return false; + } + + ArrayList required = new ArrayList(input); + + for (int x = 0; x < checkedList.size(); x++) + { + ItemStack slot = checkedList.get(x); + + if (slot != null) + { + boolean inRecipe = false; + Iterator req = required.iterator(); + + while (req.hasNext()) + { + boolean match = false; + + Object next = req.next(); + + if (next instanceof ItemStack) + { + match = OreDictionary.itemMatches((ItemStack) next, slot, false); + } else if (next instanceof List) + { + Iterator itr = ((List) next).iterator(); + while (itr.hasNext() && !match) + { + match = OreDictionary.itemMatches(itr.next(), slot, false); + } + } + + if (match) + { + inRecipe = true; + required.remove(next); + break; + } + } + + if (!inRecipe) + { + return false; + } + } + } + + return required.isEmpty(); + } + + /** + * Returns the input for this recipe, any mod accessing this value should + * never manipulate the values in this array as it will effect the recipe + * itself. + * + * @return The recipes input vales. + */ + public ArrayList getInput() + { + return this.input; + } +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/api/registry/LivingArmourDowngradeRecipeRegistry.java b/src/main/java/WayofTime/bloodmagic/api/registry/LivingArmourDowngradeRecipeRegistry.java new file mode 100644 index 00000000..b6de0ce8 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/api/registry/LivingArmourDowngradeRecipeRegistry.java @@ -0,0 +1,72 @@ +package WayofTime.bloodmagic.api.registry; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; +import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; +import WayofTime.bloodmagic.api.recipe.LivingArmourDowngradeRecipe; + +public class LivingArmourDowngradeRecipeRegistry +{ + private static List recipeList = new ArrayList(); + private static Map>> dialogueMap = new HashMap>>(); + + public static void registerRecipe(LivingArmourDowngradeRecipe recipe) + { + recipeList.add(recipe); + } + + public static void registerDialog(ItemStack keyStack, Map> map) + { + dialogueMap.put(keyStack, map); + } + + public static List getDialogForProcessTick(ItemStack keyStack, int tick) + { + for (Entry>> entry : dialogueMap.entrySet()) + { + ItemStack key = entry.getKey(); + if (OreDictionary.itemMatches(key, keyStack, false)) + { + Map> map = entry.getValue(); + if (map.containsKey(tick)) + { + return map.get(tick); + } + } + } + + return null; + } + + public static void registerRecipe(LivingArmourUpgrade upgrade, ItemStack keyStack, Object... recipe) + { + registerRecipe(new LivingArmourDowngradeRecipe(upgrade, keyStack, recipe)); + } + + public static LivingArmourDowngradeRecipe getMatchingRecipe(ItemStack keyStack, List itemList, World world, BlockPos pos) + { + for (LivingArmourDowngradeRecipe recipe : recipeList) + { + if (recipe.matches(keyStack, itemList, world, pos)) + { + return recipe; + } + } + + return null; + } + + public static List getRecipeList() + { + return new ArrayList(recipeList); + } +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmour.java b/src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmour.java index 63f6c883..93c4b4eb 100644 --- a/src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmour.java +++ b/src/main/java/WayofTime/bloodmagic/livingArmour/LivingArmour.java @@ -109,7 +109,7 @@ public class LivingArmour implements ILivingArmour if (nextLevel > currentLevel) { int upgradePointDifference = upgrade.getCostOfUpgrade() - upgradeMap.get(key).getCostOfUpgrade(); - if (Math.abs(upgradePointDifference) >= 0 && totalUpgradePoints + upgradePointDifference <= maxUpgradePoints) + if (totalUpgradePoints + upgradePointDifference <= maxUpgradePoints) { upgradeMap.put(key, upgrade); totalUpgradePoints += upgradePointDifference; @@ -142,6 +142,36 @@ public class LivingArmour implements ILivingArmour return false; } + @Override + public boolean canApplyUpgrade(EntityPlayer user, LivingArmourUpgrade upgrade) + { + String key = upgrade.getUniqueIdentifier(); + if (upgradeMap.containsKey(key)) + { + //Check if this is a higher level than the previous upgrade + int nextLevel = upgrade.getUpgradeLevel(); + int currentLevel = upgradeMap.get(key).getUpgradeLevel(); + + if (nextLevel > currentLevel) + { + int upgradePointDifference = upgrade.getCostOfUpgrade() - upgradeMap.get(key).getCostOfUpgrade(); + if (totalUpgradePoints + upgradePointDifference <= maxUpgradePoints) + { + return true; + } + } + } else + { + int upgradePoints = upgrade.getCostOfUpgrade(); + if (totalUpgradePoints + upgradePoints <= maxUpgradePoints) + { + return true; + } + } + + return false; + } + @Override public void notifyPlayerOfUpgrade(EntityPlayer user, LivingArmourUpgrade upgrade) { diff --git a/src/main/java/WayofTime/bloodmagic/livingArmour/downgrade/LivingArmourUpgradeStormTrooper.java b/src/main/java/WayofTime/bloodmagic/livingArmour/downgrade/LivingArmourUpgradeStormTrooper.java new file mode 100644 index 00000000..b86315a3 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/livingArmour/downgrade/LivingArmourUpgradeStormTrooper.java @@ -0,0 +1,64 @@ +package WayofTime.bloodmagic.livingArmour.downgrade; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.api.livingArmour.ILivingArmour; +import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; + +public class LivingArmourUpgradeStormTrooper extends LivingArmourUpgrade +{ + public static final int[] costs = new int[] { -150 }; + public static final float[] inaccuracy = new float[] { 0.04f, 0.08f, 0.12f, 0.16f, 0.2f }; + + public LivingArmourUpgradeStormTrooper(int level) + { + super(level); + } + + @Override + public void onTick(World world, EntityPlayer player, ILivingArmour livingArmour) + { + + } + + public float getArrowJiggle(EntityPlayer player) + { + return inaccuracy[this.level]; + } + + @Override + public String getUniqueIdentifier() + { + return Constants.Mod.MODID + ".upgrade.stormTrooper"; + } + + @Override + public int getMaxTier() + { + return 1; + } + + @Override + public int getCostOfUpgrade() + { + return costs[this.level]; + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + } + + @Override + public String getUnlocalizedName() + { + return tooltipBase + "stormTrooper"; + } +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModArmourTrackers.java b/src/main/java/WayofTime/bloodmagic/registry/ModArmourTrackers.java index b555fc0d..9018fa21 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModArmourTrackers.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModArmourTrackers.java @@ -9,6 +9,7 @@ import WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeMeleeDecre import WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeQuenched; import WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeSlippery; import WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeSlowness; +import WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeStormTrooper; import WayofTime.bloodmagic.livingArmour.tracker.StatTrackerArrowShot; import WayofTime.bloodmagic.livingArmour.tracker.StatTrackerCriticalStrike; import WayofTime.bloodmagic.livingArmour.tracker.StatTrackerDigging; @@ -121,5 +122,6 @@ public class ModArmourTrackers LivingArmourHandler.registerArmourUpgrade(new LivingArmourUpgradeMeleeDecrease(0)); LivingArmourHandler.registerArmourUpgrade(new LivingArmourUpgradeDisoriented(0)); LivingArmourHandler.registerArmourUpgrade(new LivingArmourUpgradeDigSlowdown(0)); + LivingArmourHandler.registerArmourUpgrade(new LivingArmourUpgradeStormTrooper(0)); } } diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java b/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java index 304aed4e..ebd4974e 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java @@ -1,7 +1,10 @@ package WayofTime.bloodmagic.registry; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -10,12 +13,17 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraftforge.common.ForgeModContainer; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.RecipeSorter; import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe; + +import org.apache.commons.lang3.tuple.Pair; + import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectAttractor; import WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectBinding; @@ -31,6 +39,7 @@ import WayofTime.bloodmagic.api.recipe.ShapelessBloodOrbRecipe; import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry; import WayofTime.bloodmagic.api.registry.AlchemyTableRecipeRegistry; import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry; +import WayofTime.bloodmagic.api.registry.LivingArmourDowngradeRecipeRegistry; import WayofTime.bloodmagic.api.registry.OrbRegistry; import WayofTime.bloodmagic.api.registry.TartaricForgeRecipeRegistry; import WayofTime.bloodmagic.api.ritual.EnumRuneType; @@ -47,6 +56,7 @@ import WayofTime.bloodmagic.item.ItemDemonCrystal; import WayofTime.bloodmagic.item.alchemy.ItemCuttingFluid; import WayofTime.bloodmagic.item.alchemy.ItemLivingArmourPointsUpgrade; import WayofTime.bloodmagic.item.soul.ItemSoulGem; +import WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeStormTrooper; import WayofTime.bloodmagic.potion.BMPotionUtils; import WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTableDyeableRecipe; import WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTablePotionRecipe; @@ -72,6 +82,7 @@ public class ModRecipes addAlchemyTableRecipes(); addOreDoublingAlchemyRecipes(); addPotionRecipes(); + addLivingArmourDowngradeRecipes(); } public static void initOreDict() @@ -465,4 +476,32 @@ public class ModRecipes powerList.add(mundanePowerStack); AlchemyTableRecipeRegistry.registerRecipe(BMPotionUtils.getPowerAugmentRecipe(lpDrained, 100, tier, powerList, baseEffect, 1)); } + + public static void addLivingArmourDowngradeRecipes() + { + String messageBase = "ritual.BloodMagic.downgradeRitual.dialogue."; + + ItemStack bowStack = new ItemStack(Items.BOW); + + Map> dialogueMap = new HashMap>(); + dialogueMap.put(bowStack, Pair.of("bow", new int[] { 1, 200, 400, 600 })); + + for (Entry> entry : dialogueMap.entrySet()) + { + ItemStack keyStack = entry.getKey(); + String str = entry.getValue().getKey(); + Map> textMap = new HashMap>(); + for (int tick : entry.getValue().getValue()) + { + List textList = new ArrayList(); + textList.add(new TextComponentTranslation(messageBase + str + "." + tick)); + textMap.put(tick, textList); + } + + LivingArmourDowngradeRecipeRegistry.registerDialog(keyStack, textMap); + } + + LivingArmourDowngradeRecipeRegistry.registerRecipe(new LivingArmourUpgradeStormTrooper(0), bowStack, "gemDiamond"); +// LivingArmourDowngradeRecipeRegistry.registerDialog(bowStack, bowMap); + } } diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java b/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java index 1c7757aa..b03ccce2 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java @@ -25,6 +25,7 @@ import WayofTime.bloodmagic.ritual.RitualHarvest; import WayofTime.bloodmagic.ritual.RitualInterdiction; import WayofTime.bloodmagic.ritual.RitualJumping; import WayofTime.bloodmagic.ritual.RitualLava; +import WayofTime.bloodmagic.ritual.RitualLivingArmourDowngrade; import WayofTime.bloodmagic.ritual.RitualMagnetic; import WayofTime.bloodmagic.ritual.RitualMeteor; import WayofTime.bloodmagic.ritual.RitualPlacer; @@ -79,6 +80,8 @@ public class ModRituals public static Ritual meteorRitual; + public static Ritual downgradeRitual; + public static ImperfectRitual imperfectNight; public static ImperfectRitual imperfectRain; public static ImperfectRitual imperfectResistance; @@ -145,7 +148,10 @@ public class ModRituals portalRitual = new RitualPortal(); RitualRegistry.registerRitual(portalRitual, ConfigHandler.portalRitual); meteorRitual = new RitualMeteor(); - RitualRegistry.registerRitual(meteorRitual, true); + RitualRegistry.registerRitual(meteorRitual, ConfigHandler.meteorRitual); + + downgradeRitual = new RitualLivingArmourDowngrade(); + RitualRegistry.registerRitual(downgradeRitual, ConfigHandler.downgradeRitual); RitualCrushing.registerCuttingFluid(ItemCuttingFluid.getStack(ItemCuttingFluid.BASIC), 250, 0.5); RitualCrushing.registerCuttingFluid(ItemCuttingFluid.getStack(ItemCuttingFluid.EXPLOSIVE), 25, 0.05); diff --git a/src/main/java/WayofTime/bloodmagic/ritual/RitualLivingArmourDowngrade.java b/src/main/java/WayofTime/bloodmagic/ritual/RitualLivingArmourDowngrade.java new file mode 100644 index 00000000..7143aa30 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/ritual/RitualLivingArmourDowngrade.java @@ -0,0 +1,253 @@ +package WayofTime.bloodmagic.ritual; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.item.EntityItemFrame; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.world.World; +import net.minecraftforge.items.IItemHandler; +import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; +import WayofTime.bloodmagic.api.recipe.LivingArmourDowngradeRecipe; +import WayofTime.bloodmagic.api.registry.LivingArmourDowngradeRecipeRegistry; +import WayofTime.bloodmagic.api.ritual.AreaDescriptor; +import WayofTime.bloodmagic.api.ritual.EnumRuneType; +import WayofTime.bloodmagic.api.ritual.IMasterRitualStone; +import WayofTime.bloodmagic.api.ritual.Ritual; +import WayofTime.bloodmagic.api.ritual.RitualComponent; +import WayofTime.bloodmagic.api.saving.SoulNetwork; +import WayofTime.bloodmagic.api.util.helper.NetworkHelper; +import WayofTime.bloodmagic.item.armour.ItemLivingArmour; +import WayofTime.bloodmagic.livingArmour.LivingArmour; +import WayofTime.bloodmagic.util.ChatUtil; +import WayofTime.bloodmagic.util.Utils; + +public class RitualLivingArmourDowngrade extends Ritual +{ + public static final String DOWNGRADE_RANGE = "containmentRange"; + private int internalTimer = 0; + + public RitualLivingArmourDowngrade() + { + super("ritualDowngrade", 0, 10000, "ritual." + Constants.Mod.MODID + ".downgradeRitual"); + addBlockRange(DOWNGRADE_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-3, 0, -3), 7)); + } + + @Override + public void performRitual(IMasterRitualStone masterRitualStone) + { + World world = masterRitualStone.getWorldObj(); + SoulNetwork network = NetworkHelper.getSoulNetwork(masterRitualStone.getOwner()); + int currentEssence = network.getCurrentEssence(); + + if (currentEssence < getRefreshCost()) + { + network.causeNausea(); + return; + } + + BlockPos masterPos = masterRitualStone.getBlockPos(); + + AreaDescriptor downgradeRange = getBlockRange(DOWNGRADE_RANGE); + + boolean isActivatorPresent = false; + for (EntityPlayer player : world.getEntitiesWithinAABB(EntityPlayer.class, downgradeRange.getAABB(masterRitualStone.getBlockPos()))) + { + if (player.getUniqueID().toString().equals(masterRitualStone.getOwner())) + { + isActivatorPresent = true; + ItemStack keyStack = getStackFromItemFrame(world, masterPos, masterRitualStone.getDirection()); + if (keyStack == null) + { + return; + } + + List textList = LivingArmourDowngradeRecipeRegistry.getDialogForProcessTick(keyStack, internalTimer); + if (textList != null) + { + ChatUtil.sendChat(player, textList.toArray(new ITextComponent[textList.size()])); + } + + internalTimer++; + + if (player.isSneaking()) + { + //TODO: Check if you are kneeling on top of it. + + BlockPos chestPos = masterPos.offset(masterRitualStone.getDirection(), 2).offset(EnumFacing.UP); + TileEntity tile = world.getTileEntity(chestPos); + if (tile == null) + { + return; + } + IItemHandler inv = Utils.getInventory(tile, null); + if (inv != null) + { + List recipeList = new ArrayList(); + for (int i = 0; i < inv.getSlots(); i++) + { + ItemStack invStack = inv.getStackInSlot(i); + if (invStack != null) + { + recipeList.add(invStack); + } + } + + LivingArmourDowngradeRecipe recipe = LivingArmourDowngradeRecipeRegistry.getMatchingRecipe(keyStack, recipeList, world, masterPos); + if (recipe != null) + { + + LivingArmourUpgrade upgrade = recipe.getRecipeOutput(); + if (LivingArmour.hasFullSet(player)) + { + ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST); + LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack); + if (armour != null) + { + if (armour.canApplyUpgrade(player, upgrade)) + { + if (armour.upgradeArmour(player, upgrade)) + { + ItemLivingArmour.setLivingArmour(chestStack, armour); + for (int i = 0; i < inv.getSlots(); i++) + { + ItemStack invStack = inv.getStackInSlot(i); + if (invStack != null) + { + inv.extractItem(i, invStack.stackSize, false); + } + } + + EntityLightningBolt lightning = new EntityLightningBolt(world, chestPos.getX(), chestPos.getY(), chestPos.getZ(), true); + world.spawnEntityInWorld(lightning); + + masterRitualStone.setActive(false); + } + } else + { + //TODO: You are not able to receive my blessing... + //TODO: Need to add a timer that will stop it from working. + } + } + } + } + } + } + + return; + } + } + + if (!isActivatorPresent) + { + internalTimer = 0; + } + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT(tag); + + this.internalTimer = tag.getInteger("internalTimer"); + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT(tag); + + tag.setInteger("internalTimer", internalTimer); + } + + public ItemStack getStackFromItemFrame(World world, BlockPos masterPos, EnumFacing direction) + { + BlockPos offsetPos = new BlockPos(0, 3, 0); + offsetPos = offsetPos.offset(direction, 2); + + AxisAlignedBB bb = new AxisAlignedBB(masterPos.add(offsetPos)); + List frames = world.getEntitiesWithinAABB(EntityItemFrame.class, bb); + for (EntityItemFrame frame : frames) + { + if (frame.getDisplayedItem() != null) + { + return frame.getDisplayedItem(); + } + } + + return null; + } + + @Override + public int getRefreshTime() + { + return 1; + } + + @Override + public int getRefreshCost() + { + return 0; + } + + @Override + public ArrayList getComponents() + { + ArrayList components = new ArrayList(); + + this.addRune(components, 0, 0, -1, EnumRuneType.AIR); + this.addRune(components, 0, 0, -2, EnumRuneType.DUSK); + this.addRune(components, 0, 1, -3, EnumRuneType.DUSK); + this.addRune(components, 0, 2, -3, EnumRuneType.BLANK); + this.addRune(components, 0, 3, -3, EnumRuneType.BLANK); + this.addRune(components, 0, 1, -4, EnumRuneType.FIRE); + + for (int i = 1; i <= 3; i++) + this.addRune(components, 0, 0, i, EnumRuneType.AIR); + + for (int sgn = -1; sgn <= 1; sgn += 2) + { + this.addRune(components, sgn, 0, 4, EnumRuneType.AIR); + this.addRune(components, sgn * 2, 0, 2, EnumRuneType.AIR); + this.addRune(components, sgn * 3, 0, 2, EnumRuneType.AIR); + this.addRune(components, sgn * 3, 0, 3, EnumRuneType.AIR); + this.addRune(components, sgn * 1, 0, 0, EnumRuneType.EARTH); + this.addRune(components, sgn * 1, 0, 1, EnumRuneType.EARTH); + this.addRune(components, sgn * 2, 0, -1, EnumRuneType.FIRE); + this.addRune(components, sgn * 2, 0, -2, EnumRuneType.FIRE); + this.addRune(components, sgn * 3, 0, -2, EnumRuneType.FIRE); + this.addRune(components, sgn * 3, 0, -3, EnumRuneType.FIRE); + this.addRune(components, sgn * 3, 0, -4, EnumRuneType.FIRE); + this.addRune(components, sgn * 1, 1, -1, EnumRuneType.AIR); + this.addRune(components, sgn * 1, 1, -2, EnumRuneType.AIR); + this.addRune(components, sgn * 1, 1, -4, EnumRuneType.FIRE); + this.addRune(components, sgn * 2, 1, -4, EnumRuneType.FIRE); + this.addRune(components, sgn * 1, 0, -3, EnumRuneType.EARTH); + this.addRune(components, sgn * 1, 0, -4, EnumRuneType.EARTH); + this.addRune(components, sgn * 1, 0, -5, EnumRuneType.EARTH); + this.addRune(components, sgn * 1, 1, -5, EnumRuneType.EARTH); + this.addRune(components, sgn * 1, 2, -5, EnumRuneType.EARTH); + this.addRune(components, sgn * 1, 3, -5, EnumRuneType.EARTH); + + this.addRune(components, sgn * 1, 3, -4, EnumRuneType.EARTH); + } + + return components; + } + + @Override + public Ritual getNewCopy() + { + return new RitualLivingArmourDowngrade(); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/event/LivingArmourHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/event/LivingArmourHandler.java index 56fe0c24..18480aa0 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/event/LivingArmourHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/event/LivingArmourHandler.java @@ -1,8 +1,10 @@ package WayofTime.bloodmagic.util.handler.event; import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.init.Enchantments; import net.minecraft.init.Items; import net.minecraft.inventory.EntityEquipmentSlot; @@ -11,6 +13,7 @@ import net.minecraft.item.ItemArrow; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; import net.minecraft.world.World; +import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent; import net.minecraftforge.event.entity.living.LivingEvent; @@ -27,6 +30,7 @@ import WayofTime.bloodmagic.item.armour.ItemLivingArmour; import WayofTime.bloodmagic.livingArmour.LivingArmour; import WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeCrippledArm; import WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeQuenched; +import WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeStormTrooper; import WayofTime.bloodmagic.livingArmour.tracker.StatTrackerArrowShot; import WayofTime.bloodmagic.livingArmour.tracker.StatTrackerGrimReaperSprint; import WayofTime.bloodmagic.livingArmour.tracker.StatTrackerJump; @@ -65,6 +69,44 @@ public class LivingArmourHandler } } + // Applies: Storm Trooper + @SubscribeEvent + public void onEntityJoinedWorld(EntityJoinWorldEvent event) + { + Entity owner = null; + if (event.getEntity() instanceof EntityArrow) + { + owner = ((EntityArrow) event.getEntity()).shootingEntity; + } else if (event.getEntity() instanceof EntityThrowable) + { + owner = ((EntityThrowable) event.getEntity()).getThrower(); + } + + if (owner instanceof EntityPlayer) + { + Entity projectile = event.getEntity(); + EntityPlayer player = (EntityPlayer) owner; + if (LivingArmour.hasFullSet(player)) + { + ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST); + LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack); + if (armour != null) + { + LivingArmourUpgrade upgrade = ItemLivingArmour.getUpgrade(Constants.Mod.MODID + ".upgrade.stormTrooper", chestStack); + + if (upgrade instanceof LivingArmourUpgradeStormTrooper) + { + float velocityModifier = (float) (((LivingArmourUpgradeStormTrooper) upgrade).getArrowJiggle(player) * Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ)); + + projectile.motionX += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier; + projectile.motionY += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier; + projectile.motionZ += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier; + } + } + } + } + } + @SubscribeEvent public void onFinishedItem(LivingEntityUseItemEvent.Finish event) { diff --git a/src/main/resources/assets/bloodmagic/lang/en_US.lang b/src/main/resources/assets/bloodmagic/lang/en_US.lang index c4658e6d..cc0057a5 100644 --- a/src/main/resources/assets/bloodmagic/lang/en_US.lang +++ b/src/main/resources/assets/bloodmagic/lang/en_US.lang @@ -594,7 +594,7 @@ ritual.BloodMagic.fellingRitual=Crash of the Timberman ritual.BloodMagic.pumpRitual=Hymn of Siphoning ritual.BloodMagic.altarBuilderRitual=The Assembly of the High Altar ritual.BloodMagic.portalRitual=The Gate of the Fold - +ritual.BloodMagic.downgradeRitual=Downgrade Ritual ritual.BloodMagic.waterRitual.info=Generates a source of water from the master ritual stone. ritual.BloodMagic.lavaRitual.info=Generates a source of lava from the master ritual stone. @@ -668,6 +668,11 @@ ritual.BloodMagic.fellingRitual.fellingRange.info=(Cutting) The range that the r ritual.BloodMagic.fellingRitual.chest.info=(Chest) The location of the inventory that the ritual will place the results into. ritual.BloodMagic.pumpRitual.pumpRange.info=(Pump) The region that the ritual will look for fluids to grab from the world. +ritual.BloodMagic.downgradeRitual.dialogue.bow.1=So, Mortal, you wish to gain more power... +ritual.BloodMagic.downgradeRitual.dialogue.bow.200=By kneeling at this altar, you may gain further strength, however you will have to give up something as recompense... +ritual.BloodMagic.downgradeRitual.dialogue.bow.400=All it takes is a little sacrifice. By forfeighting your aim with a bow, you may attain further heights in other aspects. +ritual.BloodMagic.downgradeRitual.dialogue.bow.600=What will you choose... + # Chat chat.BloodMagic.altarMaker.setTier=Set Tier to: %d chat.BloodMagic.altarMaker.building=Building a Tier %d Altar