From 5cee3ed8fa7e6a69674c41fc354412fc5681816a Mon Sep 17 00:00:00 2001 From: Boblet Date: Wed, 24 Jun 2026 15:02:08 +0200 Subject: [PATCH 1/3] MS-ES v1.1 (first extended instruction set, now with stacks and split) --- changelog | 3 +- src/main/java/com/hbm/blocks/ModBlocks.java | 10 +-- .../com/hbm/blocks/network/RadioAUTOCAL.java | 2 +- .../pneumatic/PneumoStorageExporter.java | 19 +++++ .../pneumatic/PneumoStorageImporter.java | 19 +---- .../network/pneumatic/PneumoStorageMono.java | 46 +++++++++++ .../inventory/gui/GUIScreenRadioAUTOCAL.java | 6 ++ src/main/java/com/hbm/module/IParse.java | 77 ++++++++++++++++- src/main/java/com/hbm/module/ParseMSES1.java | 80 +++++++++--------- .../java/com/hbm/module/ParseMSES1Ext1.java | 82 +++++++++++++++++++ .../network/TileEntityRadioAUTOCAL.java | 32 +++----- 11 files changed, 289 insertions(+), 87 deletions(-) create mode 100644 src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageExporter.java create mode 100644 src/main/java/com/hbm/module/ParseMSES1Ext1.java diff --git a/changelog b/changelog index 958841776..b5b39f0d4 100644 --- a/changelog +++ b/changelog @@ -38,4 +38,5 @@ * Fixed AUTOCAL's file opening buttons not working on some systems, it will fall back to opening the folder instead * Fixed some recipes not using ore dict when they should * Fixed `anyBismoid` group not being a proper group, causing other mods' bismuth and arsenic to not be included -* Fixed RoR gauge not using SI suffixes on values below 0 \ No newline at end of file +* Fixed RoR gauge not using SI suffixes on values below 0 +* Fixed AUTOCAL units not closing their GUI when the unit is destroyed \ No newline at end of file diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index 15339b386..537d02097 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -12,12 +12,7 @@ import com.hbm.blocks.machine.fusion.*; import com.hbm.blocks.machine.pile.*; import com.hbm.blocks.machine.rbmk.*; import com.hbm.blocks.network.*; -import com.hbm.blocks.network.pneumatic.PneumoStorageAccess; -import com.hbm.blocks.network.pneumatic.PneumoStorageClutter; -import com.hbm.blocks.network.pneumatic.PneumoStorageImporter; -import com.hbm.blocks.network.pneumatic.PneumoStorageMono; -import com.hbm.blocks.network.pneumatic.PneumoTube; -import com.hbm.blocks.network.pneumatic.PneumoTubePaintableBlock; +import com.hbm.blocks.network.pneumatic.*; import com.hbm.blocks.rail.*; import com.hbm.blocks.test.*; import com.hbm.blocks.turret.*; @@ -810,6 +805,7 @@ public class ModBlocks { public static Block pneumatic_storage_clutter; public static Block pneumatic_storage_mono; public static Block pneumatic_storage_importer; + public static Block pneumatic_storage_exporter; public static Block fan; public static Block piston_inserter; @@ -1915,6 +1911,7 @@ public class ModBlocks { pneumatic_storage_clutter = new PneumoStorageClutter().setBlockName("pneumatic_storage_clutter").setStepSound(ModSoundTypes.pipe).setHardness(5.0F).setResistance(10.0F).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":pneumatic_storage_clutter"); pneumatic_storage_mono = new PneumoStorageMono().setBlockName("pneumatic_storage_mono").setStepSound(ModSoundTypes.pipe).setHardness(5.0F).setResistance(10.0F).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":pneumatic_storage_mono"); pneumatic_storage_importer = new PneumoStorageImporter().setBlockName("pneumatic_storage_importer").setStepSound(ModSoundTypes.pipe).setHardness(5.0F).setResistance(10.0F).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":pneumatic_storage_importer"); + pneumatic_storage_exporter = new PneumoStorageExporter().setBlockName("pneumatic_storage_exporter").setStepSound(ModSoundTypes.pipe).setHardness(5.0F).setResistance(10.0F).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":pneumatic_storage_exporter"); chain = new BlockChain(Material.iron).setBlockName("dungeon_chain").setHardness(0.25F).setResistance(2.0F).setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":chain"); @@ -3183,6 +3180,7 @@ public class ModBlocks { register(pneumatic_storage_clutter); register(pneumatic_storage_mono); register(pneumatic_storage_importer); + register(pneumatic_storage_exporter); register(fan); register(piston_inserter); diff --git a/src/main/java/com/hbm/blocks/network/RadioAUTOCAL.java b/src/main/java/com/hbm/blocks/network/RadioAUTOCAL.java index ca989f365..8b7c6f7b2 100644 --- a/src/main/java/com/hbm/blocks/network/RadioAUTOCAL.java +++ b/src/main/java/com/hbm/blocks/network/RadioAUTOCAL.java @@ -22,7 +22,7 @@ public class RadioAUTOCAL extends BlockDummyable { return null; } - @Override public int[] getDimensions() { return new int[] {1, 0, 0, 0, 0 ,0}; } + @Override public int[] getDimensions() { return new int[] {1, 0, 0, 0, 0, 0}; } @Override public int getOffset() { return 0; } @Override diff --git a/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageExporter.java b/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageExporter.java new file mode 100644 index 000000000..49d0724e4 --- /dev/null +++ b/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageExporter.java @@ -0,0 +1,19 @@ +package com.hbm.blocks.network.pneumatic; + +import com.hbm.blocks.machine.BlockMachineBase; + +import net.minecraft.block.material.Material; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class PneumoStorageExporter extends BlockMachineBase { + + public PneumoStorageExporter() { + super(Material.iron, 0); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return null; + } +} diff --git a/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageImporter.java b/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageImporter.java index 5df23cec8..a6a70e5b2 100644 --- a/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageImporter.java +++ b/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageImporter.java @@ -1,33 +1,20 @@ package com.hbm.blocks.network.pneumatic; -import com.hbm.main.MainRegistry; +import com.hbm.blocks.machine.BlockMachineBase; import com.hbm.tileentity.network.pneumatic.TileEntityPneumoStorageImporter; -import cpw.mods.fml.common.network.internal.FMLNetworkHandler; -import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -public class PneumoStorageImporter extends BlockContainer { +public class PneumoStorageImporter extends BlockMachineBase { public PneumoStorageImporter() { - super(Material.iron); + super(Material.iron, 0); } @Override public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityPneumoStorageImporter(); } - - @Override - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { - if(world.isRemote) return true; - if(!player.isSneaking()) { - FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z); - return true; - } - return false; - } } diff --git a/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageMono.java b/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageMono.java index 898af831e..73d9f4742 100644 --- a/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageMono.java +++ b/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageMono.java @@ -6,7 +6,11 @@ import com.hbm.tileentity.network.pneumatic.TileEntityPneumoStorageMono; import cpw.mods.fml.common.network.internal.FMLNetworkHandler; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; @@ -30,4 +34,46 @@ public class PneumoStorageMono extends BlockContainer { } return false; } + + @Override + public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) { + + if(!player.capabilities.isCreativeMode && !world.isRemote && willHarvest) { + + TileEntityPneumoStorageMono inv = (TileEntityPneumoStorageMono) world.getTileEntity(x, y, z); + ItemStack drop = new ItemStack(this); + NBTTagCompound nbt = new NBTTagCompound(); + + if(inv != null) { + for(int i = 0; i < 3; i++) { + ItemStack stack = inv.getStackInSlot(i); + if(stack == null) continue; + NBTTagCompound slot = new NBTTagCompound(); + stack.writeToNBT(slot); + nbt.setTag("slot" + i, slot); + nbt.setInteger("amount" + i, inv.amounts[i]); + } + } + + if(!nbt.hasNoTags()) drop.stackTagCompound = nbt; + world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, drop)); + } + + return world.setBlockToAir(x, y, z); + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) { + + TileEntityPneumoStorageMono inv = (TileEntityPneumoStorageMono) world.getTileEntity(x, y, z); + + if(inv != null && stack.hasTagCompound()) { + for(int i = 0; i < 3; i++) { + inv.setInventorySlotContents(i, ItemStack.loadItemStackFromNBT(stack.stackTagCompound.getCompoundTag("slot" + i))); + inv.amounts[i] = stack.stackTagCompound.getInteger("amount" + i); + } + } + + super.onBlockPlacedBy(world, x, y, z, player, stack); + } } \ No newline at end of file diff --git a/src/main/java/com/hbm/inventory/gui/GUIScreenRadioAUTOCAL.java b/src/main/java/com/hbm/inventory/gui/GUIScreenRadioAUTOCAL.java index b509c167b..3344dec11 100644 --- a/src/main/java/com/hbm/inventory/gui/GUIScreenRadioAUTOCAL.java +++ b/src/main/java/com/hbm/inventory/gui/GUIScreenRadioAUTOCAL.java @@ -64,6 +64,12 @@ public class GUIScreenRadioAUTOCAL extends GuiScreen { @Override public void drawScreen(int mouseX, int mouseY, float f) { + + if(this.autocal == null || this.autocal.isInvalid()) { + Minecraft.getMinecraft().thePlayer.closeScreen(); + return; + } + this.drawDefaultBackground(); this.drawGuiContainerBackgroundLayer(f, mouseX, mouseY); GL11.glDisable(GL11.GL_LIGHTING); diff --git a/src/main/java/com/hbm/module/IParse.java b/src/main/java/com/hbm/module/IParse.java index df96547ee..bc29bdd7f 100644 --- a/src/main/java/com/hbm/module/IParse.java +++ b/src/main/java/com/hbm/module/IParse.java @@ -15,12 +15,59 @@ public interface IParse { public NBTTagCompound variables = new NBTTagCompound(); public HashMap jmp = new HashMap(); - public String buffer = ""; + public static final int MAX_BUFFER_LENGTH = 256; + public static final int MAX_STACK_SIZE = 256; + + private String buffer = ""; + private String[] stack = new String[MAX_STACK_SIZE]; + private int stackSize = 0; + public String splitString = ";"; public int clockSpeed = 1; public int current = 0; public ParseContext(World world) { this.world = world; + + for(int i = 0; i < MAX_STACK_SIZE; i++) stack[i] = ""; + } + + public String readBuffer() { + return this.buffer; + } + + /** Sets the buffer and imposes length restrictions. Returns true if successful, and false if truncation has taken place. */ + public boolean writeBuffer(String buffer) { + + if(buffer.length() > MAX_BUFFER_LENGTH) { + this.buffer = buffer.substring(0, MAX_BUFFER_LENGTH); + return false; + } + + this.buffer = buffer; + return true; + } + + public boolean push(String line) { + if(stackSize >= MAX_STACK_SIZE) return false; + if(line.length() > MAX_BUFFER_LENGTH) line = line.substring(0, MAX_BUFFER_LENGTH); + stack[stackSize] = line; + stackSize++; + return true; + } + + public String pop() { + if(stackSize <= 0) return null; + if(stackSize > MAX_STACK_SIZE) stackSize = MAX_STACK_SIZE; + String ret = stack[stackSize - 1]; + stack[stackSize - 1] = ""; + stackSize--; + return ret; + } + + public String peek() { + if(stackSize <= 0) return null; + if(stackSize > MAX_STACK_SIZE) stackSize = MAX_STACK_SIZE; + return stack[stackSize - 1]; } public void turnOff() { @@ -29,6 +76,30 @@ public interface IParse { this.buffer = ""; if(!this.variables.hasNoTags()) this.variables = new NBTTagCompound(); } + + // NBT R/W is now in control of the CTX, meaning additions to the AUTOCAL runtime should be a lot easier + public void readFromNBT(NBTTagCompound nbt, String[] script, IParse parser) { + current = nbt.getInteger("current"); + clockSpeed = nbt.getInteger("clockSpeed"); + buffer = nbt.getString("buffer"); + splitString = nbt.getString("splitString"); + variables = nbt.getCompoundTag("variables"); + + stackSize = nbt.getInteger("stackSize"); + for(int i = 0; i < MAX_STACK_SIZE; i++) stack[i] = nbt.getString("st" + i); + for(int i = 0; i < script.length; i++) parser.generateJumpPoints(this, script[i], i); + } + + public void writeToNBT(NBTTagCompound nbt) { + nbt.setInteger("current", current); + nbt.setInteger("clockSpeed", clockSpeed); + nbt.setString("buffer", buffer); + nbt.setString("splitString", splitString); + nbt.setTag("variables", variables); + + nbt.setInteger("stackSize", stackSize); + for(int i = 0; i < MAX_STACK_SIZE; i++) nbt.setString("st" + i, stack[i]); + } } public static enum EnumStatementReturn { @@ -45,6 +116,8 @@ public interface IParse { /** Skips the instruction, doesn't use up a clock cycle */ SKIP, /** General undefined behavior */ - UNDEFINED + UNDEFINED, + /** Stack ran full */ + STACK_EXCEEDED } } diff --git a/src/main/java/com/hbm/module/ParseMSES1.java b/src/main/java/com/hbm/module/ParseMSES1.java index 1f9c8c931..1814d3b7c 100644 --- a/src/main/java/com/hbm/module/ParseMSES1.java +++ b/src/main/java/com/hbm/module/ParseMSES1.java @@ -48,7 +48,7 @@ public class ParseMSES1 implements IParse { // sets the script index to the jump point, if the buffer is the string 'true' if(lower.startsWith("jmpif ")) { if(line.length() <= 6) return EnumStatementReturn.PARAMETER_ERROR; - if(!ctx.buffer.equals("true")) return EnumStatementReturn.OK; + if(!ctx.readBuffer().equals("true")) return EnumStatementReturn.OK; String jmpKey = substitute(ctx, line.substring(6), false); if(ctx.jmp.containsKey(jmpKey)) { ctx.current = ctx.jmp.get(jmpKey); @@ -60,7 +60,7 @@ public class ParseMSES1 implements IParse { // sets the script index to the jump point, if the buffer is the NOT 'true' if(lower.startsWith("jmpnot ")) { if(line.length() <= 7) return EnumStatementReturn.PARAMETER_ERROR; - if(ctx.buffer.equals("true")) return EnumStatementReturn.OK; + if(ctx.readBuffer().equals("true")) return EnumStatementReturn.OK; String jmpKey = substitute(ctx, line.substring(7), false); if(ctx.jmp.containsKey(jmpKey)) { ctx.current = ctx.jmp.get(jmpKey); @@ -82,21 +82,21 @@ public class ParseMSES1 implements IParse { // loads the requested variable into the buffer if(lower.startsWith("load ")) { if(line.length() <= 5) return EnumStatementReturn.PARAMETER_ERROR; - ctx.buffer = ctx.variables.getString(line.substring(5)); + ctx.writeBuffer(ctx.variables.getString(line.substring(5))); return EnumStatementReturn.OK; } // saves the buffer with the specified name if(lower.startsWith("save ")) { - if(line.length() <= 5 || ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; - ctx.variables.setString(line.substring(5), ctx.buffer); + if(line.length() <= 5 || ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + ctx.variables.setString(line.substring(5), ctx.readBuffer()); return EnumStatementReturn.OK; } // stores the specified value in the buffer if(lower.startsWith("buffer ")) { if(line.length() <= 7) return EnumStatementReturn.PARAMETER_ERROR; - ctx.buffer = line.substring(7); + ctx.writeBuffer(line.substring(7)); return EnumStatementReturn.OK; } @@ -106,7 +106,7 @@ public class ParseMSES1 implements IParse { String statement = substitute(ctx, line.substring(5), true); try { double result = Calculator.evaluateExpression(statement); - ctx.buffer = "" + result; + ctx.writeBuffer("" + result); } catch(Throwable ex) { return EnumStatementReturn.PARAMETER_ERROR; } return EnumStatementReturn.OK; } @@ -117,115 +117,115 @@ public class ParseMSES1 implements IParse { String statement = substitute(ctx, line.substring(6), true); try { double result = Calculator.evaluateExpression(statement); - ctx.buffer = "" + (int) Math.round(result); + ctx.writeBuffer("" + (int) Math.round(result)); } catch(Throwable ex) { return EnumStatementReturn.PARAMETER_ERROR; } return EnumStatementReturn.OK; } // runs the calculation from the buffer, allows string substitution, saves result to buffer if(lower.equals("evalr")) { - if(ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; - String statement = substitute(ctx, ctx.buffer, true); + if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + String statement = substitute(ctx, ctx.readBuffer(), true); try { double result = Calculator.evaluateExpression(statement); - ctx.buffer = "" + (int) Math.round(result); + ctx.writeBuffer("" + (int) Math.round(result)); } catch(Throwable ex) { return EnumStatementReturn.PARAMETER_ERROR; } return EnumStatementReturn.OK; } // rounds the buffer down to the nearest integer if(lower.equals("rounddown") || lower.equals("floor")) { - if(ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; try { - double d = Double.parseDouble(ctx.buffer); - ctx.buffer = "" + (int) Math.floor(d); + double d = Double.parseDouble(ctx.readBuffer()); + ctx.writeBuffer("" + (int) Math.floor(d)); } catch(Exception ex) { return EnumStatementReturn.PARAMETER_ERROR; } return EnumStatementReturn.OK; } // rounds the buffer up to the nearest integer if(lower.equals("roundup") || lower.equals("ceil")) { - if(ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; try { - double d = Double.parseDouble(ctx.buffer); - ctx.buffer = "" + (int) Math.ceil(d); + double d = Double.parseDouble(ctx.readBuffer()); + ctx.writeBuffer("" + (int) Math.ceil(d)); } catch(Exception ex) { return EnumStatementReturn.PARAMETER_ERROR; } return EnumStatementReturn.OK; } // rounds the buffer to the nearest integer (.5 cutoff rule) if(lower.equals("round") || lower.equals("nearest")) { - if(ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; try { - double d = Double.parseDouble(ctx.buffer); - ctx.buffer = "" + (int) Math.round(d); + double d = Double.parseDouble(ctx.readBuffer()); + ctx.writeBuffer("" + (int) Math.round(d)); } catch(Exception ex) { return EnumStatementReturn.PARAMETER_ERROR; } return EnumStatementReturn.OK; } // concatenate, same as buffer but evaluates $var$ substitutions if(lower.startsWith("concat ")) { - if(line.length() <= 7 || ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + if(line.length() <= 7 || ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; String concat = substitute(ctx, line.substring(7), false); - ctx.buffer = concat; + ctx.writeBuffer(concat); return EnumStatementReturn.OK; } // compares the buffer with a value, allows substitutions if(lower.startsWith("eq ")) { - if(line.length() <= 3 || ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; - ctx.buffer = ctx.buffer.equals(substitute(ctx, line.substring(3), false)) ? "true" : "false"; + if(line.length() <= 3 || ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + ctx.writeBuffer(ctx.readBuffer().equals(substitute(ctx, line.substring(3), false)) ? "true" : "false"); return EnumStatementReturn.OK; } // greater than buffer if(lower.startsWith("gtb ")) { - if(line.length() <= 4 || ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + if(line.length() <= 4 || ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; try { - double buffer = Double.parseDouble(ctx.buffer); + double buffer = Double.parseDouble(ctx.readBuffer()); double val = Double.parseDouble(substitute(ctx, line.substring(4), false)); - ctx.buffer = val > buffer ? "true" : "false"; + ctx.writeBuffer(val > buffer ? "true" : "false"); } catch(Exception ex) { return EnumStatementReturn.PARAMETER_ERROR; } return EnumStatementReturn.OK; } // lower than buffer if(lower.startsWith("ltb ")) { - if(line.length() <= 4 || ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + if(line.length() <= 4 || ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; try { - double buffer = Double.parseDouble(ctx.buffer); + double buffer = Double.parseDouble(ctx.readBuffer()); double val = Double.parseDouble(substitute(ctx, line.substring(4), false)); - ctx.buffer = val < buffer ? "true" : "false"; + ctx.writeBuffer(val < buffer ? "true" : "false"); } catch(Exception ex) { return EnumStatementReturn.PARAMETER_ERROR; } return EnumStatementReturn.OK; } // greater than or equal buffer if(lower.startsWith("geb ")) { - if(line.length() <= 4 || ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + if(line.length() <= 4 || ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; try { - double buffer = Double.parseDouble(ctx.buffer); + double buffer = Double.parseDouble(ctx.readBuffer()); double val = Double.parseDouble(substitute(ctx, line.substring(4), false)); - ctx.buffer = val >= buffer ? "true" : "false"; + ctx.writeBuffer(val >= buffer ? "true" : "false"); } catch(Exception ex) { return EnumStatementReturn.PARAMETER_ERROR; } return EnumStatementReturn.OK; } // lower than or equal buffer if(lower.startsWith("leb ")) { - if(line.length() <= 4 || ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + if(line.length() <= 4 || ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; try { - double buffer = Double.parseDouble(ctx.buffer); + double buffer = Double.parseDouble(ctx.readBuffer()); double val = Double.parseDouble(substitute(ctx, line.substring(4), false)); - ctx.buffer = val <= buffer ? "true" : "false"; + ctx.writeBuffer(val <= buffer ? "true" : "false"); } catch(Exception ex) { return EnumStatementReturn.PARAMETER_ERROR; } return EnumStatementReturn.OK; } // sends an RoR signal using the buffer's contents as the message over the supplied channel if(lower.startsWith("send ")) { - if(line.length() <= 5 || ctx.buffer.isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; - RTTYSystem.broadcast(ctx.world, substitute(ctx, line.substring(5), false), ctx.buffer); + if(line.length() <= 5 || ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + RTTYSystem.broadcast(ctx.world, substitute(ctx, line.substring(5), false), ctx.readBuffer()); return EnumStatementReturn.OK; } @@ -233,7 +233,7 @@ public class ParseMSES1 implements IParse { if(lower.startsWith("listen ")) { if(line.length() <= 7) return EnumStatementReturn.PARAMETER_ERROR; RTTYChannel chan = RTTYSystem.listen(ctx.world, substitute(ctx, line.substring(7), false)); - if(chan != null) ctx.buffer = chan.signal + ""; + if(chan != null) ctx.writeBuffer(chan.signal + ""); return EnumStatementReturn.OK; } @@ -254,7 +254,7 @@ public class ParseMSES1 implements IParse { readingVar = true; } else { if("buffer".equals(var)) { - joined.append(ctx.buffer); + joined.append(ctx.readBuffer()); } else { String variable = ctx.variables.getString(var.toString()); if(forceNumber && variable.isEmpty()) variable = "0"; diff --git a/src/main/java/com/hbm/module/ParseMSES1Ext1.java b/src/main/java/com/hbm/module/ParseMSES1Ext1.java new file mode 100644 index 000000000..072e6ed58 --- /dev/null +++ b/src/main/java/com/hbm/module/ParseMSES1Ext1.java @@ -0,0 +1,82 @@ +package com.hbm.module; + +import java.util.Locale; +import java.util.regex.Pattern; + +/** + * MSES1-FEIS: Machine Script, Equestrian Standard - First Extended Instruction Set (v1.1) + * + * Additions compared to v1 Standard: + * * Support for splitter chars, splitting and split count + * * Support for the stack, a secondary buffer that can push, pop and peek + * + * @author hbm + */ +public class ParseMSES1Ext1 extends ParseMSES1 { + + @Override + public EnumStatementReturn eval(ParseContext ctx, String line) { + String lower = line.toLowerCase(Locale.US); + + // sets the splitter char + if(lower.startsWith("splitter ")) { + if(line.length() <= 9) return EnumStatementReturn.PARAMETER_ERROR; + String splitter = substitute(ctx, line.substring(9), false); + ctx.splitString = splitter; + return EnumStatementReturn.OK; + } + + // grabs a fragment based on index + if(lower.startsWith("split ")) { + if(line.length() <= 6) return EnumStatementReturn.PARAMETER_ERROR; + try { + int index = Integer.parseInt(line.substring(6)); + if(index < 1) return EnumStatementReturn.PARAMETER_ERROR; + String[] frags = ctx.readBuffer().split(Pattern.quote(ctx.splitString)); + if(index > frags.length) return EnumStatementReturn.PARAMETER_ERROR; + ctx.writeBuffer(frags[index - 1]); + return EnumStatementReturn.OK; + } catch(Throwable ex) { return EnumStatementReturn.PARAMETER_ERROR; } + } + + // counts the amount of fragments in this string + if(lower.equals("splitcount")) { + if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + String[] frags = ctx.readBuffer().split(Pattern.quote(ctx.splitString)); + ctx.writeBuffer(frags.length + ""); + return EnumStatementReturn.OK; + } + + // pushes the buffer to stack + if(lower.equals("push")) { + if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + boolean succ = ctx.push(ctx.readBuffer()); + return succ ? EnumStatementReturn.OK : EnumStatementReturn.STACK_EXCEEDED; + } + + // pushes the supplied value (or variable) to stack + if(lower.startsWith("push ")) { + if(line.length() <= 5) return EnumStatementReturn.PARAMETER_ERROR; + boolean succ = ctx.push(substitute(ctx, line.substring(5), false)); + return succ ? EnumStatementReturn.OK : EnumStatementReturn.STACK_EXCEEDED; + } + + // removes the most recent element from stack and writes it to the buffer + if(lower.equals("pop")) { + String val = ctx.pop(); + if(val == null) return EnumStatementReturn.UNDEFINED; + ctx.writeBuffer(val); + return EnumStatementReturn.OK; + } + + // writes the most recent element to the buffer + if(lower.equals("peek")) { + String val = ctx.peek(); + if(val == null) return EnumStatementReturn.UNDEFINED; + ctx.writeBuffer(val); + return EnumStatementReturn.OK; + } + + return super.eval(ctx, line); + } +} diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityRadioAUTOCAL.java b/src/main/java/com/hbm/tileentity/network/TileEntityRadioAUTOCAL.java index b75a4a5b0..0d1de3d5c 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityRadioAUTOCAL.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityRadioAUTOCAL.java @@ -5,7 +5,7 @@ import com.hbm.inventory.gui.GUIScreenRadioAUTOCAL; import com.hbm.module.IParse; import com.hbm.module.IParse.EnumStatementReturn; import com.hbm.module.IParse.ParseContext; -import com.hbm.module.ParseMSES1; +import com.hbm.module.ParseMSES1Ext1; import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.TileEntityTickingBase; import com.hbm.util.BufferUtil; @@ -27,10 +27,8 @@ public class TileEntityRadioAUTOCAL extends TileEntityTickingBase implements ICo public boolean ignoreError = false; public boolean autoReboot = false; - public static final int MAX_BUFFER_LENGTH = 256; - public String[] script = new String[0]; - public IParse msesv1 = new ParseMSES1(); + public IParse msesv1ext = new ParseMSES1Ext1(); public ParseContext ctx; public String[] history = new String[] {"", "", "", "", "", ""}; @@ -69,16 +67,16 @@ public class TileEntityRadioAUTOCAL extends TileEntityTickingBase implements ICo int index = this.ctx.current; this.ctx.current ++; String line = this.script[index]; - EnumStatementReturn ret = msesv1.eval(ctx, line); - if(ctx.buffer.length() > MAX_BUFFER_LENGTH) ctx.buffer = ctx.buffer.substring(0, MAX_BUFFER_LENGTH); + EnumStatementReturn ret = msesv1ext.eval(ctx, line); if(ret != EnumStatementReturn.SKIP) pushMsg(index + ": " + line); - this.history[0] = "Buffer: " + ctx.buffer; + this.history[0] = "Buffer: " + ctx.readBuffer(); if(ret == EnumStatementReturn.END_TICK) break; if(ret == EnumStatementReturn.SHUTDOWN) this.stop("Program requested shutdown"); if(!this.ignoreError) { if(ret == EnumStatementReturn.UNRECOGNIZED_COMMAND) this.stop("Unrecognized command"); if(ret == EnumStatementReturn.PARAMETER_ERROR) this.stop("Parameter error"); if(ret == EnumStatementReturn.UNDEFINED) this.stop("Undefined behavior"); + if(ret == EnumStatementReturn.STACK_EXCEEDED) this.stop("Stack exceeded capacity"); } if(ret == EnumStatementReturn.SKIP) i--; } catch(Exception ex) { @@ -132,19 +130,14 @@ public class TileEntityRadioAUTOCAL extends TileEntityTickingBase implements ICo this.ignoreError = nbt.getBoolean("ignoreError"); this.autoReboot = nbt.getBoolean("autoReboot"); - this.ctx = new ParseContext(null); - this.ctx.current = nbt.getInteger("current"); - this.ctx.clockSpeed = nbt.getInteger("clockSpeed"); - this.ctx.buffer = nbt.getString("buffer"); - NBTTagList lineList = nbt.getTagList("script", 8); this.script = new String[lineList.tagList.size()]; for(int i = 0; i < script.length; i++) { this.script[i] = lineList.getStringTagAt(i); - this.msesv1.generateJumpPoints(ctx, script[i], i); } - - this.ctx.variables = nbt.getCompoundTag("variables"); + + this.ctx = new ParseContext(null); + this.ctx.readFromNBT(nbt, script, msesv1ext); } @Override @@ -154,17 +147,14 @@ public class TileEntityRadioAUTOCAL extends TileEntityTickingBase implements ICo nbt.setBoolean("isOn", isOn); nbt.setBoolean("ignoreError", ignoreError); nbt.setBoolean("autoReboot", autoReboot); - - nbt.setInteger("current", ctx.current); - nbt.setInteger("clockSpeed", ctx.clockSpeed); - nbt.setString("buffer", ctx.buffer); NBTTagList lineList = new NBTTagList(); for(String line : this.script) { lineList.appendTag(new NBTTagString(line)); } nbt.setTag("script", lineList); - nbt.setTag("variables", this.ctx.variables); + + this.ctx.writeToNBT(nbt); } @Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; } @@ -189,7 +179,7 @@ public class TileEntityRadioAUTOCAL extends TileEntityTickingBase implements ICo this.script = data.getString("payload").split("\n"); for(int i = 0; i < script.length; i++) { script[i] = script[i].trim(); - this.msesv1.generateJumpPoints(ctx, script[i], i); + this.msesv1ext.generateJumpPoints(ctx, script[i], i); } if(this.isOn) stop("Script has changed"); } From 85a15f1bbd29ba02109343bfa1acdb25e4f52384 Mon Sep 17 00:00:00 2001 From: Boblet Date: Thu, 25 Jun 2026 13:37:37 +0200 Subject: [PATCH 2/3] MS-ES v1.1 substring and count, pneumo storage exporter --- .../pneumatic/PneumoStorageExporter.java | 3 +- .../java/com/hbm/module/ParseMSES1Ext1.java | 31 ++++++++ .../TileEntityPneumaticMachineBase.java | 69 ++++++++++++++++++ .../TileEntityPneumoStorageExporter.java | 57 +++++++++++++++ .../TileEntityPneumoStorageImporter.java | 55 +------------- .../gui/storage/gui_pneumatic_exporter.png | Bin 0 -> 2154 bytes 6 files changed, 161 insertions(+), 54 deletions(-) create mode 100644 src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumaticMachineBase.java create mode 100644 src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumoStorageExporter.java create mode 100644 src/main/resources/assets/hbm/textures/gui/storage/gui_pneumatic_exporter.png diff --git a/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageExporter.java b/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageExporter.java index 49d0724e4..033447355 100644 --- a/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageExporter.java +++ b/src/main/java/com/hbm/blocks/network/pneumatic/PneumoStorageExporter.java @@ -1,6 +1,7 @@ package com.hbm.blocks.network.pneumatic; import com.hbm.blocks.machine.BlockMachineBase; +import com.hbm.tileentity.network.pneumatic.TileEntityPneumoStorageExporter; import net.minecraft.block.material.Material; import net.minecraft.tileentity.TileEntity; @@ -14,6 +15,6 @@ public class PneumoStorageExporter extends BlockMachineBase { @Override public TileEntity createNewTileEntity(World world, int meta) { - return null; + return new TileEntityPneumoStorageExporter(); } } diff --git a/src/main/java/com/hbm/module/ParseMSES1Ext1.java b/src/main/java/com/hbm/module/ParseMSES1Ext1.java index 072e6ed58..d59ce6ee3 100644 --- a/src/main/java/com/hbm/module/ParseMSES1Ext1.java +++ b/src/main/java/com/hbm/module/ParseMSES1Ext1.java @@ -9,6 +9,7 @@ import java.util.regex.Pattern; * Additions compared to v1 Standard: * * Support for splitter chars, splitting and split count * * Support for the stack, a secondary buffer that can push, pop and peek + * * Support for getting string length and substring using first and last * * @author hbm */ @@ -77,6 +78,36 @@ public class ParseMSES1Ext1 extends ParseMSES1 { return EnumStatementReturn.OK; } + // figures out buffer string's length + if(lower.equals("length")) { + ctx.writeBuffer("" + ctx.readBuffer().length()); + return EnumStatementReturn.OK; + } + + // grabs the first x characters from the buffer and writes them back to the buffer + if(lower.startsWith("first ")) { + if(line.length() <= 6) return EnumStatementReturn.PARAMETER_ERROR; + try { + int length = Integer.parseInt(line.substring(6)); + int max = ctx.readBuffer().length(); + if(length > max) length = max; + ctx.writeBuffer(ctx.readBuffer().substring(0, length)); + return EnumStatementReturn.OK; + } catch(Exception x) { return EnumStatementReturn.PARAMETER_ERROR; } + } + + // grabs the last x characters from the buffer and writes them back to the buffer + if(lower.startsWith("last ")) { + if(line.length() <= 5) return EnumStatementReturn.PARAMETER_ERROR; + try { + int length = Integer.parseInt(line.substring(5)); + int max = ctx.readBuffer().length(); + if(length > max) length = max; + ctx.writeBuffer(ctx.readBuffer().substring(max - length, max)); + return EnumStatementReturn.OK; + } catch(Exception x) { return EnumStatementReturn.PARAMETER_ERROR; } + } + return super.eval(ctx, line); } } diff --git a/src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumaticMachineBase.java b/src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumaticMachineBase.java new file mode 100644 index 000000000..681739cf4 --- /dev/null +++ b/src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumaticMachineBase.java @@ -0,0 +1,69 @@ +package com.hbm.tileentity.network.pneumatic; + +import com.hbm.tileentity.IGUIProvider; +import com.hbm.tileentity.TileEntityMachineBase; +import com.hbm.tileentity.network.pneumatic.TileEntityPneumoTube.PneumaticNode; +import com.hbm.uninos.UniNodespace; +import com.hbm.uninos.networkproviders.PneumaticNetworkProvider; +import com.hbm.util.fauxpointtwelve.BlockPos; + +import api.hbm.ntl.IPneumaticConnector; +import api.hbm.ntl.StackCache; + +public abstract class TileEntityPneumaticMachineBase extends TileEntityMachineBase implements IPneumaticConnector, IGUIProvider { + + protected PneumaticNode node; + public StackCache cache; + + public TileEntityPneumaticMachineBase(int slotCount) { + super(slotCount); + } + + @Override + public void updateEntity() { + + if(!worldObj.isRemote) { + + if(this.node == null || this.node.expired) { + if(this.cache != null) this.cache.dissolveCache(); + + this.node = (PneumaticNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, PneumaticNetworkProvider.THE_PROVIDER); + + if(this.node == null || this.node.expired) { + this.node = (PneumaticNode) new PneumaticNode(new BlockPos(xCoord, yCoord, zCoord)).setStandardConnections(xCoord, yCoord, zCoord); + UniNodespace.createNode(worldObj, this.node); + } + } + + if(this.cache == null || this.cache.hasExpired) { + this.cache = new StackCache(xCoord, yCoord, zCoord); + } + + if(this.node != null && this.node.hasValidNet()) { + this.node.net.addStackCache(cache); + } + } + } + + @Override + public void invalidate() { + super.invalidate(); + + if(!worldObj.isRemote && this.node != null) { + UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, PneumaticNetworkProvider.THE_PROVIDER); + } + + if(this.cache != null) this.cache.dissolveCache(); + } + + @Override + public void onChunkUnload() { + super.onChunkUnload(); + + if(!worldObj.isRemote && this.node != null) { + UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, PneumaticNetworkProvider.THE_PROVIDER); + } + + if(this.cache != null) this.cache.dissolveCache(); + } +} diff --git a/src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumoStorageExporter.java b/src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumoStorageExporter.java new file mode 100644 index 000000000..0bd594d5f --- /dev/null +++ b/src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumoStorageExporter.java @@ -0,0 +1,57 @@ +package com.hbm.tileentity.network.pneumatic; + + +import api.hbm.redstoneoverradio.IRORInteractive; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.world.World; + +public class TileEntityPneumoStorageExporter extends TileEntityPneumaticMachineBase implements IRORInteractive { + + /** If requests should be pulled repeatedly every tick */ + public boolean continuousRequest = false; + /** If ROR configuration has taken place, ignore manually defined filters entirely */ + public boolean rorConfiguredMode = false; + /** What strategy to use for handling request filters */ + public int requestMode = 0; + + /** Each slot individually tries to pull as much as it can of the configured item */ + public static final int MODE_AS_MUCH_AS_POSSIBLE = 0; + /** Each slot individually tries to pull the exact quantity configured */ + public static final int MODE_FULL_STACK = 1; + /** All request slots try to pull the desired quantities simultaneously */ + public static final int MODE_FULL_REQUEST = 2; + + public TileEntityPneumoStorageExporter() { + super(18); + } + + @Override + public String getName() { + return "container.pneumoStorageExporter"; + } + + @Override + public void updateEntity() { + super.updateEntity(); + } + + @Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; } + @Override public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; } + + @Override + public String[] getFunctionInfo() { + return new String[] { + PREFIX_FUNCTION + "setfilter" + NAME_SEPARATOR + "slot" + PARAM_SEPARATOR + "itemid" + PARAM_SEPARATOR + "itemmeta" + PARAM_SEPARATOR + "amount", + PREFIX_FUNCTION + "setcontinuous" + NAME_SEPARATOR + "slot" + PARAM_SEPARATOR + "itemid" + PARAM_SEPARATOR + "itemmeta" + PARAM_SEPARATOR + "amount", + PREFIX_FUNCTION + "request", + PREFIX_FUNCTION + "requestslot" + NAME_SEPARATOR + "slot", + PREFIX_FUNCTION + "checkavailability" + NAME_SEPARATOR + "itemid" + PARAM_SEPARATOR + "itemmeta" + PARAM_SEPARATOR + "returnchannel", + }; + } + + @Override + public String runRORFunction(String name, String[] params) { + return null; + } +} diff --git a/src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumoStorageImporter.java b/src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumoStorageImporter.java index 131486f71..60e5544d8 100644 --- a/src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumoStorageImporter.java +++ b/src/main/java/com/hbm/tileentity/network/pneumatic/TileEntityPneumoStorageImporter.java @@ -2,24 +2,13 @@ package com.hbm.tileentity.network.pneumatic; import com.hbm.inventory.container.ContainerPneumoStorageImporter; import com.hbm.inventory.gui.GUIPneumoStorageImporter; -import com.hbm.tileentity.IGUIProvider; -import com.hbm.tileentity.TileEntityMachineBase; -import com.hbm.tileentity.network.pneumatic.TileEntityPneumoTube.PneumaticNode; -import com.hbm.uninos.UniNodespace; -import com.hbm.uninos.networkproviders.PneumaticNetworkProvider; -import com.hbm.util.fauxpointtwelve.BlockPos; -import api.hbm.ntl.IPneumaticConnector; -import api.hbm.ntl.StackCache; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -public class TileEntityPneumoStorageImporter extends TileEntityMachineBase implements IPneumaticConnector, IGUIProvider { - - protected PneumaticNode node; - public StackCache cache; +public class TileEntityPneumoStorageImporter extends TileEntityPneumaticMachineBase { public int[] delay = new int[9]; public int[] SLOT_ACCESS = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -45,28 +34,10 @@ public class TileEntityPneumoStorageImporter extends TileEntityMachineBase imple @Override public void updateEntity() { + super.updateEntity(); if(!worldObj.isRemote) { - if(this.node == null || this.node.expired) { - if(this.cache != null) this.cache.dissolveCache(); - - this.node = (PneumaticNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, PneumaticNetworkProvider.THE_PROVIDER); - - if(this.node == null || this.node.expired) { - this.node = (PneumaticNode) new PneumaticNode(new BlockPos(xCoord, yCoord, zCoord)).setStandardConnections(xCoord, yCoord, zCoord); - UniNodespace.createNode(worldObj, this.node); - } - } - - if(this.cache == null || this.cache.hasExpired) { - this.cache = new StackCache(xCoord, yCoord, zCoord); - } - - if(this.node != null && this.node.hasValidNet()) { - this.node.net.addStackCache(cache); - } - if(this.cache != null && !this.cache.hasExpired) for(int i = 0; i < 9; i++) { if(this.delay[i] > 0) { this.delay[i]--; @@ -85,28 +56,6 @@ public class TileEntityPneumoStorageImporter extends TileEntityMachineBase imple } } - @Override - public void invalidate() { - super.invalidate(); - - if(!worldObj.isRemote && this.node != null) { - UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, PneumaticNetworkProvider.THE_PROVIDER); - } - - if(this.cache != null) this.cache.dissolveCache(); - } - - @Override - public void onChunkUnload() { - super.onChunkUnload(); - - if(!worldObj.isRemote && this.node != null) { - UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, PneumaticNetworkProvider.THE_PROVIDER); - } - - if(this.cache != null) this.cache.dissolveCache(); - } - @Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { return new ContainerPneumoStorageImporter(player.inventory, this); } @Override public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { return new GUIPneumoStorageImporter(player.inventory, this); } } diff --git a/src/main/resources/assets/hbm/textures/gui/storage/gui_pneumatic_exporter.png b/src/main/resources/assets/hbm/textures/gui/storage/gui_pneumatic_exporter.png new file mode 100644 index 0000000000000000000000000000000000000000..cf6e1177c0b65a22254e7c588b21439848ce1e2a GIT binary patch literal 2154 zcmb_cc~sL$67GbML?lAg5k(@dxZoh_Du)mxL>3Gv1duC$4jAwN29PU3NhF9YFo-bE z5k$pg#m6n8ETCKg*D)f|h~WxXP*xy>a0mt>IrcYuyxsTa_-D7?>#llTT~%NASKZlO zWD-WlPzL~jadUM(4gd@?VE~PU)QR}=Gmt_gIJx35Q&p}PGVUMIWV|Ognd;Y~@5k@F^J;fB z=UK&#y&gez0XM&r*8AHxFTRO9b60@68XckJyY{UX(?>-YX!=z})lVF%BWqv15ZraB zQd!z<%L}tL>f5tne8E;Om;2+@L-J0YA@ZoYX=osg==_{Vr<*>aqObDCgH{g_2-n`9 zr`#v^GkoLh)7iPU8g&)g@^xVW?ATt5gbCzD$Y(?yhkcw3l?3 zzY`@}8IDjUo1*EUIwlg%@~y1a8cy6=8(R&_CwB(S6wd`|vHU9zvBI;r|&{mJys*1J?`MnEHa@e?LIJi;!Zyyi?lrVV~()!LFFQkow{da zc4nqp-d0I?^0*UUSXg+hF-5r&Cu8RF#*eO=S3ImzNX;LkSEkghK^paYgOC^h2=z&# z`7EO%ZH+bs=9>qWO>-<3l*(dzdSvhBJf6$thrY!%aR#j1U08DemUWr+%?fvW_>J<# z>E5a!Ya0(xyWb;&b&V+905*Dm&g53;hdRJngM;xC&9j@tN?zqKlD~936h_?dhx8L_ zMW_{;EcysjzPv0>u}BuVhkKJaZ3{<s zFFgagEQT8PselOrX!F;p8<2V4!@jMVlWpET3?N1vm|gj7EYq*vBh}wXu6S zO&kDcQLhk}pCCB>rHw#Jm=XrmYmIfQQWoZO_C*=H4o&;+H_VN6bQ*kt_e=b!P$VHQ zl@__nKyuud$25bx5oTr%>Br(dT*!-x2BUf^b*y2gzXeT8ig2*J!Y#owV zCX>l9M|&heX6)k#P=EU3rM6fEaPehcYV&mXyxJ}W1Dn&iOg`8}?G8-EPhr%w16mw! zWNLE}%qzIG@!j-ROW+E%^58IXX0Ii%nPxN&d04F;fk@e;HADh$%OzXHW3gs1V#zS_ z+k-i*o(Y>!dJ&9B#lw5wHjoK;_#<;%+NPe0d(p*=LV)8aVdJ66A&esl_Rf6tzsdw-<3wLLR=S z#6Y`4IjMcv9%72J5mEI|&Z+PH$|%?WDsYVc8!`0N zQffkPk@o-AgZB{;2Qj4v17ZSib?}-vq4Z z2(Z%>Y~K$9*=xXmxdw9QFe@W;aqnnHU!T7b4p&j~W-w_RfkA0r*B|_4f)gAZTu-ZQ zZN-sDr0McH8qTxAhWGnlPWGF1RG^`uftr%iEGPGPXVMIvpNAhPa(uo8A%n2Rl2vh1VJ3rIxIYbd+AqXJY7An?To14U!!5 laaU*(((#{d^uNwl;~Je?&D&>Mkyn07<>o?mu5k*z{CBu@uQmVx literal 0 HcmV?d00001 From 24ed4224a8dac19cc4ce1de9d38caa557e82daef Mon Sep 17 00:00:00 2001 From: Boblet Date: Fri, 26 Jun 2026 12:54:35 +0200 Subject: [PATCH 3/3] more MSES crap --- src/main/java/com/hbm/module/ParseMSES1.java | 13 ++++++++++++- src/main/java/com/hbm/module/ParseMSES1Ext1.java | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hbm/module/ParseMSES1.java b/src/main/java/com/hbm/module/ParseMSES1.java index 1814d3b7c..909dc5dd6 100644 --- a/src/main/java/com/hbm/module/ParseMSES1.java +++ b/src/main/java/com/hbm/module/ParseMSES1.java @@ -111,6 +111,17 @@ public class ParseMSES1 implements IParse { return EnumStatementReturn.OK; } + // runs the calculation from the buffer, allows string substitution, saves result to buffer + if(lower.equals("eval")) { + if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + String statement = substitute(ctx, ctx.readBuffer(), true); + try { + double result = Calculator.evaluateExpression(statement); + ctx.writeBuffer("" + result); + } catch(Throwable ex) { return EnumStatementReturn.PARAMETER_ERROR; } + return EnumStatementReturn.OK; + } + // runs the calculation, allows string substitution, rounds, saves result to buffer, if(lower.startsWith("evalr ")) { if(line.length() <= 6) return EnumStatementReturn.PARAMETER_ERROR; @@ -122,7 +133,7 @@ public class ParseMSES1 implements IParse { return EnumStatementReturn.OK; } - // runs the calculation from the buffer, allows string substitution, saves result to buffer + // runs the calculation from the buffer, allows string substitution, saves rounded result to buffer if(lower.equals("evalr")) { if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; String statement = substitute(ctx, ctx.readBuffer(), true); diff --git a/src/main/java/com/hbm/module/ParseMSES1Ext1.java b/src/main/java/com/hbm/module/ParseMSES1Ext1.java index d59ce6ee3..db4a3bc48 100644 --- a/src/main/java/com/hbm/module/ParseMSES1Ext1.java +++ b/src/main/java/com/hbm/module/ParseMSES1Ext1.java @@ -3,6 +3,9 @@ package com.hbm.module; import java.util.Locale; import java.util.regex.Pattern; +import com.hbm.tileentity.network.RTTYSystem; +import com.hbm.tileentity.network.RTTYSystem.RTTYChannel; + /** * MSES1-FEIS: Machine Script, Equestrian Standard - First Extended Instruction Set (v1.1) * @@ -10,6 +13,7 @@ import java.util.regex.Pattern; * * Support for splitter chars, splitting and split count * * Support for the stack, a secondary buffer that can push, pop and peek * * Support for getting string length and substring using first and last + * * Support for listening only to recent RoR signals using poll * * @author hbm */ @@ -108,6 +112,14 @@ public class ParseMSES1Ext1 extends ParseMSES1 { } catch(Exception x) { return EnumStatementReturn.PARAMETER_ERROR; } } + // listens to an RoR signal using the supplied channel name and saves it to the buffer + if(lower.startsWith("poll ")) { + if(line.length() <= 5) return EnumStatementReturn.PARAMETER_ERROR; + RTTYChannel chan = RTTYSystem.listen(ctx.world, substitute(ctx, line.substring(5), false)); + if(chan != null && chan.timeStamp >= ctx.world.getTotalWorldTime() - 1) ctx.writeBuffer(chan.signal + ""); + return EnumStatementReturn.OK; + } + return super.eval(ctx, line); } }