From c8211cd3ba8ebd80667e2d6dfbf0c03ad418b0b4 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 15 Feb 2019 17:51:26 +0100 Subject: [PATCH] fixed effects happening more often the more spots there were, regardless of the amount of aura --- .../java/de/ellpeck/naturesaura/InternalHooks.java | 7 +++++++ .../de/ellpeck/naturesaura/api/NaturesAuraAPI.java | 5 +++++ .../naturesaura/api/aura/chunk/IAuraChunk.java | 13 +++++++++++++ .../ellpeck/naturesaura/api/internal/StubHooks.java | 5 +++++ .../naturesaura/chunk/effect/AnimalEffect.java | 2 +- .../chunk/effect/CacheRechargeEffect.java | 2 +- .../naturesaura/chunk/effect/ExplosionEffect.java | 5 ++--- .../naturesaura/chunk/effect/GrassDieEffect.java | 2 +- .../naturesaura/chunk/effect/PlantBoostEffect.java | 2 +- 9 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java index fef298fb..6d802389 100644 --- a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java @@ -117,6 +117,13 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks { world.profiler.endSection(); } + @Override + public int getSpotAmountInArea(World world, BlockPos pos, int radius) { + MutableInt result = new MutableInt(); + this.getAuraSpotsInArea(world, pos, radius, (blockpos, drainSpot) -> result.increment()); + return result.intValue(); + } + @Override public int getAuraInArea(World world, BlockPos pos, int radius) { MutableInt result = new MutableInt(IAuraChunk.DEFAULT_AURA); diff --git a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java index f1acf670..2272af57 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -267,6 +267,11 @@ public final class NaturesAuraAPI { */ void getAuraSpotsInArea(World world, BlockPos pos, int radius, BiConsumer consumer); + /** + * @see IAuraChunk#getSpotAmountInArea(World, BlockPos, int) + */ + int getSpotAmountInArea(World world, BlockPos pos, int radius); + /** * @see IAuraChunk#getAuraInArea(World, BlockPos, int) */ diff --git a/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java b/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java index 40146df1..05ba2fd1 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java +++ b/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java @@ -57,6 +57,19 @@ public interface IAuraChunk extends ICapabilityProvider, INBTSerializable -5000000) return false; - this.chance = 140 - Math.abs(aura) / 200000; - if (this.chance > 1 && world.rand.nextInt(this.chance) != 0) + int chance = 140 - Math.abs(aura) / 200000; + if (chance > 1 && world.rand.nextInt(chance) != 0) return false; this.strength = Math.min(Math.abs(aura) / 5000000F, 5F); if (this.strength <= 0) diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java index 7a5f4191..ebbf1785 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java @@ -29,7 +29,7 @@ public class GrassDieEffect implements IDrainSpotEffect { if (spot < 0) { int aura = IAuraChunk.getAuraInArea(world, pos, 50); if (aura < 0) { - this.amount = Math.min(300, Math.abs(aura) / 100000); + this.amount = Math.min(300, Math.abs(aura) / 100000 / IAuraChunk.getSpotAmountInArea(world, pos, 50)); if (this.amount > 1) { this.dist = MathHelper.clamp(Math.abs(aura) / 75000, 5, 75); return true; 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 c3a30b78..4dc414cc 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java @@ -34,7 +34,7 @@ public class PlantBoostEffect implements IDrainSpotEffect { int aura = IAuraChunk.getAuraInArea(world, pos, 30); if (aura < 1500000) return false; - this.amount = Math.min(45, Math.abs(aura) / 100000); + this.amount = Math.min(45, Math.abs(aura) / 100000 / IAuraChunk.getSpotAmountInArea(world, pos, 30)); if (this.amount <= 1) return false; this.dist = MathHelper.clamp(Math.abs(aura) / 150000, 5, 35);