From 0852a61caad509ab80e55492a64cf901dcd76220 Mon Sep 17 00:00:00 2001 From: 1ue999 <106450442+1ue999@users.noreply.github.com> Date: Thu, 3 Jul 2025 19:25:22 +0200 Subject: [PATCH] Read from MessageBlocks/Builds (#10981) * Added ability to read content of messages and sensing the length of the content. Also some bundle changes for read/write * this commit will make mindustry unable to compile trust * oop missed a space --- core/assets/bundles/bundle.properties | 6 +++--- core/src/mindustry/logic/LExecutor.java | 2 ++ core/src/mindustry/world/blocks/logic/MessageBlock.java | 9 +++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index fb255a8813..e151709191 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -2455,8 +2455,8 @@ unit.evoke.description = Builds structures to defend the Bastion core. Repairs s unit.incite.description = Builds structures to defend the Citadel core. Repairs structures with a beam. Capable of carrying 2x2 structures. unit.emanate.description = Builds structures to defend the Acropolis core. Repairs structures with beams. Capable of carrying 2x2 structures. -lst.read = Read a number from a linked memory cell. -lst.write = Write a number to a linked memory cell. +lst.read = Read a number from a linked memory cell.\nCan also read from variables in other processors. +lst.write = Write a number to a linked memory cell.\nCan also write to variables in other processors. lst.print = Add text to the print buffer.\nDoes not display anything until [accent]Print Flush[] is used. lst.printchar = Add a UTF-16 character or content icon to the print buffer.\nDoes not display anything until [accent]Print Flush[] is used. lst.format = Replace next placeholder in text buffer with a value.\nDoes not do anything if placeholder pattern is invalid.\nPlaceholder pattern: "{[accent]number 0-9[]}"\nExample:\n[accent]print "test {0}"\nformat "example" @@ -2566,7 +2566,7 @@ laccess.size = Size of a unit/building or the length of a string. laccess.id = ID of a unit/block/item/liquid.\nThis is the inverse of the lookup operation. laccess.displaywidth = Width of a display block in pixels. laccess.displayheight = Height of a display block in pixels. -laccess.bufferusage = Number of unprocessed commands in the graphics buffer of a display. +laccess.bufferusage = Number of unprocessed commands in the graphics buffer of a display.\nLength of the content of a message. laccess.operations = Number of operations performed on the block.\nFor displays, returns the number of drawflush operations. lcategory.unknown = Unknown diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 0609458a31..db4ad013ff 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -580,6 +580,8 @@ public class LExecutor{ output.numval = fromVar.numval; output.isobj = fromVar.isobj; } + }else if(from instanceof MessageBuild msg){ + output.setnum(address < 0 || address >= msg.message.length() ? Double.NaN : (int)msg.message.charAt(address)); }else if(target.isobj && target.objval instanceof CharSequence str){ output.setnum(address < 0 || address >= str.length() ? Double.NaN : (int)str.charAt(address)); }else if(from instanceof CanvasBuild canvas && (exec.privileged || (from.team == exec.team))){ diff --git a/core/src/mindustry/world/blocks/logic/MessageBlock.java b/core/src/mindustry/world/blocks/logic/MessageBlock.java index f00b7f2ce7..5f78145bdb 100644 --- a/core/src/mindustry/world/blocks/logic/MessageBlock.java +++ b/core/src/mindustry/world/blocks/logic/MessageBlock.java @@ -14,6 +14,7 @@ import arc.util.io.*; import arc.util.pooling.*; import mindustry.core.*; import mindustry.gen.*; +import mindustry.logic.*; import mindustry.ui.*; import mindustry.ui.dialogs.*; import mindustry.world.*; @@ -165,6 +166,14 @@ public class MessageBlock extends Block{ return !accessible() ? SystemCursor.arrow : super.getCursor(); } + @Override + public double sense(LAccess sensor){ + return switch(sensor){ + case bufferUsage -> message.length(); + default -> super.sense(sensor); + }; + } + @Override public void damage(float damage){ if(privileged) return;