fix: allow minecraft patch versions to have 2 digits

patch includes game drops now but whatever
This commit is contained in:
trafficlunar 2025-10-08 17:54:25 +01:00
parent a27f529276
commit e7dd18bbc0
4 changed files with 30 additions and 31 deletions

View file

@ -10,7 +10,7 @@ import { numberToVersion, versionToNumber } from "@/utils/version";
import { HistoryContext } from "@/context/History";
const versions = [
"1.21.9",
"1.21.10",
"1.21.4",
"1.21",
"1.20",

View file

@ -33,7 +33,7 @@ export const CanvasProvider = ({ children }: Props) => {
const [blocks, setBlocks] = useState<Block[]>(welcomeBlocksData);
const [coords, setCoords] = useState<Position>({ x: 0, y: 0 });
const [scale, setScale] = useState(1);
const [version, setVersion] = useState(1219);
const [version, setVersion] = useState(12110);
// Get the farthest away blocks in each direction
const canvasSize = useMemo(() => {

View file

@ -1,17 +1,17 @@
{
"1219": 4440,
"1214": 4189,
"1210": 3953,
"1200": 3463,
"1190": 3105,
"1180": 2860,
"1170": 2724,
"1160": 2566,
"1150": 2225,
"1140": 1952,
"1130": 1519,
"1120": 1139,
"1110": 819,
"1000": 510,
"1090": 169
"12110": 4440,
"12104": 4189,
"12100": 3953,
"12000": 3463,
"11900": 3105,
"11800": 2860,
"11700": 2724,
"11600": 2566,
"11500": 2225,
"11400": 1952,
"11300": 1519,
"11200": 1139,
"11100": 819,
"10000": 510,
"10900": 169
}

View file

@ -1,18 +1,17 @@
export function versionToNumber(version: string) {
const parts = version.split(".").map(Number);
return parts[0] * 1000 + (parts[1] || 0) * 10 + (parts[2] || 0);
// For Minecraft versions
// 12110 = 1.21.10
// 12109 = 1.21.9
export function versionToNumber(version: string): number {
const [major, minor = 0, patch = 0] = version.split(".").map(Number);
return major * 10000 + minor * 100 + patch;
}
export function numberToVersion(version: number) {
const major = Math.floor(version / 1000);
const minor = version % 1000; // Remainder becomes the minor and patch version
export function numberToVersion(version: number): string {
const major = Math.floor(version / 10000);
const minor = Math.floor((version % 10000) / 100);
const patch = version % 100;
// If minor is a multiple of 10, it's just minor with no patch
if (minor % 10 === 0) {
return `${major}.${Math.floor(minor / 10)}`;
}
// Otherwise, split into minor and patch
const patch = minor % 10;
return `${major}.${Math.floor(minor / 10)}.${patch}`;
if (patch === 0) return `${major}.${minor}`;
return `${major}.${minor}.${patch}`;
}