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 7, 2016
1 parent 1f6fb0e commit c8ae858
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 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,39 @@ 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)

self.channels.send('MC|ItemName', 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 c8ae858

Please # to comment.