From d14cdfd59c6834df810422c5c5357dfd1631ee21 Mon Sep 17 00:00:00 2001 From: BalaM314 <71201189+BalaM314@users.noreply.github.com> Date: Fri, 16 Jun 2023 23:57:05 +0530 Subject: [PATCH 1/2] Allow ulocate to output enemy buildings (#6704) * Allow ulocate to output enemy buildings Previously you would have to use ucontrol getblock to get the actual Building that's weird and just confuses newbs like me * whoops, turns out ulocate doesn't have a range * c o d e s t y l e * Always return building object if on same team --- core/src/mindustry/logic/LExecutor.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index b8ca76ec07..d4b788d637 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -322,7 +322,14 @@ public class LExecutor{ cache.found = false; exec.setnum(outFound, 0); } - exec.setobj(outBuild, res != null && res.build != null && res.build.team == exec.team ? cache.build = res.build : null); + + if(res != null && res.build != null && + (unit.within(res.build.x, res.build.y, Math.max(unit.range(), buildingRange)) || res.build.team == exec.team)){ + cache.build = res.build; + exec.setobj(outBuild, res.build); + }else{ + exec.setobj(outBuild, null); + } }else{ exec.setobj(outBuild, cache.build); exec.setbool(outFound, cache.found); From 26c0c7467b62e298399491bfafa0788705613c82 Mon Sep 17 00:00:00 2001 From: MEEPofFaith <54301439+MEEPofFaith@users.noreply.github.com> Date: Fri, 16 Jun 2023 12:57:54 -0700 Subject: [PATCH 2/2] Lock rotation of blocks with `rotate = false` to 0 (#8531) * Lock rotation of blocks that don't rotate * Fix input visuals * Default to false Quick, stop forcing changes to mods before sk yells at me. * lock GenericCrafter rotation if rotate = false * Convert from a setter a to block method * Simplify * Revert "lock GenericCrafter rotation if rotate = false" This reverts commit 26ac41baf52b2fd852b197bb0b83f86e122730b0. * Remove `lockRotation` boolean. Pointless. If you want something to rotate, just do `rotate = true; drawArrow = false;` --- core/src/mindustry/entities/units/BuildPlan.java | 6 +++--- core/src/mindustry/input/DesktopInput.java | 11 ++++++----- core/src/mindustry/input/InputHandler.java | 2 +- core/src/mindustry/input/MobileInput.java | 5 +++-- core/src/mindustry/world/Block.java | 7 ++++++- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/core/src/mindustry/entities/units/BuildPlan.java b/core/src/mindustry/entities/units/BuildPlan.java index 9e1be93361..f4f1f1fb07 100644 --- a/core/src/mindustry/entities/units/BuildPlan.java +++ b/core/src/mindustry/entities/units/BuildPlan.java @@ -37,7 +37,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; + this.rotation = block.planRotation(rotation); this.block = block; this.breaking = false; } @@ -46,7 +46,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; + this.rotation = block.planRotation(rotation); this.block = block; this.breaking = false; this.config = config; @@ -138,7 +138,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; + this.rotation = block.planRotation(rotation); this.block = block; this.breaking = false; return this; diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 70277ef24e..935e1b5631 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -178,17 +178,18 @@ public class DesktopInput extends InputHandler{ } linePlans.each(this::drawOverPlan); }else if(isPlacing()){ + int rot = block.planRotation(rotation); if(block.rotate && block.drawArrow){ - drawArrow(block, cursorX, cursorY, rotation); + drawArrow(block, cursorX, cursorY, rot); } Draw.color(); - boolean valid = validPlace(cursorX, cursorY, block, rotation); - drawPlan(cursorX, cursorY, block, rotation); - block.drawPlace(cursorX, cursorY, rotation, valid); + boolean valid = validPlace(cursorX, cursorY, block, rot); + drawPlan(cursorX, cursorY, block, rot); + block.drawPlace(cursorX, cursorY, rot, valid); if(block.saveConfig){ Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f)); - bplan.set(cursorX, cursorY, rotation, block); + bplan.set(cursorX, cursorY, rot, block); bplan.config = block.lastConfig; block.drawPlanConfig(bplan, allPlans()); bplan.config = null; diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index 91787021f1..54e162e35f 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -1044,7 +1044,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.rotation = plan.block.planRotation(Mathf.mod(plan.rotation + direction, 4)); }); } diff --git a/core/src/mindustry/input/MobileInput.java b/core/src/mindustry/input/MobileInput.java index 126032c5e1..3f8009ae4a 100644 --- a/core/src/mindustry/input/MobileInput.java +++ b/core/src/mindustry/input/MobileInput.java @@ -415,9 +415,10 @@ public class MobileInput extends InputHandler implements GestureListener{ //draw last placed plan if(!plan.breaking && plan == lastPlaced && plan.block != null){ - boolean valid = validPlace(tile.x, tile.y, plan.block, rotation); + int rot = block.planRotation(rotation); + boolean valid = validPlace(tile.x, tile.y, plan.block, rot); Draw.mixcol(); - plan.block.drawPlace(tile.x, tile.y, rotation, valid); + plan.block.drawPlace(tile.x, tile.y, rot, valid); drawOverlapCheck(plan.block, tile.x, tile.y, valid); } diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index cb149be40a..4f1b77c850 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -1341,9 +1341,14 @@ public class Block extends UnlockableContent implements Senseable{ packer.add(PageType.editor, name + "-icon-editor", editorBase); } + public int planRotation(int rot){ + if(!rotate) return 0; + return rot; + } + public void flipRotation(BuildPlan req, boolean x){ if((x == (req.rotation % 2 == 0)) != invertFlip){ - req.rotation = Mathf.mod(req.rotation + 2, 4); + req.rotation = planRotation(Mathf.mod(req.rotation + 2, 4)); } }