diff --git a/core/src/io/anuke/mindustry/ai/WaveSpawner.java b/core/src/io/anuke/mindustry/ai/WaveSpawner.java index 573edec198..ed25754b93 100644 --- a/core/src/io/anuke/mindustry/ai/WaveSpawner.java +++ b/core/src/io/anuke/mindustry/ai/WaveSpawner.java @@ -180,7 +180,13 @@ public class WaveSpawner{ } private void setQuad(int quadx, int quady, boolean valid){ - if(quadrants == null) quadrants = new GridBits(quadWidth(), quadHeight()); + if(quadrants == null){ + quadrants = new GridBits(quadWidth(), quadHeight()); + } + + if(!Mathf.inBounds(quadx, quady, quadWidth(), quadHeight())){ + return; + } quadrants.set(quadx, quady, valid); } diff --git a/core/src/io/anuke/mindustry/world/Build.java b/core/src/io/anuke/mindustry/world/Build.java index 0beab97250..addaa507ea 100644 --- a/core/src/io/anuke/mindustry/world/Build.java +++ b/core/src/io/anuke/mindustry/world/Build.java @@ -1,5 +1,6 @@ package io.anuke.mindustry.world; +import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import io.anuke.mindustry.content.blocks.Blocks; @@ -10,6 +11,7 @@ import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity; import io.anuke.ucore.core.Events; import io.anuke.ucore.entities.Entities; +import io.anuke.ucore.util.Geometry; import static io.anuke.mindustry.Vars.*; @@ -154,6 +156,10 @@ public class Build{ return true; } + if(!contactsGround(tile.x, tile.y, type)){ + return false; + } + if(!type.canPlaceOn(tile)){ return false; } @@ -173,6 +179,7 @@ public class Build{ return true; }else{ return (tile.getTeam() == Team.none || tile.getTeam() == team) + && contactsGround(tile.x, tile.y, type) && (!tile.floor().isLiquid || type.floating) && tile.floor().placeableOn && !tile.hasCliffs() && ((type.canReplace(tile.block()) @@ -181,6 +188,27 @@ public class Build{ } } + private static boolean contactsGround(int x, int y, Block block){ + if(block.isMultiblock()){ + for(GridPoint2 point : Edges.getInsideEdges(block.size)){ + Tile tile = world.tile(x + point.x, y + point.y); + if(tile != null && !tile.floor().isLiquid) return true; + } + + for(GridPoint2 point : Edges.getEdges(block.size)){ + Tile tile = world.tile(x + point.x, y + point.y); + if(tile != null && !tile.floor().isLiquid) return true; + } + }else{ + for(GridPoint2 point : Geometry.d4){ + Tile tile = world.tile(x + point.x, y + point.y); + if(tile != null && !tile.floor().isLiquid) return true; + } + return world.tile(x, y) != null && !world.tile(x, y).floor().isLiquid; + } + return false; + } + /**Returns whether the tile at this position is breakable by this team*/ public static boolean validBreak(Team team, int x, int y){ Tile tile = world.tile(x, y); diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java index 2061950eb1..826d9d52dd 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java @@ -23,6 +23,7 @@ public class Conduit extends LiquidBlock{ super(name); rotate = true; solid = false; + floating = true; } @Override