|
6 | 6 | - use the held (active) item |
7 | 7 | - use/attack entities |
8 | 8 | - steer vehicles |
| 9 | +- place and write signs |
9 | 10 | - edit and sign books |
10 | 11 |
|
11 | 12 | By default, the client sends swing and look packets like the vanilla client. |
|
17 | 18 | from spockbot.mcp import nbt |
18 | 19 | from spockbot.mcp.proto import MC_SLOT |
19 | 20 | from spockbot.plugins.base import PluginBase, pl_announce |
| 21 | +from spockbot.plugins.tools.event import EVENT_UNREGISTER |
20 | 22 | from spockbot.vector import Vector3 |
21 | 23 |
|
22 | 24 |
|
23 | 25 | @pl_announce('Interact') |
24 | 26 | class InteractPlugin(PluginBase): |
25 | | - requires = ('ClientInfo', 'Inventory', 'Net', 'Channels') |
| 27 | + requires = ('ClientInfo', 'Event', 'Inventory', 'Net', 'Channels') |
26 | 28 |
|
27 | 29 | def __init__(self, ploader, settings): |
28 | 30 | super(InteractPlugin, self).__init__(ploader, settings) |
@@ -174,6 +176,25 @@ def use_bucket(self, pos): # TODO |
174 | 176 | """ |
175 | 177 | raise NotImplementedError(self.use_bucket.__doc__) |
176 | 178 |
|
| 179 | + def place_sign(self, pos, lines=[], **place_block_kwargs): |
| 180 | + """ |
| 181 | + Place a sign block and write on it. |
| 182 | + """ |
| 183 | + if self.inventory.active_slot.item_id != 323: |
| 184 | + raise ValueError('Must hold sign to place, not "%s"' |
| 185 | + % self.inventory.active_slot.item) |
| 186 | + |
| 187 | + def write_sign_text(event, packet): |
| 188 | + data = {'location': packet.data['location']} |
| 189 | + for i in range(4): |
| 190 | + data['line_%i' % (i + 1)] = lines[i] if i < len(lines) else '' |
| 191 | + |
| 192 | + self.net.push_packet('PLAY>Update Sign', data) |
| 193 | + return EVENT_UNREGISTER |
| 194 | + |
| 195 | + self.event.reg_event_handler('PLAY<Sign Editor Open', write_sign_text) |
| 196 | + self.place_block(pos, **place_block_kwargs) |
| 197 | + |
177 | 198 | def activate_item(self): |
178 | 199 | """ |
179 | 200 | Use (hold right-click) the item in the active slot. |
|
0 commit comments