Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-264620

'merge string' subcommand always causes an error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.20.1, 23w31a
    • Community Consensus
    • Commands
    • Low
    • Platform

      Trying to get a command to succeed with the subcommand `merge string` is impossible.
      No matter what data you try to input, the command will always result in an error.

      Example:

      # Storage 'minecraft:strings' has this data: {Z:{ExistingData:"bla"},S:'{Data:"NBTString"}',C:{Data:"NBTCompound"},V:"StringValue"}
      # Running this would give error: `Expected object, got: '{Data:"NBTString"}'`
      /data modify storage minecraft:strings Z merge string storage minecraft:strings S
      
      # Running this would give error: `Expected value, got: {Data:"NBTCompound"}`
      /data modify storage minecraft:strings Z merge string storage minecraft:strings C
      
      # Running this would give error: `Expected object, got: "StringValue"`
      /data modify storage minecraft:strings Z merge string storage minecraft:strings V

      This is because the sub command `string` expects Type 'string' as input and produces Type 'string' as output.
      While sub command `merge` expects Type 'compound' as input and merges it with an existing compound producing another compound.

      From this logic, we get that any `merge string` usage with any inputs will always result in errors, because the `string` sub command would always supply a string typed value to the `merge` sub command.

      My suggestion
      A: remove this syntax suggestion and give the appropriate error that 'string' is not an expected sub command, use (from|value) instead.

      B: Make the behavior of `merge string` work (and useful), by interpreting the resulting string as NBT. Only if the string is a valid compound e.g. '{Valid:1b}' will it merge this data by treating it as {Valid:1b}. Any invalid NBT or non-compound e.g. '{Invalid}' or '[0, 1, 2]' cannot be merged. This means calling `... merge string 4 -4` with 'pre {Valid:1b} suf' would properly substring into '{Valid:1b}' which can be interpreted as NBT compound and be merged into whatever it is you want it merged in.

            Unassigned Unassigned
            m124367 AgentM
            Votes:
            3 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              CHK: