Skip to content

Commit

Permalink
Add sanity-check for min/max expected minecraft region coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Jan 6, 2025
1 parent 77e793c commit 0a1dbbe
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,17 @@ public String getRegionFileName(int regionX, int regionZ) {
public @Nullable Vector2i getRegionFromFileName(String fileName) {
Matcher matcher = regionFileNamePattern.matcher(fileName);
if (!matcher.matches()) return null;
return new Vector2i(
Integer.parseInt(matcher.group(1)),
Integer.parseInt(matcher.group(2))
);

int regionX = Integer.parseInt(matcher.group(1));
int regionZ = Integer.parseInt(matcher.group(2));

// sanity-check for roughly minecraft max boundaries (-30 000 000 to 30 000 000)
if (
regionX < -100000 || regionX > 100000 ||
regionZ < -100000 || regionZ > 100000
) return null;

return new Vector2i(regionX, regionZ);
}

}
Expand Down

0 comments on commit 0a1dbbe

Please sign in to comment.