Skip to content

Instantly share code, notes, and snippets.

@jkunkee
Created June 29, 2020 00:05
Show Gist options
  • Save jkunkee/71847e1565e2152cf4c1e42b6aa6cd9e to your computer and use it in GitHub Desktop.
Save jkunkee/71847e1565e2152cf4c1e42b6aa6cd9e to your computer and use it in GitHub Desktop.
Minecraft InhabitedTime chunk purge PowerShell script (very slow)
$nbtUtil = "<path to>\NBTUtil.exe"
$saveRoot = "$($env:APPDATA)\.minecraft\saves"
$targetWorldName = "<name of world>"
$worldRoot = "$saveRoot\$targetWorldName"
Get-ChildItem -Recurse -Path "$worldRoot\region" |
#select -Skip 10 -First 1 -last 20 |
% {
$regionFile = $_
Write-Warning "Currently processing $regionFile"
$fileName = $_.FullName
$chunkLines = & $nbtUtil --path="$fileName" --print | findstr Chunk
$chunkLines | % {
$chunkLine = $_
Write-Host "Currently processing $chunkLine"
$fragments = (($chunkLine -isplit '\[')[1] -isplit '\]')[0] -isplit ', '
$x = $fragments[0]
$z = $fragments[1]
# Perform intended operation
$path = "$filename\$x.$z"
$inhabitedTimeString = ((& $nbtUtil --path="$path\Level\InhabitedTime" --print) -isplit ": ")[1]
$inhabitedTime = [Int]::Parse($inhabitedTimeString)
if ($inhabitedTime -eq 0) {
Write-Warning "Deleting $x.$z"
#Write-Warning "Command: $nbtUtil --delete --path=`"$path`""
& $nbtUtil --delete --path="$path"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment