Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Minecraft从列表中获取对象,并由abbe进行操作_Java_Arraylist_Minecraft - Fatal编程技术网

Java Minecraft从列表中获取对象,并由abbe进行操作

Java Minecraft从列表中获取对象,并由abbe进行操作,java,arraylist,minecraft,Java,Arraylist,Minecraft,嘿,在我的minecraft mod中,我试图从我的实体中获得接近的实体,并能够操纵它们 这就是我得到近实体的方式: List entitylist = this.getEntityWorld().getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(5.0D, 10.0D, 5.0D)); 那么如何从列表中删除实体呢?这段代码应该可以工作!,它从所选实体中获取所有实体 // Worl

嘿,在我的minecraft mod中,我试图从我的实体中获得接近的实体,并能够操纵它们

这就是我得到近实体的方式:

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

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

这段代码应该可以工作!,它从所选实体中获取所有实体

// 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
}
//实体的世界
World entityWorld=getEntityWorld();
//谁在实体附近?
List nearEntities=entityWorld.GetEntitiesWithInAbbexExcludingEntity(此,getEntityBoundingBox().expand(5.0D,10.0D,5.0D));
//世界上所有的实体
List Allenties=entityWorld.loadedEntityList;
//创建将包含外部实体的新列表
List outerEntities=new ArrayList();
//将世界上的所有实体添加到列表中
地址(Allenties);
//删除所有邻近实体
outerEntities.removeAll(近实体);
//outerEntity现在包含所有外部实体
for(实体outerEntity:outerEntities){
//关于外部实体的行动
}

像这样的东西可能会成功:)

List entitylist=this.getEntityWorld().getEntitywithinabExcludinGenty(this,this.getEntityBoundingBox().expand(5.0D,10.0D,5.0D));
对于(int i=0;i
您的
entitylist
现在包含对象。在本例中,您会说,“这是一个包含实体的列表”。(我只是假设它们是实体……我们不确定!)

您可以使用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
    }
}
for(对象实体:entitylist){//对于列表中的每个实体

if(o EntityLiving的instanceof){//entityList.get(index)或者一个简单的foreach?我改变了它没有。因为我不完全确定Bukkit/Minecraft/spiget的实体类名是什么,我在更新的回答中使用了实体。他想得到另一个实体范围之外的所有实体,他正在使用forge。老实说……我不认为你的代码会编译。既然
entitylist
是原始类型,那么你能返回一个特定的类型吗?同意@Tom的说法,entitylist中的对象必须是Casted的Minecraft库使用rawtypes真奇怪。我上次检查的泛型在Minecraft发布时已经是Java的一部分了。也许这个库是由一个PHP开发人员编写的,“随心所欲”language:-DHe想要获取另一个实体范围之外的所有实体。您可能想在这里将所有内容放入集合中…我相信List.removeAll是O(n^2)。也就是说,我不知道我们谈论的对象有多少。(我只是假设有很多。)@burnsy通常它们接近100,所以这段代码不需要太多时间来完成,真正慢的部分是使用getEntitywithinabExcludinGenty计算near实体
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
    }
}