Skip to content

Instantly share code, notes, and snippets.

@DeltaWhy
Last active August 29, 2015 14:11
Show Gist options
  • Save DeltaWhy/b2a135cbe1eecbe77a6d to your computer and use it in GitHub Desktop.
Save DeltaWhy/b2a135cbe1eecbe77a6d to your computer and use it in GitHub Desktop.
Minecraft 1.8 world updater
#1. Download Khroki/MCEdit-Unified.
#2. Copy this script and your existing Minecraft world into the MCEdit-Unified folder.
#3. Run the script to add the new stone types and regenerate rabbits, horses, and wolves.
from __future__ import print_function
import pymclevel
import pymclevel.minecraft_server
import time
import sys
def playerChunk(world):
x,y,z = world.getPlayerPosition()
return world.getChunk(int(x)>>4, int(z)>>4)
gen = pymclevel.minecraft_server.MCServerChunkGenerator('Release 1.8.1')
world = pymclevel.fromFile("world")
worldTmp = pymclevel.MCInfdevOldLevel("tmp-world", create=True, random_seed=world.RandomSeed)
print("%d chunks in old world"%len(list(world.allChunks)), file=sys.stderr)
print("%d chunks already generated"%len(list(worldTmp.allChunks)), file=sys.stderr)
chunks = list(set(world.allChunks) - set(worldTmp.allChunks))
print("Generating %d chunks..."%(len(chunks)), file=sys.stderr)
startGen = time.time()
progress = 0
for x in gen.generateChunksInLevelIter(worldTmp, chunks):
if x[0] > progress:
progress = x[0]
dt = time.time()-startGen
print("Generated %d of %d (%d:%02d)"%(x[0],x[1],int(dt/60),int(dt%60)), file=sys.stderr)
endGen = time.time()
print("Copying stone from new chunks...", file=sys.stderr)
startCopy = time.time()
progress = 0
total = len(list(world.allChunks))
for cx,cz in world.allChunks:
chunk = world.getChunk(cx,cz)
chunkTmp = worldTmp.getChunk(cx,cz)
selector = (chunk.Blocks == 1) & (chunkTmp.Blocks == 1) & \
(chunk.Data != chunkTmp.Data)
chunk.Data[selector] = chunkTmp.Data[selector]
entities = []
for e in chunkTmp.Entities:
if e['id'].value in [u'Rabbit', u'Wolf', u'EntityHorse']:
entities.append(e)
chunk.addEntities(entities)
chunk.chunkChanged(calcLighting=False)
chunk.close()
progress += 1
dt = time.time()-startCopy
print("Copied %d of %d (%d:%02d)"%(progress, total, int(dt/60),int(dt%60)), file=sys.stderr)
endCopy = time.time()
startSave = time.time()
print("Saving...", file=sys.stderr)
world.saveInPlace()
world.close()
endSave = time.time()
print("Finished generation in %d:%02d"%(int((endGen-startGen)/60),int((endGen-startGen)%60)), file=sys.stderr)
print("Finished copying in %d:%02d"%(int((endCopy-startCopy)/60),int((endCopy-startCopy)%60)), file=sys.stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment