friendlyhj/ZenUtils

[Feature] AoE Entity List methods

Closed this issue · 3 comments

TLDR: a method to allow someone to get a list of enitties within a set radus around another entity or point in the world; like how the @e(distance=..value) in newer versions would do this (yeah, only (type=) exists with @e in this version)

id imagine it would be something like this; whether you use the syntax or not is up to you; just thinking ideas here
entity.getNearbyEntities( radius as int, type/focus as optional [put in the instanceOf to filter it out; if its not present then it assumes any entity type (Ientity, Iplayer, IitemEntity, IEntityLivingBase, etc)]

can use an POSsition in the world or an entity directly (since they will have a XYZ on them for the most part, only difference is that an entity pos will be more percise than using a block pos (unless you wanna punch floats in by hand XD)

pos.getNearbyEntities( x as int, game.getEntity("sheep")); //Returns a list of entities that are "minecraft:sheep"
pos.getNearbyEntities( 12, IItemEntity ); // returns a list of entities that are an instanceOf a IItemEntity within a 12 block/meter radius
pos.getNearbyEntities( 0, IBlock ); // would return null as there would be nothing; but would error because IBlock is not a type of entity [no mater how hard you want it to be, tileEntities wont count as being a valid entity to check for with this as well]

there ya go; hope that helps man :P

Since zs doesn't support generic type, the syntax is a little complex.
Example:

events.onEntityLivingAttacked(function(event as EntityLivingAttackedEvent) {
    if (event.entity.world.remote) return;
    var i as int = 0;
    // true -> exclude event.entity
    // livings getter to get List<IEntityLivingBase>
    // items -> List<IEntityItem>
    // players -> List<IPlayer>
    // entities -> List<IEntity>
    // these also filter entity class, so .filterTypes(<entity:minecraft:item>).items is unneccessary
    for entity in event.entity.world.nearbyEntities(event.entity, 16, true).filterType(<entity:minecraft:creeper>).livings {
        print("entity " ~ i ~ " " ~ entity.health ~ " " ~ typeof(entity) ~ " " ~ entity.x ~ " " ~ entity.y ~ " " ~ entity.z);
        i += 1;
    }
});

great, though I am wondering if you can also use specific world cords deffined in an IblockPos or something

other than that its what I need; thanks