Commit 5681a468 authored by Petter Reinholdtsen's avatar Petter Reinholdtsen

Added 1010-python3.patch porting python library to python 3.

parent 0ba4562f
Description: Port library code to python 3
Author: Petter Reinholdtsen <pere@debian.org>
Origin: https://github.com/sprintingkiwi/pycraft_mod/pull/1
Forwarded: https://github.com/sprintingkiwi/pycraft_mod/pull/1
Reviewed-By: Petter Reinholdtsen <pere@debian.org>
Last-Update: 2018-12-02
--- minetest-mod-pycraft-0.20+git20180331.0376a0a.orig/mcpipy/mcpi/block.py
+++ minetest-mod-pycraft-0.20+git20180331.0376a0a/mcpipy/mcpi/block.py
@@ -1,4 +1,4 @@
-import settings
+from . import settings
class Block:
"""Minecraft PI block description. Can be sent to Minecraft.setBlock/s"""
--- minetest-mod-pycraft-0.20+git20180331.0376a0a.orig/mcpipy/mcpi/connection.py
+++ minetest-mod-pycraft-0.20+git20180331.0376a0a/mcpipy/mcpi/connection.py
@@ -7,7 +7,7 @@ import os
import platform
import base64
from hashlib import md5
-from util import flatten_parameters_to_string
+from .util import flatten_parameters_to_string
""" @author: Aron Nieminen, Mojang AB"""
--- minetest-mod-pycraft-0.20+git20180331.0376a0a.orig/mcpipy/mcpi/event.py
+++ minetest-mod-pycraft-0.20+git20180331.0376a0a/mcpipy/mcpi/event.py
@@ -1,4 +1,4 @@
-from vec3 import Vec3
+from .vec3 import Vec3
class BlockEvent:
"""An Event related to blocks (e.g. placed, removed, hit)"""
--- minetest-mod-pycraft-0.20+git20180331.0376a0a.orig/mcpipy/mcpi/minecraft.py
+++ minetest-mod-pycraft-0.20+git20180331.0376a0a/mcpipy/mcpi/minecraft.py
@@ -1,11 +1,11 @@
-from connection import Connection,RequestError
-from vec3 import Vec3
-from event import BlockEvent,ChatEvent
-from block import Block
+from .connection import Connection,RequestError
+from .vec3 import Vec3
+from .event import BlockEvent,ChatEvent
+from .block import Block
import math
from os import environ
-from util import flatten,floorFlatten
-import security
+from .util import flatten,floorFlatten
+from . import security
""" Minecraft PI low level api v0.1_1
@@ -62,12 +62,12 @@ class CmdPositioner:
def getDirection(self, id):
"""Get entity direction (entityId:int) => Vec3"""
s = self.conn.sendReceive(self.pkg + ".getDirection", id)
- return Vec3(*map(float, s.split(",")))
+ return Vec3(*list(map(float, s.split(","))))
def getPos(self, id):
"""Get entity position (entityId:int) => Vec3"""
s = self.conn.sendReceive(self.pkg + ".getPos", id)
- return Vec3(*map(float, s.split(",")))
+ return Vec3(*list(map(float, s.split(","))))
def setPos(self, id, *args):
"""Set entity position (entityId:int, x,y,z)"""
@@ -88,7 +88,7 @@ class CmdPositioner:
def getTilePos(self, id, *args):
"""Get entity tile position (entityId:int) => Vec3"""
s = self.conn.sendReceive(self.pkg + ".getTile", id)
- return Vec3(*map(int, s.split(",")))
+ return Vec3(*list(map(int, s.split(","))))
def setTilePos(self, id, *args):
"""Set entity tile position (entityId:int) => Vec3"""
@@ -169,7 +169,7 @@ class CmdEvents:
"""Only triggered by sword => [BlockEvent]"""
s = self.conn.sendReceive("events.block.hits")
events = [e for e in s.split("|") if e]
- return [BlockEvent.Hit(*map(int, e.split(","))) for e in events]
+ return [BlockEvent.Hit(*list(map(int, e.split(",")))) for e in events]
def pollChatPosts(self):
"""Triggered by posts to chat => [ChatEvent]"""
@@ -233,7 +233,7 @@ class Minecraft:
def getBlockWithData(self, *args):
"""Get block with data (x,y,z) => Block"""
ans = self.conn.sendReceive_flat("world.getBlockWithData", floorFlatten(args))
- return Block(*map(int, ans.split(",")[:2]))
+ return Block(*list(map(int, ans.split(",")[:2])))
def getBlockWithNBT(self, *args):
"""
@@ -256,7 +256,7 @@ class Minecraft:
"""
def fallbackGetCuboid(self, getBlock, *args):
- (x0,y0,z0,x1,y1,z1) = map(lambda x:int(math.floor(float(x))), flatten(args))
+ (x0,y0,z0,x1,y1,z1) = [int(math.floor(float(x))) for x in flatten(args)]
out = []
for y in range(min(y0,y1),max(y0,y1)+1):
for x in range(min(x0,x1),max(x0,x1)+1):
@@ -280,7 +280,7 @@ class Minecraft:
"""
try:
ans = self.conn.sendReceive_flat("world.getBlocks", floorFlatten(args))
- return map(int, ans.split(","))
+ return list(map(int, ans.split(",")))
except:
self.getBlocks = self.fallbackGetBlocks
return self.fallbackGetBlocks(*args)
@@ -289,7 +289,7 @@ class Minecraft:
"""Get a cuboid of blocks (x0,y0,z0,x1,y1,z1) => [Block(id:int, meta:int)]"""
try:
ans = self.conn.sendReceive_flat("world.getBlocksWithData", floorFlatten(args))
- return [Block(*map(int, x.split(",")[:2])) for x in ans.split("|")]
+ return [Block(*list(map(int, x.split(",")[:2]))) for x in ans.split("|")]
except:
self.getBlocksWithData = self.fallbackGetBlocksWithData
return self.fallbackGetBlocksWithData(*args)
@@ -348,7 +348,7 @@ class Minecraft:
def getPlayerEntityIds(self):
"""Get the entity ids of the connected players => [id:int]"""
ids = self.conn.sendReceive("world.getPlayerIds")
- return map(int, ids.split("|"))
+ return list(map(int, ids.split("|")))
def saveCheckpoint(self):
"""Save a checkpoint that can be used for restoring the world"""
--- minetest-mod-pycraft-0.20+git20180331.0376a0a.orig/mcpipy/mcpi/nbt.py
+++ minetest-mod-pycraft-0.20+git20180331.0376a0a/mcpipy/mcpi/nbt.py
@@ -29,11 +29,11 @@ from collections import MutableMapping,
import os, io
try:
- unicode
- basestring
+ str
+ str
except NameError:
- unicode = str # compatibility for Python 3
- basestring = str # compatibility for Python 3
+ str = str # compatibility for Python 3
+ str = str # compatibility for Python 3
TAG_END = 0
@@ -76,7 +76,7 @@ class TAG(object):
": " + self.valuestr()
def valuestr(self):
"""Return Unicode string of unnested value. For iterators, this returns a summary."""
- return unicode(self.value)
+ return str(self.value)
def pretty_tree(self, indent=0):
"""Return formated Unicode string of self, where iterable items are recursively listed in detail."""
@@ -85,7 +85,7 @@ class TAG(object):
# Python 2 compatibility; Python 3 uses __str__ instead.
def __unicode__(self):
"""Return a unicode string with the result in human readable format. Unlike valuestr(), the result is recursive for iterators till at least one level deep."""
- return unicode(self.value)
+ return str(self.value)
def __str__(self):
"""Return a string (ascii formated for Python 2, unicode for Python 3) with the result in human readable format. Unlike valuestr(), the result is recursive for iterators till at least one level deep."""
@@ -208,7 +208,7 @@ class TAG_Byte_Array(TAG, MutableSequenc
return "[%i byte(s)]" % len(self.value)
def __unicode__(self):
- return '['+",".join([unicode(x) for x in self.value])+']'
+ return '['+",".join([str(x) for x in self.value])+']'
def __str__(self):
return '['+",".join([str(x) for x in self.value])+']'
@@ -435,7 +435,7 @@ class TAG_Compound(TAG, MutableMapping):
def __contains__(self, key):
if isinstance(key, int):
return key <= len(self.tags)
- elif isinstance(key, basestring):
+ elif isinstance(key, str):
for tag in self.tags:
if tag.name == key:
return True
@@ -447,7 +447,7 @@ class TAG_Compound(TAG, MutableMapping):
def __getitem__(self, key):
if isinstance(key, int):
return self.tags[key]
- elif isinstance(key, basestring):
+ elif isinstance(key, str):
for tag in self.tags:
if tag.name == key:
return tag
@@ -461,7 +461,7 @@ class TAG_Compound(TAG, MutableMapping):
if isinstance(key, int):
# Just try it. The proper error will be raised if it doesn't work.
self.tags[key] = value
- elif isinstance(key, basestring):
+ elif isinstance(key, str):
value.name = key
for i, tag in enumerate(self.tags):
if tag.name == key:
@@ -472,7 +472,7 @@ class TAG_Compound(TAG, MutableMapping):
def __delitem__(self, key):
if isinstance(key, int):
del(self.tags[key])
- elif isinstance(key, basestring):
+ elif isinstance(key, str):
self.tags.remove(self.__getitem__(key))
else:
raise ValueError("key needs to be either name of tag, or index of tag")
@@ -621,4 +621,4 @@ class NBTFile(TAG_Compound):
TAG_Compound.__name__, self.name, id(self))
if __name__=="__main__":
- print "NBT library"
\ No newline at end of file
+ print("NBT library")
--- minetest-mod-pycraft-0.20+git20180331.0376a0a.orig/mcpipy/mcpi/util.py
+++ minetest-mod-pycraft-0.20+git20180331.0376a0a/mcpipy/mcpi/util.py
@@ -3,7 +3,7 @@ import math
def flatten(l):
for e in l:
- if isinstance(e, collections.Iterable) and not isinstance(e, basestring):
+ if isinstance(e, collections.Iterable) and not isinstance(e, str):
for ee in flatten(e): yield ee
else: yield e
1000-busted-test.patch
1010-python3.patch
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment