-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcraft_api.py
More file actions
61 lines (46 loc) · 1.6 KB
/
craft_api.py
File metadata and controls
61 lines (46 loc) · 1.6 KB
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
"""
craft_api.py -- The pycraft API
"""
import msgpack
import zmq
from deprecated import deprecated
class CraftAPI:
"""a class for pycraft API"""
def __init__(self):
"""
The constructor for class CraftAPI
The constructor creates ZeroMQ context and connects the socket to
port 1234, the default port of pycraft.
"""
self.context = zmq.Context()
self.socket = self.context.socket(zmq.PUSH)
self.socket.connect('tcp://localhost:1234')
@deprecated
def add_brick_block(self, position):
"""
add_brick_block -- add a brick block to a given position
Arguments:
position -- the position of the block
"""
self.socket.send(' '.join(repr(n) for n in position).encode('utf-8'))
def add_block(self, position, texture):
"""
add_block -- add a block with specified texture to a given position
Argument:
position -- the position of the block
texture -- the texture of the block
"""
command = {'cmd': 'add_block',
'args': {'position': position, 'texture': texture}}
message = msgpack.packb(command, use_bin_type=True)
self.socket.send(message)
def delete_block(self, position):
"""
delete_block -- delete a block in a given position
Arguments:
position -- the position of the block
"""
command = {'cmd': 'delete_block',
'args': {'position': position}}
message = msgpack.packb(command, use_bin_type=True)
self.socket.send(message)