Java Code Examples for net.minecraft.world.World#getEntitiesWithinAABB()
The following examples show how to use
net.minecraft.world.World#getEntitiesWithinAABB() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockEnderCharge.java From EnderZoo with Creative Commons Zero v1.0 Universal | 6 votes |
public static void doEntityTeleport(EntityPrimedCharge entity) { World world = entity.getEntityWorld(); world.playSound((EntityPlayer)null, entity.posX, entity.posY, entity.posZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 1F, 1.4f + ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F)); world.playSound((EntityPlayer)null, entity.posX, entity.posY, entity.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, 2F, 1 + ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F)); AxisAlignedBB bb = EntityUtil.getBoundsAround(entity, Config.enderChargeRange); List<EntityLivingBase> ents = world.getEntitiesWithinAABB(EntityLivingBase.class, bb); for (EntityLivingBase ent : ents) { boolean done = false; for (int i = 0; i < 20 && !done; i++) { done = TeleportHelper.teleportRandomly(ent, Config.enderChargeMaxTeleportRange); } } }
Example 2
Source File: ItemShinai.java From Sakura_mod with MIT License | 5 votes |
@Override public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { int i = this.getMaxItemUseDuration(stack) - timeLeft; if (i < 0) return; entityLiving.swingArm(entityLiving.getActiveHand()); float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.2F; float f1 = i / 15F; f1 = (f1 * f1 + f1 * 2.0F) / 2F; if(f1>8F) f1=8f; float f3 = f1 + EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f ; float sweepingRatio = EnchantmentHelper.getSweepingDamageRatio(entityLiving); for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.6D + sweepingRatio * 1.2D, 0.5D + sweepingRatio * 0.15D, 1.6D + sweepingRatio * 1.2D))) { if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) { if (entitylivingbase instanceof EntityLivingBase) { f1 = f1/10; ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.6F * f1 * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F))); entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } if (entitylivingbase instanceof MultiPartEntityPart) { entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } } } worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F); if (worldIn instanceof WorldServer) { double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F)); double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F); ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D); } stack.damageItem(2, entityLiving); ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 25); }
Example 3
Source File: StorageChunk.java From AdvancedRocketry with MIT License | 5 votes |
public static StorageChunk cutWorldBB(World worldObj, AxisAlignedBB bb) { StorageChunk chunk = StorageChunk.copyWorldBB(worldObj, bb); for(int x = (int)bb.minX; x <= bb.maxX; x++) { for(int z = (int)bb.minZ; z <= bb.maxZ; z++) { for(int y = (int)bb.minY; y<= bb.maxY; y++) { BlockPos pos = new BlockPos(x, y, z); //Workaround for dupe TileEntity tile = worldObj.getTileEntity(pos); if(tile instanceof IInventory) { IInventory inv = (IInventory) tile; for(int i = 0; i < inv.getSizeInventory(); i++) { inv.setInventorySlotContents(i, ItemStack.EMPTY); } } worldObj.setBlockState(pos, Blocks.AIR.getDefaultState(),2); } } } //Carpenter's block's dupe for(Object entity : worldObj.getEntitiesWithinAABB(EntityItem.class, bb.grow(5, 5, 5)) ) { ((Entity)entity).setDead(); } return chunk; }
Example 4
Source File: CartTools.java From NEI-Integration with MIT License | 5 votes |
public static List<EntityMinecart> getMinecartsIn(World world, int i1, int j1, int k1, int i2, int j2, int k2) { List entities = world.getEntitiesWithinAABB(EntityMinecart.class, AxisAlignedBB.getBoundingBox(i1, j1, k1, i2, j2, k2)); List<EntityMinecart> carts = new ArrayList<EntityMinecart>(); for (Object o : entities) { EntityMinecart cart = (EntityMinecart) o; if (!cart.isDead) carts.add((EntityMinecart) o); } return carts; }
Example 5
Source File: RegisteredFamiliarAI_Old.java From Gadomancy with GNU Lesser General Public License v3.0 | 5 votes |
private List<EntityLivingBase> getCloseEnoughTargetters(World world, EntityPlayer parent, int rangeInc) { LinkedList<EntityLivingBase> lastTargetters = FamiliarAIController_Old.getLastTargetters(parent); if(lastTargetters == null || lastTargetters.isEmpty()) return new ArrayList<EntityLivingBase>(); List<EntityLivingBase> closeEnoughLastTargetters = new ArrayList<EntityLivingBase>(); int range = 8 + rangeInc; List livingAround = world.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(parent.posX - 0.5, parent.posY - 0.5, parent.posZ - 0.5, parent.posX + 0.5, parent.posY + 0.5, parent.posZ + 0.5).expand(range, range, range)); for(Object living : livingAround) { if(!(living instanceof EntityLivingBase)) continue; if(lastTargetters.contains(living)) closeEnoughLastTargetters.add((EntityLivingBase) living); } return closeEnoughLastTargetters; }
Example 6
Source File: CartTools.java From NEI-Integration with MIT License | 5 votes |
/** * @param world * @param i * @param j * @param k * @param sensitivity Controls the size of the search box, ranges from * (-inf, 0.49]. * @return */ public static List<EntityMinecart> getMinecartsAt(World world, int i, int j, int k, float sensitivity) { sensitivity = Math.min(sensitivity, 0.49f); List entities = world.getEntitiesWithinAABB(EntityMinecart.class, AxisAlignedBB.getBoundingBox(i + sensitivity, j + sensitivity, k + sensitivity, i + 1 - sensitivity, j + 1 - sensitivity, k + 1 - sensitivity)); List<EntityMinecart> carts = new ArrayList<EntityMinecart>(); for (Object o : entities) { EntityMinecart cart = (EntityMinecart) o; if (!cart.isDead) carts.add((EntityMinecart) o); } return carts; }
Example 7
Source File: TileLandingPad.java From AdvancedRocketry with MIT License | 5 votes |
public void registerTileWithStation(World world, BlockPos pos) { if(!world.isRemote && world.provider.getDimension() == Configuration.spaceDimId) { ISpaceObject spaceObj = SpaceObjectManager.getSpaceManager().getSpaceStationFromBlockCoords(pos); if(spaceObj instanceof SpaceObject) { ((SpaceObject)spaceObj).addLandingPad(pos, name); AxisAlignedBB bbCache = new AxisAlignedBB(this.getPos().add(-1,0,-1), this.getPos().add(1,2,1)); List<EntityRocketBase> rockets = world.getEntitiesWithinAABB(EntityRocketBase.class, bbCache); if(rockets != null && !rockets.isEmpty()) ((SpaceObject)spaceObj).setPadStatus(pos, true); } } }
Example 8
Source File: BlockSeat.java From AdvancedRocketry with MIT License | 5 votes |
@Override public void onBlockDestroyedByExplosion(World world, BlockPos pos, Explosion explosionIn) { // TODO Auto-generated method stub super.onBlockDestroyedByExplosion(world, pos, explosionIn); List<EntityDummy> list = world.getEntitiesWithinAABB(EntityDummy.class, new AxisAlignedBB(pos, pos.add(1,1,1))); //We only expect one but just be sure for(EntityDummy e : list) { if(e instanceof EntityDummy) { e.setDead(); } } }
Example 9
Source File: BlockArtifactsPressurePlate.java From Artifacts with MIT License | 5 votes |
@Override //getPlateState protected int func_150065_e(World world, int x, int y, int z) { List list = null; if (this.triggerMobType == BlockPressurePlate.Sensitivity.everything) { list = world.getEntitiesWithinAABBExcludingEntity((Entity)null, this.func_150061_a/*getSensitiveAABB*/(x, y, z)); } if (this.triggerMobType == BlockPressurePlate.Sensitivity.mobs) { list = world.getEntitiesWithinAABB(EntityLivingBase.class, this.func_150061_a(x, y, z)); } if (this.triggerMobType == BlockPressurePlate.Sensitivity.players) { list = world.getEntitiesWithinAABB(EntityPlayer.class, this.func_150061_a(x, y, z)); } if (!list.isEmpty()) { Iterator iterator = list.iterator(); while (iterator.hasNext()) { Entity entity = (Entity)iterator.next(); if (!entity.doesEntityNotTriggerPressurePlate()) { return 15; } } } return 0; }
Example 10
Source File: BlockButton.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
private void checkPressed(IBlockState state, World worldIn, BlockPos pos) { List<? extends Entity> list = worldIn.<Entity>getEntitiesWithinAABB(EntityArrow.class, state.getBoundingBox(worldIn, pos).offset(pos)); boolean flag = !list.isEmpty(); boolean flag1 = state.getValue(POWERED); if (flag && !flag1) { worldIn.setBlockState(pos, state.withProperty(POWERED, true)); this.notifyNeighbors(worldIn, pos, state.getValue(FACING)); worldIn.markBlockRangeForRenderUpdate(pos, pos); this.playClickSound(null, worldIn, pos); } if (!flag && flag1) { worldIn.setBlockState(pos, state.withProperty(POWERED, false)); this.notifyNeighbors(worldIn, pos, state.getValue(FACING)); worldIn.markBlockRangeForRenderUpdate(pos, pos); this.playReleaseSound(worldIn, pos); } if (flag) { worldIn.scheduleUpdate(new BlockPos(pos), this, this.tickRate(worldIn)); } }
Example 11
Source File: GTItemElectromagnet.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int slot, boolean selected) { NBTTagCompound nbt = StackUtil.getNbtData((stack)); if (worldIn.getTotalWorldTime() % 2 == 0) { if (!(entityIn instanceof EntityPlayer) || !nbt.getBoolean(ACTIVE)) { this.setDamage(stack, 0); return; } double x = entityIn.posX; double y = entityIn.posY + 1.5; double z = entityIn.posZ; int pulled = 0; for (EntityItem item : worldIn.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(x, y, z, x + 1, y + 1, z + 1).grow(range))) { if (item.getEntityData().getBoolean("PreventRemoteMovement")) { continue; } if (!canPull(stack) || pulled > 200) { break; } item.addVelocity((x - item.posX) * speed, (y - item.posY) * speed, (z - item.posZ) * speed); ElectricItem.manager.use(stack, energyCost, (EntityLivingBase) entityIn); pulled++; } this.setDamage(stack, pulled > 0 ? 1 : 0); } }
Example 12
Source File: BlockHumanDetector.java From BaseMetals with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected int computeRedstoneStrength(World w, BlockPos pos){ AxisAlignedBB axisalignedbb = PRESSURE_AABB.offset(pos); List<? extends Entity > list = w.<Entity>getEntitiesWithinAABB(EntityPlayer.class, axisalignedbb); if (!list.isEmpty()) { return 15; } return 0; }
Example 13
Source File: BlockWallPlate.java From Artifacts with MIT License | 5 votes |
@Override //getPlateState protected int func_150065_e(World world, int x, int y, int z) { List list = null; int meta = world.getBlockMetadata(x, y, z); if (this.triggerMobType == BlockPressurePlate.Sensitivity.everything) { list = world.getEntitiesWithinAABBExcludingEntity((Entity)null, this.getMetaSensitiveAABB(x, y, z, meta)); } if (this.triggerMobType == BlockPressurePlate.Sensitivity.mobs) { list = world.getEntitiesWithinAABB(EntityLivingBase.class, this.getMetaSensitiveAABB(x, y, z, meta)); } if (this.triggerMobType == BlockPressurePlate.Sensitivity.players) { list = world.getEntitiesWithinAABB(EntityPlayer.class, this.getMetaSensitiveAABB(x, y, z, meta)); } if (!list.isEmpty()) { Iterator iterator = list.iterator(); while (iterator.hasNext()) { Entity entity = (Entity)iterator.next(); if (!entity.doesEntityNotTriggerPressurePlate()) { return 15; } } } return 0; }
Example 14
Source File: BiomeTorikkiSea.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
private int getEntityCount(Class<? extends Entity> entity, BlockPos pos, World world, int range) { List<Entity> entities = world.getEntitiesWithinAABB(entity, new AxisAlignedBB(pos).grow(range)); return entities.size(); }
Example 15
Source File: BiomeTorikki.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
private int getEntityCount(Class<? extends Entity> entity, BlockPos pos, World world, int range) { List<Entity> entities = world.getEntitiesWithinAABB(entity, new AxisAlignedBB(pos).grow(range)); return entities.size(); }
Example 16
Source File: BiomeUnderWorld.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
private int getEntityCount(Class<? extends Entity> entity, BlockPos pos, World world, int range) { List<Entity> entities = world.getEntitiesWithinAABB(entity, new AxisAlignedBB(pos).grow(range)); return entities.size(); }
Example 17
Source File: WandHandler.java From Gadomancy with GNU Lesser General Public License v3.0 | 4 votes |
private static void tryAuraCoreCreation(ItemStack i, EntityPlayer entityPlayer, World world, int x, int y, int z) { if(world.isRemote) return; List items = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1) .expand(EntityAuraCore.CLUSTER_RANGE, EntityAuraCore.CLUSTER_RANGE, EntityAuraCore.CLUSTER_RANGE)); Iterator it = items.iterator(); EntityItem itemAuraCore = null; while(itemAuraCore == null && it.hasNext()) { Object item = it.next(); if(item != null && item instanceof EntityItem && !((EntityItem) item).isDead) { EntityItem entityItem = (EntityItem) item; if(entityItem.getEntityItem() != null && entityItem.getEntityItem().getItem() != null && entityItem.getEntityItem().getItem() instanceof ItemAuraCore && !(item instanceof EntityAuraCore)) { if(((ItemAuraCore) entityItem.getEntityItem().getItem()).isBlank(entityItem.getEntityItem())) itemAuraCore = entityItem; } } } if(itemAuraCore == null) return; int meta = world.getBlockMetadata(x, y, z); if(meta <= 6) { Aspect[] aspects; switch (meta) { case 0: aspects = new Aspect[]{Aspect.AIR}; break; case 1: aspects = new Aspect[]{Aspect.FIRE}; break; case 2: aspects = new Aspect[]{Aspect.WATER}; break; case 3: aspects = new Aspect[]{Aspect.EARTH}; break; case 4: aspects = new Aspect[]{Aspect.ORDER}; break; case 5: aspects = new Aspect[]{Aspect.ENTROPY}; break; case 6: aspects = new Aspect[]{Aspect.AIR, Aspect.FIRE, Aspect.EARTH, Aspect.WATER, Aspect.ORDER, Aspect.ENTROPY}; break; default: return; } if(!ThaumcraftApiHelper.consumeVisFromWandCrafting(i, entityPlayer, (AspectList)RegisteredRecipes.auraCoreRecipes[meta].get(0), true)) return; PacketStartAnimation packet = new PacketStartAnimation(PacketStartAnimation.ID_BURST, x, y, z); PacketHandler.INSTANCE.sendToAllAround(packet, new NetworkRegistry.TargetPoint(world.provider.dimensionId, x, y, z, 32.0D)); world.createExplosion(null, x + 0.5D, y + 0.5D, z + 0.5D, 1.5F, false); world.setBlockToAir(x, y, z); EntityAuraCore ea = new EntityAuraCore(itemAuraCore.worldObj, itemAuraCore.posX, itemAuraCore.posY, itemAuraCore.posZ, itemAuraCore.getEntityItem(), new ChunkCoordinates(x, y, z), aspects); ea.age = itemAuraCore.age; ea.hoverStart = itemAuraCore.hoverStart; ea.motionX = itemAuraCore.motionX; ea.motionY = itemAuraCore.motionY; ea.motionZ = itemAuraCore.motionZ; itemAuraCore.worldObj.spawnEntityInWorld(ea); itemAuraCore.setDead(); } }
Example 18
Source File: ItemMetalCrackHammer.java From BaseMetals with GNU Lesser General Public License v2.1 | 4 votes |
@Override public EnumActionResult onItemUse(final ItemStack item, final EntityPlayer player, final World w, final BlockPos coord, EnumHand hand, final EnumFacing facing, final float partialX, final float partialY, final float partialZ) { if(facing != EnumFacing.UP) return EnumActionResult.PASS; List<EntityItem> entities = w.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB( coord.getX(),coord.getY()+1,coord.getZ(), coord.getX()+1,coord.getY()+2,coord.getZ()+1)); boolean success = false; for(EntityItem target : entities){ ItemStack targetItem = ((net.minecraft.entity.item.EntityItem)target).getEntityItem(); if(targetItem != null ){ ICrusherRecipe recipe = CrusherRecipeRegistry.getInstance().getRecipeForInputItem(targetItem); if(recipe != null){ // hardness check if(BaseMetals.enforceHardness){ if(targetItem.getItem() instanceof ItemBlock){ Block b = ((ItemBlock)targetItem.getItem()).getBlock(); if(!this.canHarvestBlock(b.getStateFromMeta(targetItem.getMetadata()))){ // cannot harvest the block, no crush for you! return EnumActionResult.PASS; } } } // crush the item (server side only) if(!w.isRemote) { ItemStack output = recipe.getOutput().copy(); int count = output.stackSize; output.stackSize = 1; double x = target.posX; double y = target.posY; double z = target.posZ; targetItem.stackSize--; if (targetItem.stackSize <= 0) { w.removeEntity(target); } for (int i = 0; i < count; i++) { w.spawnEntityInWorld(new EntityItem(w, x, y, z, output.copy())); } item.damageItem(1, player); } success = true; break; } } } if(success){ w.playSound(player, coord, SoundEvents.BLOCK_GRAVEL_BREAK, SoundCategory.BLOCKS, 0.5F, 0.5F + (itemRand.nextFloat() * 0.3F)); } return success ? EnumActionResult.SUCCESS : EnumActionResult.PASS; }
Example 19
Source File: SpawnUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 4 votes |
public static boolean containsLiving(World world, Point3i blockCoord) { AxisAlignedBB bb = new AxisAlignedBB(blockCoord.x, blockCoord.y, blockCoord.z, blockCoord.x + 1, blockCoord.y + 1, blockCoord.z + 1); List<?> ents = world.getEntitiesWithinAABB(EntityLivingBase.class, bb); return ents != null && !ents.isEmpty(); }
Example 20
Source File: ItemKotachi.java From Sakura_mod with MIT License | 4 votes |
@Override public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.SWEEPING, stack); if (k > 0) { //big sweep!!! entityLiving.swingArm(entityLiving.getActiveHand()); float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.5F; float f3 = EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f; float sweepingRatio = EnchantmentHelper.getSweepingDamageRatio(entityLiving); for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.4D + sweepingRatio * 1.2D, 0.3D + sweepingRatio * 0.15D, 1.4D + sweepingRatio * 1.2D))) { if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) { if (entitylivingbase instanceof EntityLivingBase) { if (entitylivingbase instanceof EntityPlayer && ((EntityPlayer) entitylivingbase).isActiveItemStackBlocking()) { //disable shield ((EntityPlayer) entitylivingbase).disableShield(false); } ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.1F * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F))); entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } if (entitylivingbase instanceof MultiPartEntityPart) { entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } } } worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F); if (worldIn instanceof WorldServer) { double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F)); double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F); ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D); } stack.damageItem(2, entityLiving); ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 16); } }