From 767ecf78c258b05e0d89567211e433338b7266e7 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Mon, 30 Apr 2018 02:03:24 -0500 Subject: [PATCH] Narrow bounds of some getEntitiesWithinAAB calls, should yield a very minor performance boost --- .../common/block/tile/mana/TileManaDetector.java | 4 ++-- .../botania/common/block/tile/mana/TileSpreader.java | 3 ++- .../botania/common/entity/EntityMagicMissile.java | 8 +++++++- .../common/item/equipment/bauble/ItemTinyPlanet.java | 5 +++-- .../botania/common/item/lens/LensInfluence.java | 11 ++++++----- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/java/vazkii/botania/common/block/tile/mana/TileManaDetector.java b/src/main/java/vazkii/botania/common/block/tile/mana/TileManaDetector.java index 819f61d8f..c9bd8c04b 100644 --- a/src/main/java/vazkii/botania/common/block/tile/mana/TileManaDetector.java +++ b/src/main/java/vazkii/botania/common/block/tile/mana/TileManaDetector.java @@ -11,7 +11,7 @@ package vazkii.botania.common.block.tile.mana; import com.google.common.base.Predicates; -import net.minecraft.entity.Entity; +import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.util.ITickable; import net.minecraft.util.math.AxisAlignedBB; import vazkii.botania.api.internal.IManaBurst; @@ -24,7 +24,7 @@ public class TileManaDetector extends TileMod implements ITickable { @Override public void update() { boolean state = world.getBlockState(getPos()).getValue(BotaniaStateProps.POWERED); - boolean expectedState = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos, pos.add(1, 1, 1)), Predicates.instanceOf(IManaBurst.class)).size() != 0; + boolean expectedState = world.getEntitiesWithinAABB(EntityThrowable.class, new AxisAlignedBB(pos, pos.add(1, 1, 1)), Predicates.instanceOf(IManaBurst.class)).size() != 0; if(state != expectedState && !world.isRemote) world.setBlockState(getPos(), world.getBlockState(getPos()).withProperty(BotaniaStateProps.POWERED, expectedState), 1 | 2); diff --git a/src/main/java/vazkii/botania/common/block/tile/mana/TileSpreader.java b/src/main/java/vazkii/botania/common/block/tile/mana/TileSpreader.java index eb774517f..ccae31870 100644 --- a/src/main/java/vazkii/botania/common/block/tile/mana/TileSpreader.java +++ b/src/main/java/vazkii/botania/common/block/tile/mana/TileSpreader.java @@ -20,6 +20,7 @@ import net.minecraft.client.resources.I18n; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.play.server.SPacketUpdateTileEntity; @@ -225,7 +226,7 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector, double y = lastPingbackY; double z = lastPingbackZ; AxisAlignedBB aabb = new AxisAlignedBB(x, y, z, x, y, z).grow(PINGBACK_EXPIRED_SEARCH_DISTANCE, PINGBACK_EXPIRED_SEARCH_DISTANCE, PINGBACK_EXPIRED_SEARCH_DISTANCE); - List bursts = world.getEntitiesWithinAABB(Entity.class, aabb, Predicates.instanceOf(IManaBurst.class)); + List bursts = world.getEntitiesWithinAABB(EntityThrowable.class, aabb, Predicates.instanceOf(IManaBurst.class)); IManaBurst found = null; UUID identity = getIdentifier(); for(IManaBurst burst : (List) bursts) diff --git a/src/main/java/vazkii/botania/common/entity/EntityMagicMissile.java b/src/main/java/vazkii/botania/common/entity/EntityMagicMissile.java index 5f82080c0..99d92ea62 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityMagicMissile.java +++ b/src/main/java/vazkii/botania/common/entity/EntityMagicMissile.java @@ -169,7 +169,13 @@ public class EntityMagicMissile extends EntityThrowable { setTarget(null); double range = 12; - List entities = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(posX - range, posY - range, posZ - range, posX + range, posY + range, posZ + range), Predicates.instanceOf(isEvil() ? EntityPlayer.class : IMob.class)); + AxisAlignedBB bounds = new AxisAlignedBB(posX - range, posY - range, posZ - range, posX + range, posY + range, posZ + range); + List entities; + if(isEvil()) { + entities = world.getEntitiesWithinAABB(EntityPlayer.class, bounds); + } else { + entities = world.getEntitiesWithinAABB(Entity.class, bounds, Predicates.instanceOf(IMob.class)); + } while(entities.size() > 0) { Entity e = (Entity) entities.get(world.rand.nextInt(entities.size())); if(!(e instanceof EntityLivingBase) || e.isDead) { // Just in case... diff --git a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemTinyPlanet.java b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemTinyPlanet.java index afb742989..c8f25d642 100644 --- a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemTinyPlanet.java +++ b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemTinyPlanet.java @@ -18,6 +18,7 @@ import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.AxisAlignedBB; @@ -61,8 +62,8 @@ public class ItemTinyPlanet extends ItemBauble implements IBaubleRender { public static void applyEffect(World world, double x, double y, double z) { int range = 8; - List entities = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range), Predicates.instanceOf(IManaBurst.class)); - for(Entity entity : entities) { + List entities = world.getEntitiesWithinAABB(EntityThrowable.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range), Predicates.instanceOf(IManaBurst.class)); + for(EntityThrowable entity : entities) { IManaBurst burst = (IManaBurst) entity; ItemStack lens = burst.getSourceLens(); if(lens != null && lens.getItem() instanceof ITinyPlanetExcempt && !((ITinyPlanetExcempt) lens.getItem()).shouldPull(lens)) diff --git a/src/main/java/vazkii/botania/common/item/lens/LensInfluence.java b/src/main/java/vazkii/botania/common/item/lens/LensInfluence.java index 7a7f988bf..71a259e1b 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensInfluence.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensInfluence.java @@ -30,11 +30,12 @@ public class LensInfluence extends Lens { public void updateBurst(IManaBurst burst, EntityThrowable entity, ItemStack stack) { if(!burst.isFake()) { double range = 3.5; - List movables = entity.world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range)); - movables.addAll(entity.world.getEntitiesWithinAABB(EntityXPOrb.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); - movables.addAll(entity.world.getEntitiesWithinAABB(EntityArrow.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); - movables.addAll(entity.world.getEntitiesWithinAABB(EntityFallingBlock.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); - movables.addAll(entity.world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range), Predicates.instanceOf(IManaBurst.class))); + AxisAlignedBB bounds = new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range); + List movables = entity.world.getEntitiesWithinAABB(EntityItem.class, bounds); + movables.addAll(entity.world.getEntitiesWithinAABB(EntityXPOrb.class, bounds)); + movables.addAll(entity.world.getEntitiesWithinAABB(EntityArrow.class, bounds)); + movables.addAll(entity.world.getEntitiesWithinAABB(EntityFallingBlock.class, bounds)); + movables.addAll(entity.world.getEntitiesWithinAABB(EntityThrowable.class, bounds, Predicates.instanceOf(IManaBurst.class))); for(Entity movable : movables) { if(movable == burst)