another crafting table backup point

This commit is contained in:
DrPerkyLegit committed 2026-10-29 19:55:19 -04:00
1 parent 350ada405f
commit e010da4376
15 files changed
+1752 -852

No files matched your search

+171 -113
View File
@@ -3570,135 +3570,193 @@ void PlayerConnection::handleDebugOptions(shared_ptr<DebugOptionsPacket> packet)
void PlayerConnection::handleCraftItem(shared_ptr<CraftItemPacket> packet)
{
int iRecipe = packet->recipe;
if(iRecipe == -1)
return;
int recipeCount = (int)Recipes::getInstance()->getRecipies()->size();
if(iRecipe < 0 || iRecipe >= recipeCount)
return;
Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray();
shared_ptr<ItemInstance> pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr);
if(app.DebugSettingsOn() && (player->GetDebugOptions()&(1L<<eDebugSetting_CraftAnything)))
{
pTempItemInst->onCraftedBy(player->level, dynamic_pointer_cast<Player>( player->shared_from_this() ), pTempItemInst->count );
if(player->inventory->add(pTempItemInst)==false )
{
// no room in inventory, so throw it down
player->drop(pTempItemInst);
}
}
else if (pTempItemInst->id == Item::firework_charge_Id || pTempItemInst->id == Item::fireworks_Id)
{
CraftingMenu *menu = static_cast<CraftingMenu *>(player->containerMenu);
player->openFireworks(menu->getX(), menu->getY(), menu->getZ() );
}
else
{
Recipy::INGREDIENTS_REQUIRED &req = pRecipeIngredientsRequired[iRecipe];
if (req.iType == RECIPE_TYPE_3x3 && dynamic_cast<CraftingMenu *>(player->containerMenu) == nullptr)
{
server->warn(L"Player " + player->getName() + L" tried to craft a 3x3 recipe without a crafting bench");
if (packet->isBanner) {
if (dynamic_cast<CraftingMenu*>(player->containerMenu) == nullptr) {
server->warn(L"Player " + player->getName() + L" tried to craft a 3x3 banner 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;
shared_ptr<ItemInstance> foundBannerItem = nullptr;
if (packet->patternColors.size() == packet->patternIndexs.size()) return;
for (int i = 0; i < player->inventory->items.length && foundBannerItem == nullptr; i++) {
shared_ptr<ItemInstance>& item = player->inventory->items[i];
if (item->id != Tile::standing_banner_Id) continue;
if (item->getAuxValue() != packet->findBannerAux) continue;
std::vector<char> bannerPatternIndexs = BannerPatternRecipe::getBannerPatternIndexs(item);
if (bannerPatternIndexs.size() != packet->findPatternIndexs.size()) continue;
bool failedPatternMatches = false;
for (int j = 0; j < bannerPatternIndexs.size(); j++) {
if (packet->findPatternIndexs[j] != bannerPatternIndexs[j]) {
failedPatternMatches = true;
}
}
if (failedPatternMatches) continue;
std::vector<char> bannerPatternColors = BannerPatternRecipe::getBannerColorIndexs(item);
if (bannerPatternColors.size() != packet->findPatternColors.size()) continue;
for (int j = 0; j < bannerPatternColors.size(); j++) {
if (packet->findPatternColors[j] != bannerPatternColors[j]) {
failedPatternMatches = true;
}
}
if (failedPatternMatches) continue;
foundBannerItem = item;
}
pTempItemInst->onCraftedBy(player->level, dynamic_pointer_cast<Player>( player->shared_from_this() ), pTempItemInst->count );
if (foundBannerItem != nullptr) {
auto newBanner = ItemInstance::clone(foundBannerItem);
// and remove those resources from your inventory
for(int i=0;i<pRecipeIngredientsRequired[iRecipe].iIngC;i++)
for (int i = 0; i < packet->patternIndexs.size(); i++) {
char patternIndex = packet->patternIndexs[i];
BannerPatternRecipe::addBannerPattern(newBanner, BannerPatternRecipe::PATTERNS[patternIndex].id, packet->patternColors[i]);
}
if (app.DebugSettingsOn() && (player->GetDebugOptions() & (1L << eDebugSetting_CraftAnything))) {
if (player->inventory->add(foundBannerItem) == false) {
player->drop(foundBannerItem);
}
} else {
}
}
} else {
int iRecipe = packet->recipe;
if (iRecipe == -1)
return;
int recipeCount = (int)Recipes::getInstance()->getRecipies()->size();
if (iRecipe < 0 || iRecipe >= recipeCount)
return;
Recipy::INGREDIENTS_REQUIRED* pRecipeIngredientsRequired = Recipes::getInstance()->getRecipeIngredientsArray();
shared_ptr<ItemInstance> pTempItemInst = pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr);
if (app.DebugSettingsOn() && (player->GetDebugOptions() & (1L << eDebugSetting_CraftAnything)))
{
for(int j=0;j<pRecipeIngredientsRequired[iRecipe].iIngValA[i];j++)
pTempItemInst->onCraftedBy(player->level, dynamic_pointer_cast<Player>(player->shared_from_this()), pTempItemInst->count);
if (player->inventory->add(pTempItemInst) == false)
{
shared_ptr<ItemInstance> ingItemInst = nullptr;
// do we need to remove a specific aux value?
if(pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i]!=Recipes::ANY_AUX_VALUE)
{
ingItemInst = player->inventory->getResourceItem( pRecipeIngredientsRequired[iRecipe].iIngIDA[i],pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i] );
player->inventory->removeResource(pRecipeIngredientsRequired[iRecipe].iIngIDA[i],pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i]);
}
else
{
ingItemInst = player->inventory->getResourceItem( pRecipeIngredientsRequired[iRecipe].iIngIDA[i] );
player->inventory->removeResource(pRecipeIngredientsRequired[iRecipe].iIngIDA[i]);
}
// 4J Stu - Fix for #13097 - Bug: Milk Buckets are removed when crafting Cake
if (ingItemInst != nullptr)
{
if (ingItemInst->getItem()->hasCraftingRemainingItem())
{
// replace item with remaining result
player->inventory->add(std::make_shared<ItemInstance>(ingItemInst->getItem()->getCraftingRemainingItem()));
}
}
// no room in inventory, so throw it down
player->drop(pTempItemInst);
}
}
// 4J Stu - Fix for #13119 - We should add the item after we remove the ingredients
if(player->inventory->add(pTempItemInst)==false )
else if (pTempItemInst->id == Item::firework_charge_Id || pTempItemInst->id == Item::fireworks_Id)
{
// no room in inventory, so throw it down
player->drop(pTempItemInst);
}
if( pTempItemInst->id == Item::map_Id )
{
// 4J Stu - Maps need to have their aux value update, so the client should always be assumed to be wrong
// This is how the Java works, as the client also incorrectly predicts the auxvalue of the mapItem
vector<shared_ptr<ItemInstance> > items;
for (unsigned int i = 0; i < player->containerMenu->slots.size(); i++)
{
items.push_back(player->containerMenu->slots.at(i)->getItem());
}
player->refreshContainer(player->containerMenu, &items);
CraftingMenu* menu = static_cast<CraftingMenu*>(player->containerMenu);
player->openFireworks(menu->getX(), menu->getY(), menu->getZ());
}
else
{
// Do same hack as PlayerConnection::handleContainerClick does - do our broadcast of changes just now, but with a hack so it just thinks it has sent
// things but hasn't really. This will stop the client getting a message back confirming the current inventory items, which might then arrive
// after another local change has been made on the client and be stale.
player->ignoreSlotUpdateHack = true;
player->containerMenu->broadcastChanges();
player->broadcastCarriedItem();
player->ignoreSlotUpdateHack = false;
}
}
// handle achievements
switch(pTempItemInst->id)
{
case Tile::crafting_table_Id: player->awardStat(GenericStats::buildWorkbench(), GenericStats::param_buildWorkbench()); break;
case Item::wooden_pickaxe_Id: player->awardStat(GenericStats::buildPickaxe(), GenericStats::param_buildPickaxe()); break;
case Tile::furnace_Id: player->awardStat(GenericStats::buildFurnace(), GenericStats::param_buildFurnace()); break;
//case Item::wooden_hoe_Id: player->awardStat(GenericStats::buildHoe(), GenericStats::param_buildHoe()); break;
case Item::bread_Id: player->awardStat(GenericStats::makeBread(), GenericStats::param_makeBread()); break;
case Item::cake_Id: player->awardStat(GenericStats::bakeCake(), GenericStats::param_bakeCake()); break;
case Item::stone_pickaxe_Id: player->awardStat(GenericStats::buildBetterPickaxe(), GenericStats::param_buildBetterPickaxe()); break;
//case Item::wooden_sword_Id: player->awardStat(GenericStats::buildSword(), GenericStats::param_buildSword()); break;
case Tile::dispenser_Id: player->awardStat(GenericStats::dispenseWithThis(), GenericStats::param_dispenseWithThis()); break;
case Tile::enchanting_table_Id: player->awardStat(GenericStats::enchantments(), GenericStats::param_enchantments()); break;
case Tile::bookshelf_Id: player->awardStat(GenericStats::bookcase(), GenericStats::param_bookcase()); break;
Recipy::INGREDIENTS_REQUIRED& req = pRecipeIngredientsRequired[iRecipe];
if (req.iType == RECIPE_TYPE_3x3 && dynamic_cast<CraftingMenu*>(player->containerMenu) == nullptr)
{
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
for (int i = 0; i < pRecipeIngredientsRequired[iRecipe].iIngC; i++)
{
for (int j = 0; j < pRecipeIngredientsRequired[iRecipe].iIngValA[i]; j++)
{
shared_ptr<ItemInstance> ingItemInst = nullptr;
// do we need to remove a specific aux value?
if (pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i] != Recipes::ANY_AUX_VALUE)
{
ingItemInst = player->inventory->getResourceItem(pRecipeIngredientsRequired[iRecipe].iIngIDA[i], pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i]);
player->inventory->removeResource(pRecipeIngredientsRequired[iRecipe].iIngIDA[i], pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i]);
}
else
{
ingItemInst = player->inventory->getResourceItem(pRecipeIngredientsRequired[iRecipe].iIngIDA[i]);
player->inventory->removeResource(pRecipeIngredientsRequired[iRecipe].iIngIDA[i]);
}
// 4J Stu - Fix for #13097 - Bug: Milk Buckets are removed when crafting Cake
if (ingItemInst != nullptr)
{
if (ingItemInst->getItem()->hasCraftingRemainingItem())
{
// replace item with remaining result
player->inventory->add(std::make_shared<ItemInstance>(ingItemInst->getItem()->getCraftingRemainingItem()));
}
}
}
}
// 4J Stu - Fix for #13119 - We should add the item after we remove the ingredients
if (player->inventory->add(pTempItemInst) == false)
{
// no room in inventory, so throw it down
player->drop(pTempItemInst);
}
if (pTempItemInst->id == Item::map_Id)
{
// 4J Stu - Maps need to have their aux value update, so the client should always be assumed to be wrong
// This is how the Java works, as the client also incorrectly predicts the auxvalue of the mapItem
vector<shared_ptr<ItemInstance> > items;
for (unsigned int i = 0; i < player->containerMenu->slots.size(); i++)
{
items.push_back(player->containerMenu->slots.at(i)->getItem());
}
player->refreshContainer(player->containerMenu, &items);
}
else
{
// Do same hack as PlayerConnection::handleContainerClick does - do our broadcast of changes just now, but with a hack so it just thinks it has sent
// things but hasn't really. This will stop the client getting a message back confirming the current inventory items, which might then arrive
// after another local change has been made on the client and be stale.
player->ignoreSlotUpdateHack = true;
player->containerMenu->broadcastChanges();
player->broadcastCarriedItem();
player->ignoreSlotUpdateHack = false;
}
}
// handle achievements
switch (pTempItemInst->id)
{
case Tile::crafting_table_Id: player->awardStat(GenericStats::buildWorkbench(), GenericStats::param_buildWorkbench()); break;
case Item::wooden_pickaxe_Id: player->awardStat(GenericStats::buildPickaxe(), GenericStats::param_buildPickaxe()); break;
case Tile::furnace_Id: player->awardStat(GenericStats::buildFurnace(), GenericStats::param_buildFurnace()); break;
//case Item::wooden_hoe_Id: player->awardStat(GenericStats::buildHoe(), GenericStats::param_buildHoe()); break;
case Item::bread_Id: player->awardStat(GenericStats::makeBread(), GenericStats::param_makeBread()); break;
case Item::cake_Id: player->awardStat(GenericStats::bakeCake(), GenericStats::param_bakeCake()); break;
case Item::stone_pickaxe_Id: player->awardStat(GenericStats::buildBetterPickaxe(), GenericStats::param_buildBetterPickaxe()); break;
//case Item::wooden_sword_Id: player->awardStat(GenericStats::buildSword(), GenericStats::param_buildSword()); break;
case Tile::dispenser_Id: player->awardStat(GenericStats::dispenseWithThis(), GenericStats::param_dispenseWithThis()); break;
case Tile::enchanting_table_Id: player->awardStat(GenericStats::enchantments(), GenericStats::param_enchantments()); break;
case Tile::bookshelf_Id: player->awardStat(GenericStats::bookcase(), GenericStats::param_bookcase()); break;
}
switch (pTempItemInst->getItem()->getBaseItemType()) {
case Item::eBaseItemType_hoe: player->awardStat(GenericStats::buildHoe(), GenericStats::param_buildHoe()); break;
case Item::eBaseItemType_sword: player->awardStat(GenericStats::buildSword(), GenericStats::param_buildSword()); break;
}
//}
// ELSE The server thinks the client was wrong...
}
switch (pTempItemInst->getItem()->getBaseItemType()) {
case Item::eBaseItemType_hoe: player->awardStat(GenericStats::buildHoe(), GenericStats::param_buildHoe()); break;
case Item::eBaseItemType_sword: player->awardStat(GenericStats::buildSword(), GenericStats::param_buildSword()); break;
}
//}
// ELSE The server thinks the client was wrong...
}