From 47d565a70ce48ad1c1452072af09661a3ead547f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 28 Jan 2019 14:58:08 +0100 Subject: [PATCH] rework effect powder to have its range based on the stack size --- .../de/ellpeck/naturesaura/InternalHooks.java | 14 +++++++++++--- .../ellpeck/naturesaura/api/NaturesAuraAPI.java | 17 ++++++++--------- .../naturesaura/api/internal/StubHooks.java | 2 +- .../naturesaura/chunk/effect/AnimalEffect.java | 4 ++-- .../chunk/effect/CacheRechargeEffect.java | 2 +- .../chunk/effect/PlantBoostEffect.java | 2 +- .../entities/EntityEffectInhibitor.java | 5 ++++- .../naturesaura/items/ItemEffectPowder.java | 3 ++- .../ellpeck/naturesaura/recipes/ModRecipes.java | 6 +++--- .../book/en_us/entries/effects/animal.json | 2 +- .../en_us/entries/effects/cache_recharge.json | 2 +- .../en_us/entries/effects/effect_powder.json | 4 ++-- .../book/en_us/entries/effects/plant_boost.json | 2 +- 13 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java index c7413753..0fd4030d 100644 --- a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java @@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.items.IItemHandler; @@ -95,11 +96,18 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks { } @Override - public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name, int radius) { + public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name) { List inhibitors = world.getEntitiesWithinAABB( EntityEffectInhibitor.class, - new AxisAlignedBB(pos).grow(radius), - entity -> entity.getDistanceSq(pos) <= radius * radius && name.equals(entity.getInhibitedEffect())); + new AxisAlignedBB(pos).grow(64), + entity -> { + if (!name.equals(entity.getInhibitedEffect())) + return false; + AxisAlignedBB bounds = new AxisAlignedBB( + entity.posX, entity.posY, entity.posZ, + entity.posX, entity.posY, entity.posZ).grow(entity.amount); + return bounds.contains(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5)); + }); return !inhibitors.isEmpty(); } diff --git a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java index 6da16162..8c1de715 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -40,7 +40,7 @@ public final class NaturesAuraAPI { public static final String MOD_ID = "naturesaura"; public static final String API_ID = MOD_ID + "api"; - public static final String VERSION = "6"; + public static final String VERSION = "7"; /** * The list of all {@link AltarRecipe} instances which are the recipes used @@ -96,7 +96,7 @@ public final class NaturesAuraAPI { * A map of all effect powder type. The integer the effect is registered to * is the color that the powder and its effect should have. To check if a * powder is active in any given area, use {@link IInternalHooks#isEffectPowderActive(World, - * BlockPos, ResourceLocation, int)} + * BlockPos, ResourceLocation)} */ public static final Map EFFECT_POWDERS = new HashMap<>(); /** @@ -250,16 +250,15 @@ public final class NaturesAuraAPI { /** * Returns true if there is an effect powder entity active anywhere - * around the given position in the given radius. To register a powder - * with the supplied name, use {@link #EFFECT_POWDERS} + * around the given position based on the radius it has. To register a + * powder with the supplied name, use {@link #EFFECT_POWDERS} * - * @param world The world - * @param pos The center position - * @param name The registry name of the powder - * @param radius The radius around the center to check for + * @param world The world + * @param pos The center position + * @param name The registry name of the powder * @return If the effect is currently inhibited by any inhibitors */ - boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name, int radius); + boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name); /** * @see IAuraChunk#getSpotsInArea(World, BlockPos, int, BiConsumer) 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 5db4b68e..8291b1c0 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/api/internal/StubHooks.java @@ -37,7 +37,7 @@ public class StubHooks implements NaturesAuraAPI.IInternalHooks { } @Override - public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name, int radius) { + public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name) { return false; } diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/AnimalEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/AnimalEffect.java index b4517b6f..0a9c6068 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/AnimalEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/AnimalEffect.java @@ -50,7 +50,7 @@ public class AnimalEffect implements IDrainSpotEffect { for (EntityItem item : items) { if (item.isDead) continue; - if (NaturesAuraAPI.instance().isEffectPowderActive(world, item.getPosition(), NAME, 35)) + if (NaturesAuraAPI.instance().isEffectPowderActive(world, item.getPosition(), NAME)) continue; ItemStack stack = item.getItem(); @@ -84,7 +84,7 @@ public class AnimalEffect implements IDrainSpotEffect { EntityAnimal first = animals.get(world.rand.nextInt(animals.size())); if (first.isChild() || first.isInLove()) return; - if (NaturesAuraAPI.instance().isEffectPowderActive(world, first.getPosition(), NAME, 35)) + if (NaturesAuraAPI.instance().isEffectPowderActive(world, first.getPosition(), NAME)) return; Optional secondOptional = animals.stream() diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/CacheRechargeEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/CacheRechargeEffect.java index 40e84629..20b982e1 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/CacheRechargeEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/CacheRechargeEffect.java @@ -27,7 +27,7 @@ public class CacheRechargeEffect implements IDrainSpotEffect { int aura = IAuraChunk.getAuraInArea(world, pos, 20); if (aura < 15000) return; - if (NaturesAuraAPI.instance().isEffectPowderActive(world, pos, NAME, 30)) + if (NaturesAuraAPI.instance().isEffectPowderActive(world, pos, NAME)) return; int dist = MathHelper.clamp(aura / 3500, 3, 15); int amount = aura / 2500 - 2; diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java index 73e1ca11..3ea6b895 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java @@ -39,7 +39,7 @@ public class PlantBoostEffect implements IDrainSpotEffect { int z = MathHelper.floor(pos.getZ() + world.rand.nextGaussian() * dist); BlockPos plantPos = new BlockPos(x, world.getHeight(x, z), z); if (plantPos.distanceSq(pos) <= dist * dist && world.isBlockLoaded(plantPos)) { - if (NaturesAuraAPI.instance().isEffectPowderActive(world, plantPos, NAME, 15)) + if (NaturesAuraAPI.instance().isEffectPowderActive(world, plantPos, NAME)) continue; IBlockState state = world.getBlockState(plantPos); diff --git a/src/main/java/de/ellpeck/naturesaura/entities/EntityEffectInhibitor.java b/src/main/java/de/ellpeck/naturesaura/entities/EntityEffectInhibitor.java index d82368c2..e3cadc58 100644 --- a/src/main/java/de/ellpeck/naturesaura/entities/EntityEffectInhibitor.java +++ b/src/main/java/de/ellpeck/naturesaura/entities/EntityEffectInhibitor.java @@ -18,6 +18,7 @@ public class EntityEffectInhibitor extends Entity { private static final DataParameter INHIBITED_EFFECT = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.STRING); private static final DataParameter COLOR = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT); + public int amount; public EntityEffectInhibitor(World worldIn) { super(worldIn); @@ -34,12 +35,14 @@ public class EntityEffectInhibitor extends Entity { protected void readEntityFromNBT(NBTTagCompound compound) { this.setInhibitedEffect(new ResourceLocation(compound.getString("effect"))); this.setColor(compound.getInteger("color")); + this.amount = compound.hasKey("amount") ? compound.getInteger("amount") : 24; } @Override protected void writeEntityToNBT(NBTTagCompound compound) { compound.setString("effect", this.getInhibitedEffect().toString()); compound.setInteger("color", this.getColor()); + compound.setInteger("amount", this.amount); } @Override @@ -67,7 +70,7 @@ public class EntityEffectInhibitor extends Entity { public boolean attackEntityFrom(DamageSource source, float amount) { if (source instanceof EntityDamageSource && !this.world.isRemote) { this.setDead(); - this.entityDropItem(ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER), this.getInhibitedEffect()), 0F); + this.entityDropItem(ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, this.amount), this.getInhibitedEffect()), 0F); return true; } else return super.attackEntityFrom(source, amount); diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemEffectPowder.java b/src/main/java/de/ellpeck/naturesaura/items/ItemEffectPowder.java index d44ab25a..411bd81e 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemEffectPowder.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemEffectPowder.java @@ -29,9 +29,10 @@ public class ItemEffectPowder extends ItemImpl implements IColorProvidingItem { EntityEffectInhibitor entity = new EntityEffectInhibitor(worldIn); entity.setInhibitedEffect(effect); entity.setColor(NaturesAuraAPI.EFFECT_POWDERS.get(effect)); + entity.amount = stack.getCount(); entity.setPosition(pos.getX() + hitX, pos.getY() + hitY + 1, pos.getZ() + hitZ); worldIn.spawnEntity(entity); - stack.shrink(1); + stack.setCount(0); } return EnumActionResult.SUCCESS; } diff --git a/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java b/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java index c62f17d2..b10d52d3 100644 --- a/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java +++ b/src/main/java/de/ellpeck/naturesaura/recipes/ModRecipes.java @@ -84,21 +84,21 @@ public final class ModRecipes { Helper.blockIng(Blocks.GLOWSTONE)).register(); new TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "plant_powder"), Ingredient.fromStacks(new ItemStack(Blocks.SAPLING)), - ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER), PlantBoostEffect.NAME), 400, + ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, 24), PlantBoostEffect.NAME), 400, Helper.blockIng(ModBlocks.GOLD_POWDER), 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)), - ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER), CacheRechargeEffect.NAME), 400, + ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, 32), 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 TreeRitualRecipe(new ResourceLocation(NaturesAura.MOD_ID, "animal_powder"), Ingredient.fromStacks(new ItemStack(Blocks.SAPLING, 1, 3)), - ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER), AnimalEffect.NAME), 400, + ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, 24), AnimalEffect.NAME), 400, Helper.blockIng(ModBlocks.GOLD_POWDER), Helper.blockIng(ModBlocks.GOLD_POWDER), Ingredient.fromItem(ModItems.SKY_INGOT), diff --git a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/animal.json b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/animal.json index 686669cb..9df20669 100644 --- a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/animal.json +++ b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/animal.json @@ -15,7 +15,7 @@ { "type": "naturesaura:tree_ritual", "recipe": "naturesaura:animal_powder", - "text": "This effect can be inhibited in a radius of about 15 blocks using $(l:effects/effect_powder)Powder of Chastity$()." + "text": "This effect can be inhibited using $(l:effects/effect_powder)Powder of Chastity$()." } ] } \ No newline at end of file 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 index 51d721c1..e3d8895c 100644 --- 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 @@ -11,7 +11,7 @@ { "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/effect_powder)Powder of no Storage$()." + "text": "This effect can be inhibited using $(l:effects/effect_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/effect_powder.json b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/effect_powder.json index a7e39ba0..d5340a93 100644 --- a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/effect_powder.json +++ b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/effect_powder.json @@ -7,11 +7,11 @@ "pages": [ { "type": "text", - "text": "$(item)Effect Powder$() is a magical substance that has two purposes: For one, it can $(thing)inhibit$() existing passive effects from happening in a certain area around it. Additionally, some effects can only happen with it around in the first place, meaning that it also has $(thing)creational$() abilities.$(p)The powder, of course, only works on positive effects." + "text": "$(item)Effect Powder$() is a magical substance that has two purposes: For one, it can $(thing)inhibit$() existing passive effects from happening. Additionally, some effects can only happen with it around in the first place, meaning that it also has $(thing)creational$() abilities.$(p)The powder, of course, only works on positive effects." }, { "type": "text", - "text": "To use it, simply placing it down on the ground will cause it to either stop its effect or create it, depending on the type of powder used. Hitting it while it is on the ground will cause it to go back into its item form.$(p)Each effect that has an $(item)Effect Powder$() attached to it will show the recipe and radius in its chapter." + "text": "To use it, simply placing a stack of any size down on the ground will cause it to either stop its effect or create it, depending on the type of powder used. The $(thing)range$() the effect will have in blocks is equal to the size of the stack placed down. Hitting it while it is on the ground will cause it to go back into its item form.$(p)Each effect that has an $(item)Effect Powder$() attached to it will show the recipe in its chapter." } ] } \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/plant_boost.json b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/plant_boost.json index e14dcd6a..3d994f2a 100644 --- a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/plant_boost.json +++ b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/plant_boost.json @@ -15,7 +15,7 @@ { "type": "naturesaura:tree_ritual", "recipe": "naturesaura:plant_powder", - "text": "This effect can be inhibited in a radius of about 15 blocks using $(l:effects/effect_powder)Powder of Steady Growth$()." + "text": "This effect can be inhibited using $(l:effects/effect_powder)Powder of Steady Growth$()." } ] } \ No newline at end of file