From 02164252098c21362e4e50fcce413794d343a52b Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 29 Jun 2018 09:15:07 -0400 Subject: [PATCH] Fixed more building desync --- core/src/io/anuke/mindustry/core/NetServer.java | 1 + core/src/io/anuke/mindustry/entities/Player.java | 2 +- .../src/io/anuke/mindustry/input/DefaultKeybinds.java | 1 - core/src/io/anuke/mindustry/world/Build.java | 2 +- .../io/anuke/mindustry/world/blocks/BreakBlock.java | 11 +++++++++-- .../io/anuke/mindustry/world/blocks/BuildBlock.java | 4 ++-- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/core/src/io/anuke/mindustry/core/NetServer.java b/core/src/io/anuke/mindustry/core/NetServer.java index f4d5e8bcb1..a25d12f8e8 100644 --- a/core/src/io/anuke/mindustry/core/NetServer.java +++ b/core/src/io/anuke/mindustry/core/NetServer.java @@ -431,6 +431,7 @@ public class NetServer extends Module{ while(remaining > 0){ int used = Math.min(remaining, maxSnapshotSize); byte[] toSend; + //re-use sent byte arrays when possible if(used == maxSnapshotSize){ toSend = reusableSnapArray; System.arraycopy(bytes, offset, toSend, 0, Math.min(offset + maxSnapshotSize, bytes.length) - offset); diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 40c361b57d..ab8f8605f6 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -613,7 +613,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra if(lastShooting != isShooting){ CallEntity.setShooting(isShooting); } - }else if(isShooting()){ //desktop shooting, TODO + }else if(isShooting()){ Vector2 vec = Graphics.world(Vars.control.input(playerIndex).getMouseX(), Vars.control.input(playerIndex).getMouseY()); pointerX = vec.x; diff --git a/core/src/io/anuke/mindustry/input/DefaultKeybinds.java b/core/src/io/anuke/mindustry/input/DefaultKeybinds.java index 49726d4cf4..f32f650c14 100644 --- a/core/src/io/anuke/mindustry/input/DefaultKeybinds.java +++ b/core/src/io/anuke/mindustry/input/DefaultKeybinds.java @@ -22,7 +22,6 @@ public class DefaultKeybinds { "select", Input.MOUSE_LEFT, "break", Input.MOUSE_RIGHT, "shoot", Input.MOUSE_LEFT, - "rotate_alt", new Axis(Input.R, Input.E), "rotate", new Axis(Input.SCROLL), "dash", Input.SHIFT_LEFT, "drop_unit", Input.SHIFT_LEFT, diff --git a/core/src/io/anuke/mindustry/world/Build.java b/core/src/io/anuke/mindustry/world/Build.java index 01bd8ed6e4..d3bb953e9e 100644 --- a/core/src/io/anuke/mindustry/world/Build.java +++ b/core/src/io/anuke/mindustry/world/Build.java @@ -102,7 +102,7 @@ public class Build { Block previous = tile.block(); //remote players only - if(!player.isLocal){ + if(player != null && !player.isLocal){ player.getPlaceQueue().clear(); player.getPlaceQueue().addFirst(new BuildRequest(x, y, rotation, recipe)); } diff --git a/core/src/io/anuke/mindustry/world/blocks/BreakBlock.java b/core/src/io/anuke/mindustry/world/blocks/BreakBlock.java index 10f26d73ac..efecd7ebcc 100644 --- a/core/src/io/anuke/mindustry/world/blocks/BreakBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/BreakBlock.java @@ -55,8 +55,7 @@ public class BreakBlock extends Block { @Override public void tapped(Tile tile, Player player) { - player.clearBuilding(); - player.addBuildRequest(new BuildRequest(tile.x, tile.y)); + CallBlocks.onBreakSelect(player, tile); } @Override @@ -147,6 +146,14 @@ public class BreakBlock extends Block { world.removeBlock(tile); } + @Remote(called = Loc.both, targets = Loc.both, in = In.blocks, forward = true) + public static void onBreakSelect(Player player, Tile tile){ + if(player == null || !(tile.entity instanceof BreakEntity)) return; + + player.getPlaceQueue().clear(); + player.addBuildRequest(new BuildRequest(tile.x, tile.y)); + } + public class BreakEntity extends TileEntity{ private double[] accumulator; diff --git a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java index dc0a32cf6b..ee27e7efa5 100644 --- a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java @@ -165,13 +165,13 @@ public class BuildBlock extends Block { } } - @Remote(called = Loc.server, targets = Loc.both, in = In.blocks, forward = true) + @Remote(called = Loc.both, targets = Loc.both, in = In.blocks, forward = true) public static void onBuildSelect(Player player, Tile tile){ if(player == null || !(tile.entity instanceof BuildEntity)) return; BuildEntity entity = tile.entity(); - player.clearBuilding(); + player.getPlaceQueue().clear(); player.addBuildRequest(new BuildRequest(tile.x, tile.y, tile.getRotation(), entity.recipe)); }