diff options
| author | Kevin <115616336+lag@users.noreply.github.com> | 2026-03-05 21:20:40 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-05 21:20:40 -0600 |
| commit | d22ab815e3006835ec55ffe75184be9d926b2547 (patch) | |
| tree | 0ffb6c50cd8d974ed44ea1f69e4c31c34e120068 /Minecraft.Client/PlayerConnection.cpp | |
| parent | 0c2e27cae7b613644eca3a9b4e4778afe2094efb (diff) | |
Initial fixes for ContainerSetSlotPacket and CraftItemPacket (#649)
Diffstat (limited to 'Minecraft.Client/PlayerConnection.cpp')
| -rw-r--r-- | Minecraft.Client/PlayerConnection.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/Minecraft.Client/PlayerConnection.cpp b/Minecraft.Client/PlayerConnection.cpp index 266cae36..ab8ae20b 100644 --- a/Minecraft.Client/PlayerConnection.cpp +++ b/Minecraft.Client/PlayerConnection.cpp @@ -1093,6 +1093,10 @@ void PlayerConnection::handleContainerClose(shared_ptr<ContainerClosePacket> pac #ifndef _CONTENT_PACKAGE void PlayerConnection::handleContainerSetSlot(shared_ptr<ContainerSetSlotPacket> packet) { + if(player->gameMode->isSurvival()){ // Still allow creative players to change slots manually with packets(?) -- might want this different. + server->warn(L"Player " + player->getName() + L" just tried to set a slot in a container in survival mode"); + return; + } if (packet->containerId == AbstractContainerMenu::CONTAINER_ID_CARRIED ) { player->inventory->setCarried(packet->item); @@ -1589,6 +1593,10 @@ void PlayerConnection::handleCraftItem(shared_ptr<CraftItemPacket> packet) Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray(); shared_ptr<ItemInstance> pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr); + size_t recipeCount = Recipes::getInstance()->getRecipies()->size(); + if (iRecipe < 0 || iRecipe >= (int)recipeCount) + return; + if(app.DebugSettingsOn() && (player->GetDebugOptions()&(1L<<eDebugSetting_CraftAnything))) { pTempItemInst->onCraftedBy(player->level, dynamic_pointer_cast<Player>( player->shared_from_this() ), pTempItemInst->count ); @@ -1607,9 +1615,21 @@ void PlayerConnection::handleCraftItem(shared_ptr<CraftItemPacket> packet) { - // TODO 4J Stu - Assume at the moment that the client can work this out for us... - //if(pRecipeIngredientsRequired[iRecipe].bCanMake) - //{ + Recipy::INGREDIENTS_REQUIRED &req = pRecipeIngredientsRequired[iRecipe]; + if (req.iType == RECIPE_TYPE_3x3 && dynamic_cast<CraftingMenu *>(player->containerMenu) == NULL) + { + server->warn(L"Player " + player->getName() + L" tried to craft a 3x3 recipe without a crafting bench"); + return; + } + for (int i = 0; i < req.iIngC; i++){ + int need = req.iIngValA[i]; + int have = player->inventory->countResource(req.iIngIDA[i], req.iIngAuxValA[i]); + if (have < need){ + server->warn(L"Player " + player->getName() + L" just tried to craft item " + to_wstring(pTempItemInst->id) + L" with insufficient ingredients"); + return; + } + } + pTempItemInst->onCraftedBy(player->level, dynamic_pointer_cast<Player>( player->shared_from_this() ), pTempItemInst->count ); // and remove those resources from your inventory |
