Skip to content

Commit

Permalink
Add enchant_item, set_item_name, select_trade to interact plugin
Browse files Browse the repository at this point in the history
Closes Gjum/Bat#5
  • Loading branch information
Gjum committed Jan 8, 2016
1 parent 9592c0c commit 5ada1dc
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion spockbot/plugins/helpers/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
By default, the client sends swing and look packets like the vanilla client.
This can be disabled by setting the ``auto_swing`` and ``auto_look`` flags.
"""
from spockbot.mcdata import constants
from spockbot.mcdata import constants, windows
from spockbot.mcp import nbt
from spockbot.mcp.proto import MC_SLOT
from spockbot.plugins.base import PluginBase, pl_announce
Expand Down Expand Up @@ -230,6 +230,40 @@ def unmount_vehicle(self):
def jump_vehicle(self):
self.steer_vehicle(jump=True)

def enchant_item(self, enchantment_nr):
if enchantment_nr not in range(3):
raise ValueError('enchantment_nr must be 0, 1, or 2, not "%s"'
% enchantment_nr)

inv_type = self.inventory.window.inv_type
if inv_type != 'minecraft:enchanting_table': # sic
raise ValueError('Can only enchant items in enchantment window, '
'but open window is "%s"' % inv_type)

self.net.push_packet('PLAY>Enchant Item', {
'enchantment': enchantment_nr,
'window_id': self.inventory.window.window_id,
})

def set_item_name(self, name):
"""Set the name of the item in the open anvil"""
inv_type = self.inventory.window.inv_type
if inv_type != 'minecraft:anvil':
raise ValueError('Can only rename items in anvil window, '
'but open window is "%s"' % inv_type)

self.channels.send('MC|ItemName', name.encode('ascii'))

def select_trade(self, index):
"""Select a trade in the active villager trading window"""
inv_type = self.inventory.window.inv_type
if inv_type != 'minecraft:villager':
raise ValueError('Can only select trade in villager window, '
'but open window is "%s"' % inv_type)

# TODO check index against available trades
self.channels.send('MC|TrSel', int(index))

def write_book(self, text, author="", title="", sign=False):
"""Write text to the current book in hand, optionally sign the book"""
book = self._setup_book()
Expand Down

0 comments on commit 5ada1dc

Please # to comment.