From 8007fcb62ba17df67774edd561e067e73431bcbe Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 14 Dec 2018 13:51:08 +0100 Subject: [PATCH] added a passive effect where aura gets added to aura caches around --- .../de/ellpeck/naturesaura/InternalHooks.java | 24 +++++++-- .../de/ellpeck/naturesaura/ModConfig.java | 2 + .../naturesaura/api/NaturesAuraAPI.java | 12 +++++ .../naturesaura/api/internal/StubHooks.java | 5 ++ .../chunk/effect/CacheRechargeEffect.java | 53 +++++++++++++++++++ .../chunk/effect/DrainSpotEffects.java | 2 + .../naturesaura/recipes/ModRecipes.java | 8 +++ .../naturesaura/advancements/aura_cache.json | 26 +++++++++ .../assets/naturesaura/lang/en_US.lang | 3 ++ .../en_us/entries/effects/cache_recharge.json | 17 ++++++ .../entries/effects/inhibiting_powder.json | 2 +- 11 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/chunk/effect/CacheRechargeEffect.java create mode 100644 src/main/resources/assets/naturesaura/advancements/aura_cache.json create mode 100644 src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/cache_recharge.json diff --git a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java index 1fac9617..587c9bad 100644 --- a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java @@ -3,6 +3,7 @@ package de.ellpeck.naturesaura; import baubles.api.BaublesApi; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.multiblock.IMultiblock; import de.ellpeck.naturesaura.blocks.multi.Multiblock; import de.ellpeck.naturesaura.compat.Compat; @@ -26,7 +27,16 @@ import java.util.function.BiConsumer; public class InternalHooks implements NaturesAuraAPI.IInternalHooks { @Override public boolean extractAuraFromPlayer(EntityPlayer player, int amount, boolean simulate) { - if (player.capabilities.isCreativeMode) + return this.auraPlayerInteraction(player, amount, true, simulate); + } + + @Override + public boolean insertAuraIntoPlayer(EntityPlayer player, int amount, boolean simulate) { + return this.auraPlayerInteraction(player, amount, false, simulate); + } + + private boolean auraPlayerInteraction(EntityPlayer player, int amount, boolean extract, boolean simulate) { + if (extract && player.capabilities.isCreativeMode) return true; if (Compat.baubles) { @@ -34,7 +44,11 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks { for (int i = 0; i < baubles.getSlots(); i++) { ItemStack stack = baubles.getStackInSlot(i); if (!stack.isEmpty() && stack.hasCapability(NaturesAuraAPI.capAuraContainer, null)) { - amount -= stack.getCapability(NaturesAuraAPI.capAuraContainer, null).drainAura(amount, simulate); + IAuraContainer container = stack.getCapability(NaturesAuraAPI.capAuraContainer, null); + if (extract) + amount -= container.drainAura(amount, simulate); + else + amount -= container.storeAura(amount, simulate); if (amount <= 0) return true; } @@ -44,7 +58,11 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks { for (int i = 0; i < player.inventory.getSizeInventory(); i++) { ItemStack stack = player.inventory.getStackInSlot(i); if (!stack.isEmpty() && stack.hasCapability(NaturesAuraAPI.capAuraContainer, null)) { - amount -= stack.getCapability(NaturesAuraAPI.capAuraContainer, null).drainAura(amount, simulate); + IAuraContainer container = stack.getCapability(NaturesAuraAPI.capAuraContainer, null); + if (extract) + amount -= container.drainAura(amount, simulate); + else + amount -= container.storeAura(amount, simulate); if (amount <= 0) return true; } diff --git a/src/main/java/de/ellpeck/naturesaura/ModConfig.java b/src/main/java/de/ellpeck/naturesaura/ModConfig.java index 0a6f3b96..804c825b 100644 --- a/src/main/java/de/ellpeck/naturesaura/ModConfig.java +++ b/src/main/java/de/ellpeck/naturesaura/ModConfig.java @@ -40,6 +40,8 @@ public final class ModConfig { public boolean grassDieEffect = true; @Comment("If the Aura Imbalance effect of plant growth being boosted if the Aura levels are high enough should occur") public boolean plantBoostEffect = true; + @Comment("If the Aura Imbalance effect of aura containers in players' inventories being filled if the Aura levels are high enough should occur") + public boolean cacheRechargeEffect = true; @Comment("If the Aura Imbalance effect of explosions happening randomly if Aura levels are too low should occur") public boolean explosionEffect = true; @Comment("If the Aura Imbalance effect of breathlessness if Aura levels are too low should occur") diff --git a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java index 9d82e76e..becd9ba0 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -173,6 +173,18 @@ public final class NaturesAuraAPI { */ boolean extractAuraFromPlayer(EntityPlayer player, int amount, boolean simulate); + /** + * Helper method to insert aura into an {@link IAuraContainer} in the + * supplied player's inventory or baubles slots. The method returns true + * if the aura could be inserted. + * + * @param player The player + * @param amount The amount to insert + * @param simulate If the insertion should be simulated + * @return If the insertion was successful + */ + boolean insertAuraIntoPlayer(EntityPlayer player, int amount, boolean simulate); + /** * This method can be used to spawn the magic particle effect used by * Nature's Aura. It will not have an effect on the client side, so if diff --git a/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java b/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java index c184eb3b..bea9b7fa 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java @@ -16,6 +16,11 @@ public class StubHooks implements NaturesAuraAPI.IInternalHooks { return false; } + @Override + public boolean insertAuraIntoPlayer(EntityPlayer player, int amount, boolean simulate) { + return false; + } + @Override public void spawnMagicParticle(double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) { diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/CacheRechargeEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/CacheRechargeEffect.java new file mode 100644 index 00000000..a45d462d --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/CacheRechargeEffect.java @@ -0,0 +1,53 @@ +package de.ellpeck.naturesaura.chunk.effect; + +import de.ellpeck.naturesaura.ModConfig; +import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect; +import de.ellpeck.naturesaura.api.aura.type.IAuraType; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +import java.util.List; + +public class CacheRechargeEffect implements IDrainSpotEffect { + + public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "cache_recharge"); + + @Override + public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { + if (spot < 1000) + return; + int aura = IAuraChunk.getAuraInArea(world, pos, 20); + if (aura < 15000) + return; + if (NaturesAuraAPI.instance().isEffectInhibited(world, pos, NAME, 30)) + return; + int dist = MathHelper.clamp(aura / 3500, 3, 15); + int amount = aura / 2500 - 2; + + List players = world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos).grow(dist)); + for (EntityPlayer player : players) { + if (NaturesAuraAPI.instance().insertAuraIntoPlayer(player, amount, true)) { + NaturesAuraAPI.instance().insertAuraIntoPlayer(player, amount, false); + auraChunk.drainAura(pos, amount); + } + } + } + + @Override + public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) { + return ModConfig.enabledFeatures.cacheRechargeEffect; + } + + @Override + public ResourceLocation getName() { + return NAME; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java index a04f52ee..6ff3128a 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java @@ -12,7 +12,9 @@ public final class DrainSpotEffects { NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(ExplosionEffect.NAME, ExplosionEffect::new); NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(BreathlessEffect.NAME, BreathlessEffect::new); NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(SpreadEffect.NAME, SpreadEffect::new); + NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(CacheRechargeEffect.NAME, CacheRechargeEffect::new); NaturesAuraAPI.INHIBITED_EFFECTS.put(PlantBoostEffect.NAME, 0xc2f442); + NaturesAuraAPI.INHIBITED_EFFECTS.put(CacheRechargeEffect.NAME, 0x1fb0d1); } } diff --git a/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java b/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java index 6125c3ea..20c078b1 100644 --- a/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java +++ b/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java @@ -9,6 +9,7 @@ import de.ellpeck.naturesaura.api.recipes.TreeRitualRecipe; import de.ellpeck.naturesaura.api.recipes.ing.AmountIngredient; import de.ellpeck.naturesaura.api.recipes.ing.NBTIngredient; import de.ellpeck.naturesaura.blocks.ModBlocks; +import de.ellpeck.naturesaura.chunk.effect.CacheRechargeEffect; import de.ellpeck.naturesaura.chunk.effect.PlantBoostEffect; import de.ellpeck.naturesaura.items.ItemAuraBottle; import de.ellpeck.naturesaura.items.ItemInhibitingPowder; @@ -73,6 +74,13 @@ public final class ModRecipes { Helper.blockIng(ModBlocks.GOLD_POWDER), Ingredient.fromItem(ModItems.SKY_INGOT), Ingredient.fromItem(Items.WHEAT)).register(); + new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "cache_powder"), + Ingredient.fromStacks(new ItemStack(Blocks.SAPLING)), + ItemInhibitingPowder.setEffect(new ItemStack(ModItems.INHIBITING_POWDER), CacheRechargeEffect.NAME), 400, + Helper.blockIng(ModBlocks.GOLD_POWDER), + Helper.blockIng(ModBlocks.GOLD_POWDER), + Ingredient.fromItem(ModItems.SKY_INGOT), + Ingredient.fromItem(ModItems.AURA_CACHE)).register(); new AltarRecipe(new ResourceLocation(NaturesAura.MOD_ID, "infused_iron"), Ingredient.fromItem(Items.IRON_INGOT), new ItemStack(ModItems.INFUSED_IRON), diff --git a/src/main/resources/assets/naturesaura/advancements/aura_cache.json b/src/main/resources/assets/naturesaura/advancements/aura_cache.json new file mode 100644 index 00000000..81fcea2b --- /dev/null +++ b/src/main/resources/assets/naturesaura/advancements/aura_cache.json @@ -0,0 +1,26 @@ +{ + "display": { + "icon": { + "item": "naturesaura:aura_cache" + }, + "title": { + "translate": "advancement.naturesaura.aura_cache" + }, + "description": { + "translate": "advancement.naturesaura.aura_cache.desc" + } + }, + "parent": "naturesaura:infused_materials", + "criteria": { + "cache": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { + "item": "naturesaura:aura_cache" + } + ] + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/lang/en_US.lang b/src/main/resources/assets/naturesaura/lang/en_US.lang index df6b5f5a..ca6f8457 100644 --- a/src/main/resources/assets/naturesaura/lang/en_US.lang +++ b/src/main/resources/assets/naturesaura/lang/en_US.lang @@ -64,6 +64,7 @@ item.naturesaura.infused_iron_chest.name=Botanist's Chestplate item.naturesaura.infused_iron_pants.name=Botanist's Leggings item.naturesaura.infused_iron_shoes.name=Botanist's Shoes item.naturesaura.inhibiting_powder.naturesaura:plant_boost.name=Powder of Steady Growth +item.naturesaura.inhibiting_powder.naturesaura:cache_recharge.name=Powder of no Storage container.naturesaura.tree_ritual.name=Ritual of the Forest container.naturesaura.altar.name=Natural Altar Infusion @@ -112,6 +113,8 @@ advancement.naturesaura.offering=Yo God, ya want this? advancement.naturesaura.offering.desc=Create an Offering Table for the Offering to the Gods advancement.naturesaura.sky_ingot=Sturdy and light advancement.naturesaura.sky_ingot.desc=Create an Ingot of the Skies using the Offering to the Gods +advancement.naturesaura.aura_cache=Ca-ching +advancement.naturesaura.aura_cache.desc=Create an Aura Cache to store Aura in your inventory command.naturesaura.aura.usage=/naaura diff --git a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/cache_recharge.json b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/cache_recharge.json new file mode 100644 index 00000000..9e6d6be9 --- /dev/null +++ b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/cache_recharge.json @@ -0,0 +1,17 @@ +{ + "name": "Natural Storage", + "icon": "naturesaura:aura_cache", + "category": "effects", + "advancement": "naturesaura:aura_cache", + "pages": [ + { + "type": "text", + "text": "If enough $(aura) is present in the environment, so much so that the bar of the $(l:items/eye)Environmental Eye$() is filled up by about half above the regular amount, $(item)Natural Storage$() will start to occur: For any players around a saturated area that carry an $(l:items/aura_cache)Aura Cache$() with them, it will slowly start to $(thing)fill up$(), draining from the oversaturated $(aura)." + }, + { + "type": "naturesaura:tree_ritual", + "recipe": "naturesaura:cache_powder", + "text": "This effect can be inhibited in a radius of about 30 blocks around the saturated area using $(l:effects/inhibiting_powder)Powder of no Storage$()." + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/inhibiting_powder.json b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/inhibiting_powder.json index d8077b5c..8a35d341 100644 --- a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/inhibiting_powder.json +++ b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/inhibiting_powder.json @@ -2,7 +2,7 @@ "name": "Inhibition Powder", "icon": "naturesaura:inhibiting_powder{effect:'naturesaura:plant_boost'}", "category": "effects", - "advancement": "naturesaura:flower_generator", + "advancement": "naturesaura:aura_cache", "priority": true, "pages": [ {