Skip to content

Commit

Permalink
Finished the port to Python 3.4, successful build and test generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjc committed Oct 6, 2015
1 parent c40b203 commit ec0664a
Show file tree
Hide file tree
Showing 31 changed files with 51 additions and 49 deletions.
Empty file added pymclevel/__init__.py
Empty file.
File renamed without changes.
8 changes: 4 additions & 4 deletions block_copy.py → pymclevel/block_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
log = logging.getLogger(__name__)

import numpy
from box import BoundingBox, Vector
from mclevelbase import exhaust
import materials
from entity import Entity, TileEntity
from .box import BoundingBox, Vector
from .mclevelbase import exhaust
from . import materials
from .entity import Entity, TileEntity


def convertBlocks(destLevel, sourceLevel, blocks, blockData):
Expand Down
8 changes: 4 additions & 4 deletions block_fill.py → pymclevel/block_fill.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import logging
import materials
from . import materials

log = logging.getLogger(__name__)

import numpy

from mclevelbase import exhaust
import blockrotation
from entity import TileEntity
from .mclevelbase import exhaust
from . import blockrotation
from .entity import TileEntity

def blockReplaceTable(blocksToReplace):
blocktable = numpy.zeros((materials.id_limit, 16), dtype='bool')
Expand Down
4 changes: 2 additions & 2 deletions blockrotation.py → pymclevel/blockrotation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import materials
from materials import alphaMaterials
from . import materials
from .materials import alphaMaterials
from numpy import arange, zeros


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions entity.py → pymclevel/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
@author: Rio
'''
from math import isnan

import nbt
from copy import deepcopy

from .import nbt

__all__ = ["Entity", "TileEntity"]

class TileEntity(object):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 14 additions & 13 deletions infiniteworld.py → pymclevel/infiniteworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
import zlib
import sys

import blockrotation
from box import BoundingBox
from entity import Entity, TileEntity
from faces import FaceXDecreasing, FaceXIncreasing, FaceZDecreasing, FaceZIncreasing
from level import LightedChunk, EntityLevel, computeChunkHeightMap, MCLevel, ChunkBase
from materials import alphaMaterials
from mclevelbase import ChunkMalformed, ChunkNotPresent, exhaust, PlayerNotFound
import nbt
from numpy import array, clip, maximum, zeros
from regionfile import MCRegionFile

from . import blockrotation
from .box import BoundingBox
from .entity import Entity, TileEntity
from .faces import FaceXDecreasing, FaceXIncreasing, FaceZDecreasing, FaceZIncreasing
from .level import LightedChunk, EntityLevel, computeChunkHeightMap, MCLevel, ChunkBase
from .materials import alphaMaterials
from .mclevelbase import ChunkMalformed, ChunkNotPresent, exhaust, PlayerNotFound
from . import nbt
from .regionfile import MCRegionFile

log = getLogger(__name__)

Expand Down Expand Up @@ -112,7 +113,7 @@ def __init__(self, world, chunkPosition, root_tag = None, create = False):
self.world = world
self.root_tag = root_tag
self.dirty = False

self.Blocks = zeros((16, 16, world.Height), 'uint16')
self.Data = zeros((16, 16, world.Height), 'uint8')
self.BlockLight = zeros((16, 16, world.Height), 'uint8')
Expand Down Expand Up @@ -1015,7 +1016,7 @@ def __init__(self, filename=None, create=False, random_seed=None, last_played=No

self.Length = 0
self.Width = 0
self.Height = 256
self.Height = 128

self.playerTagCache = {}
self.players = []
Expand Down Expand Up @@ -1114,7 +1115,7 @@ def checkSessionLock(self):

lockfile = self.worldFolder.getFilePath("session.lock")
try:
(lock, ) = struct.unpack(">q", file(lockfile, "rb").read())
(lock, ) = struct.unpack(">q", open(lockfile, "rb").read())
except struct.error:
lock = -1
if lock != self.initTime:
Expand Down Expand Up @@ -1220,7 +1221,7 @@ def close(self):
isInfinite = True
parentWorld = None
dimNo = 0
Height = 256
Height = 128
_bounds = None

# --- NBT Tag variables ---
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions level.py → pymclevel/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
@author: Rio
'''

import blockrotation
from box import BoundingBox
from . import blockrotation
from .box import BoundingBox
from collections import defaultdict
from entity import Entity, TileEntity
from .entity import Entity, TileEntity
import itertools
from logging import getLogger
import materials
from . import materials
from math import floor
from mclevelbase import ChunkMalformed, ChunkNotPresent, exhaust
import nbt
from .mclevelbase import ChunkMalformed, ChunkNotPresent, exhaust
from . import nbt
from numpy import argmax, swapaxes, zeros, zeros_like
import os.path

Expand Down Expand Up @@ -354,7 +354,7 @@ def setBlockAt(self, x, y, z, blockID):

# --- Fill and Replace ---

from block_fill import fillBlocks, fillBlocksIter
from .block_fill import fillBlocks, fillBlocksIter

# --- Transformations ---
def rotateLeft(self):
Expand All @@ -379,7 +379,7 @@ def flipEastWest(self):

# --- Copying ---

from block_copy import copyBlocksFrom, copyBlocksFromIter
from .block_copy import copyBlocksFrom, copyBlocksFromIter


def saveInPlace(self):
Expand Down
6 changes: 4 additions & 2 deletions materials.py → pymclevel/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def addYamlBlocksFromFile(self, filename):

log.exception("Failed to read %s using pkg_resources. Trying %s instead." % (filename, path))

f = file(path)
f = open(path)
try:
log.info("Loading block info from %s", f)
blockyaml = yaml.load(f)
Expand Down Expand Up @@ -299,7 +299,9 @@ def addBlock(self, blockID, blockData=0, **kw):
"Stem": 10,
"Top": 5,
}
from faces import FaceXDecreasing, FaceXIncreasing, FaceYIncreasing, FaceZDecreasing, FaceZIncreasing


from .faces import FaceXDecreasing, FaceXIncreasing, FaceYIncreasing, FaceZDecreasing, FaceZIncreasing

Red = (0xD0, 0x70)
Brown = (0xE0, 0x70)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions nbt.py → pymclevel/nbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __repr__(self):
return '<%s name="%s" value=%r>' % (str(self.__class__.__name__), self.name, self.value)

def write_tag(self, buf):
buf.write(chr(self.tagID))
buf.write(struct.pack('>c', bytes([self.tagID])))

def write_name(self, buf):
if self.name is not None:
Expand Down Expand Up @@ -303,7 +303,7 @@ def save(self, filename_or_buf=None, compressed=True):
if self.name is None:
self.name = ''

buf = StringIO()
buf = BytesIO()
self.write_tag(buf)
self.write_name(buf)
self.write_value(buf)
Expand Down Expand Up @@ -331,7 +331,7 @@ def write_value(self, buf):
tag.write_name(buf)
tag.write_value(buf)

buf.write('\x00')
buf.write(bytes([0]))

# --- collection functions ---

Expand Down Expand Up @@ -431,7 +431,7 @@ def load_from(cls, ctx):


def write_value(self, buf):
buf.write(chr(self.list_type))
buf.write(struct.pack('>c', bytes([self.list_type])))
buf.write(TAG_Int.fmt.pack(len(self.value)))
for i in self.value:
i.write_value(buf)
Expand Down Expand Up @@ -537,7 +537,7 @@ def _load_buffer(buf):

__all__ = [a.__name__ for a in tag_classes.values()] + ['load', 'gunzip']

import nbt_util
from . import nbt_util

TAG_Value.__str__ = nbt_util.nested_string

Expand Down
3 changes: 1 addition & 2 deletions nbt_util.py → pymclevel/nbt_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import nbt

def nested_string(tag, indent_string=" ", indent=0):
from . import nbt
result = ""

if tag.tagID == nbt.TAG_COMPOUND:
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions regionfile.py → pymclevel/regionfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from numpy import fromstring
import time
from mclevelbase import notclosing, RegionMalformed, ChunkNotPresent
import nbt
from .mclevelbase import notclosing, RegionMalformed, ChunkNotPresent
from . import nbt

log = logging.getLogger(__name__)

Expand All @@ -24,7 +24,7 @@ class MCRegionFile(object):

@property
def file(self):
openfile = lambda: file(self.path, "rb+")
openfile = lambda: open(self.path, "rb+")
if MCRegionFile.holdFileOpen:
if self._file is None:
self._file = openfile()
Expand All @@ -45,7 +45,7 @@ def __init__(self, path, regionCoords):
self.regionCoords = regionCoords
self._file = None
if not os.path.exists(path):
file(path, "w").close()
open(path, "w").close()

with self.file as f:

Expand All @@ -62,7 +62,7 @@ def __init__(self, path, regionCoords):
offsetsData = f.read(self.SECTOR_BYTES)
modTimesData = f.read(self.SECTOR_BYTES)

self.freeSectors = [True] * (filesize / self.SECTOR_BYTES)
self.freeSectors = [True] * (filesize // self.SECTOR_BYTES)
self.freeSectors[0:2] = False, False

self.offsets = fromstring(offsetsData, dtype='>u4')
Expand Down Expand Up @@ -225,7 +225,7 @@ def _saveChunk(self, cx, cz, data, format):

sectorNumber = offset >> 8
sectorsAllocated = offset & 0xff
sectorsNeeded = (len(data) + self.CHUNK_HEADER_SIZE) / self.SECTOR_BYTES + 1
sectorsNeeded = (len(data) + self.CHUNK_HEADER_SIZE) // self.SECTOR_BYTES + 1

if sectorsNeeded >= 256:
raise ChunkTooBig("Chunk too big! %d bytes exceeds 1MB" % len(data))
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
author_email='[email protected]',
url='https://github.com/mcedit/pymclevel',
license='MIT License',
package_dir={'pymclevel': '.'},
package_dir={'pymclevel': 'pymclevel'},
packages=["pymclevel"],
ext_modules=ext_modules,
include_dirs=numpy.get_include(),
Expand Down

0 comments on commit ec0664a

Please sign in to comment.