Skip to content

Commit

Permalink
fix negative number parsing for positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Mar 22, 2022
1 parent 9403962 commit 1e39d57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 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 @@ -79,8 +79,8 @@ void testPosEquality() {
@Test
void testLocalPosNoDecimalParsing() {
assertEquals(
BlockNBTComponent.LocalPos.localPos(1.0d, 2.0d, 3.89d),
BlockNBTComponent.Pos.fromString("^1 ^2 ^3.89")
BlockNBTComponent.LocalPos.localPos(1.0d, 2.0d, -3.89d),
BlockNBTComponent.Pos.fromString("^1 ^2 ^-3.89")
);
}

Expand All @@ -95,16 +95,16 @@ void testLocalPosParsing() {
@Test
void testAbsoluteWorldPosParsing() {
assertEquals(
BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.absolute(4), BlockNBTComponent.WorldPos.Coordinate.absolute(5), BlockNBTComponent.WorldPos.Coordinate.absolute(6)),
BlockNBTComponent.Pos.fromString("4 5 6")
BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.absolute(4), BlockNBTComponent.WorldPos.Coordinate.absolute(-5), BlockNBTComponent.WorldPos.Coordinate.absolute(6)),
BlockNBTComponent.Pos.fromString("4 -5 6")
);
}

@Test
void testRelativeWorldPosParsing() {
assertEquals(
BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.relative(7), BlockNBTComponent.WorldPos.Coordinate.relative(83), BlockNBTComponent.WorldPos.Coordinate.relative(900)),
BlockNBTComponent.Pos.fromString("~7 ~83 ~900")
BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.relative(-7), BlockNBTComponent.WorldPos.Coordinate.relative(83), BlockNBTComponent.WorldPos.Coordinate.relative(900)),
BlockNBTComponent.Pos.fromString("~-7 ~83 ~900")
);
}

Expand Down

0 comments on commit 1e39d57

Please sign in to comment.