Issues with motion in plugin

Discussion in 'Plugin Development' started by lukejw, Feb 27, 2024.

  1. Offline

    lukejw

    i have spent about 10 days working on this plugin that would add /motion to minecraft
    right now i am clueless on what to do now, right now the only thing that works is ^ ^1 ^ or any other y values, but any other value like ^ ^ ^1, ^1 ^ ^, ~ ~ ~1, ~ ~1 ~, ~1 ~ ~ ect dont work at all, and i have no idea how to continue or what to do
    heres the code
    https://pastebin.com/ZwR7mZ5j
    any help is greatly appreciated!!!!!
    also i left some notes in the code so you can get an idea of what some of it does
     
  2. Offline

    KarimAKL

    @lukejw I skimmed through the code, and it looks to me like you're passing each argument to the method that handles the relative motion.
    Code:Java
    1. // Parse the motion values for dx, dy, and dz using parseMotionValue method
    2. Vector dxVector = parseMotionValue(player, args[1]);
    3. Vector dyVector = parseMotionValue(player, args[2]);
    4. Vector dzVector = parseMotionValue(player, args[3]);

    Afterwards, you split the argument at each '^' character.
    Code:Java
    1. ...else if (value.startsWith("^")) {
    2. // Handle ^ ^ ^ for relative motion
    3. String[] components = value.split("\\^");
    4. for (int i = 1; i < components.length; i++) {
    5. if (!components[ i ].isEmpty()) {
    6. double offset = Double.parseDouble(components);
    7. switch (i - 1) {
    8. case 0:
    9. offsetY = offset;
    10. break;
    11. case 1:
    12. offsetZ = offset;
    13. break;
    14. case 2:
    15. offsetX = offset;
    16. break;
    17. }
    18. }
    19. }
    20. }...

    Because the 'value' is just one argument, it will always have just 1 '^' character which means 'components' always has a length of 2, an empty string (before the '^' character) and the number following the '^' character. Starting the for-loop at index 1 therefore always iterates only once, for the number. The switch statement will then only have have the value 0 which sets the Y-offset.
     
  3. Offline

    lukejw

    oh! thanks a ton i didnt even see this!
     
    KarimAKL likes this.

Share This Page