Skip to content

Commit

Permalink
Merge pull request #733 from Machine-Maker/fix/negative-positions
Browse files Browse the repository at this point in the history
fix negative number parsing for positions
  • Loading branch information
kashike committed Mar 30, 2022
2 parents 9403962 + b2a00d6 commit b39f15a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -326,8 +326,8 @@ public String toString() {
}

static final class Tokens {
static final Pattern LOCAL_PATTERN = Pattern.compile("^\\^(\\d+(\\.\\d+)?) \\^(\\d+(\\.\\d+)?) \\^(\\d+(\\.\\d+)?)$");
static final Pattern WORLD_PATTERN = Pattern.compile("^(~?)(\\d+) (~?)(\\d+) (~?)(\\d+)$");
static final Pattern LOCAL_PATTERN = Pattern.compile("^\\^(-?\\d+(\\.\\d+)?) \\^(-?\\d+(\\.\\d+)?) \\^(-?\\d+(\\.\\d+)?)$");
static final Pattern WORLD_PATTERN = Pattern.compile("^(~?)(-?\\d+) (~?)(-?\\d+) (~?)(-?\\d+)$");

static final String LOCAL_SYMBOL = "^";
static final String RELATIVE_SYMBOL = "~";
Expand Down
Expand Up @@ -115,4 +115,20 @@ void testWorldPosParsing() {
BlockNBTComponent.Pos.fromString("12 ~3 1200")
);
}

@Test
void testLocalPosParsingWithNegatives() {
assertEquals(
BlockNBTComponent.LocalPos.localPos(-4.5, 3, -35.67),
BlockNBTComponent.Pos.fromString("^-4.5 ^3 ^-35.67")
);
}

@Test
void testWorldPosParsingWithNegatives() {
assertEquals(
BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.relative(-6), BlockNBTComponent.WorldPos.Coordinate.absolute(-34), BlockNBTComponent.WorldPos.Coordinate.relative(13)),
BlockNBTComponent.Pos.fromString("~-6 -34 ~13")
);
}
}

0 comments on commit b39f15a

Please sign in to comment.