forked from mcedit/pymclevel
-
Notifications
You must be signed in to change notification settings - Fork 5
/
mclevelbase.py
115 lines (88 loc) · 2.97 KB
/
mclevelbase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'''
Created on Jul 22, 2011
@author: Rio
'''
import os
import traceback
from datetime import datetime
from cStringIO import StringIO
from copy import deepcopy
import itertools
from contextlib import closing, contextmanager
import gzip
from numpy import *
import logging
import nbt
from nbt import *
from box import BoundingBox, FloatBox
from materials import *
import blockrotation
from entity import *
from faces import *
#String constants for common tag names
log = logging.getLogger(__name__)
warn, error, info, debug = log.warn, log.error, log.info, log.debug
Entities = "Entities"
TileEntities = "TileEntities"
Map = "Map"
Width = "Width"
Height = "Height"
Length = "Length"
Blocks = "Blocks"
Data = "Data"
Inventory = 'Inventory'
@contextmanager
def notclosing(f):
yield f
def decompress_first(func):
def dec_first(self, *args, **kw):
self.decompress()
return func(self, *args, **kw)
dec_first.__doc__ = func.__doc__
return dec_first
def unpack_first(func):
def upk_first(self, *args, **kw):
self.unpackChunkData()
return func(self, *args, **kw)
upk_first.__doc__ = func.__doc__
return upk_first
class PlayerNotFound(Exception): pass
class ChunkNotPresent(Exception): pass
class RegionMalformed(Exception): pass
class ChunkMalformed(ChunkNotPresent): pass
def exhaust(_iter):
"""Functions named ending in "Iter" return an iterable object that does
long-running work and yields progress information on each call. exhaust()
is used to implement the non-Iter equivalents"""
i = None
for i in _iter:
pass
return i
# we need to decode file paths from environment variables or else we get an error
# if they are formatted or joined to a unicode string
import sys
if sys.platform == "win32":
#not sure why win32com is needed if the %APPDATA% var is available
try:
import win32com.client
objShell = win32com.client.Dispatch("WScript.Shell")
appDataDir = objShell.SpecialFolders("AppData")
except Exception, e:
print "Error while getting AppData folder using WScript.Shell.SpecialFolders: {0!r}".format(e)
try:
from win32com.shell import shell, shellcon
appDataDir = shell.SHGetPathFromIDListEx (
shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_APPDATA)
)
except Exception, e:
print "Error while getting AppData folder using SHGetSpecialFolderLocation: {0!r}".format(e)
appDataDir = os.environ['APPDATA'].decode(sys.getfilesystemencoding())
minecraftDir = os.path.join(appDataDir, u".minecraft")
elif sys.platform == "darwin":
appDataDir = os.path.expanduser(u"~/Library/Application Support")
minecraftDir = os.path.join(appDataDir, u"minecraft")
minecraftDir.decode(sys.getfilesystemencoding())
else:
appDataDir = os.path.expanduser(u"~")
minecraftDir = os.path.expanduser(u"~/.minecraft")
saveFileDir = os.path.join(minecraftDir, u"saves")