public <T extends Entity> T findNearestEntityWithinAABB(Class <? extends T > entityType, AxisAlignedBB aabb, T closestTo) { List<T> list = this.<T>getEntitiesWithinAABB(entityType, aabb); T t = null; double d0 = Double.MAX_VALUE; for (int i = 0; i < list.size(); ++i) { T t1 = list.get(i); if (t1 != closestTo && EntitySelectors.NOT_SPECTATING.apply(t1)) { double d1 = closestTo.getDistanceSqToEntity(t1); if (d1 <= d0) { t = t1; d0 = d1; } } } return t; }
/** * Gets the closest player to the point within the specified distance (distance can be set to less than 0 to not * limit the distance). Args: x, y, z, dist */ public EntityPlayer getClosestPlayer(double x, double y, double z, double distance) { double d0 = -1.0D; EntityPlayer entityplayer = null; for (int i = 0; i < this.playerEntities.size(); ++i) { EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i); if (EntitySelectors.NOT_SPECTATING.apply(entityplayer1)) { double d1 = entityplayer1.getDistanceSq(x, y, z); if ((distance < 0.0D || d1 < distance * distance) && (d0 == -1.0D || d1 < d0)) { d0 = d1; entityplayer = entityplayer1; } } } return entityplayer; }
public boolean isAnyPlayerWithinRangeAt(double x, double y, double z, double range) { for (int i = 0; i < this.playerEntities.size(); ++i) { EntityPlayer entityplayer = (EntityPlayer)this.playerEntities.get(i); if (EntitySelectors.NOT_SPECTATING.apply(entityplayer)) { double d0 = entityplayer.getDistanceSq(x, y, z); if (range < 0.0D || d0 < range * range) { return true; } } } return false; }
/** * Returns whether the EntityAIBase should begin execution. */ public boolean shouldExecute() { if (this.targetChance > 0 && this.taskOwner.getRNG().nextInt(this.targetChance) != 0) { return false; } else { double d0 = this.getTargetDistance(); List<T> list = this.taskOwner.worldObj.<T>getEntitiesWithinAABB(this.targetClass, this.taskOwner.getEntityBoundingBox().expand(d0, 4.0D, d0), Predicates.<T> and (this.targetEntitySelector, EntitySelectors.NOT_SPECTATING)); Collections.sort(list, this.theNearestAttackableTargetSorter); if (list.isEmpty()) { return false; } else { this.targetEntity = (EntityLivingBase)list.get(0); return true; } } }
public boolean func_96112_aD() { if (TileEntityHopper.captureDroppedItems(this)) { return true; } else { List<EntityItem> list = this.worldObj.<EntityItem>getEntitiesWithinAABB(EntityItem.class, this.getEntityBoundingBox().expand(0.25D, 0.0D, 0.25D), EntitySelectors.selectAnything); if (list.size() > 0) { TileEntityHopper.putDropInInventoryAllSlots(this, (EntityItem)list.get(0)); } return false; } }
protected void collideWithNearbyEntities() { List<Entity> list = this.worldObj.getEntitiesInAABBexcluding(this, this.getEntityBoundingBox().expand(0.20000000298023224D, 0.0D, 0.20000000298023224D), Predicates.<Entity> and (EntitySelectors.NOT_SPECTATING, new Predicate<Entity>() { public boolean apply(Entity p_apply_1_) { return p_apply_1_.canBePushed(); } })); if (!list.isEmpty()) { for (int i = 0; i < list.size(); ++i) { Entity entity = (Entity)list.get(i); this.collideWithEntity(entity); } } }
public int getComparatorInputOverride(World worldIn, BlockPos pos) { if (((Boolean)worldIn.getBlockState(pos).getValue(POWERED)).booleanValue()) { List<EntityMinecartCommandBlock> list = this.<EntityMinecartCommandBlock>findMinecarts(worldIn, pos, EntityMinecartCommandBlock.class, new Predicate[0]); if (!list.isEmpty()) { return ((EntityMinecartCommandBlock)list.get(0)).getCommandBlockLogic().getSuccessCount(); } List<EntityMinecart> list1 = this.<EntityMinecart>findMinecarts(worldIn, pos, EntityMinecart.class, new Predicate[] {EntitySelectors.selectInventories}); if (!list1.isEmpty()) { return Container.calcRedstoneFromInventory((IInventory)list1.get(0)); } } return 0; }
@Nullable public <T extends Entity> T findNearestEntityWithinAABB(Class <? extends T > entityType, AxisAlignedBB aabb, T closestTo) { List<T> list = this.<T>getEntitiesWithinAABB(entityType, aabb); T t = null; double d0 = Double.MAX_VALUE; for (int i = 0; i < list.size(); ++i) { T t1 = list.get(i); if (t1 != closestTo && EntitySelectors.NOT_SPECTATING.apply(t1)) { double d1 = closestTo.getDistanceSqToEntity(t1); if (d1 <= d0) { t = t1; d0 = d1; } } } return t; }
public boolean captureDroppedItems() { if (TileEntityHopper.captureDroppedItems(this)) { return true; } else { List<EntityItem> list = this.world.<EntityItem>getEntitiesWithinAABB(EntityItem.class, this.getEntityBoundingBox().expand(0.25D, 0.0D, 0.25D), EntitySelectors.IS_ALIVE); if (!list.isEmpty()) { TileEntityHopper.putDropInInventoryAllSlots((IInventory)null, this, (EntityItem)list.get(0)); } return false; } }
public static ItemStack dispenseArmor(IBlockSource blockSource, ItemStack stack) { BlockPos blockpos = blockSource.getBlockPos().offset((EnumFacing)blockSource.getBlockState().getValue(BlockDispenser.FACING)); List<EntityLivingBase> list = blockSource.getWorld().<EntityLivingBase>getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(blockpos), Predicates.<EntityLivingBase> and (EntitySelectors.NOT_SPECTATING, new EntitySelectors.ArmoredMob(stack))); if (list.isEmpty()) { return ItemStack.field_190927_a; } else { EntityLivingBase entitylivingbase = (EntityLivingBase)list.get(0); EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(stack); ItemStack itemstack = stack.splitStack(1); entitylivingbase.setItemStackToSlot(entityequipmentslot, itemstack); if (entitylivingbase instanceof EntityLiving) { ((EntityLiving)entitylivingbase).setDropChance(entityequipmentslot, 2.0F); } return stack; } }
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) { if (((Boolean)blockState.getValue(POWERED)).booleanValue()) { List<EntityMinecartCommandBlock> list = this.<EntityMinecartCommandBlock>findMinecarts(worldIn, pos, EntityMinecartCommandBlock.class, new Predicate[0]); if (!list.isEmpty()) { return ((EntityMinecartCommandBlock)list.get(0)).getCommandBlockLogic().getSuccessCount(); } List<EntityMinecart> list1 = this.<EntityMinecart>findMinecarts(worldIn, pos, EntityMinecart.class, new Predicate[] {EntitySelectors.HAS_INVENTORY}); if (!list1.isEmpty()) { return Container.calcRedstoneFromInventory((IInventory)list1.get(0)); } } return 0; }
@Nullable public EntityPlayer getClosestPlayer(double posX, double posY, double posZ, double distance, boolean spectator) { double d0 = -1.0D; EntityPlayer entityplayer = null; for (int i = 0; i < this.playerEntities.size(); ++i) { EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i); if ((EntitySelectors.CAN_AI_TARGET.apply(entityplayer1) || !spectator) && (EntitySelectors.NOT_SPECTATING.apply(entityplayer1) || spectator)) { double d1 = entityplayer1.getDistanceSq(posX, posY, posZ); if ((distance < 0.0D || d1 < distance * distance) && (d0 == -1.0D || d1 < d0)) { d0 = d1; entityplayer = entityplayer1; } } } return entityplayer; }
public boolean captureDroppedItems() { if (TileEntityHopper.captureDroppedItems(this)) { return true; } else { List<EntityItem> list = this.worldObj.<EntityItem>getEntitiesWithinAABB(EntityItem.class, this.getEntityBoundingBox().expand(0.25D, 0.0D, 0.25D), EntitySelectors.IS_ALIVE); if (!list.isEmpty()) { TileEntityHopper.putDropInInventoryAllSlots(this, (EntityItem)list.get(0)); } return false; } }
public static ItemStack dispenseArmor(IBlockSource blockSource, ItemStack stack) { BlockPos blockpos = blockSource.getBlockPos().offset((EnumFacing)blockSource.getBlockState().getValue(BlockDispenser.FACING)); List<EntityLivingBase> list = blockSource.getWorld().<EntityLivingBase>getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(blockpos), Predicates.<EntityLivingBase>and(EntitySelectors.NOT_SPECTATING, new EntitySelectors.ArmoredMob(stack))); if (list.isEmpty()) { return null; } else { EntityLivingBase entitylivingbase = (EntityLivingBase)list.get(0); EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(stack); ItemStack itemstack = stack.copy(); itemstack.stackSize = 1; entitylivingbase.setItemStackToSlot(entityequipmentslot, itemstack); if (entitylivingbase instanceof EntityLiving) { ((EntityLiving)entitylivingbase).setDropChance(entityequipmentslot, 2.0F); } --stack.stackSize; return stack; } }
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) { if (((Boolean)blockState.getValue(POWERED)).booleanValue()) { List<EntityMinecart> carts = this.findMinecarts(worldIn, pos, EntityMinecart.class); if (!carts.isEmpty() && carts.get(0).getComparatorLevel() > -1) return carts.get(0).getComparatorLevel(); List<EntityMinecartCommandBlock> list = this.<EntityMinecartCommandBlock>findMinecarts(worldIn, pos, EntityMinecartCommandBlock.class, new Predicate[0]); if (!list.isEmpty()) { return ((EntityMinecartCommandBlock)list.get(0)).getCommandBlockLogic().getSuccessCount(); } List<EntityMinecart> list1 = this.<EntityMinecart>findMinecarts(worldIn, pos, EntityMinecart.class, new Predicate[] {EntitySelectors.HAS_INVENTORY}); if (!list1.isEmpty()) { return Container.calcRedstoneFromInventory((IInventory)list1.get(0)); } } return 0; }
public EntityAINearestAttackableCivTarget(EntityToroNpc npc) { super(npc, false, false); this.taskOwner = npc; this.theNearestAttackableTargetSorter = new EntityAINearestAttackableTarget.Sorter(npc); this.setMutexBits(1); this.targetEntitySelector = new Predicate<EntityPlayer>() { public boolean apply(@Nullable EntityPlayer target) { if (target == null) { return false; } if (!EntitySelectors.NOT_SPECTATING.apply(target)) { return false; } if (!isSuitableTarget(taskOwner, target, false, true)) { return false; } return shouldAttackPlayerBasedOnCivilization(target); } }; }