Narrow bounds of some getEntitiesWithinAAB calls, should yield a very minor performance boost

This commit is contained in:
Vincent Lee committed 2018-04-30 02:03:24 -05:00
1 parent 24c542f31f
commit 767ecf78c2
5 files changed
+20 -11

No files matched your search

@@ -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);
@@ -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<IManaBurst>) bursts)
@@ -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...
@@ -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<Entity> 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<EntityThrowable> 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))
@@ -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<Entity> 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<Entity> 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)