Skip to content

Commit 1a84868

Browse files
dos2unix on everything
2to3 spits out unix line endings, and I want the 2to3 commit to be minimal
1 parent dac1e16 commit 1a84868

File tree

6 files changed

+461
-461
lines changed

6 files changed

+461
-461
lines changed

api/python/mcpi/block.py

Lines changed: 94 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,94 @@
1-
class Block:
2-
"""Minecraft PI block description. Can be sent to Minecraft.setBlock/s"""
3-
def __init__(self, id, data=0):
4-
self.id = id
5-
self.data = data
6-
7-
def __cmp__(self, rhs):
8-
return hash(self) - hash(rhs)
9-
10-
def __hash__(self):
11-
return (self.id << 8) + self.data
12-
13-
def withData(self, data):
14-
return Block(self.id, data)
15-
16-
def __iter__(self):
17-
"""Allows a Block to be sent whenever id [and data] is needed"""
18-
return iter((self.id, self.data))
19-
20-
def __repr__(self):
21-
return "Block(%d, %d)"%(self.id, self.data)
22-
23-
AIR = Block(0)
24-
STONE = Block(1)
25-
GRASS = Block(2)
26-
DIRT = Block(3)
27-
COBBLESTONE = Block(4)
28-
WOOD_PLANKS = Block(5)
29-
SAPLING = Block(6)
30-
BEDROCK = Block(7)
31-
WATER_FLOWING = Block(8)
32-
WATER = WATER_FLOWING
33-
WATER_STATIONARY = Block(9)
34-
LAVA_FLOWING = Block(10)
35-
LAVA = LAVA_FLOWING
36-
LAVA_STATIONARY = Block(11)
37-
SAND = Block(12)
38-
GRAVEL = Block(13)
39-
GOLD_ORE = Block(14)
40-
IRON_ORE = Block(15)
41-
COAL_ORE = Block(16)
42-
WOOD = Block(17)
43-
LEAVES = Block(18)
44-
GLASS = Block(20)
45-
LAPIS_LAZULI_ORE = Block(21)
46-
LAPIS_LAZULI_BLOCK = Block(22)
47-
SANDSTONE = Block(24)
48-
BED = Block(26)
49-
COBWEB = Block(30)
50-
GRASS_TALL = Block(31)
51-
WOOL = Block(35)
52-
FLOWER_YELLOW = Block(37)
53-
FLOWER_CYAN = Block(38)
54-
MUSHROOM_BROWN = Block(39)
55-
MUSHROOM_RED = Block(40)
56-
GOLD_BLOCK = Block(41)
57-
IRON_BLOCK = Block(42)
58-
STONE_SLAB_DOUBLE = Block(43)
59-
STONE_SLAB = Block(44)
60-
BRICK_BLOCK = Block(45)
61-
TNT = Block(46)
62-
BOOKSHELF = Block(47)
63-
MOSS_STONE = Block(48)
64-
OBSIDIAN = Block(49)
65-
TORCH = Block(50)
66-
FIRE = Block(51)
67-
STAIRS_WOOD = Block(53)
68-
CHEST = Block(54)
69-
DIAMOND_ORE = Block(56)
70-
DIAMOND_BLOCK = Block(57)
71-
CRAFTING_TABLE = Block(58)
72-
FARMLAND = Block(60)
73-
FURNACE_INACTIVE = Block(61)
74-
FURNACE_ACTIVE = Block(62)
75-
DOOR_WOOD = Block(64)
76-
LADDER = Block(65)
77-
STAIRS_COBBLESTONE = Block(67)
78-
DOOR_IRON = Block(71)
79-
REDSTONE_ORE = Block(73)
80-
SNOW = Block(78)
81-
ICE = Block(79)
82-
SNOW_BLOCK = Block(80)
83-
CACTUS = Block(81)
84-
CLAY = Block(82)
85-
SUGAR_CANE = Block(83)
86-
FENCE = Block(85)
87-
GLOWSTONE_BLOCK = Block(89)
88-
BEDROCK_INVISIBLE = Block(95)
89-
STONE_BRICK = Block(98)
90-
GLASS_PANE = Block(102)
91-
MELON = Block(103)
92-
FENCE_GATE = Block(107)
93-
GLOWING_OBSIDIAN = Block(246)
94-
NETHER_REACTOR_CORE = Block(247)
1+
class Block:
2+
"""Minecraft PI block description. Can be sent to Minecraft.setBlock/s"""
3+
def __init__(self, id, data=0):
4+
self.id = id
5+
self.data = data
6+
7+
def __cmp__(self, rhs):
8+
return hash(self) - hash(rhs)
9+
10+
def __hash__(self):
11+
return (self.id << 8) + self.data
12+
13+
def withData(self, data):
14+
return Block(self.id, data)
15+
16+
def __iter__(self):
17+
"""Allows a Block to be sent whenever id [and data] is needed"""
18+
return iter((self.id, self.data))
19+
20+
def __repr__(self):
21+
return "Block(%d, %d)"%(self.id, self.data)
22+
23+
AIR = Block(0)
24+
STONE = Block(1)
25+
GRASS = Block(2)
26+
DIRT = Block(3)
27+
COBBLESTONE = Block(4)
28+
WOOD_PLANKS = Block(5)
29+
SAPLING = Block(6)
30+
BEDROCK = Block(7)
31+
WATER_FLOWING = Block(8)
32+
WATER = WATER_FLOWING
33+
WATER_STATIONARY = Block(9)
34+
LAVA_FLOWING = Block(10)
35+
LAVA = LAVA_FLOWING
36+
LAVA_STATIONARY = Block(11)
37+
SAND = Block(12)
38+
GRAVEL = Block(13)
39+
GOLD_ORE = Block(14)
40+
IRON_ORE = Block(15)
41+
COAL_ORE = Block(16)
42+
WOOD = Block(17)
43+
LEAVES = Block(18)
44+
GLASS = Block(20)
45+
LAPIS_LAZULI_ORE = Block(21)
46+
LAPIS_LAZULI_BLOCK = Block(22)
47+
SANDSTONE = Block(24)
48+
BED = Block(26)
49+
COBWEB = Block(30)
50+
GRASS_TALL = Block(31)
51+
WOOL = Block(35)
52+
FLOWER_YELLOW = Block(37)
53+
FLOWER_CYAN = Block(38)
54+
MUSHROOM_BROWN = Block(39)
55+
MUSHROOM_RED = Block(40)
56+
GOLD_BLOCK = Block(41)
57+
IRON_BLOCK = Block(42)
58+
STONE_SLAB_DOUBLE = Block(43)
59+
STONE_SLAB = Block(44)
60+
BRICK_BLOCK = Block(45)
61+
TNT = Block(46)
62+
BOOKSHELF = Block(47)
63+
MOSS_STONE = Block(48)
64+
OBSIDIAN = Block(49)
65+
TORCH = Block(50)
66+
FIRE = Block(51)
67+
STAIRS_WOOD = Block(53)
68+
CHEST = Block(54)
69+
DIAMOND_ORE = Block(56)
70+
DIAMOND_BLOCK = Block(57)
71+
CRAFTING_TABLE = Block(58)
72+
FARMLAND = Block(60)
73+
FURNACE_INACTIVE = Block(61)
74+
FURNACE_ACTIVE = Block(62)
75+
DOOR_WOOD = Block(64)
76+
LADDER = Block(65)
77+
STAIRS_COBBLESTONE = Block(67)
78+
DOOR_IRON = Block(71)
79+
REDSTONE_ORE = Block(73)
80+
SNOW = Block(78)
81+
ICE = Block(79)
82+
SNOW_BLOCK = Block(80)
83+
CACTUS = Block(81)
84+
CLAY = Block(82)
85+
SUGAR_CANE = Block(83)
86+
FENCE = Block(85)
87+
GLOWSTONE_BLOCK = Block(89)
88+
BEDROCK_INVISIBLE = Block(95)
89+
STONE_BRICK = Block(98)
90+
GLASS_PANE = Block(102)
91+
MELON = Block(103)
92+
FENCE_GATE = Block(107)
93+
GLOWING_OBSIDIAN = Block(246)
94+
NETHER_REACTOR_CORE = Block(247)

api/python/mcpi/connection.py

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
import socket
2-
import select
3-
import sys
4-
from util import flatten_parameters_to_string
5-
6-
""" @author: Aron Nieminen, Mojang AB"""
7-
8-
class RequestError(Exception):
9-
pass
10-
11-
class Connection:
12-
"""Connection to a Minecraft Pi game"""
13-
RequestFailed = "Fail"
14-
15-
def __init__(self, address, port):
16-
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
17-
self.socket.connect((address, port))
18-
self.lastSent = ""
19-
20-
def drain(self):
21-
"""Drains the socket of incoming data"""
22-
while True:
23-
readable, _, _ = select.select([self.socket], [], [], 0.0)
24-
if not readable:
25-
break
26-
data = self.socket.recv(1500)
27-
e = "Drained Data: <%s>\n"%data.strip()
28-
e += "Last Message: <%s>\n"%self.lastSent.strip()
29-
sys.stderr.write(e)
30-
31-
def send(self, f, *data):
32-
"""Sends data. Note that a trailing newline '\n' is added here"""
33-
s = "%s(%s)\n"%(f, flatten_parameters_to_string(data))
34-
#print "f,data:",f,data
35-
#print "s",s
36-
self.drain()
37-
self.lastSent = s
38-
self.socket.sendall(s)
39-
40-
def receive(self):
41-
"""Receives data. Note that the trailing newline '\n' is trimmed"""
42-
s = self.socket.makefile("r").readline().rstrip("\n")
43-
if s == Connection.RequestFailed:
44-
raise RequestError("%s failed"%self.lastSent.strip())
45-
return s
46-
47-
def sendReceive(self, *data):
48-
"""Sends and receive data"""
49-
self.send(*data)
50-
return self.receive()
1+
import socket
2+
import select
3+
import sys
4+
from util import flatten_parameters_to_string
5+
6+
""" @author: Aron Nieminen, Mojang AB"""
7+
8+
class RequestError(Exception):
9+
pass
10+
11+
class Connection:
12+
"""Connection to a Minecraft Pi game"""
13+
RequestFailed = "Fail"
14+
15+
def __init__(self, address, port):
16+
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
17+
self.socket.connect((address, port))
18+
self.lastSent = ""
19+
20+
def drain(self):
21+
"""Drains the socket of incoming data"""
22+
while True:
23+
readable, _, _ = select.select([self.socket], [], [], 0.0)
24+
if not readable:
25+
break
26+
data = self.socket.recv(1500)
27+
e = "Drained Data: <%s>\n"%data.strip()
28+
e += "Last Message: <%s>\n"%self.lastSent.strip()
29+
sys.stderr.write(e)
30+
31+
def send(self, f, *data):
32+
"""Sends data. Note that a trailing newline '\n' is added here"""
33+
s = "%s(%s)\n"%(f, flatten_parameters_to_string(data))
34+
#print "f,data:",f,data
35+
#print "s",s
36+
self.drain()
37+
self.lastSent = s
38+
self.socket.sendall(s)
39+
40+
def receive(self):
41+
"""Receives data. Note that the trailing newline '\n' is trimmed"""
42+
s = self.socket.makefile("r").readline().rstrip("\n")
43+
if s == Connection.RequestFailed:
44+
raise RequestError("%s failed"%self.lastSent.strip())
45+
return s
46+
47+
def sendReceive(self, *data):
48+
"""Sends and receive data"""
49+
self.send(*data)
50+
return self.receive()

api/python/mcpi/event.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
from vec3 import Vec3
2-
3-
class BlockEvent:
4-
"""An Event related to blocks (e.g. placed, removed, hit)"""
5-
HIT = 0
6-
7-
def __init__(self, type, x, y, z, face, entityId):
8-
self.type = type
9-
self.pos = Vec3(x, y, z)
10-
self.face = face
11-
self.entityId = entityId
12-
13-
def __repr__(self):
14-
sType = {
15-
BlockEvent.HIT: "BlockEvent.HIT"
16-
}.get(self.type, "???")
17-
18-
return "BlockEvent(%s, %d, %d, %d, %d, %d)"%(
19-
sType,self.pos.x,self.pos.y,self.pos.z,self.face,self.entityId);
20-
21-
@staticmethod
22-
def Hit(x, y, z, face, entityId):
23-
return BlockEvent(BlockEvent.HIT, x, y, z, face, entityId)
1+
from vec3 import Vec3
2+
3+
class BlockEvent:
4+
"""An Event related to blocks (e.g. placed, removed, hit)"""
5+
HIT = 0
6+
7+
def __init__(self, type, x, y, z, face, entityId):
8+
self.type = type
9+
self.pos = Vec3(x, y, z)
10+
self.face = face
11+
self.entityId = entityId
12+
13+
def __repr__(self):
14+
sType = {
15+
BlockEvent.HIT: "BlockEvent.HIT"
16+
}.get(self.type, "???")
17+
18+
return "BlockEvent(%s, %d, %d, %d, %d, %d)"%(
19+
sType,self.pos.x,self.pos.y,self.pos.z,self.face,self.entityId);
20+
21+
@staticmethod
22+
def Hit(x, y, z, face, entityId):
23+
return BlockEvent(BlockEvent.HIT, x, y, z, face, entityId)

0 commit comments

Comments
 (0)