@@ -199,8 +199,11 @@ def __init__(self, slot, button=constants.INV_BUTTON_LEFT):
199199 'Clicking with button %s not implemented' % button )
200200
201201 def get_packet (self , inv_plugin ):
202+ slot_nr = self .slot .slot_nr
203+ if self .slot == inv_plugin .cursor_slot :
204+ slot_nr = constants .INV_OUTSIDE_WINDOW
202205 return {
203- 'slot' : self . slot . slot_nr ,
206+ 'slot' : slot_nr ,
204207 'button' : self .button ,
205208 'mode' : 0 ,
206209 'clicked_item' : self .slot .get_dict (),
@@ -209,13 +212,19 @@ def get_packet(self, inv_plugin):
209212 def apply (self , inv_plugin ):
210213 clicked = self .slot
211214 cursor = inv_plugin .cursor_slot
212- if self .button == constants .INV_BUTTON_LEFT :
215+ if clicked == cursor :
216+ if self .button == constants .INV_BUTTON_LEFT :
217+ clicked .amount = 0
218+ elif self .button == constants .INV_BUTTON_RIGHT :
219+ clicked .amount -= 1
220+ self .cleanup_if_empty (clicked )
221+ elif self .button == constants .INV_BUTTON_LEFT :
213222 if clicked .stacks_with (cursor ):
214223 self .transfer (cursor , clicked , cursor .amount )
215224 else :
216225 self .swap_slots (cursor , clicked )
217226 elif self .button == constants .INV_BUTTON_RIGHT :
218- if cursor .item_id == constants . INV_ITEMID_EMPTY :
227+ if cursor .is_empty :
219228 # transfer half, round up
220229 self .transfer (clicked , cursor , (clicked .amount + 1 ) // 2 )
221230 elif clicked .is_empty or clicked .stacks_with (cursor ):
@@ -233,27 +242,24 @@ def __init__(self, slot, drop_stack=False):
233242 self .drop_stack = drop_stack
234243
235244 def get_packet (self , inv_plugin ):
236- if self .slot == inv_plugin .active_slot :
237- slot_nr = constants .INV_OUTSIDE_WINDOW # drop cursor slot
238- elif inv_plugin .cursor_slot .item_id != constants .INV_ITEMID_EMPTY :
239- return None # can't drop while holding an item
240- else : # default case
241- slot_nr = self .slot .slot_nr
245+ if self .slot == inv_plugin .cursor_slot :
246+ raise ValueError ("Can't drop cursor slot, use SingleClick" )
247+ if not inv_plugin .cursor_slot .is_empty :
248+ raise ValueError ("Can't drop other slots: cursor slot is occupied" )
249+
242250 return {
243- 'slot' : slot_nr ,
251+ 'slot' : self . slot . slot_nr ,
244252 'button' : 1 if self .drop_stack else 0 ,
245253 'mode' : 4 ,
246254 'clicked_item' : inv_plugin .cursor_slot .get_dict (),
247255 }
248256
249257 def apply (self , inv_plugin ):
250- if inv_plugin .cursor_slot .is_empty :
251- if self .drop_stack :
252- self .slot .amount = 0
253- else :
254- self .slot .amount -= 1
255- self .cleanup_if_empty (self .slot )
256- # else: cursor not empty, can't drop while holding an item
258+ if self .drop_stack :
259+ self .slot .amount = 0
260+ else :
261+ self .slot .amount -= 1
262+ self .cleanup_if_empty (self .slot )
257263
258264
259265class Window (object ):
0 commit comments