net.minecraft.command.IEntitySelector Java Examples

The following examples show how to use net.minecraft.command.IEntitySelector. 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: ProgWidgetAreaItemBase.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public static List<Entity> getEntitiesInArea(ProgWidgetArea whitelistWidget, ProgWidgetArea blacklistWidget, World world, IEntitySelector whitelistFilter, IEntitySelector blacklistFilter){
    if(whitelistWidget == null) return new ArrayList<Entity>();
    Set<Entity> entities = new HashSet<Entity>();
    ProgWidgetArea widget = whitelistWidget;
    while(widget != null) {
        entities.addAll(widget.getEntitiesWithinArea(world, whitelistFilter));
        widget = (ProgWidgetArea)widget.getConnectedParameters()[0];
    }
    widget = blacklistWidget;
    while(widget != null) {
        entities.removeAll(widget.getEntitiesWithinArea(world, whitelistFilter));
        widget = (ProgWidgetArea)widget.getConnectedParameters()[0];
    }
    if(blacklistFilter != null) {
        Entity[] entArray = entities.toArray(new Entity[entities.size()]);
        for(Entity entity : entArray) {
            if(blacklistFilter.isEntityApplicable(entity)) {
                entities.remove(entity);
            }
        }
    }
    return new ArrayList<Entity>(entities);
}
 
Example #2
Source File: EntityEndermite.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void onLivingUpdate() {
	super.onLivingUpdate();

	if (worldObj.isRemote)
		for (int i = 0; i < 2; i++)
			worldObj.spawnParticle("portal", posX + (rand.nextDouble() - 0.5D) * width, posY + rand.nextDouble() * height, posZ + (rand.nextDouble() - 0.5D) * width, (rand.nextDouble() - 0.5D) * 2.0D, -rand.nextDouble(), (rand.nextDouble() - 0.5D) * 2.0D);
	else {
		if (!isNoDespawnRequired())
			lifetime++;

		if (lifetime >= 2400)
			setDead();
	}

	if (isSpawnedByPlayer()) {
		double range = 64;
		double radius = range / 2.0;
		int tagetChance = 10;
		if (rand.nextInt(tagetChance) != 0) {
			List<EntityEnderman> list = worldObj.getEntitiesWithinAABBExcludingEntity(this, AxisAlignedBB.getBoundingBox(posX - radius, posY - 4, posZ - radius, posX + radius, posY + 4, posZ + radius), new IEntitySelector() {
				@Override
				public boolean isEntityApplicable(Entity entity) {
					return entity instanceof EntityEnderman;
				}
			});
			Collections.sort(list, sorter);
			if (!list.isEmpty()) {
				EntityEnderman enderman = list.get(0);
				enderman.setTarget(this);
			}
		}
	}
}
 
Example #3
Source File: DroneEntityAIPickupItems.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns whether the EntityAIBase should begin execution.
 */
@Override
public boolean shouldExecute(){
    List<Entity> pickableItems = itemPickupWidget.getEntitiesInArea(drone.getWorld(), new IEntitySelector(){
        @Override
        public boolean isEntityApplicable(Entity entity){
            return entity instanceof EntityItem && entity.isEntityAlive();
        }
    });

    Collections.sort(pickableItems, theNearestAttackableTargetSorter);
    for(Entity ent : pickableItems) {
        ItemStack stack = ((EntityItem)ent).getEntityItem();
        if(itemPickupWidget.isItemValidForFilters(stack)) {
            for(int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
                ItemStack droneStack = drone.getInventory().getStackInSlot(i);
                if(droneStack == null || droneStack.isItemEqual(stack) && droneStack.stackSize < droneStack.getMaxStackSize()) {
                    if(drone.getPathNavigator().moveToEntity(ent)) {
                        curPickingUpEntity = (EntityItem)ent;
                        return true;
                    }
                }
            }
        } else {
            drone.addDebugEntry("gui.progWidget.itemPickup.debug.itemNotValid");
        }
    }
    return false; // 

}
 
Example #4
Source File: TileKnowledgeBook.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void tryVortexUnfinishedResearchNotes() {
    float centerY = yCoord + 0.4F;
    List entityItems = worldObj.selectEntitiesWithinAABB(EntityItem.class,
            AxisAlignedBB.getBoundingBox(xCoord - 0.5, centerY - 0.5, zCoord - 0.5, xCoord + 0.5, centerY + 0.5, zCoord + 0.5).expand(8, 8, 8), new IEntitySelector() {
                @Override
                public boolean isEntityApplicable(Entity e) {
                    return !(e instanceof EntityPermanentItem) && !(e instanceof EntitySpecialItem) &&
                            e instanceof EntityItem && ((EntityItem) e).getEntityItem() != null &&
                            ((EntityItem) e).getEntityItem().getItem() instanceof ItemResearchNotes &&
                            shouldVortexResearchNote(((EntityItem) e).getEntityItem());
                }
            });

    Entity dummy = new EntityItem(worldObj);
    dummy.posX = xCoord + 0.5;
    dummy.posY = centerY + 0.5;
    dummy.posZ = zCoord + 0.5;

    //MC code.
    EntityItem entity = null;
    double d0 = Double.MAX_VALUE;
    for (Object entityItem : entityItems) {
        EntityItem entityIt = (EntityItem) entityItem;
        if (entityIt != dummy) {
            double d1 = dummy.getDistanceSqToEntity(entityIt);
            if (d1 <= d0) {
                entity = entityIt;
                d0 = d1;
            }
        }
    }
    if(entity == null) return;
    if(dummy.getDistanceToEntity(entity) < 1 && !worldObj.isRemote) {
        ItemStack inter = entity.getEntityItem();
        inter.stackSize--;
        this.storedResearchNote = inter.copy();
        this.storedResearchNote.stackSize = 1;

        EntityPermNoClipItem item = new EntityPermNoClipItem(entity.worldObj, xCoord + 0.5F, centerY + 0.3F, zCoord + 0.5F, storedResearchNote, xCoord, yCoord, zCoord);
        entity.worldObj.spawnEntityInWorld(item);
        item.motionX = 0;
        item.motionY = 0;
        item.motionZ = 0;
        item.hoverStart = entity.hoverStart;
        item.age = entity.age;
        item.noClip = true;

        timeSinceLastItemInfo = 0;

        if(inter.stackSize <= 0) entity.setDead();
        entity.noClip = false;
        item.delayBeforeCanPickup = 60;
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
        markDirty();
    } else {
        entity.noClip = true;
        applyMovementVectors(entity);
    }
}
 
Example #5
Source File: TileAuraPylon.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void tryVortexPossibleItems() {
    TileAuraPylon io = getInputTile();
    if (io == null) return;

    int masterY = yCoord + 1;
    float dst = ((float) (masterY - io.yCoord)) / 2F;
    float yC = masterY - dst;
    List entityItems = worldObj.selectEntitiesWithinAABB(EntityItem.class,
            AxisAlignedBB.getBoundingBox(xCoord - 0.5, yC - 0.5, zCoord - 0.5, xCoord + 0.5, yC + 0.5, zCoord + 0.5).expand(8, 8, 8), new IEntitySelector() {
                @Override
                public boolean isEntityApplicable(Entity e) {
                    return !(e instanceof EntityPermanentItem) && !(e instanceof EntitySpecialItem) &&
                            e instanceof EntityItem && ((EntityItem) e).getEntityItem() != null &&
                            ((EntityItem) e).getEntityItem().getItem() instanceof ItemCrystalEssence &&
                            ((ItemCrystalEssence) ((EntityItem) e).getEntityItem().getItem()).getAspects(((EntityItem) e).getEntityItem()) != null;
                }
            });
    Entity dummy = new EntityItem(worldObj);
    dummy.posX = xCoord + 0.5;
    dummy.posY = yC + 0.5;
    dummy.posZ = zCoord + 0.5;

    //MC code.
    EntityItem entity = null;
    double d0 = Double.MAX_VALUE;
    for (Object entityItem : entityItems) {
        EntityItem entityIt = (EntityItem) entityItem;
        if (entityIt != dummy) {
            double d1 = dummy.getDistanceSqToEntity(entityIt);
            if (d1 <= d0) {
                entity = entityIt;
                d0 = d1;
            }
        }
    }
    if(entity == null) return;
    if(dummy.getDistanceToEntity(entity) < 1 && !worldObj.isRemote) {
        ItemStack inter = entity.getEntityItem();
        inter.stackSize--;
        this.crystalEssentiaStack = inter.copy();
        this.crystalEssentiaStack.stackSize = 1;

        EntityPermNoClipItem item = new EntityPermNoClipItem(entity.worldObj, xCoord + 0.5F, yC + 0.3F, zCoord + 0.5F, crystalEssentiaStack, xCoord, yCoord, zCoord);
        entity.worldObj.spawnEntityInWorld(item);
        item.motionX = 0;
        item.motionY = 0;
        item.motionZ = 0;
        item.hoverStart = entity.hoverStart;
        item.age = entity.age;
        item.noClip = true;

        timeSinceLastItemInfo = 0;

        holdingAspect = ((ItemCrystalEssence) crystalEssentiaStack.getItem()).getAspects(crystalEssentiaStack).getAspects()[0];
        distributeAspectInformation();

        if(inter.stackSize <= 0) entity.setDead();
        entity.noClip = false;
        item.delayBeforeCanPickup = 60;
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
        markDirty();
    } else {
        entity.noClip = true;
        applyMovementVectors(entity);
    }
}
 
Example #6
Source File: ProgWidgetCC.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public synchronized List<Entity> getEntitiesInArea(World world, IEntitySelector filter){
    return ProgWidgetAreaItemBase.getEntitiesInArea(getEntityAreaWidget(), null, world, filter, null);
}
 
Example #7
Source File: ProgWidgetArea.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public List<Entity> getEntitiesWithinArea(World world, IEntitySelector filter){
    AxisAlignedBB aabb = getAABB();
    return aabb != null ? world.getEntitiesWithinAABBExcludingEntity(null, aabb, filter) : new ArrayList<Entity>();
}
 
Example #8
Source File: ProgWidgetAreaItemBase.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public List<Entity> getEntitiesInArea(World world, IEntitySelector filter){
    return getEntitiesInArea((ProgWidgetArea)getConnectedParameters()[0], (ProgWidgetArea)getConnectedParameters()[getParameters().length], world, filter, null);
}