From 5ada1dc81799cbec03557e334732407169477f01 Mon Sep 17 00:00:00 2001 From: Gjum Date: Sun, 3 Jan 2016 23:43:17 +0100 Subject: [PATCH] Add enchant_item, set_item_name, select_trade to interact plugin Closes Gjum/Bat#5 --- spockbot/plugins/helpers/interact.py | 36 +++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/spockbot/plugins/helpers/interact.py b/spockbot/plugins/helpers/interact.py index e9c9f93..1e8ac7a 100644 --- a/spockbot/plugins/helpers/interact.py +++ b/spockbot/plugins/helpers/interact.py @@ -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 @@ -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()