From 8f6bfa1e0f3d7bcdf9514afb4183d7486830461e Mon Sep 17 00:00:00 2001 From: MEEP of Faith Date: Sun, 23 Apr 2023 10:45:20 -0700 Subject: [PATCH] Lock rotation of blocks that don't rotate --- core/src/mindustry/entities/units/BuildPlan.java | 14 +++++++++++--- core/src/mindustry/input/InputHandler.java | 2 +- core/src/mindustry/world/Block.java | 4 +++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/src/mindustry/entities/units/BuildPlan.java b/core/src/mindustry/entities/units/BuildPlan.java index 26811b741f..b2570951df 100644 --- a/core/src/mindustry/entities/units/BuildPlan.java +++ b/core/src/mindustry/entities/units/BuildPlan.java @@ -35,7 +35,7 @@ public class BuildPlan implements Position, QuadTreeObject{ public BuildPlan(int x, int y, int rotation, Block block){ this.x = x; this.y = y; - this.rotation = rotation; + setRotation(block, rotation); this.block = block; this.breaking = false; } @@ -44,7 +44,7 @@ public class BuildPlan implements Position, QuadTreeObject{ public BuildPlan(int x, int y, int rotation, Block block, Object config){ this.x = x; this.y = y; - this.rotation = rotation; + setRotation(block, rotation); this.block = block; this.breaking = false; this.config = config; @@ -136,7 +136,7 @@ public class BuildPlan implements Position, QuadTreeObject{ public BuildPlan set(int x, int y, int rotation, Block block){ this.x = x; this.y = y; - this.rotation = rotation; + setRotation(block, rotation); this.block = block; this.breaking = false; return this; @@ -177,6 +177,14 @@ public class BuildPlan implements Position, QuadTreeObject{ return drawy(); } + public void setRotation(Block block, int rotation){ + this.rotation = !block.rotate && block.lockRotation ? 0 : rotation; + } + + public void setRotation(int rotation){ + if(block != null) setRotation(block, rotation); + } + @Override public String toString(){ return "BuildPlan{" + diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index 11877512e5..f9102b0c1a 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -1038,7 +1038,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ } plan.x = World.toTile(wx - plan.block.offset) + ox; plan.y = World.toTile(wy - plan.block.offset) + oy; - plan.rotation = Mathf.mod(plan.rotation + direction, 4); + plan.setRotation(Mathf.mod(plan.rotation + direction, 4)); }); } diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index cb149be40a..4895963eb3 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -106,6 +106,8 @@ public class Block extends UnlockableContent implements Senseable{ public boolean underBullets; /** whether this is rotatable */ public boolean rotate; + /** if rotate is false and this is true, building rotation is set to 0 regardless of player input */ + public boolean lockRotation = true; /** if rotate is true and this is false, the region won't rotate when drawing */ public boolean rotateDraw = true; /** if true, schematic flips with this block are inverted. */ @@ -1343,7 +1345,7 @@ public class Block extends UnlockableContent implements Senseable{ public void flipRotation(BuildPlan req, boolean x){ if((x == (req.rotation % 2 == 0)) != invertFlip){ - req.rotation = Mathf.mod(req.rotation + 2, 4); + req.setRotation(Mathf.mod(req.rotation + 2, 4)); } }