@@ -266,13 +266,23 @@ protected virtual void ProcessSwapAction(SwapAction action, List<StackResponseCo
266266 Item sourceItem = GetContainerItem ( source . ContainerId , source . Slot ) ;
267267 Item destItem = GetContainerItem ( destination . ContainerId , destination . Slot ) ;
268268
269- SetContainerItem ( source . ContainerId , source . Slot , destItem ) ;
270- SetContainerItem ( destination . ContainerId , destination . Slot , sourceItem ) ;
271269
272- if ( source . ContainerId == 21 || source . ContainerId == 22 || destination . ContainerId == 21 || destination . ContainerId == 22 )
270+ if ( ! _player . OnItemTransaction ( new ItemTransactionEventArgs ( _player , _player . Level , sourceItem , action ) ) )
273271 {
274- if ( ! ( GetContainerItem ( 21 , 14 ) is ItemAir ) && ! ( GetContainerItem ( 22 , 15 ) is ItemAir ) ) Enchantment . SendEnchantments ( _player , GetContainerItem ( 21 , 14 ) ) ;
275- else Enchantment . SendEmptyEnchantments ( _player ) ;
272+ //revert. Empty looks ok
273+ }
274+ else
275+ {
276+ SetContainerItem ( source . ContainerId , source . Slot , destItem ) ;
277+ SetContainerItem ( destination . ContainerId , destination . Slot , sourceItem ) ;
278+
279+ if ( source . ContainerId == 21 || source . ContainerId == 22 || destination . ContainerId == 21 || destination . ContainerId == 22 )
280+ {
281+ if ( ! ( GetContainerItem ( 21 , 14 ) is ItemAir ) && ! ( GetContainerItem ( 22 , 15 ) is ItemAir ) )
282+ Enchantment . SendEnchantments ( _player , GetContainerItem ( 21 , 14 ) ) ;
283+ else
284+ Enchantment . SendEmptyEnchantments ( _player ) ;
285+ }
276286 }
277287
278288 stackResponses . Add ( new StackResponseContainerInfo
@@ -309,61 +319,68 @@ protected virtual StackRequestSlotInfo ProcessPlaceAction(PlaceAction action, Li
309319 {
310320 byte count = action . Count ;
311321 Item sourceItem ;
312- Item destItem ;
322+ Item destItem = new ItemAir ( ) ;
313323 StackRequestSlotInfo source = action . Source ;
314324 StackRequestSlotInfo destination = action . Destination ;
315325
316326 sourceItem = GetContainerItem ( source . ContainerId , source . Slot ) ;
317327
318- if ( sourceItem . Count == count || sourceItem . Count - count <= 0 )
319- {
320- destItem = sourceItem ;
321- sourceItem = new ItemAir ( ) ;
322- sourceItem . UniqueId = 0 ;
323- SetContainerItem ( source . ContainerId , source . Slot , sourceItem ) ;
324- }
325- else
326- {
327- destItem = ( Item ) sourceItem . Clone ( ) ;
328- sourceItem . Count -= count ;
329- destItem . Count = count ;
330- destItem . UniqueId = Environment . TickCount ;
331- }
332-
333- Item existingItem = GetContainerItem ( destination . ContainerId , destination . Slot ) ;
334- if ( existingItem . UniqueId > 0 ) // is empty/air is what this means
328+ if ( ! _player . OnItemTransaction ( new ItemTransactionEventArgs ( _player , _player . Level , sourceItem , action ) ) )
335329 {
336- existingItem . Count += count ;
337- destItem = existingItem ;
330+ //revert. Empty looks ok
338331 }
339332 else
340333 {
341- SetContainerItem ( destination . ContainerId , destination . Slot , destItem ) ;
342- }
343- if ( destination . ContainerId == 6 || source . ContainerId == 6 )
344- {
345- _player . SendArmorForPlayer ( _player . Level . GetSpawnedPlayers ( ) ) ;
346- }
347- else if ( destination . ContainerId == 22 )
348- {
349- if ( Enum . IsDefined ( typeof ( ItemType ) , GetContainerItem ( 21 , 14 ) . ItemType ) && ! ( GetContainerItem ( 22 , 15 ) is ItemAir ) )
334+ if ( sourceItem . Count == count || sourceItem . Count - count <= 0 )
350335 {
351- Enchantment . SendEnchantments ( _player , GetContainerItem ( 21 , 14 ) ) ;
336+ destItem = sourceItem ;
337+ sourceItem = new ItemAir ( ) ;
338+ sourceItem . UniqueId = 0 ;
339+ SetContainerItem ( source . ContainerId , source . Slot , sourceItem ) ;
352340 }
353341 else
354342 {
355- Enchantment . SendEmptyEnchantments ( _player ) ;
343+ destItem = ( Item ) sourceItem . Clone ( ) ;
344+ sourceItem . Count -= count ;
345+ destItem . Count = count ;
346+ destItem . UniqueId = Environment . TickCount ;
356347 }
357- }
358- else if ( destination . ContainerId == 23 )
359- {
360- if ( Enum . IsDefined ( typeof ( ItemType ) , GetContainerItem ( 21 , 14 ) . ItemType ) && ! ( GetContainerItem ( 21 , 14 ) is ItemAir ) && ! ( GetContainerItem ( 22 , 15 ) is ItemAir ) )
348+
349+ Item existingItem = GetContainerItem ( destination . ContainerId , destination . Slot ) ;
350+ if ( existingItem . UniqueId > 0 ) // is empty/air is what this means
361351 {
362- Enchantment . SendEnchantments ( _player , GetContainerItem ( 21 , 14 ) ) ;
352+ existingItem . Count += count ;
353+ destItem = existingItem ;
363354 }
364355 else
365356 {
366- Enchantment . SendEmptyEnchantments ( _player ) ;
357+ SetContainerItem ( destination . ContainerId , destination . Slot , destItem ) ;
358+ }
359+ if ( destination . ContainerId == 6 || source . ContainerId == 6 )
360+ {
361+ _player . SendArmorForPlayer ( _player . Level . GetSpawnedPlayers ( ) ) ;
362+ }
363+ else if ( destination . ContainerId == 22 )
364+ {
365+ if ( Enum . IsDefined ( typeof ( ItemType ) , GetContainerItem ( 21 , 14 ) . ItemType ) && ! ( GetContainerItem ( 22 , 15 ) is ItemAir ) )
366+ {
367+ Enchantment . SendEnchantments ( _player , GetContainerItem ( 21 , 14 ) ) ;
368+ }
369+ else
370+ {
371+ Enchantment . SendEmptyEnchantments ( _player ) ;
372+ }
373+ }
374+ else if ( destination . ContainerId == 23 )
375+ {
376+ if ( Enum . IsDefined ( typeof ( ItemType ) , GetContainerItem ( 21 , 14 ) . ItemType ) && ! ( GetContainerItem ( 21 , 14 ) is ItemAir ) && ! ( GetContainerItem ( 22 , 15 ) is ItemAir ) )
377+ {
378+ Enchantment . SendEnchantments ( _player , GetContainerItem ( 21 , 14 ) ) ;
379+ }
380+ else
381+ {
382+ Enchantment . SendEmptyEnchantments ( _player ) ;
383+ }
367384 }
368385 }
369386
@@ -403,48 +420,54 @@ protected virtual void ProcessTakeAction(TakeAction action, List<StackResponseCo
403420 byte count = action . Count ;
404421 Item sourceItem ;
405422 Item destinationItem ;
406- Item destItem ;
423+ Item destItem = new ItemAir ( ) ;
407424 StackRequestSlotInfo source = action . Source ;
408425 StackRequestSlotInfo destination = action . Destination ;
409426
410427 sourceItem = GetContainerItem ( source . ContainerId , source . Slot ) ;
411428 destinationItem = GetContainerItem ( destination . ContainerId , destination . Slot ) ;
412429
413-
414- if ( source . ContainerId == 60 && sourceItem . Id == destinationItem . Id )
415- {
416- destItem = ( Item ) destinationItem . Clone ( ) ;
417- destItem . Count += count ;
418- destItem . UniqueId = Environment . TickCount ;
419- }
420- else if ( source . ContainerId != 60 && sourceItem . Count == count )
430+ if ( ! _player . OnItemTransaction ( new ItemTransactionEventArgs ( _player , _player . Level , sourceItem , action ) ) )
421431 {
422- destItem = ( Item ) sourceItem . Clone ( ) ;
423- destItem . Count = ( byte ) ( destinationItem . Count + count ) ;
424- destItem . UniqueId = Environment . TickCount ;
425- sourceItem = new ItemAir ( ) ;
426- sourceItem . UniqueId = 0 ;
427- SetContainerItem ( source . ContainerId , source . Slot , sourceItem ) ;
432+ //revert. Empty looks ok
428433 }
429434 else
430435 {
431- destItem = ( Item ) sourceItem . Clone ( ) ;
432- destItem . Count = count ;
433- destItem . UniqueId = Environment . TickCount ;
434- sourceItem . Count -= count ;
435- SetContainerItem ( source . ContainerId , source . Slot , sourceItem ) ;
436- }
436+ if ( source . ContainerId == 60 && sourceItem . Id == destinationItem . Id )
437+ {
438+ destItem = ( Item ) destinationItem . Clone ( ) ;
439+ destItem . Count += count ;
440+ destItem . UniqueId = Environment . TickCount ;
441+ }
442+ else if ( source . ContainerId != 60 && sourceItem . Count == count )
443+ {
444+ destItem = ( Item ) sourceItem . Clone ( ) ;
445+ destItem . Count = ( byte ) ( destinationItem . Count + count ) ;
446+ destItem . UniqueId = Environment . TickCount ;
447+ sourceItem = new ItemAir ( ) ;
448+ sourceItem . UniqueId = 0 ;
449+ SetContainerItem ( source . ContainerId , source . Slot , sourceItem ) ;
450+ }
451+ else
452+ {
453+ destItem = ( Item ) sourceItem . Clone ( ) ;
454+ destItem . Count = count ;
455+ destItem . UniqueId = Environment . TickCount ;
456+ sourceItem . Count -= count ;
457+ SetContainerItem ( source . ContainerId , source . Slot , sourceItem ) ;
458+ }
437459
438- SetContainerItem ( destination . ContainerId , destination . Slot , destItem ) ;
460+ SetContainerItem ( destination . ContainerId , destination . Slot , destItem ) ;
439461
440- if ( source . ContainerId == 22 || source . ContainerId == 23 )
441- {
442- Enchantment . SendEmptyEnchantments ( _player ) ;
443- }
462+ if ( source . ContainerId == 22 || source . ContainerId == 23 )
463+ {
464+ Enchantment . SendEmptyEnchantments ( _player ) ;
465+ }
444466
445- if ( source . ContainerId == 6 )
446- {
447- _player . SendArmorForPlayer ( _player . Level . GetSpawnedPlayers ( ) ) ;
467+ if ( source . ContainerId == 6 )
468+ {
469+ _player . SendArmorForPlayer ( _player . Level . GetSpawnedPlayers ( ) ) ;
470+ }
448471 }
449472
450473 stackResponses . Add ( new StackResponseContainerInfo
0 commit comments