slightly increase performance by reducing the activity of some effects

This commit is contained in:
Ell 2021-01-30 17:21:41 +01:00
parent ba6c274842
commit 8417523e31
3 changed files with 34 additions and 30 deletions

View file

@ -66,6 +66,8 @@ public class AnimalEffect implements IDrainSpotEffect {
@Override @Override
public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { 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)) if (!this.calcValues(world, pos, spot))
return; return;
@ -73,40 +75,38 @@ public class AnimalEffect implements IDrainSpotEffect {
if (animals.size() >= 200) if (animals.size() >= 200)
return; return;
if (world.getGameTime() % 200 == 0) { List<ItemEntity> items = world.getEntitiesWithinAABB(ItemEntity.class, this.bb);
List<ItemEntity> items = world.getEntitiesWithinAABB(ItemEntity.class, this.bb); for (ItemEntity item : items) {
for (ItemEntity item : items) { if (!item.isAlive())
if (!item.isAlive()) continue;
continue; if (!NaturesAuraAPI.instance().isEffectPowderActive(world, item.getPosition(), NAME))
if (!NaturesAuraAPI.instance().isEffectPowderActive(world, item.getPosition(), NAME)) continue;
continue;
ItemStack stack = item.getItem(); ItemStack stack = item.getItem();
if (!(stack.getItem() instanceof EggItem)) if (!(stack.getItem() instanceof EggItem))
continue; continue;
// The getAge() method is client-side only for absolutely no reason but I want it so I don't care // 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"); int age = ObfuscationReflectionHelper.getPrivateValue(ItemEntity.class, item, "field_70292_b");
if (age < item.lifespan / 2) if (age < item.lifespan / 2)
continue; continue;
if (stack.getCount() <= 1) if (stack.getCount() <= 1)
item.remove(); item.remove();
else { else {
stack.shrink(1); stack.shrink(1);
item.setItem(stack); 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);
} }
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) if (animals.size() < 2)
return; return;
AnimalEntity first = animals.get(world.rand.nextInt(animals.size())); AnimalEntity first = animals.get(world.rand.nextInt(animals.size()));

View file

@ -18,6 +18,8 @@ public class BalanceEffect implements IDrainSpotEffect {
public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (spot < 100000) if (spot < 100000)
return; return;
if (world.getGameTime() % 200 != 0)
return;
int searchRadius = Math.min(45, spot / 10000); int searchRadius = Math.min(45, spot / 10000);
MutableInt positiveAura = new MutableInt(); MutableInt positiveAura = new MutableInt();
IAuraChunk.getSpotsInArea(world, pos, searchRadius, (otherPos, otherSpot) -> { IAuraChunk.getSpotsInArea(world, pos, searchRadius, (otherPos, otherSpot) -> {
@ -28,7 +30,7 @@ public class BalanceEffect implements IDrainSpotEffect {
BlockPos lowestPos = IAuraChunk.getLowestSpot(world, pos, radius, null); BlockPos lowestPos = IAuraChunk.getLowestSpot(world, pos, radius, null);
if (lowestPos == null) if (lowestPos == null)
return; 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); auraChunk.drainAura(pos, stored);
} }

View file

@ -59,6 +59,8 @@ public class NetherGrassEffect implements IDrainSpotEffect {
@Override @Override
public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { 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)) if (!this.calcValues(world, pos, spot))
return; return;
for (int i = this.amount / 2 + world.rand.nextInt(this.amount / 2); i >= 0; i--) { for (int i = this.amount / 2 + world.rand.nextInt(this.amount / 2); i >= 0; i--) {