From 1a89fc9f8e441f746849341b5486343aab72a901 Mon Sep 17 00:00:00 2001 From: Redstonneur1256 <29004178+Redstonneur1256@users.noreply.github.com> Date: Sun, 28 Dec 2025 03:38:44 +0100 Subject: [PATCH] Allow displays on `draw image` (#11140) * Display on display drawing * Update draw image description --- core/assets/bundles/bundle.properties | 2 +- core/src/mindustry/logic/LExecutor.java | 17 ++++++----- .../world/blocks/logic/LogicDisplay.java | 28 ++++++++++++++++++- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 437a27e84c..16f5e4e545 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -2661,7 +2661,7 @@ graphicstype.linerect = Draw a rectangle outline. graphicstype.poly = Fill a regular polygon. graphicstype.linepoly = Draw a regular polygon outline. graphicstype.triangle = Fill a triangle. -graphicstype.image = Draw an image of some content.\nex: [accent]@router[] or [accent]@dagger[]. +graphicstype.image = Draw an image of some content or copies another display.\nex content: [accent]@router[], [accent]@dagger[] or a display [accent]display1[]. graphicstype.print = Draws text from the print buffer.\nOnly ASCII characters are allowed.\nClears the print buffer. lenum.always = Always true. diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 9410a3d411..1ddd2cecaf 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -943,25 +943,24 @@ public class LExecutor{ exec.textBuffer.setLength(0); } }else{ - int num1 = p1.numi(), num4 = p4.numi(), xval = packSign(x.numi()), yval = packSign(y.numi()); + int num1 = packSign(p1.numi()), num4 = packSign(p4.numi()), xval = packSign(x.numi()), yval = packSign(y.numi()); if(type == LogicDisplay.commandImage){ + int packed = -1; if(p1.obj() instanceof UnlockableContent u){ - //TODO: with mods, this will overflow (ID >= 512), but that's better than the previous system, at least - num1 = u.id; - num4 = u.getContentType().ordinal(); - }else{ - num1 = -1; - num4 = -1; + packed = (u.id << 5) | (u.getContentType().ordinal() & 31); + }else if(p1.obj() instanceof LogicDisplayBuild d){ + packed = (d.index << 5) | 30; } - //num1 = p1.obj() instanceof UnlockableContent u ? u.iconId : 0; + num1 = packed & 0x3FF; + num4 = packed >> 10; }else if(type == LogicDisplay.commandScale){ xval = packSign((int)(x.numf() / LogicDisplay.scaleStep)); yval = packSign((int)(y.numf() / LogicDisplay.scaleStep)); } //add graphics calls, cap graphics buffer size - exec.graphicsBuffer.add(DisplayCmd.get(type, xval, yval, packSign(num1), packSign(p2.numi()), packSign(p3.numi()), packSign(num4))); + exec.graphicsBuffer.add(DisplayCmd.get(type, xval, yval, num1, packSign(p2.numi()), packSign(p3.numi()), num4)); } } diff --git a/core/src/mindustry/world/blocks/logic/LogicDisplay.java b/core/src/mindustry/world/blocks/logic/LogicDisplay.java index c238da05d3..6a851342f7 100644 --- a/core/src/mindustry/world/blocks/logic/LogicDisplay.java +++ b/core/src/mindustry/world/blocks/logic/LogicDisplay.java @@ -41,6 +41,8 @@ public class LogicDisplay extends Block{ commandResetTransform = 15 ; + public static final Seq displays = new Seq<>(false); + public static final float scaleStep = 0.05f; public int maxSides = 25; @@ -81,6 +83,7 @@ public class LogicDisplay extends Block{ public LongQueue commands = new LongQueue(256); public @Nullable Mat transform; public long operations; + public int index = -1; @Override public void draw(){ @@ -167,7 +170,15 @@ public class LogicDisplay extends Block{ case commandColor -> Draw.color(this.color = Color.toFloatBits(x, y, p1, p2)); case commandStroke -> Lines.stroke(this.stroke = x); case commandImage -> { - if(p4 >= 0 && p4 < ContentType.all.length && Vars.content.getByID(ContentType.all[p4], p1) instanceof UnlockableContent u){ + int packed = (DisplayCmd.p4(c) << 10) | DisplayCmd.p1(c); + int ctype = packed & 0x1F; + int id = packed >> 5; + if(ctype == 30){ + if(id != index && id < displays.size && displays.get(id).buffer != null){ + Tmp.tr1.set(displays.get(id).buffer.getTexture()); + Draw.rect(Tmp.tr1, x, y, p2, p2, p3 + 90); + } + }else if(ctype < ContentType.all.length && Vars.content.getByID(ContentType.all[p4], id) instanceof UnlockableContent u){ var icon = u.fullIcon; Draw.rect(icon, x, y, p2, p2 / icon.ratio(), p3); } @@ -231,9 +242,24 @@ public class LogicDisplay extends Block{ } } + @Override + public void add(){ + super.add(); + + index = displays.size; + displays.add(this); + } + @Override public void remove(){ super.remove(); + + if(index != -1){ + displays.get(displays.size - 1).index = index; + displays.remove(index); + index = -1; + } + if(buffer != null){ buffer.dispose(); buffer = null;