fixed effects happening more often the more spots there were, regardless of the amount of aura

This commit is contained in:
Ellpeck 2019-02-15 17:51:26 +01:00
parent 8fba5c7f90
commit c8211cd3ba
9 changed files with 36 additions and 7 deletions

View file

@ -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);

View file

@ -267,6 +267,11 @@ public final class NaturesAuraAPI {
*/
void getAuraSpotsInArea(World world, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer);
/**
* @see IAuraChunk#getSpotAmountInArea(World, BlockPos, int)
*/
int getSpotAmountInArea(World world, BlockPos pos, int radius);
/**
* @see IAuraChunk#getAuraInArea(World, BlockPos, int)
*/

View file

@ -57,6 +57,19 @@ public interface IAuraChunk extends ICapabilityProvider, INBTSerializable<NBTTag
NaturesAuraAPI.instance().getAuraSpotsInArea(world, pos, radius, consumer);
}
/**
* Convenience method that adds up the amount of aura spots from {@link
* #getSpotsInArea(World, BlockPos, int, BiConsumer)} and returns it.
*
* @param world The world
* @param pos The center position
* @param radius The radius around the center to search for spots in
* @return The amount of spots found in the area
*/
static int getSpotAmountInArea(World world, BlockPos pos, int radius) {
return NaturesAuraAPI.instance().getSpotAmountInArea(world, pos, radius);
}
/**
* Convenience method that adds up all of the aura from each drain spot from
* {@link #getSpotsInArea(World, BlockPos, int, BiConsumer)} and

View file

@ -46,6 +46,11 @@ public class StubHooks implements NaturesAuraAPI.IInternalHooks {
}
@Override
public int getSpotAmountInArea(World world, BlockPos pos, int radius) {
return 0;
}
@Override
public int getAuraInArea(World world, BlockPos pos, int radius) {
return IAuraChunk.DEFAULT_AURA;

View file

@ -39,7 +39,7 @@ public class AnimalEffect implements IDrainSpotEffect {
int aura = IAuraChunk.getAuraInArea(world, pos, 30);
if (aura < 1500000)
return false;
this.chance = Math.min(50, Math.abs(aura) / 500000);
this.chance = Math.min(50, Math.abs(aura) / 500000 / IAuraChunk.getSpotAmountInArea(world, pos, 30));
if (this.chance <= 0)
return false;
int dist = MathHelper.clamp(Math.abs(aura) / 150000, 5, 35);

View file

@ -33,7 +33,7 @@ public class CacheRechargeEffect implements IDrainSpotEffect {
return false;
int dist = MathHelper.clamp(aura / 3500, 3, 15);
this.bb = new AxisAlignedBB(pos).grow(dist);
this.amount = aura / 250000 - 2;
this.amount = aura / 250000 / IAuraChunk.getSpotAmountInArea(world, pos, 20) - 2;
return true;
}

View file

@ -18,7 +18,6 @@ public class ExplosionEffect implements IDrainSpotEffect {
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "explosions");
private int chance;
private float strength;
private int dist;
@ -28,8 +27,8 @@ public class ExplosionEffect implements IDrainSpotEffect {
int aura = IAuraChunk.getAuraInArea(world, pos, 85);
if (aura > -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)

View file

@ -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;

View file

@ -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);