我的世界从列表中获取对象,然后操纵它

时间:2015-06-17 18:42:29

标签: java arraylist minecraft

嘿,在我的我的Minecraft mod中,我试图从我的实体中获取近实体,并能够操纵它们。

这是我获得近实体的方式:

    List entitylist = this.getEntityWorld().getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(5.0D, 10.0D, 5.0D));

那么如何将实体从列表中删除?

3 个答案:

答案 0 :(得分:1)

这样的事可能会这样做:)

List entitylist = this.getEntityWorld().getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(5.0D, 10.0D, 5.0D));
for (int i = 0; i < entitylist.size(); i++) {
 //Do stuff with each entity  
 Entity entity = (Entity) entitylist.get(i);
}

答案 1 :(得分:0)

此代码应该有效!它会从所选实体中获取所有实体

// World of the entity
World entityWorld = getEntityWorld();

// Who is near the entity ?
List nearEntities = entityWorld.getEntitiesWithinAABBExcludingEntity(this, getEntityBoundingBox().expand(5.0D, 10.0D, 5.0D));

// All the entity in the world
List allEntities = entityWorld.loadedEntityList;

// Create a new list that will contains the outer entity
List<Entity> outerEntities = new ArrayList<Entity>();

// Add all the entity in the world to the list
outerEntities.addAll(allEntities);

// Remove all the near entity
outerEntities.removeAll(nearEntities); 

// outerEntity now contains all outer entity
for (Entity outerEntity : outerEntities) {
    // Action on outer entity
}

答案 2 :(得分:0)

您的entitylist现在包含对象。在这种情况下,您会说,&#34;它是一个包含实体&#34;的列表。 (我只是假设他们是实体......我们不确定!)

您可以使用for循环查看列表中的每个内容,如下所示:

for (Object entity : entitylist){ //for each entity in the list
    if (o instanceof EntityLiving){ //<-- replace EntityLiving with what you expect

        ((EntityLiving) o).doStuff() //for example... I'm not familiar with Minecraft code!
        //...etc
    }
}

(这比它应该更复杂,因为Minecraft代码很奇怪,并且没有告诉我们列表中包含什么类型的东西。只是我的意见!)