net.minecraft.util.EntitySelectors Java Examples
The following examples show how to use
net.minecraft.util.EntitySelectors.
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: RecipeLogicSteam.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
protected void tryDoVenting() { BlockPos machinePos = metaTileEntity.getPos(); EnumFacing ventingSide = getVentingSide(); BlockPos ventingBlockPos = machinePos.offset(ventingSide); IBlockState blockOnPos = metaTileEntity.getWorld().getBlockState(ventingBlockPos); if (blockOnPos.getCollisionBoundingBox(metaTileEntity.getWorld(), ventingBlockPos) == Block.NULL_AABB) { metaTileEntity.getWorld() .getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(ventingBlockPos), EntitySelectors.CAN_AI_TARGET) .forEach(entity -> entity.attackEntityFrom(DamageSources.getHeatDamage(), 6.0f)); WorldServer world = (WorldServer) metaTileEntity.getWorld(); double posX = machinePos.getX() + 0.5 + ventingSide.getFrontOffsetX() * 0.6; double posY = machinePos.getY() + 0.5 + ventingSide.getFrontOffsetY() * 0.6; double posZ = machinePos.getZ() + 0.5 + ventingSide.getFrontOffsetZ() * 0.6; world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, posX, posY, posZ, 7 + world.rand.nextInt(3), ventingSide.getFrontOffsetX() / 2.0, ventingSide.getFrontOffsetY() / 2.0, ventingSide.getFrontOffsetZ() / 2.0, 0.1); world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f); setNeedsVenting(false); } else if (!ventingStuck) { setVentingStuck(true); } }
Example #2
Source File: EntityAINearestAttackableCivTarget.java From ToroQuest with GNU General Public License v3.0 | 6 votes |
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); } }; }
Example #3
Source File: EntityRainbowGuard.java From ToroQuest with GNU General Public License v3.0 | 6 votes |
protected void wakeIfPlayerIsClose(boolean wakePartner) { if (world.getTotalWorldTime() % 30 != 0 || !isAtAttention()) { return; } // TODO check if visible? List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(getPosition()).expand(WAKE_DIAMETER, 6, WAKE_DIAMETER), EntitySelectors.CAN_AI_TARGET); if (players.size() < 1) { return; } if (wakePartner) { List<EntityRainbowGuard> nearbyRainbowGuards = world.getEntitiesWithinAABB(EntityRainbowGuard.class, getEntityBoundingBox().expand(5.0D, 4.0D, 2.0D)); if (nearbyRainbowGuards != null && !nearbyRainbowGuards.isEmpty()) { nearbyRainbowGuards.get(0).wokenByPartner(); } } setAtAttention(false); tasks.removeTask(new EntityAIStayCentered(this)); setAttackTarget(players.get(world.rand.nextInt(players.size()))); }
Example #4
Source File: EntityAINearestAttackableTargetBounded.java From EnderZoo with Creative Commons Zero v1.0 Universal | 6 votes |
@Override public boolean shouldExecute() { if (targetChance > 0 && taskOwner.getRNG().nextInt(targetChance) != 0) { return false; } else { double horizDist = getTargetDistance(); double vertDist = getVerticalDistance(); AxisAlignedBB bb = taskOwner.getEntityBoundingBox().expand(horizDist, vertDist, horizDist); List<T> list = taskOwner.getEntityWorld().<T> getEntitiesWithinAABB(targetClass, bb, Predicates.<T> and(targetEntitySelector, EntitySelectors.NOT_SPECTATING)); Collections.sort(list, sorter); if (list.isEmpty()) { return false; } else { this.targetEntity = list.get(0); return true; } } }
Example #5
Source File: MetaTileEntityMagicEnergyAbsorber.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private void updateConnectedCrystals() { this.connectedCrystalsIds.clear(); final double maxDistance = 64 * 64; List<EntityEnderCrystal> enderCrystals = Arrays.stream(BiomeEndDecorator.getSpikesForWorld(getWorld())) .flatMap(endSpike -> getWorld().getEntitiesWithinAABB(EntityEnderCrystal.class, endSpike.getTopBoundingBox()).stream()) .filter(crystal -> crystal.getDistanceSq(getPos()) < maxDistance) .collect(Collectors.toList()); for (EntityEnderCrystal entityEnderCrystal : enderCrystals) { BlockPos beamTarget = entityEnderCrystal.getBeamTarget(); if (beamTarget == null) { //if beam target is null, set ourselves as beam target entityEnderCrystal.setBeamTarget(getPos()); this.connectedCrystalsIds.add(entityEnderCrystal.getEntityId()); } else if (beamTarget.equals(getPos())) { //if beam target is ourselves, just add it to list this.connectedCrystalsIds.add(entityEnderCrystal.getEntityId()); } } for (EntityDragon entityDragon : getWorld().getEntities(EntityDragon.class, EntitySelectors.IS_ALIVE)) { if (entityDragon.healingEnderCrystal != null && connectedCrystalsIds.contains(entityDragon.healingEnderCrystal.getEntityId())) { //if dragon is healing from crystal we draw energy from, reset it's healing crystal entityDragon.healingEnderCrystal = null; //if dragon is holding pattern, than deal damage and set it's phase to attack ourselves if (entityDragon.getPhaseManager().getCurrentPhase().getType() == PhaseList.HOLDING_PATTERN) { entityDragon.attackEntityFrom(DamageSource.causeExplosionDamage((EntityLivingBase) null), 10.0f); entityDragon.getPhaseManager().setPhase(PhaseList.CHARGING_PLAYER); ((PhaseChargingPlayer) entityDragon.getPhaseManager().getCurrentPhase()).setTarget(new Vec3d(getPos())); } } } }
Example #6
Source File: RayTraceTools.java From YouTubeModdingTutorial with MIT License | 5 votes |
public static void rayTrace(Beam beam, Function<Entity, Boolean> consumer) { // Based on EntityRender.getMouseOver(float partialTicks) which we can't use because that's client only Vec3d start = beam.getStart(); Vec3d lookVec = beam.getLookVec(); Vec3d end = beam.getEnd(); double dist = beam.getDist(); World world = beam.getWorld(); EntityPlayer player = beam.getPlayer(); List<Entity> targets = world.getEntitiesInAABBexcluding(player, player.getEntityBoundingBox().expand(lookVec.x * dist, lookVec.y * dist, lookVec.z * dist).grow(1.0D, 1.0D, 1.0D), Predicates.and(EntitySelectors.NOT_SPECTATING, ent -> ent != null && ent.canBeCollidedWith())); List<Pair<Entity, Double>> hitTargets = new ArrayList<>(); for (Entity target : targets) { AxisAlignedBB targetBB = target.getEntityBoundingBox().grow(target.getCollisionBorderSize()); if (targetBB.contains(start)) { hitTargets.add(Pair.of(target, 0.0)); } else { RayTraceResult targetResult = targetBB.calculateIntercept(start, end); if (targetResult != null) { double d3 = start.distanceTo(targetResult.hitVec); if (d3 < dist) { hitTargets.add(Pair.of(target, d3)); } } } } hitTargets.sort(Comparator.comparing(Pair::getRight)); hitTargets.stream().filter(pair -> consumer.apply(pair.getLeft())).findFirst(); }
Example #7
Source File: EntityAINearestAttackableTargetFiltered.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
public EntityAINearestAttackableTargetFiltered(EntityCreature creature, Class<T> classTarget, int chance, boolean checkSight, boolean onlyNearby, @Nullable final Predicate<? super T> targetSelector) { super(creature, checkSight, onlyNearby); this.targetClass = classTarget; this.targetChance = chance; this.sorter = new EntityAINearestAttackableTarget.Sorter(creature); this.setMutexBits(1); UUID exclude = creature.getEntityData().getUniqueId("owner"); this.targetEntitySelector = (Predicate<T>) entity -> (entity != null && !entity.getUniqueID().equals(exclude)) && (targetSelector == null || targetSelector.apply(entity) && (EntitySelectors.NOT_SPECTATING.apply(entity) && EntityAINearestAttackableTargetFiltered.this.isSuitableTarget(entity, false))); }
Example #8
Source File: EntityEndermanFighter.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable protected EntityPlayer getClosestVulnerablePlayer(double x, double y, double z, double distance) { double closest = -1.0d; EntityPlayer player = null; List<EntityPlayer> players = this.getEntityWorld().getPlayers(EntityPlayer.class, EntitySelectors.NOT_SPECTATING); for (EntityPlayer playerTmp : players) { if (playerTmp.capabilities.disableDamage == false && playerTmp.isEntityAlive() && this.isPlayerHoldingSummonItem(playerTmp) == false) { double distTmp = playerTmp.getDistanceSq(x, y, z); double distSight =playerTmp.isSneaking() ? distance * 0.8d : distance; if (playerTmp.isInvisible()) { float f = playerTmp.getArmorVisibility(); if (f < 0.1f) { f = 0.1f; } distSight *= (0.7d * f); } if ((distance < 0.0d || distTmp < (distSight * distSight)) && (closest == -1.0d || distTmp < closest)) { closest = distTmp; player = playerTmp; } } } return player; }
Example #9
Source File: LocalPlayerUtils.java From ForgeHax with MIT License | 4 votes |
public static RayTraceResult getViewTrace( Entity entity, Vec3d direction, float partialTicks, double reach, double reachAttack) { if (entity == null) { return null; } Vec3d eyes = entity.getPositionEyes(partialTicks); RayTraceResult trace = entity.rayTrace(reach, partialTicks); Vec3d dir = direction.scale(reach); Vec3d lookDir = eyes.add(dir); double hitDistance = trace == null ? reachAttack : trace.hitVec.distanceTo(eyes); Entity hitEntity = null; Vec3d hitEntityVec = null; for (Entity ent : getWorld() .getEntitiesInAABBexcluding( entity, entity.getEntityBoundingBox().expand(dir.x, dir.y, dir.y).grow(1.D), Predicates.and( EntitySelectors.NOT_SPECTATING, ent -> ent != null && ent.canBeCollidedWith()))) { AxisAlignedBB bb = ent.getEntityBoundingBox().grow(ent.getCollisionBorderSize()); RayTraceResult tr = bb.calculateIntercept(eyes, lookDir); if (bb.contains(eyes)) { if (hitDistance > 0.D) { hitEntity = ent; hitEntityVec = tr == null ? eyes : tr.hitVec; hitDistance = 0.D; } } else if (tr != null) { double dist = eyes.distanceTo(tr.hitVec); if (dist < hitDistance || hitDistance == 0.D) { if (entity.getLowestRidingEntity() == ent.getLowestRidingEntity() && !ent.canRiderInteract()) { if (hitDistance == 0.D) { hitEntity = ent; hitEntityVec = tr.hitVec; } } else { hitEntity = ent; hitEntityVec = tr.hitVec; hitDistance = dist; } } } } if (hitEntity != null && reach > 3.D && eyes.distanceTo(hitEntityVec) > 3.D) { return new RayTraceResult(Type.MISS, hitEntityVec, EnumFacing.UP, new BlockPos(hitEntityVec)); } else if (hitEntity != null && trace == null && hitDistance < reachAttack) { return new RayTraceResult(hitEntity, hitEntityVec); } else { return trace; } }
Example #10
Source File: ChunkLoadHandler.java From TFC2 with GNU General Public License v3.0 | 4 votes |
@SubscribeEvent public void onChunkUnload(ChunkEvent.Unload event) { if(!event.getWorld().isRemote && event.getWorld().provider.getDimension() == 0) { BlockPos chunkWorldPos = new BlockPos(event.getChunk().xPosition * 16, 0, event.getChunk().zPosition * 16); IslandMap map = Core.getMapForWorld(event.getWorld(), chunkWorldPos); Point islandPos = new Point(chunkWorldPos.getX(), chunkWorldPos.getZ()).toIslandCoord(); AxisAlignedBB chunkAABB = new AxisAlignedBB(islandPos.getX(), 0, islandPos.getZ(), islandPos.getX()+16, 1, islandPos.getZ()+16); Center temp = map.getClosestCenter(islandPos); ArrayList<Center> genList = new ArrayList<Center>(); genList.add(temp); genList.addAll(temp.neighbors); if(loadedCentersMap.containsKey(map.getParams().getCantorizedID())) { ArrayList<Center> loaded = loadedCentersMap.get(map.getParams().getCantorizedID()); for(Center c : genList) { AxisAlignedBB aabb = c.getAABB(); boolean intersect =aabb.intersectsWith(chunkAABB); if(intersect && loaded.contains(c) ) { loaded.remove(c); ArrayList<Herd> herdsToUnload = map.getIslandData().wildlifeManager.getHerdsInCenter(c); for(Herd h : herdsToUnload) { h.setUnloaded(); for(VirtualAnimal animal : h.getVirtualAnimals()) { if(animal.getEntity() == null) { animal.setUnloaded(); continue; } Predicate<Entity> predicate = Predicates.<Entity>and(EntitySelectors.NOT_SPECTATING, EntitySelectors.notRiding(animal.getEntity())); Entity closestEntity = animal.getEntity().world.getClosestPlayer(animal.getEntity().posX, animal.getEntity().posY, animal.getEntity().posZ, 100D, predicate); if(closestEntity == null) { animal.getEntity().setDead(); animal.setUnloaded(); } } } } } } } }