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

File diff suppressed because it is too large. Load diff
@@ -1,12 +1,15 @@
#pragma once
#include "../../../Minecraft.World/Recipy.h"
#include "../../../Minecraft.World/Item.h"
#include "../../../Minecraft.World/BannerPatternRecipe.h"
class LocalPlayer;
// 4J Stu - Crafting menu code that's shared across Iggy and XUI
class IUIScene_CraftingMenu
{
public:
typedef struct _PreviewBannerData { char id = 0; char color = 0; _PreviewBannerData(char _id, char _color) : id(_id), color(_color) {} } PreviewBannerData;
protected:
#define DISPLAY_INVENTORY 0
#define DISPLAY_DESCRIPTION 1
@@ -40,11 +43,10 @@ protected:
static const int m_iMaxGroupH3x3 = 7;
static const int m_iMaxGroupH2x2 = 6;
static const int m_iMaxGroupV2x2 = 4;
static const int m_iMaxGroupV2x2 = 0;
static const int m_iMaxGroupV3x3 = 4;
static const int m_iMaxBannerGroupH3x3 = 6;
static const int m_iMaxBannerGroupH2x2 = 6;
static int m_iBaseTypeMapA[Item::eBaseItemType_MAXTYPES];
@@ -57,6 +59,14 @@ protected:
CANBEMADE;
CANBEMADE CanBeMadeA[m_iMaxHSlotC];
std::vector<std::shared_ptr<ItemInstance>> CurrentInventoryBanners;
shared_ptr<ItemInstance> m_selectedBannerEdit;
vector<PreviewBannerData> m_bannerPreviewData;
shared_ptr<ItemInstance> m_bannerPreviewHolder;
int m_iCurrentSlotHIndex;
int m_iCurrentSlotVIndex;
@@ -64,15 +74,17 @@ protected:
int m_iContainerType; // 2x2 or 3x3
shared_ptr<LocalPlayer> m_pPlayer;
char m_aBannerCraftPatterns[5][12];
int m_iGroupHIndex;
int m_iGroupVIndex;
int iVSlotIndexA[3]; // index of the v slots currently displayed
int iHSlotState[7];
static LPCWSTR m_GroupIconNameA[m_iMaxGroupH3x3];
static Recipy::_eGroupType m_GroupTypeMapping4GridA[m_iMaxGroupH2x2];
static Recipy::_eGroupType m_GroupTypeMapping9GridA[m_iMaxGroupH3x3];
static Recipy::_eGroupType m_GroupTypeBannerMapping4GridA[m_iMaxBannerGroupH2x2];
static Recipy::_eGroupType m_GroupTypeBannerMapping9GridA[m_iMaxBannerGroupH3x3];
Recipy::_eGroupType** m_pGroupA;
@@ -100,6 +112,10 @@ public:
protected:
LPCWSTR GetGroupNameText(int iGroupType);
bool hasItem(int id, int requiredCount = 1, int aux = -1);
int hasItemCounts(int id, int requiredCount = -1, int aux = -1);
bool canCraftPattern(const BannerPatternRecipe::PatternInfo& pattern, char color);
void CheckRecipesAvailable();
void UpdateHighlight();
void UpdateVerticalSlots();
@@ -131,11 +147,16 @@ protected:
virtual void setVGroupHighlight(int iIndex) = 0;
virtual void setGroupText(LPCWSTR text) = 0;
virtual void setDescriptionText(LPCWSTR text) = 0;
virtual void setDescriptionTextTop(LPCWSTR text) = 0;
virtual void setItemText(LPCWSTR text) = 0;
virtual void scrollDescriptionUp() = 0;
virtual void scrollDescriptionDown() = 0;
virtual void updateHighlightAndScrollPositions() = 0;
virtual void updateVSlotPositions(int iSlots, int i) = 0;
virtual void UpdateCraftingPanels() = 0;
void rebuildPreviewItem();
virtual void setSelectedBannerEdit(shared_ptr<ItemInstance> banner) = 0;
virtual void UpdateMultiPanel() = 0;
};
@@ -31,14 +31,18 @@ int IUIScene_PauseMenu::ExitGameDialogReturned(void *pParam,int iPad,C4JStorage:
const bool consoleAutosave = (controlType == 0 || controlType == 1 || controlType == 4); // windows, xbox one and ps4
const bool autosaveEnabled = consoleAutosave && !StorageManager.GetSaveDisabled() && (app.GetGameHostOption(eGameHostOption_DisableSaving) == 0);
if(autosaveEnabled)
{
MinecraftServer::getInstance()->setSaveOnExit(true);
}
else
{
MinecraftServer::getInstance()->setSaveOnExit(false);
MinecraftServer* serverInstance = MinecraftServer::getInstance();
if (serverInstance != nullptr) {
if (autosaveEnabled)
{
serverInstance->setSaveOnExit(true);
}
else
{
serverInstance->setSaveOnExit(false);
}
}
if(pScene) pScene->SetIgnoreInput(true);
app.SetAction(iPad,eAppAction_ExitWorld);
@@ -5,6 +5,7 @@
#include "../../../Minecraft.World/net.minecraft.world.inventory.h"
#include "../../../Minecraft.World/DyePowderItem.h"
#include "../../../Minecraft.World/Tile.h"
#include "../../../Minecraft.World/BannerPatternRecipe.h"
#include "UIScene_CraftingMenu.h"
#ifdef _WINDOWS64
#include "../../Windows64/Iggy/gdraw/gdraw_d3d11.h"
@@ -33,12 +34,14 @@ UIScene_CraftingMenu::UIScene_CraftingMenu(int iPad, void *_initData, UILayer *p
initialiseMovie();
for(unsigned int i = 0; i < 9; ++i) m_labelIngredientsDesc[i].init(L"");
m_labelDescription.init(L"");
m_labelDescriptionText.init(L"");
m_labelDescriptionTextTop.init(L"");
m_labelGroupName.init(L"");
m_labelSpinnerTitle.init(L"");
m_labelItemName.init(L"");
m_labelItemNameSmall.init(L"");
m_labelInventory.init( app.GetString(IDS_INVENTORY) );
m_labelPreview.init(L"Preview");
m_labelIngredients.init(app.GetString(IDS_INGREDIENTS));
if(m_iContainerType==RECIPE_TYPE_2x2)
@@ -62,20 +65,55 @@ UIScene_CraftingMenu::UIScene_CraftingMenu(int iPad, void *_initData, UILayer *p
{
int maxGroupVLimit = ((m_iContainerType == RECIPE_TYPE_2x2) ? m_iMaxGroupV2x2 : m_iMaxGroupV3x3);
{
m_vGroupIconCache[0].item = make_shared<ItemInstance>(Tile::workBench, 1);
m_vGroupIconCache[0].show = (1 <= maxGroupVLimit);
m_vGroupIconCache[0].VSlot.item = make_shared<ItemInstance>(Tile::workBench, 1);
m_vGroupIconCache[0].VSlot.show = (1 <= maxGroupVLimit);
}
{
m_vGroupIconCache[1].item = make_shared<ItemInstance>(Tile::standing_banner_Id, 1, 0);
m_vGroupIconCache[1].show = (2 <= maxGroupVLimit);
m_vGroupIconCache[1].VSlot.item = make_shared<ItemInstance>(Tile::standing_banner_Id, 1, 0);
m_vGroupIconCache[1].VSlot.show = (2 <= maxGroupVLimit);
{
m_vGroupIconCache[1].HSlots.push_back(SlotInfo(make_shared<ItemInstance>(Tile::standing_banner_Id, 1, 0)));
}
{
SlotInfo slotInfo = SlotInfo(make_shared<ItemInstance>(Tile::standing_banner_Id, 1, 0));
BannerPatternRecipe::addBannerPattern(slotInfo.item, L"cr", DyePowderItem::BLACK);
m_vGroupIconCache[1].HSlots.push_back(slotInfo);
}
{
SlotInfo slotInfo = SlotInfo(make_shared<ItemInstance>(Tile::standing_banner_Id, 1, 0));
BannerPatternRecipe::addBannerPattern(slotInfo.item, L"ld", DyePowderItem::BLACK);
m_vGroupIconCache[1].HSlots.push_back(slotInfo);
}
{
SlotInfo slotInfo = SlotInfo(make_shared<ItemInstance>(Tile::standing_banner_Id, 1, 0));
BannerPatternRecipe::addBannerPattern(slotInfo.item, L"mc", DyePowderItem::BLACK);
m_vGroupIconCache[1].HSlots.push_back(slotInfo);
}
{
SlotInfo slotInfo = SlotInfo(make_shared<ItemInstance>(Tile::standing_banner_Id, 1, 0));
BannerPatternRecipe::addBannerPattern(slotInfo.item, L"bo", DyePowderItem::BLACK);
m_vGroupIconCache[1].HSlots.push_back(slotInfo);
}
{
SlotInfo slotInfo = SlotInfo(make_shared<ItemInstance>(Tile::standing_banner_Id, 1, 0));
BannerPatternRecipe::addBannerPattern(slotInfo.item, L"cre", DyePowderItem::BLACK);
m_vGroupIconCache[1].HSlots.push_back(slotInfo);
}
}
{
m_vGroupIconCache[2].item = make_shared<ItemInstance>(Item::fireworks_Id, 1, 0);
m_vGroupIconCache[2].show = (3 <= maxGroupVLimit);
m_vGroupIconCache[2].VSlot.item = make_shared<ItemInstance>(Item::fireworks_Id, 1, 0);
m_vGroupIconCache[2].VSlot.show = (3 <= maxGroupVLimit);
}
{
m_vGroupIconCache[3].item = make_shared<ItemInstance>(Item::dye_Id, 1, DyePowderItem::CYAN);
m_vGroupIconCache[3].show = (4 <= maxGroupVLimit);
m_vGroupIconCache[3].VSlot.item = make_shared<ItemInstance>(Item::dye_Id, 1, DyePowderItem::CYAN);
m_vGroupIconCache[3].VSlot.show = (4 <= maxGroupVLimit);
}
}
@@ -106,7 +144,6 @@ UIScene_CraftingMenu::UIScene_CraftingMenu(int iPad, void *_initData, UILayer *p
m_pGroupTabA=(_eGroupTab *)&m_GroupTabBkgMapping2x2A;
m_pGroupA[eGroupVType::eGroupVType_Workbench] = (Recipy::_eGroupType*)&m_GroupTypeMapping4GridA;
m_pGroupA[eGroupVType::eGroupVType_Banner] = (Recipy::_eGroupType*)&m_GroupTypeBannerMapping4GridA;
}
m_iCraftablesMaxHSlotC = m_iMaxHSlot;
@@ -156,6 +193,7 @@ UIScene_CraftingMenu::UIScene_CraftingMenu(int iPad, void *_initData, UILayer *p
m_Slot3_2.addSlot(CRAFTING_SLOT_EXTRA_START + 1);
m_Slot3_3.addSlot(CRAFTING_SLOT_EXTRA_START + 2);
m_slotPreviewSlot.addSlot(CRAFTING_SLOT_EXTRA_START + 0);
// 3 Slot vertical scroll
m_slotListCrafting3VSlots[0].addSlot(CRAFTING_V_SLOT_START + 0);
@@ -266,20 +304,74 @@ UIControl* UIScene_CraftingMenu::GetMainPanel()
#endif
#ifdef _WINDOWS64
void UIScene_CraftingMenu::handleLeftMouseClick(F32 x, F32 y, F32 sceneX, F32 sceneY) {
void UIScene_CraftingMenu::handleCraftingGroupSwitch() {
m_iCurrentSlotHIndex = 0;
m_iCurrentSlotVIndex = 1;
UpdateCraftingPanels();
CheckRecipesAvailable();
if (m_iGroupVIndex == eGroupVType_Banner && m_iGroupHIndex > 0) {
iVSlotIndexA[0] = 15; // White
iVSlotIndexA[1] = 0; // Black (center)
iVSlotIndexA[2] = 1; // Red
} else {
iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1;
iVSlotIndexA[1] = 0;
iVSlotIndexA[2] = 1;
}
ui.PlayUISFX(eSFX_Focus);
UpdateVerticalSlots();
UpdateHighlight();
setGroupText(GetGroupNameText(m_pGroupA[m_iGroupVIndex][m_iGroupHIndex]));
}
void UIScene_CraftingMenu::handleCraftingSlotClick(int iIndex) {
if (iIndex == m_iCurrentSlotHIndex) {
// Click on already-selected slot — craft the item
if (m_iGroupVIndex == eGroupVType_Banner && m_iGroupHIndex > 0) {
handleKeyDown(m_iPad, ACTION_MENU_Y, false);
} else {
handleKeyDown(m_iPad, ACTION_MENU_A, false);
}
} else {
int iOldHSlot = m_iCurrentSlotHIndex;
m_iCurrentSlotHIndex = iIndex;
m_iCurrentSlotVIndex = 1;
if (m_iGroupVIndex == eGroupVType_Banner && m_iGroupHIndex > 0) {
iVSlotIndexA[0] = 15; // White
iVSlotIndexA[1] = 0; // Black (center)
iVSlotIndexA[2] = 1; // Red
} else {
iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1;
iVSlotIndexA[1] = 0;
iVSlotIndexA[2] = 1;
}
UpdateVerticalSlots();
UpdateHighlight();
//if (CanBeMadeA[iOldHSlot].iCount > 0) {
setShowCraftHSlot(iOldHSlot, true);
//}
ui.PlayUISFX(eSFX_Focus);
}
}
bool isClickInsideControl(F32 x, F32 y, UIControl& control) {
F32 rectX = control.getXPos();
F32 rectY = control.getYPos();
return x >= rectX && x < rectX + control.getWidth() && y >= rectY && y < rectY + control.getHeight();
}
void UIScene_CraftingMenu::handleLeftMouseClick(F32 x, F32 y, F32 sceneX, F32 sceneY) {
{
int maxHorizontalTabs = (m_iContainerType == RECIPE_TYPE_3x3) ? m_iMaxGroupH3x3 : m_iMaxGroupH2x2;
F32 groupRowX1 = m_GroupH1.getXPos();
F32 groupRowX2 = m_GroupH2.getXPos();
F32 groupRowWidth = m_GroupH1.getWidth();
F32 groupRowSpacing = groupRowX2 - (groupRowX1 + groupRowWidth);
F32 groupRowX1 = m_GroupH[0].getXPos();
F32 groupRowWidth = m_GroupH[0].getWidth();
F32 tabStep = groupRowWidth + groupRowSpacing;
F32 rowX = groupRowX1;
F32 rowY = m_GroupH1.getYPos();
F32 rowHeight = m_GroupH1.getHeight();
F32 tabStep = groupRowWidth + (m_GroupH[1].getXPos() - (groupRowX1 + groupRowWidth));
F32 rowY = m_GroupH[0].getYPos();
F32 rowHeight = m_GroupH[0].getHeight();
if (sceneY >= rowY && sceneY < rowY + rowHeight && sceneX >= groupRowX1 && tabStep > 0.0f) {
F32 offsetX = sceneX - groupRowX1;
@@ -289,20 +381,12 @@ void UIScene_CraftingMenu::handleLeftMouseClick(F32 x, F32 y, F32 sceneX, F32 sc
F32 tabOffset = offsetX - tabIndex * tabStep;
if (tabOffset < groupRowWidth) {
m_iGroupHIndex = tabIndex;
setHGroupHighlight(m_iGroupHIndex);
m_iCurrentSlotHIndex = 0;
m_iCurrentSlotVIndex = 1;
UpdateCraftingPanels();
CheckRecipesAvailable();
iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1;
iVSlotIndexA[1] = 0;
iVSlotIndexA[2] = 1;
ui.PlayUISFX(eSFX_Focus);
UpdateVerticalSlots();
UpdateHighlight();
setGroupText(GetGroupNameText(m_pGroupA[m_iGroupVIndex][m_iGroupHIndex]));
if (iHSlotState[tabIndex]) {
m_iGroupHIndex = tabIndex;
setHGroupHighlight(m_iGroupHIndex);
handleCraftingGroupSwitch();
}
return;
}
}
@@ -311,14 +395,12 @@ void UIScene_CraftingMenu::handleLeftMouseClick(F32 x, F32 y, F32 sceneX, F32 sc
{
int maxVerticalTabs = (m_iContainerType == RECIPE_TYPE_3x3) ? m_iMaxGroupV3x3 : m_iMaxGroupV2x2;
F32 groupRowY1 = m_GroupV1.getYPos();
F32 groupRowY2 = m_GroupV2.getYPos();
F32 groupRowHeight = m_GroupV1.getHeight();
F32 groupRowSpacing = groupRowY2 - (groupRowY1 + groupRowHeight);
F32 groupRowY1 = m_GroupV[0].getYPos();
F32 groupRowHeight = m_GroupV[0].getHeight();
F32 tabStep = groupRowHeight + groupRowSpacing;
F32 rowX = m_GroupV1.getXPos();
F32 rowWidth = m_GroupV1.getWidth();
F32 tabStep = groupRowHeight + (m_GroupV[1].getYPos() - (groupRowY1 + groupRowHeight));
F32 rowX = m_GroupV[0].getXPos();
F32 rowWidth = m_GroupV[0].getWidth();
if (sceneY >= groupRowY1 && sceneX >= rowX && sceneX < rowX + rowWidth && tabStep > 0.0f) {
F32 offsetY = sceneY - groupRowY1;
@@ -328,58 +410,48 @@ void UIScene_CraftingMenu::handleLeftMouseClick(F32 x, F32 y, F32 sceneX, F32 sc
F32 tabOffset = offsetY - tabIndex * tabStep;
if (tabOffset < groupRowHeight) {
m_iGroupHIndex = 0;
m_iGroupVIndex = tabIndex;
setVGroupHighlight(m_iGroupVIndex);
m_iCurrentSlotHIndex = 0;
m_iCurrentSlotVIndex = 1;
UpdateCraftingPanels();
CheckRecipesAvailable();
iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1;
iVSlotIndexA[1] = 0;
iVSlotIndexA[2] = 1;
ui.PlayUISFX(eSFX_Focus);
UpdateVerticalSlots();
UpdateHighlight();
setGroupText(GetGroupNameText(m_pGroupA[m_iGroupVIndex][m_iGroupHIndex]));
handleCraftingGroupSwitch();
return;
}
}
}
}
//if (m_iGroupVIndex == eGroupVType::eGroupVType_Workbench) {
bool showingSpecial3 = (m_iGroupVIndex == eGroupVType_Banner && m_iGroupHIndex == 0);
bool showingSpecial2 = false;
bool showingNormalSlots = (!showingSpecial3 && !showingSpecial2);
if (showingSpecial3) {
if (isClickInsideControl(sceneX, sceneY, m_Slot3_1)) {
handleCraftingSlotClick(0);
UpdateCraftingPanels();
} else if (isClickInsideControl(sceneX, sceneY, m_Slot3_2)) {
handleCraftingSlotClick(1);
UpdateCraftingPanels();
} else if (isClickInsideControl(sceneX, sceneY, m_Slot3_3)) {
handleCraftingSlotClick(2);
UpdateCraftingPanels();
}
} else if (showingSpecial2) {
} else if (showingNormalSlots) {
if (m_hSlotBoundsValid && m_hSlotSpacing > 0) {
F32 rowWidth = m_hSlotSpacing * m_iCraftablesMaxHSlotC;
if (x >= m_hSlotX0 && x < m_hSlotX0 + rowWidth && y >= m_hSlotY0 && y < m_hSlotY1) {
int iNewSlot = (int)((x - m_hSlotX0) / m_hSlotSpacing);
if (iNewSlot >= 0 && iNewSlot < m_iCraftablesMaxHSlotC) {
// Only interact with populated slots
if (CanBeMadeA[iNewSlot].iCount != 0) {
if (iNewSlot == m_iCurrentSlotHIndex)
{
// Click on already-selected slot — craft the item
handleKeyDown(m_iPad, ACTION_MENU_A, false);
} else {
int iOldHSlot = m_iCurrentSlotHIndex;
m_iCurrentSlotHIndex = iNewSlot;
m_iCurrentSlotVIndex = 1;
iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1;
iVSlotIndexA[1] = 0;
iVSlotIndexA[2] = 1;
UpdateVerticalSlots();
UpdateHighlight();
if (CanBeMadeA[iOldHSlot].iCount > 0) {
setShowCraftHSlot(iOldHSlot, true);
}
ui.PlayUISFX(eSFX_Focus);
}
}
//if (CanBeMadeA[iNewSlot].iCount != 0) {
handleCraftingSlotClick(iNewSlot);
//}
}
}
}
//}
}
}
@@ -416,6 +488,8 @@ void UIScene_CraftingMenu::handleReload()
m_Slot3_2.addSlot(CRAFTING_SLOT_EXTRA_START + 1);
m_Slot3_3.addSlot(CRAFTING_SLOT_EXTRA_START + 2);
m_slotPreviewSlot.addSlot(CRAFTING_SLOT_EXTRA_START + 0);
// 3 Slot vertical scroll
m_slotListCrafting3VSlots[0].addSlot(CRAFTING_V_SLOT_START + 0);
m_slotListCrafting3VSlots[1].addSlot(CRAFTING_V_SLOT_START + 1);
@@ -452,7 +526,6 @@ void UIScene_CraftingMenu::handleReload()
UpdateHighlight();
app.DebugPrintf(app.USER_SR,"Reloading tabs\n");
setHGroupHighlight(m_iGroupHIndex);
setVGroupHighlight(m_iGroupVIndex);
UpdateCraftingPanels();
}
@@ -552,44 +625,30 @@ void UIScene_CraftingMenu::customDraw(IggyCustomDrawCallbackRegion *region)
else if (slotId >= CRAFTING_SLOT_EXTRA_START && slotId < CRAFTING_SLOT_EXTRA_END) {
int iIndex = (slotId - CRAFTING_SLOT_EXTRA_START);
if (iIndex == 0) {
if (m_hSlotsInfo[0].show) {
item = m_hSlotsInfo[0].item;
alpha = static_cast<float>(m_hSlotsInfo[0].alpha) / 31.0f;
if (m_iGroupHIndex > 0) {
item = m_bannerPreviewHolder;
alpha = 1.0f;
} else {
if (m_craftingOutputSlotInfo.show)
{
item = m_craftingOutputSlotInfo.item;
alpha = static_cast<float>(m_craftingOutputSlotInfo.alpha) / 31.0f;
if (m_hSlotsInfo[0].show) {
item = m_hSlotsInfo[0].item;
alpha = static_cast<float>(m_hSlotsInfo[0].alpha) / 31.0f;
} else {
if (m_craftingOutputSlotInfo.show)
{
item = m_craftingOutputSlotInfo.item;
alpha = static_cast<float>(m_hSlotsInfo[0].alpha) / 31.0f;
}
}
}
} else if (iIndex == 1) {
if (CurrentInventoryBanners.size() > 0) {
if (m_iCurrentSlotHIndex == 1) {
item = CurrentInventoryBanners[m_iCurrentSlotVIndex-1];
} else {
item = CurrentInventoryBanners[0];
}
}
}
#ifdef _WINDOWS64
// Cache H slot SWF-space positions from the custom draw transform matrix
if (iIndex == 0 || iIndex == 1)
{
F32 mat[16];
gdraw_D3D11_CalculateCustomDraw_4J(region, mat);
// Matrix to SWF coords (same formula as setupCustomDrawMatrices)
F32 sw = (F32)getRenderWidth();
F32 sh = (F32)getRenderHeight();
F32 swfX = sw * (1.0f + mat[3]) / 2.0f;
F32 swfY = sh * (1.0f - mat[7]) / 2.0f;
if (iIndex == 0)
{
m_hSlotX0 = swfX;
m_hSlotY0 = swfY;
// Slot visual height from matrix scale and region height
F32 slotH = sh * (-mat[5]) / 2.0f * region->y1;
m_hSlotY1 = swfY + slotH;
}
else
{
m_hSlotSpacing = swfX - m_hSlotX0;
m_hSlotBoundsValid = (m_hSlotSpacing > 0);
}
}
#endif
}
else if (slotId >= CRAFTING_INGREDIENTS_DESCRIPTION_START && slotId < (CRAFTING_INGREDIENTS_DESCRIPTION_START + 9))
{
@@ -609,13 +668,26 @@ void UIScene_CraftingMenu::customDraw(IggyCustomDrawCallbackRegion *region)
}
}
} else if (swscanf(static_cast<wchar_t*>(region->name), L"TabV_%d", &iTabV) == 1) {
SlotInfo& vGroupIconInfo = m_vGroupIconCache[iTabV - 1];
if (vGroupIconInfo.show) {
item = vGroupIconInfo.item;
alpha = vGroupIconInfo.alpha;
GroupIcons& vGroupIconInfo = m_vGroupIconCache[iTabV - 1];
if (vGroupIconInfo.VSlot.show) {
item = vGroupIconInfo.VSlot.item;
alpha = static_cast<float>(vGroupIconInfo.VSlot.alpha)/31.0f;
}
} else if (swscanf(static_cast<wchar_t*>(region->name), L"TabH_%d", &iTabH) == 1) {
GroupIcons& vGroupIconInfo = m_vGroupIconCache[m_iGroupVIndex];
if (m_selectedBannerEdit == nullptr) {
if (vGroupIconInfo.HSlots.size() >= iTabH && iTabH == 1) {
item = vGroupIconInfo.HSlots[iTabH - 1].item;
}
} else {
if (vGroupIconInfo.HSlots.size() >= iTabH && iTabH != 1) {
item = vGroupIconInfo.HSlots[iTabH - 1].item;
}
}
//alpha = static_cast<float>(vGroupIconInfo.HSlots[iTabH - 1].alpha)/31.0f;
}
if(item != nullptr) {
@@ -633,6 +705,11 @@ void UIScene_CraftingMenu::customDraw(IggyCustomDrawCallbackRegion *region)
}
}
void UIScene_CraftingMenu::tick()
{
UIScene::tick();
}
int UIScene_CraftingMenu::getPad()
{
return m_iPad;
@@ -654,19 +731,25 @@ void UIScene_CraftingMenu::handleInput(int iPad, int key, bool repeat, bool pres
//app.DebugPrintf("UIScene_InventoryMenu handling input for pad %d, key %d, down- %s, pressed- %s, released- %s\n", iPad, key, down?"TRUE":"FALSE", pressed?"TRUE":"FALSE", released?"TRUE":"FALSE");
ui.AnimateKeyPress(m_iPad, key, repeat, pressed, released);
switch(key)
{
case ACTION_MENU_OTHER_STICK_UP:
case ACTION_MENU_OTHER_STICK_DOWN:
sendInputToMovie(key,repeat,pressed,released);
break;
default:
if(pressed)
//if (m_iGroupVIndex == eGroupVType_Banner && m_iCurrentSlotHIndex == 1) {
//} else {
switch(key)
{
handled = handleKeyDown(m_iPad, key, repeat);
}
break;
};
case ACTION_MENU_OTHER_STICK_UP:
case ACTION_MENU_OTHER_STICK_DOWN:
sendInputToMovie(key,repeat,pressed,released);
break;
default:
if(pressed)
{
handled = handleKeyDown(m_iPad, key, repeat);
}
break;
};
//}
}
void UIScene_CraftingMenu::hideAllHSlots()
@@ -727,6 +810,9 @@ void UIScene_CraftingMenu::setCraftVSlotItem(int iPad, int iIndex, shared_ptr<It
void UIScene_CraftingMenu::setCraftingOutputSlotItem(int iPad, shared_ptr<ItemInstance> item)
{
if (m_iGroupVIndex == eGroupVType_Banner && m_iGroupHIndex == 0) {
setDescriptionTextTop(item->getHoverName().c_str());
}
m_craftingOutputSlotInfo.item = item;
m_craftingOutputSlotInfo.alpha = 31;
m_craftingOutputSlotInfo.show = item != nullptr;
@@ -797,6 +883,8 @@ void UIScene_CraftingMenu::setHGroupHighlight(int iIndex)
void UIScene_CraftingMenu::setVGroupHighlight(int iIndex) {
setHGroupHighlight(m_iGroupHIndex);
m_selectedBannerEdit = nullptr;
m_bannerPreviewHolder = nullptr;
}
@@ -807,18 +895,23 @@ void UIScene_CraftingMenu::setGroupText(LPCWSTR text)
void UIScene_CraftingMenu::setDescriptionText(LPCWSTR text)
{
m_labelDescription.setLabel(text);
m_labelDescriptionText.setLabel(text);
}
void UIScene_CraftingMenu::setDescriptionTextTop(LPCWSTR text)
{
m_labelDescriptionTextTop.setLabel(text);
}
void UIScene_CraftingMenu::setItemText(LPCWSTR text)
{
if (m_iContainerType == RECIPE_TYPE_2x2) {
m_labelItemNameSmall.setLabel(text);
m_labelItemName.setLabel(L"");
} else {
//if (m_iContainerType == RECIPE_TYPE_2x2) {
// m_labelItemNameSmall.setLabel(text);
// m_labelItemName.setLabel(L"");
//} else {
m_labelItemName.setLabel(text);
m_labelItemNameSmall.setLabel(L"");
}
//}
}
void UIScene_CraftingMenu::UpdateMultiPanel()
@@ -853,13 +946,21 @@ void UIScene_CraftingMenu::updateHighlightAndScrollPositions()
value[0].number = m_iCurrentSlotHIndex;
int selectorType = 0;
if(CanBeMadeA[m_iCurrentSlotHIndex].iCount == 2)
{
selectorType = 1;
}
else if( CanBeMadeA[m_iCurrentSlotHIndex].iCount > 2)
{
if (m_iGroupVIndex == eGroupVType_Banner && m_iGroupHIndex == 0 && m_iCurrentSlotHIndex == 1) {
if (CurrentInventoryBanners.size() == 2) {
selectorType = 1;
} else if (CurrentInventoryBanners.size() > 2) {
selectorType = 2;
}
} else if (m_iGroupVIndex == eGroupVType_Banner && m_iGroupHIndex > 0) {
selectorType = 2;
} else {
if(CanBeMadeA[m_iCurrentSlotHIndex].iCount == 2) {
selectorType = 1;
} else if( CanBeMadeA[m_iCurrentSlotHIndex].iCount > 2) {
selectorType = 2;
}
}
value[1].type = IGGY_DATATYPE_number;
@@ -904,6 +1005,19 @@ void UIScene_CraftingMenu::HandleMessage(EUIMessage message, void *data)
void UIScene_CraftingMenu::handleInventoryUpdated(LPVOID data)
{
HandleInventoryUpdated();
if (m_selectedBannerEdit != nullptr) {
bool stillHasEditingBanner = false;
for (unsigned int i = 0; i < CurrentInventoryBanners.size(); i++) {
if (CurrentInventoryBanners[i] == nullptr) continue;
if (CurrentInventoryBanners[i].get() == m_selectedBannerEdit.get()) {
stillHasEditingBanner = true;
break;
}
}
if (!stillHasEditingBanner) setSelectedBannerEdit(nullptr);
}
}
void UIScene_CraftingMenu::updateVSlotPositions(int iSlots, int i)
@@ -926,7 +1040,7 @@ void UIScene_CraftingMenu::SetCraftingMenu() {
int currentHGroups = (m_iContainerType == RECIPE_TYPE_3x3 ? m_iMaxGroupH3x3 : m_iMaxGroupH2x2);
if (m_iGroupVIndex == eGroupVType_Banner) {
currentHGroups = (m_iContainerType == RECIPE_TYPE_3x3 ? m_iMaxBannerGroupH3x3 : m_iMaxBannerGroupH2x2);
currentHGroups = m_iMaxBannerGroupH3x3;
}
value[0].type = IGGY_DATATYPE_number;
@@ -940,27 +1054,83 @@ void UIScene_CraftingMenu::SetCraftingMenu() {
void UIScene_CraftingMenu::UpdateCraftingPanels() {
UpdateEnabledTabs();
if (m_iGroupVIndex == eGroupVType_Workbench) {
m_iDisplayDescription = DISPLAY_INVENTORY;
ShowSuperCraftingSlots(0);
ShowDescriptionPanel(false);
} else if (m_iGroupVIndex == eGroupVType_Banner) {
ShowDescriptionPanel(m_iGroupHIndex == 0);
if (m_iGroupHIndex == 0) {
ShowSuperCraftingSlots(3);
m_iDisplayDescription = DISPLAY_INVENTORY;
if (m_iCurrentSlotHIndex == 0) {
m_labelSpinnerTitle.setLabel(L"Create Banner");
} else if (m_iCurrentSlotHIndex == 1) {
m_labelSpinnerTitle.setLabel(L"Select Banner");
}
} else {
ShowSuperCraftingSlots(0);
m_iDisplayDescription = DISPLAY_PREVIEW;
}
if (m_iCurrentSlotHIndex == 0) {
m_labelSpinnerTitle.setLabel(L"Create Banner");
} else if (m_iCurrentSlotHIndex == 1) {
m_labelSpinnerTitle.setLabel(L"Select Banner");
}
}
SetCraftingMenu();
UpdateMultiPanel();
updateHighlightAndScrollPositions();
}
}
void UIScene_CraftingMenu::UpdateEnabledTabs() {
int maxHGroups = (m_iContainerType == RECIPE_TYPE_2x2) ? m_iMaxGroupH2x2 : m_iMaxGroupH3x3;
for (int i = 0; i < maxHGroups; i++) {
EnableTab(i, true);
}
if (m_iGroupVIndex == eGroupVType_Banner) {
if (m_selectedBannerEdit == nullptr) {
for (int i = 1; i < maxHGroups; i++) {
EnableTab(i, false);
}
} else {
EnableTab(0, false);
}
}
}
void UIScene_CraftingMenu::EnableTab(int iIndex, bool enabled) {
IggyDataValue result;
IggyDataValue value[2];
value[0].type = IGGY_DATATYPE_number;
value[0].number = iIndex;
value[1].type = IGGY_DATATYPE_boolean;
value[1].boolval = enabled;
IggyResult out = IggyPlayerCallMethodRS(getMovie(), &result, IggyPlayerRootPath(getMovie()), m_funcEnableTab, 2, value);
iHSlotState[iIndex] = enabled;
}
void UIScene_CraftingMenu::ShowDescriptionPanel(bool show) {
m_controlDescriptionPanel.setVisible(show);
m_labelDescriptionTextTop.setVisible(show);
}
void UIScene_CraftingMenu::setSelectedBannerEdit(shared_ptr<ItemInstance> banner) {
m_selectedBannerEdit = banner;
if (m_selectedBannerEdit == nullptr) {
m_iGroupHIndex = 0;
m_bannerPreviewHolder = nullptr;
} else {
m_iGroupHIndex = 1;
m_bannerPreviewHolder = ItemInstance::clone(m_selectedBannerEdit);
}
setHGroupHighlight(m_iGroupHIndex);
handleCraftingGroupSwitch();
}
@@ -39,12 +39,8 @@ private:
unsigned int alpha;
bool show;
_SlotInfo()
{
item = nullptr;
alpha = 31;
show = true;
}
_SlotInfo() : item(nullptr), alpha(31), show(true) {}
_SlotInfo(shared_ptr<ItemInstance> _item) : item(_item), alpha(31), show(true) { }
} SlotInfo;
SlotInfo m_hSlotsInfo[m_iMaxHSlotC];
@@ -53,7 +49,12 @@ private:
SlotInfo m_craftingOutputSlotInfo;
SlotInfo m_ingredientsInfo[9];
SlotInfo m_vGroupIconCache[4];
typedef struct _GroupIcons {
SlotInfo VSlot;
std::vector<SlotInfo> HSlots;
} GroupIcons;
GroupIcons m_vGroupIconCache[4];
AbstractContainerMenu *m_menu;
@@ -85,14 +86,16 @@ public:
bool m_hSlotBoundsValid;
//cached from swf at startup
UIControl m_GroupH1, m_GroupH2;
UIControl m_GroupV1, m_GroupV2;
UIControl m_GroupH[2];
UIControl m_GroupV[2];
void handleCraftingGroupSwitch();
void handleCraftingSlotClick(int iIndex);
void handleLeftMouseClick(F32 x, F32 y, F32 sceneX, F32 sceneY);
#endif
protected:
UIControl m_controlMainPanel;
UIControl m_controlMainPanel, m_controlDescriptionPanel;
UIControl m_control1Selector, m_control2Selector, m_control3Selector;
UIControl_SlotList m_slotListCraftingHSlots;
UIControl_SlotList m_slotListCrafting1VSlots, m_slotListCrafting2VSlots[2], m_slotListCrafting3VSlots[3];
@@ -100,10 +103,10 @@ protected:
UIControl_SlotList m_slotListIngredients[9];
UIControl_SlotList m_Slot2_1, m_Slot2_2;
UIControl_SlotList m_Slot3_1, m_Slot3_2, m_Slot3_3;
UIControl_SlotList m_slotListInventory, m_slotListHotBar;
UIControl_SlotList m_slotListInventory, m_slotListHotBar, m_slotPreviewSlot;
UIControl_Label m_labelIngredientsDesc[9];
UIControl_HTMLLabel m_labelDescription;
UIControl_Label m_labelGroupName, m_labelSpinnerTitle, m_labelItemName, m_labelItemNameSmall, m_labelInventory, m_labelIngredients;
UIControl_HTMLLabel m_labelDescriptionText, m_labelDescriptionTextTop;
UIControl_Label m_labelGroupName, m_labelSpinnerTitle, m_labelItemName, m_labelItemNameSmall, m_labelInventory, m_labelPreview, m_labelIngredients;
IggyName m_funcMoveSelector, m_funcSelectVerticalItem, m_funcSetActiveTab;
IggyName m_funcShowPanelDisplay, m_funcShowIngredientSlot;
@@ -175,6 +178,8 @@ protected:
UI_MAP_ELEMENT( m_labelIngredientsDesc[7], "Ingredient8Desc")
UI_MAP_ELEMENT( m_labelIngredientsDesc[8], "Ingredient9Desc")
UI_MAP_ELEMENT( m_controlDescriptionPanel, "DescriptionPanel" )
UI_MAP_ELEMENT( m_Slot2_1, "Slot2_1")
UI_MAP_ELEMENT( m_Slot2_2, "Slot2_2")
@@ -184,16 +189,19 @@ protected:
UI_MAP_ELEMENT( m_labelIngredients, "IngredientsLabel")
UI_MAP_ELEMENT( m_labelDescription, "DescriptionText")
UI_MAP_ELEMENT( m_labelDescriptionText, "DescriptionText")
UI_MAP_ELEMENT( m_labelDescriptionTextTop, "DescriptionTextTop")
UI_MAP_ELEMENT( m_slotListInventory, "Inventory")
UI_MAP_ELEMENT( m_slotListHotBar, "HotBar")
UI_MAP_ELEMENT( m_slotPreviewSlot, "PreviewSlot")
UI_MAP_ELEMENT( m_labelSpinnerTitle, "SpinnerTitle")
UI_MAP_ELEMENT( m_labelGroupName, "GroupName")
UI_MAP_ELEMENT( m_labelItemName, "ItemName")
UI_MAP_ELEMENT( m_labelItemNameSmall, "ItemNameSmall")
UI_MAP_ELEMENT( m_labelInventory, "InventoryLabel")
UI_MAP_ELEMENT( m_labelPreview, "PreviewLabel")
UI_MAP_NAME( m_funcMoveSelector, L"MoveSelector")
UI_MAP_NAME( m_funcSelectVerticalItem, L"SelectVerticalItem")
@@ -207,11 +215,11 @@ protected:
UI_MAP_NAME( m_funcShowSuperCraftingSlots, L"ShowSuperCraftingSlots" )
#ifdef _WINDOWS64
UI_MAP_ELEMENT(m_GroupH1, "TabH_1")
UI_MAP_ELEMENT(m_GroupH2, "TabH_2")
UI_MAP_ELEMENT(m_GroupH[0], "TabH_1")
UI_MAP_ELEMENT(m_GroupH[1], "TabH_2")
UI_MAP_ELEMENT(m_GroupV1, "TabV_1")
UI_MAP_ELEMENT(m_GroupV2, "TabV_2")
UI_MAP_ELEMENT(m_GroupV[0], "TabV_1")
UI_MAP_ELEMENT(m_GroupV[1], "TabV_2")
#endif
#ifdef __PSVITA__
@@ -235,6 +243,8 @@ protected:
void handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled);
protected:
virtual void tick();
virtual int getPad();
virtual void hideAllHSlots();
virtual void hideAllVSlots();
@@ -246,6 +256,7 @@ protected:
virtual void setIngredientSlotItem(int iPad, int index, shared_ptr<ItemInstance> item);
virtual void setIngredientSlotRedBox(int index, bool show);
virtual void setIngredientDescriptionItem(int iPad, int index, shared_ptr<ItemInstance> item);
virtual void setSelectedBannerEdit(shared_ptr<ItemInstance> banner);
virtual void setIngredientDescriptionRedBox(int index, bool show);
virtual void setIngredientDescriptionText(int index, LPCWSTR text);
virtual void setShowCraftHSlot(int iIndex, bool show);
@@ -253,6 +264,7 @@ protected:
virtual void setVGroupHighlight(int iIndex);
virtual void setGroupText(LPCWSTR text);
virtual void setDescriptionText(LPCWSTR text);
virtual void setDescriptionTextTop(LPCWSTR text);
virtual void setItemText(LPCWSTR text);
virtual void scrollDescriptionUp();
virtual void scrollDescriptionDown();
@@ -263,9 +275,13 @@ protected:
virtual void UpdateMultiPanel();
virtual void UpdateCraftingPanels();
virtual void UpdateEnabledTabs();
virtual void ShowSuperCraftingSlots(int iIndex);
virtual void ShowDescriptionPanel(bool show);
virtual void SetCraftingMenu();
virtual void EnableTab(int iIndex, bool enabled);
virtual void HandleMessage(EUIMessage message, void *data);
void handleInventoryUpdated(LPVOID data);
+11 -2
View File
@@ -548,11 +548,20 @@ bool MultiPlayerGameMode::isServerControlledInventory()
bool MultiPlayerGameMode::handleCraftItem(int recipe, shared_ptr<Player> player)
{
short changeUid = player->containerMenu->backup(player->inventory);
short changeUid = player->containerMenu->backup(player->inventory);
connection->send(std::make_shared<CraftItemPacket>(recipe, changeUid));
return true;
return true;
}
bool MultiPlayerGameMode::handleCraftBanner(shared_ptr<ItemInstance> craftingBanner, vector<IUIScene_CraftingMenu::PreviewBannerData>& data, shared_ptr<Player> player) {
short changeUid = player->containerMenu->backup(player->inventory);
connection->send(std::make_shared<CraftItemPacket>(craftingBanner, data, changeUid));
return true;
}
void MultiPlayerGameMode::handleDebugOptions(unsigned int uiVal, shared_ptr<Player> player)
+3
View File
@@ -1,5 +1,7 @@
#pragma once
#include "GameMode.h"
#include "../Minecraft.Client/Common/UI/IUIScene_CraftingMenu.h"
class ClientConnection;
class GameType;
class Vec3;
@@ -61,6 +63,7 @@ public:
// 4J Stu - Added so we can send packets for this in the network game
virtual bool handleCraftItem(int recipe, shared_ptr<Player> player);
virtual bool handleCraftBanner(shared_ptr<ItemInstance> craftingBanner,vector<IUIScene_CraftingMenu::PreviewBannerData>& data, shared_ptr<Player> player);
virtual void handleDebugOptions(unsigned int uiVal, shared_ptr<Player> player);
// 4J Stu - Added for tutorial checks
+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...
}