From e2855aadffa5600f3c85eecfe5274d8d78720e32 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 14 Jul 2022 20:47:38 +0100 Subject: [PATCH] Simplify handling of broken transactions for crafting and friends this allows stuff like smithing tables to work without needing any extra hacks. Implementing enchanting or anvils would require some extra work, but I don't plan to implement those under the legacy transaction system anyway. --- src/network/mcpe/convert/TypeConverter.php | 13 ++++--------- src/network/mcpe/handler/InGamePacketHandler.php | 7 +------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/network/mcpe/convert/TypeConverter.php b/src/network/mcpe/convert/TypeConverter.php index 2a74c9f07..424f5d875 100644 --- a/src/network/mcpe/convert/TypeConverter.php +++ b/src/network/mcpe/convert/TypeConverter.php @@ -326,15 +326,10 @@ class TypeConverter{ } case NetworkInventoryAction::SOURCE_TODO: - //These types need special handling. - switch($action->windowId){ - case NetworkInventoryAction::SOURCE_TYPE_CRAFTING_RESULT: - case NetworkInventoryAction::SOURCE_TYPE_CRAFTING_USE_INGREDIENT: - return null; - } - - //TODO: more stuff - throw new TypeConversionException("No open container with window ID $action->windowId"); + //These are used to balance a transaction that involves special actions, like crafting, enchanting, etc. + //The vanilla server just accepted these without verifying them. We don't need to care about them since + //we verify crafting by checking for imbalances anyway. + return null; default: throw new TypeConversionException("Unknown inventory source type $action->sourceType"); } diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index 83c2d03cf..8fd6894f9 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -319,12 +319,7 @@ class InGamePacketHandler extends PacketHandler{ $converter = TypeConverter::getInstance(); foreach($data->getActions() as $networkInventoryAction){ if( - ( - $networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_TODO && ( - $networkInventoryAction->windowId === NetworkInventoryAction::SOURCE_TYPE_CRAFTING_RESULT || - $networkInventoryAction->windowId === NetworkInventoryAction::SOURCE_TYPE_CRAFTING_USE_INGREDIENT - ) - ) || ( + $networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_TODO || ( $this->craftingTransaction !== null && !$networkInventoryAction->oldItem->getItemStack()->equals($networkInventoryAction->newItem->getItemStack()) && $networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_CONTAINER &&