Skip to content

Instantly share code, notes, and snippets.

@132ikl
Created March 25, 2020 05:54
Show Gist options
  • Save 132ikl/623d7aa1ef83007137dac7a9cf786e34 to your computer and use it in GitHub Desktop.
Save 132ikl/623d7aa1ef83007137dac7a9cf786e34 to your computer and use it in GitHub Desktop.
Minecraft script to move a player's location, without using an external NBT editor
#include <iostream>
#include <cstdio>
int main(int argc, char **argv) {
double a;
std::cin >> a;
union
{
long long i;
double d;
} conv;
conv.d = a;
printf("%016llx", conv.i);
return 0;
}
#!/bin/bash -e
if [ -z $2 ] || [ $1 == "-h" ]; then
echo "usage: $(basename $0) <world folder> <username> [x] [y] [z] [dim]"
echo "Default is 0, 70, 0 in Overworld (Dim 0)"
exit 0;
fi
if [ ! -z $3 ]; then x=$3; else x=0; fi
if [ ! -z $4 ]; then y=$4; else y=70; fi
if [ ! -z $5 ]; then z=$5; else z=0; fi
if [ ! -z $6 ]; then d=$6; else d=0; fi
# Get user's FILE, then decompress it
U="$(curl -s https://api.mojang.com/users/profiles/minecraft/$2 | jq -r '.["id"]')"
UUID=$(echo ${U:0:8}-${U:8:4}-${U:12:4}-${U:16:4}-${U:20:12})
FILE="$1/playerdata/$UUID"
cp "$FILE.dat" "$FILE.dat-bak"
cat "$FILE.dat" | gunzip > "$FILE.bin"
d=$(printf '%08x\n' $d | cut -c1-8)
# use last 8 chars because bash thinks 08 means 16
xxd -p "$FILE.bin" | tr -d '\n' | sed -r "s/(03000944696d656e73696f6e)[a-fA-F0-9]{8}(.+)/\1${d:(-8)}\2/" | xxd -p -r > "$FILE.bin.temp"
mv "$FILE.bin.temp" "$FILE.bin"
g++ double2hex.cpp -o double2hex
x=$(echo $x | ./double2hex)
y=$(echo $y | ./double2hex)
z=$(echo $z | ./double2hex)
xxd -p "$FILE.bin" | tr -d '\n' | sed -r "s/(090003506f73[a-fA-F0-9]{10})[a-fA-F0-9]{48}(.+)/\1$x$y$z\2/" | xxd -p -r > "$FILE.bin.temp"
mv "$FILE.bin.temp" "$FILE.bin"
cat "$FILE.bin" | gzip > "$FILE.dat"
rm "$FILE.bin"
rm ./double2hex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment