Uploaded image for project: 'Minecraft (Bedrock codebase)'
  1. Minecraft (Bedrock codebase)
  2. MCPE-116447

In animation controllers, commands executions out of order.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • None
    • 1.16.201 Hotfix
    • None
    • Unconfirmed
    • Windows

      1.17.20.21 fixed

      Commands ran through animations now will run in the order defined in animation files on all platforms, including Realms

      Currently, it is suspected that this bug occurs when there are too many commands.

      The JSON is too complex. The size of JSON file is 7 MB. I give you my Java program designed to generate the JSON.
      This animation controller is designed to flip the current chunk by moving blocks and entities from Y=127~0 to Y=128~255.

      It doesn't work.
      But if you delete these lines at the end of my Java program

      write(',');
      write('\"');
      write("/setblock ~" + xNonZeroString + " 255 ~" + zNonZeroString + " bedrock 0 keep");
      write('\"');
      

      it will work.

      Obviously the last command "/setblock x 255 z bedrock 0 keep" is not the last one being executed.
      Then other commands, which should have been executed before, are all invalidated because the existence of the new bedrock.

      import java.io.FileOutputStream;
      import java.io.IOException;
      
      public class Main {
          public static void main(String[] args) {
              (new Main()).writeStates();
          }
      
          private FileOutputStream o = null;
      
          private void write(String string) throws IOException {
              final byte[] s = string.getBytes();
              if (s.length == string.codePointCount(0, string.length())) {
                  o.write(s);
              } else {
                  throw new IOException("multi-byte char");
              }
          }
      
          private void write(char... codeUnits) throws IOException {
              final byte[] s = new byte[codeUnits.length];
              for (int i = 0; i != s.length; i++) {
                  final byte c = ((byte) codeUnits[i]);
                  if (((char) c) == codeUnits[i]) {
                      s[i] = ((byte) codeUnits[i]);
                  } else {
                      throw new IOException("multi-byte char");
                  }
              }
              o.write(s);
          }
      
          private static final String emptyString = new String();
      
          private String nonZeroString(int value) {
              if (value == 0) {
                  return emptyString;
              } else {
                  return Integer.toString(value);
              }
          }
      
          public void writeStates() {
              try {
                  o = new FileOutputStream("player.animation_controllers.json", false);
                  write("{" + "\"format_version\":\"1.10.0\"," + "\"animation_controllers\":{"
                          + "\"controller.animation.player.upside_down\":{" + "\"initial_state\":\"default\","
                          + "\"states\":{");
      
                  states();
      
                  write('}', '}', '}', '}');
                  write('\n');
      
              } catch (IOException e) {
                  e.printStackTrace();
              } finally {
                  try {
                      o.close();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }
      
          private void states() throws IOException {
              write("\"default\":{\"transitions\":[{\"distribute\":\"query.biome_has_any_tag('overworld')\"}]}");
              write(',');
              distribute();
      
              func();
          }
      
          private void distribute() throws IOException {
              write("\"distribute\":{");
              write("\"transitions\":[");
      
              write("{\"default\":\"! query.biome_has_any_tag('overworld')\"}");
              for (byte i = 0; i != 16; i++) {
                  for (byte j = 0; j != 16; j++) {
                      write(',');
                      write('{');
      
                      write('\"');
                      write("x" + i + "z" + j);
                      write('\"', ':', '\"');
                      write("(math.floor(query.position(0)) - (math.floor(query.position(0) / 16) * 16)) == " + i
                              + " && (math.floor(query.position(2)) - (math.floor(query.position(2) / 16) * 16)) == " + j);
                      write('\"');
      
                      write('}');
                  }
              }
      
              write(']');
              write('}');
          }
      
          private void func() throws IOException {
              for (byte i = 0; i != 16; i++) {
                  for (byte j = 0; j != 16; j++) {
                      write(',');
      
                      write("\"x" + i + "z" + j + "\":{");
      
                      write("\"transitions\":[{\"default\":\"1\"}]");
                      write(',');
      
                      cmd(-i, -j);
      
                      write('}');
                  }
              }
          }
      
          private void cmd(int x, int z) throws IOException {
              write("\"on_entry\":[");
      
              byte y = 0;
              final String xNonZeroString = nonZeroString(x);
              final String zNonZeroString = nonZeroString(z);
              while (true) {
                  write('\"');
                  write("/execute @s ~ ~ ~ detect ~" + xNonZeroString + " 255 ~" + zNonZeroString + " air -1 clone ~"
                          + xNonZeroString + " " + (127 - y) + " ~" + zNonZeroString + " ~" + nonZeroString(x + 15) + " "
                          + (127 - y) + " ~" + nonZeroString(z + 15) + " ~" + xNonZeroString + " " + (128 + y) + " ~"
                          + zNonZeroString + " masked move");
                  write('\"');
      
                  write(',');
      
                  write('\"');
                  write("/execute @s ~ ~ ~ detect ~" + xNonZeroString + " 255 ~" + zNonZeroString
                          + " air -1 execute @e[ rm=0, x=~" + xNonZeroString + ", y=" + y + ", z=~" + zNonZeroString
                          + ", dx=15, dy=0, dz=15 ] ~ ~ ~ teleport @s ~ ~" + nonZeroString(255 - ((int) y) * 2) + " ~");
                  write('\"');
      
                  if (y == 127) {
                      break;
                  }
                  y++;
                  write(',');
              }
              ////////////////////////////////////////////////////////////////////////
              write(',');
              write('\"');
              write("/setblock ~" + xNonZeroString + " 255 ~" + zNonZeroString + " bedrock 0 keep");
              write('\"');
              ////////////////////////////////////////////////////////////////////////
      
              write(']');
          }
      }
      

            Worldwidebrine Worldwidebrine
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: