diff --git a/core/src/mindustry/editor/MapEditor.java b/core/src/mindustry/editor/MapEditor.java index 8c743ad11f..6e9ceeb640 100644 --- a/core/src/mindustry/editor/MapEditor.java +++ b/core/src/mindustry/editor/MapEditor.java @@ -124,7 +124,9 @@ public class MapEditor{ if(drawBlock.isMultiblock()){ x = Mathf.clamp(x, (drawBlock.size - 1) / 2, width() - drawBlock.size / 2 - 1); y = Mathf.clamp(y, (drawBlock.size - 1) / 2, height() - drawBlock.size / 2 - 1); - tile(x, y).setBlock(drawBlock, drawTeam, 0); + if(!hasOverlap(x, y)){ + tile(x, y).setBlock(drawBlock, drawTeam, 0); + } }else{ boolean isFloor = drawBlock.isFloor() && drawBlock != Blocks.air; @@ -152,6 +154,33 @@ public class MapEditor{ } } + boolean hasOverlap(int x, int y){ + Tile tile = world.tile(x, y); + //allow direct replacement of blocks of the same size + if(tile != null && tile.isCenter() && tile.block() != drawBlock && tile.block().size == drawBlock.size){ + return false; + } + + //else, check for overlap + int offsetx = -(drawBlock.size - 1) / 2; + int offsety = -(drawBlock.size - 1) / 2; + for(int dx = 0; dx < drawBlock.size; dx++){ + for(int dy = 0; dy < drawBlock.size; dy++){ + int worldx = dx + offsetx + x; + int worldy = dy + offsety + y; + if(!(worldx == x && worldy == y)){ + Tile other = world.tile(worldx, worldy); + + if(other != null && other.block().isMultiblock()){ + return true; + } + } + } + } + + return false; + } + public void drawCircle(int x, int y, Cons drawer){ for(int rx = -brushSize; rx <= brushSize; rx++){ for(int ry = -brushSize; ry <= brushSize; ry++){ diff --git a/core/src/mindustry/game/Schematic.java b/core/src/mindustry/game/Schematic.java index 030b00cc78..9e798af72b 100644 --- a/core/src/mindustry/game/Schematic.java +++ b/core/src/mindustry/game/Schematic.java @@ -49,9 +49,9 @@ public class Schematic implements Publishable, Comparable{ } public @NonNull CoreBlock findCore(){ - CoreBlock block = (CoreBlock)tiles.find(s -> s.block instanceof CoreBlock).block; - if(block == null) throw new IllegalArgumentException("Schematic is missing a core!"); - return block; + Stile tile = tiles.find(s -> s.block instanceof CoreBlock); + if(tile == null) throw new IllegalArgumentException("Schematic is missing a core!"); + return (CoreBlock)tile.block; } public String name(){ diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index b890eda45c..cedc02046c 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -50,13 +50,13 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ public final OverlayFragment frag = new OverlayFragment(); - public Block block; + public @Nullable Block block; public boolean overrideLineRotation; public int rotation; public boolean droppingItem; public Group uiGroup; public boolean isShooting, isBuilding = true, buildWasAutoPaused = false; - public UnitType controlledType; + public @Nullable UnitType controlledType; protected @Nullable Schematic lastSchematic; protected GestureDetector detector; @@ -510,7 +510,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ if(request.block.saveConfig && request.block.lastConfig != null){ Object conf = request.config; - request.config = block.lastConfig; + request.config = request.block.lastConfig; request.block.drawRequestConfig(request, allRequests()); request.config = conf; }