From 8417523e3152f81a952fb8b51268817ca82be37c Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 30 Jan 2021 17:21:41 +0100 Subject: [PATCH] slightly increase performance by reducing the activity of some effects --- .../chunk/effect/AnimalEffect.java | 58 +++++++++---------- .../chunk/effect/BalanceEffect.java | 4 +- .../chunk/effect/NetherGrassEffect.java | 2 + 3 files changed, 34 insertions(+), 30 deletions(-) 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 71afcc0e..96c3cd2c 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/AnimalEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/AnimalEffect.java @@ -66,6 +66,8 @@ public class AnimalEffect implements IDrainSpotEffect { @Override public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { + if (world.getGameTime() % 200 != 0) + return; if (!this.calcValues(world, pos, spot)) return; @@ -73,40 +75,38 @@ public class AnimalEffect implements IDrainSpotEffect { if (animals.size() >= 200) return; - if (world.getGameTime() % 200 == 0) { - List items = world.getEntitiesWithinAABB(ItemEntity.class, this.bb); - for (ItemEntity item : items) { - if (!item.isAlive()) - continue; - if (!NaturesAuraAPI.instance().isEffectPowderActive(world, item.getPosition(), NAME)) - continue; + List items = world.getEntitiesWithinAABB(ItemEntity.class, this.bb); + for (ItemEntity item : items) { + if (!item.isAlive()) + continue; + if (!NaturesAuraAPI.instance().isEffectPowderActive(world, item.getPosition(), NAME)) + continue; - ItemStack stack = item.getItem(); - if (!(stack.getItem() instanceof EggItem)) - continue; - // The getAge() method is client-side only for absolutely no reason but I want it so I don't care - int age = ObfuscationReflectionHelper.getPrivateValue(ItemEntity.class, item, "field_70292_b"); - if (age < item.lifespan / 2) - continue; + ItemStack stack = item.getItem(); + if (!(stack.getItem() instanceof EggItem)) + continue; + // The getAge() method is client-side only for absolutely no reason but I want it so I don't care + int age = ObfuscationReflectionHelper.getPrivateValue(ItemEntity.class, item, "field_70292_b"); + if (age < item.lifespan / 2) + continue; - if (stack.getCount() <= 1) - item.remove(); - else { - stack.shrink(1); - item.setItem(stack); - } - - ChickenEntity chicken = new ChickenEntity(EntityType.CHICKEN, world); - chicken.setGrowingAge(-24000); - chicken.setPosition(item.getPosX(), item.getPosY(), item.getPosZ()); - world.addEntity(chicken); - - BlockPos closestSpot = IAuraChunk.getHighestSpot(world, item.getPosition(), 35, pos); - IAuraChunk.getAuraChunk(world, closestSpot).drainAura(closestSpot, 2000); + if (stack.getCount() <= 1) + item.remove(); + else { + stack.shrink(1); + item.setItem(stack); } + + ChickenEntity chicken = new ChickenEntity(EntityType.CHICKEN, world); + chicken.setGrowingAge(-24000); + chicken.setPosition(item.getPosX(), item.getPosY(), item.getPosZ()); + world.addEntity(chicken); + + BlockPos closestSpot = IAuraChunk.getHighestSpot(world, item.getPosition(), 35, pos); + IAuraChunk.getAuraChunk(world, closestSpot).drainAura(closestSpot, 2000); } - if (world.rand.nextInt(200) <= this.chance) { + if (world.rand.nextInt(20) <= this.chance) { if (animals.size() < 2) return; AnimalEntity first = animals.get(world.rand.nextInt(animals.size())); diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/BalanceEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/BalanceEffect.java index 70eddb61..f9f23255 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/BalanceEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/BalanceEffect.java @@ -18,6 +18,8 @@ public class BalanceEffect implements IDrainSpotEffect { public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { if (spot < 100000) return; + if (world.getGameTime() % 200 != 0) + return; int searchRadius = Math.min(45, spot / 10000); MutableInt positiveAura = new MutableInt(); IAuraChunk.getSpotsInArea(world, pos, searchRadius, (otherPos, otherSpot) -> { @@ -28,7 +30,7 @@ public class BalanceEffect implements IDrainSpotEffect { BlockPos lowestPos = IAuraChunk.getLowestSpot(world, pos, radius, null); if (lowestPos == null) return; - int stored = IAuraChunk.getAuraChunk(world, lowestPos).storeAura(lowestPos, spot / 500); + int stored = IAuraChunk.getAuraChunk(world, lowestPos).storeAura(lowestPos, spot / 50); auraChunk.drainAura(pos, stored); } diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/NetherGrassEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/NetherGrassEffect.java index 1f2d1fa1..a71c0e23 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/NetherGrassEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/NetherGrassEffect.java @@ -59,6 +59,8 @@ public class NetherGrassEffect implements IDrainSpotEffect { @Override public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { + if (world.getGameTime() % 40 != 0) + return; if (!this.calcValues(world, pos, spot)) return; for (int i = this.amount / 2 + world.rand.nextInt(this.amount / 2); i >= 0; i--) {