diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/ComPort.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/ComPort.java index dbb55d7..fc3380c 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/ComPort.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/ComPort.java @@ -40,7 +40,7 @@ public class ComPort extends CpuHardware { //Get object directly in front of the Cubot Point frontTile = cubot.getFrontTile(); - ArrayList objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y); + ArrayList objects = cubot.getWorld().getGameObjectsBlockingAt(frontTile.x, frontTile.y); if (objects.size() > 0 && objects.get(0) instanceof Programmable) { diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLaser.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLaser.java index f336b67..41688e2 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLaser.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLaser.java @@ -46,7 +46,7 @@ public class CubotLaser extends CpuHardware { Point frontTile = cubot.getFrontTile(); - ArrayList objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y); + ArrayList objects = cubot.getWorld().getGameObjectsBlockingAt(frontTile.x, frontTile.y); if (cubot.getCurrentAction() == Action.IDLE && objects.size() > 0) { diff --git a/Plugin Plant/src/main/java/net/simon987/biomassplugin/WorldUtils.java b/Plugin Plant/src/main/java/net/simon987/biomassplugin/WorldUtils.java index fda2516..e4b98bb 100644 --- a/Plugin Plant/src/main/java/net/simon987/biomassplugin/WorldUtils.java +++ b/Plugin Plant/src/main/java/net/simon987/biomassplugin/WorldUtils.java @@ -17,7 +17,7 @@ public class WorldUtils { Random random = new Random(); int blobCount = random.nextInt(maxCount - minCount) + minCount; - ArrayList biomassBlobs = new ArrayList<>(maxCount); + ArrayList biomassBlobs = new ArrayList<>(blobCount); //Count number of plain tiles. If there is less plain tiles than desired amount of blobs, //set the desired amount of blobs to the plain tile count @@ -45,7 +45,7 @@ public class WorldUtils { //Don't block worlds int counter = 0; while (p.x == 0 || p.y == 0 || p.x == World.WORLD_SIZE - 1 || p.y == World.WORLD_SIZE - 1 || - world.isTileBlocked(p.x, p.y)) { + world.getGameObjectsAt(p.x, p.y).size() != 0) { p = world.getTileMap().getRandomPlainTile(); counter++; diff --git a/Server/src/main/java/net/simon987/server/game/World.java b/Server/src/main/java/net/simon987/server/game/World.java index 60b939a..990de2d 100644 --- a/Server/src/main/java/net/simon987/server/game/World.java +++ b/Server/src/main/java/net/simon987/server/game/World.java @@ -54,7 +54,7 @@ public class World implements JSONSerialisable { */ public boolean isTileBlocked(int x, int y) { - return getGameObjectsAt(x, y).size() > 0 || tileMap.getTileAt(x, y) == TileMap.WALL_TILE; + return getGameObjectsBlockingAt(x, y).size() > 0 || tileMap.getTileAt(x, y) == TileMap.WALL_TILE; } @@ -245,13 +245,13 @@ public class World implements JSONSerialisable { } /** - * Get the list of game objects at a location + * Get the list of game objects that are blocking a tile at a set of coordinates * * @param x X coordinate on the World * @param y Y coordinate on the World - * @return the list of game objects at a location + * @return the list of game objects blocking a location */ - public ArrayList getGameObjectsAt(int x, int y) { + public ArrayList getGameObjectsBlockingAt(int x, int y) { ArrayList gameObjects = new ArrayList<>(2); @@ -266,6 +266,30 @@ public class World implements JSONSerialisable { return gameObjects; } + /** + * Get the list of game objects that are exactly at a given location + *
+ * Note: Objects like the Factory that are more than 1x1 tiles wide will only be returned + * when their exact coordinates are specified + * + * @param x X coordinate on the World + * @param y Y coordinate on the World + * @return the list of game objects at a location + */ + public ArrayList getGameObjectsAt(int x, int y) { + ArrayList gameObjects = new ArrayList<>(2); + + for (GameObject obj : this.gameObjects) { + + if (obj.getX() == x && obj.getY() == y) { + gameObjects.add(obj); + } + + } + + return gameObjects; + } + public void incUpdatable() { updatable++; }