Skip to content

Commit a1d4da6

Browse files
committed
Add place_sign() to interact
1 parent 3a8fe48 commit a1d4da6

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

spockbot/plugins/helpers/interact.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- use the held (active) item
77
- use/attack entities
88
- steer vehicles
9+
- place and write signs
910
- edit and sign books
1011
1112
By default, the client sends swing and look packets like the vanilla client.
@@ -17,12 +18,13 @@
1718
from spockbot.mcp import nbt
1819
from spockbot.mcp.proto import MC_SLOT
1920
from spockbot.plugins.base import PluginBase, pl_announce
21+
from spockbot.plugins.tools.event import EVENT_UNREGISTER
2022
from spockbot.vector import Vector3
2123

2224

2325
@pl_announce('Interact')
2426
class InteractPlugin(PluginBase):
25-
requires = ('ClientInfo', 'Inventory', 'Net', 'Channels')
27+
requires = ('ClientInfo', 'Event', 'Inventory', 'Net', 'Channels')
2628

2729
def __init__(self, ploader, settings):
2830
super(InteractPlugin, self).__init__(ploader, settings)
@@ -174,6 +176,25 @@ def use_bucket(self, pos): # TODO
174176
"""
175177
raise NotImplementedError(self.use_bucket.__doc__)
176178

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+
177198
def activate_item(self):
178199
"""
179200
Use (hold right-click) the item in the active slot.

0 commit comments

Comments
 (0)