From d3c6a474de771f8f022354e5c1d64be64ed87013 Mon Sep 17 00:00:00 2001 From: WayofTime Date: Wed, 10 Aug 2016 17:24:36 -0400 Subject: [PATCH] Added the Corrosive Green Grove augmentation --- .../item/sigil/ItemSigilGreenGrove.java | 1 - .../bloodmagic/potion/BMPotionUtils.java | 69 ++++++++++++++++ .../bloodmagic/registry/ModPotions.java | 2 + .../bloodmagic/registry/ModRecipes.java | 2 + .../bloodmagic/ritual/RitualGreenGrove.java | 81 +++++++++++++++++-- .../tile/TileDemonCrystallizer.java | 2 +- .../util/handler/event/GenericHandler.java | 11 +++ .../assets/bloodmagic/lang/en_US.lang | 2 + 8 files changed, 160 insertions(+), 10 deletions(-) diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilGreenGrove.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilGreenGrove.java index 45721444..882186b7 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilGreenGrove.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilGreenGrove.java @@ -10,7 +10,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.IPlantable; import WayofTime.bloodmagic.api.BloodMagicAPI; -import WayofTime.bloodmagic.api.Constants; public class ItemSigilGreenGrove extends ItemSigilToggleableBase { diff --git a/src/main/java/WayofTime/bloodmagic/potion/BMPotionUtils.java b/src/main/java/WayofTime/bloodmagic/potion/BMPotionUtils.java index 8eaf353a..1296ed4b 100644 --- a/src/main/java/WayofTime/bloodmagic/potion/BMPotionUtils.java +++ b/src/main/java/WayofTime/bloodmagic/potion/BMPotionUtils.java @@ -1,13 +1,23 @@ package WayofTime.bloodmagic.potion; +import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.block.IGrowable; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.IPlantable; +import WayofTime.bloodmagic.api.BloodMagicAPI; import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTablePotionAugmentRecipe; @@ -16,6 +26,65 @@ import com.google.common.base.Objects; public class BMPotionUtils { + public static Random rand = new Random(); + + public static double damageMobAndGrowSurroundingPlants(EntityLivingBase entity, int horizontalRadius, int verticalRadius, double damageRatio, int maxPlantsGrown) + { + World world = entity.worldObj; + if (world.isRemote) + { + return 0; + } + + if (entity.isDead) + { + return 0; + } + + double incurredDamage = 0; + + List growList = new ArrayList(); + + for (int i = 0; i < maxPlantsGrown; i++) + { + BlockPos blockPos = entity.getPosition().add(rand.nextInt(horizontalRadius * 2 + 1) - horizontalRadius, rand.nextInt(verticalRadius * 2 + 1) - verticalRadius, rand.nextInt(horizontalRadius * 2 + 1) - horizontalRadius); + Block block = world.getBlockState(blockPos).getBlock(); + + if (!BloodMagicAPI.getGreenGroveBlacklist().contains(block)) + { + if (block instanceof IPlantable || block instanceof IGrowable) + { + growList.add(blockPos); + } + } + } + + for (BlockPos blockPos : growList) + { + Block block = world.getBlockState(blockPos).getBlock(); +// if (world.rand.nextInt(50) == 0) + { + IBlockState preBlockState = world.getBlockState(blockPos); + for (int n = 0; n < 10; n++) + block.updateTick(world, blockPos, world.getBlockState(blockPos), world.rand); + + IBlockState newState = world.getBlockState(blockPos); + if (!newState.equals(preBlockState)) + { + world.playEvent(2001, blockPos, Block.getIdFromBlock(newState.getBlock()) + (newState.getBlock().getMetaFromState(newState) << 12)); + incurredDamage += damageRatio; + } + } + } + + if (incurredDamage > 0) + { + entity.attackEntityFrom(BloodMagicAPI.getDamageSource(), (float) incurredDamage); + } + + return incurredDamage; + } + public static double getLengthAugment(ItemStack flaskStack, Potion potion) { NBTHelper.checkNBT(flaskStack); diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModPotions.java b/src/main/java/WayofTime/bloodmagic/registry/ModPotions.java index e9ca630c..8c40f92e 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModPotions.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModPotions.java @@ -19,6 +19,7 @@ public class ModPotions public static Potion soulFray; public static Potion fireFuse; public static Potion constrict; + public static Potion plantLeech; public static void init() { @@ -44,6 +45,7 @@ public class ModPotions fireFuse = registerPotion("Fire Fuse", new ResourceLocation("fireFuse"), true, 0xFF3333, 5, 0); constrict = registerPotion("Constriction", new ResourceLocation("constrict"), true, 0x000000, 6, 0); + plantLeech = registerPotion("Plant Leech", new ResourceLocation("plantLeech"), true, 0x000000, 7, 0); // heavyHeart = new PotionBloodMagic("Heavy Heart", new // ResourceLocation(resourceLocation + // heavyHeart.getName().toLowerCase()), true, 0, 0, 0); diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java b/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java index 1c1a2b55..f2aacac7 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java @@ -402,6 +402,8 @@ public class ModRecipes addPotionRecipe(1000, 1, new ItemStack(Items.GLASS_BOTTLE), new PotionEffect(MobEffects.INVISIBILITY, 2 * 60 * 20)); addPotionRecipe(1000, 1, new ItemStack(Items.POISONOUS_POTATO), new PotionEffect(MobEffects.SATURATION, 1)); addPotionRecipe(1000, 1, new ItemStack(ModItems.bloodShard, 1, 0), new PotionEffect(MobEffects.HEALTH_BOOST, 2 * 60 * 20)); + + addPotionRecipe(1000, 1, new ItemStack(Items.BEETROOT), new PotionEffect(ModPotions.plantLeech, 1 * 60 * 20)); } static ItemStack mundaneLengtheningStack = ItemComponent.getStack(ItemComponent.CATALYST_LENGTH_1); diff --git a/src/main/java/WayofTime/bloodmagic/ritual/RitualGreenGrove.java b/src/main/java/WayofTime/bloodmagic/ritual/RitualGreenGrove.java index 2fe7750f..06324909 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/RitualGreenGrove.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/RitualGreenGrove.java @@ -1,35 +1,55 @@ package WayofTime.bloodmagic.ritual; -import WayofTime.bloodmagic.api.BloodMagicAPI; -import WayofTime.bloodmagic.api.Constants; -import WayofTime.bloodmagic.api.saving.SoulNetwork; -import WayofTime.bloodmagic.api.ritual.*; -import WayofTime.bloodmagic.api.util.helper.NetworkHelper; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + import net.minecraft.block.Block; import net.minecraft.block.IGrowable; import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.common.IPlantable; - -import java.util.ArrayList; -import java.util.Random; +import WayofTime.bloodmagic.api.BloodMagicAPI; +import WayofTime.bloodmagic.api.Constants; +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.soul.EnumDemonWillType; +import WayofTime.bloodmagic.api.util.helper.NetworkHelper; +import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler; +import WayofTime.bloodmagic.registry.ModPotions; public class RitualGreenGrove extends Ritual { public static final String GROW_RANGE = "growing"; + public static final String LEECH_RANGE = "leech"; + + public static double corrosiveWillDrain = 0.2; public RitualGreenGrove() { super("ritualGreenGrove", 0, 5000, "ritual." + Constants.Mod.MODID + ".greenGroveRitual"); addBlockRange(GROW_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-1, 2, -1), 3, 1, 3)); + addBlockRange(LEECH_RANGE, new AreaDescriptor.Rectangle(new BlockPos(0, 0, 0), 1)); setMaximumVolumeAndDistanceOfRange(GROW_RANGE, 81, 4, 4); + setMaximumVolumeAndDistanceOfRange(LEECH_RANGE, 0, 15, 15); } @Override public void performRitual(IMasterRitualStone masterRitualStone) { World world = masterRitualStone.getWorldObj(); + BlockPos pos = masterRitualStone.getBlockPos(); SoulNetwork network = NetworkHelper.getSoulNetwork(masterRitualStone.getOwner()); int currentEssence = network.getCurrentEssence(); @@ -42,6 +62,10 @@ public class RitualGreenGrove extends Ritual int maxGrowths = currentEssence / getRefreshCost(); int totalGrowths = 0; + List willConfig = masterRitualStone.getActiveWillConfig(); + + double corrosiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.CORROSIVE, willConfig); + AreaDescriptor growingRange = getBlockRange(GROW_RANGE); for (BlockPos newPos : growingRange.getContainedPositions(masterRitualStone.getBlockPos())) @@ -64,6 +88,41 @@ public class RitualGreenGrove extends Ritual } } + double corrosiveDrain = 0; + if (corrosiveWill > corrosiveWillDrain) + { + AreaDescriptor leechRange = getBlockRange(LEECH_RANGE); + AxisAlignedBB mobArea = leechRange.getAABB(pos); + List entityList = world.getEntitiesWithinAABB(EntityLivingBase.class, mobArea); + for (EntityLivingBase entityLiving : entityList) + { + if (corrosiveWill < corrosiveWillDrain) + { + break; + } + + if (entityLiving instanceof EntityPlayer) + { + continue; + } + + if (entityLiving.isPotionActive(ModPotions.plantLeech) || !entityLiving.isPotionApplicable(new PotionEffect(ModPotions.plantLeech))) + { + continue; + } + + entityLiving.addPotionEffect(new PotionEffect(ModPotions.plantLeech, 200, 0)); + + corrosiveWill -= corrosiveWillDrain; + corrosiveDrain += corrosiveWillDrain; + } + + if (corrosiveWillDrain > 0) + { + WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.CORROSIVE, corrosiveDrain, true); + } + } + network.syphon(totalGrowths * getRefreshCost()); } @@ -90,6 +149,12 @@ public class RitualGreenGrove extends Ritual return components; } + @Override + public ITextComponent[] provideInformationOfRitualToPlayer(EntityPlayer player) + { + return new ITextComponent[] { new TextComponentTranslation(this.getUnlocalizedName() + ".info"), new TextComponentTranslation(this.getUnlocalizedName() + ".corrosive.info") }; + } + @Override public Ritual getNewCopy() { diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrystallizer.java b/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrystallizer.java index 543f4b3a..9b0a49df 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrystallizer.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrystallizer.java @@ -18,7 +18,7 @@ public class TileDemonCrystallizer extends TileEntity implements ITickable, IDem public static final int maxWill = 100; public static final double drainRate = 1; - public static final double willToFormCrystal = 100; + public static final double willToFormCrystal = 99; public static final double totalFormationTime = 1000; public double internalCounter = 0; diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java index 40f457cb..5ae04283 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java @@ -54,6 +54,7 @@ import WayofTime.bloodmagic.livingArmour.tracker.StatTrackerSelfSacrifice; import WayofTime.bloodmagic.livingArmour.upgrade.LivingArmourUpgradeSelfSacrifice; import WayofTime.bloodmagic.network.BloodMagicPacketHandler; import WayofTime.bloodmagic.network.DemonAuraPacketProcessor; +import WayofTime.bloodmagic.potion.BMPotionUtils; import WayofTime.bloodmagic.registry.ModItems; import WayofTime.bloodmagic.registry.ModPotions; import WayofTime.bloodmagic.util.ChatUtil; @@ -130,6 +131,16 @@ public class GenericHandler entity.worldObj.createExplosion(null, entity.posX, entity.posY, entity.posZ, radius, false); } } + + if (entity.isPotionActive(ModPotions.plantLeech)) + { + int amplifier = entity.getActivePotionEffect(ModPotions.plantLeech).getAmplifier(); + int timeRemaining = entity.getActivePotionEffect(ModPotions.plantLeech).getDuration(); + if (timeRemaining % 10 == 0) + { + BMPotionUtils.damageMobAndGrowSurroundingPlants(entity, 2 + amplifier, 1, 0.5 * 3 / (amplifier + 3), 25 * (1 + amplifier)); + } + } } // @SideOnly(Side.SERVER) diff --git a/src/main/resources/assets/bloodmagic/lang/en_US.lang b/src/main/resources/assets/bloodmagic/lang/en_US.lang index d3d23af6..2847db31 100644 --- a/src/main/resources/assets/bloodmagic/lang/en_US.lang +++ b/src/main/resources/assets/bloodmagic/lang/en_US.lang @@ -490,6 +490,7 @@ ritual.BloodMagic.crushingRitual.info=Breaks blocks within its crushing range an ritual.BloodMagic.crushingRitual.destructive.info=(Destructive) Blocks are broken down forcefully: all blocks broken are affected by Fortune III. ritual.BloodMagic.crushingRitual.steadfast.info=(Steadfast) Causes all blocks that are broken to be picked up with silk touch. Overrides Fortune where applicable. ritual.BloodMagic.crushingRitual.corrosive.info=(Corrosive) All blocks are broken to be processed with a form of cutting fluid. Overrides Silk Touch where applicable. +ritual.BloodMagic.greenGroveRitual.corrosive.info=(Corrosive) Entities within range are attacked by nearby plants, leeching away their life. ritual.BloodMagic.fullStomachRitual.info=Takes food from the linked chest and fills the player's saturation with it. ritual.BloodMagic.interdictionRitual.info=Pushes all mobs within its area away from the master ritual stone. @@ -514,6 +515,7 @@ ritual.BloodMagic.waterRitual.waterRange.info=(Water) The area that the ritual w ritual.BloodMagic.lavaRitual.lavaRange.info=(Lava) The area that the ritual will place lava source blocks. ritual.BloodMagic.lavaRitual.fireFuse.info=(Vengeful) Entities in this range are afflicted by Fire Fuse. ritual.BloodMagic.greenGroveRitual.growing.info=(Growth) The area that the ritual will grow plants in. +ritual.BloodMagic.greenGroveRitual.leech.info=(Corrosive) Entities in this area have their life drained to grow nearby crops. ritual.BloodMagic.jumpRitual.jumpRange.info=(Jumping) Entities in this range will be launched in the air. ritual.BloodMagic.wellOfSufferingRitual.altar.info=(Altar) This range defines the area that the ritual searches for the blood altar. Changing this will either expand or limit the range to a certain region. ritual.BloodMagic.wellOfSufferingRitual.damage.info=(Damage) This defines where the ritual will damage a mob. All mobs inside of this range (except for players) will receive damage over time.