Hallo Leute,
ich arbeite schon etwas länger an einem Plugin, welches neue Traits zu Citizens hinzufügt. Momentan hänge ich jedoch an einer Stelle.
Ich habe einen NPC mit meiner Trait, soweit geht das. Nun soll dieser NPC die Blöcke um sich herum scannen und nach Feldern suchen und sich dorthin bewegen. Das klappt auch, aber das Problem liegt darin, dass der NPC nicht in dem von mir vorgeschriebenen Radius sucht (3 Blöcke), sondern auch Felder nimmt, die gute 50 Blöcke weg sind. Wo liegt also mein Fehler in diesem Code:
ich arbeite schon etwas länger an einem Plugin, welches neue Traits zu Citizens hinzufügt. Momentan hänge ich jedoch an einer Stelle.
Ich habe einen NPC mit meiner Trait, soweit geht das. Nun soll dieser NPC die Blöcke um sich herum scannen und nach Feldern suchen und sich dorthin bewegen. Das klappt auch, aber das Problem liegt darin, dass der NPC nicht in dem von mir vorgeschriebenen Radius sucht (3 Blöcke), sondern auch Felder nimmt, die gute 50 Blöcke weg sind. Wo liegt also mein Fehler in diesem Code:
Javascript:
Location pos1 = new Location(loc.getWorld(), loc.getX()+3, loc.getY()+3, loc.getZ()-3);
Location pos2 = new Location(loc.getWorld(), loc.getX()-3, loc.getY()-3, loc.getZ()+3);
for(int x = pos2.getBlockX(); x < pos1.getBlockX(); x++){
for(int y = pos2.getBlockY(); y < pos1.getBlockY(); y++){
for(int z = pos1.getBlockZ(); z < pos2.getBlockZ(); z++){
Block b = pos1.getWorld().getBlockAt(x, y, z);
if(b.getType() == Material.SOIL){
Location eloc = new Location(pos1.getWorld(), x, y+1, z);
plants.add(eloc);
}
}
}
}
Navigator n = npc.getNavigator();
int c = r.nextInt(plants.size());
Location tloc = plants.get(c);
n.setTarget(tloc);