1
0
Fork 0

cWindow: Convert XYZ to Vector3 (#4764)

This commit is contained in:
MaxwellScroggs 2020-07-04 17:49:17 -04:00 committed by GitHub
parent 868e28b44f
commit 5cdaf073be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 25 additions and 43 deletions

View File

@ -38,6 +38,7 @@ maxluchterhand1
marmot21 marmot21
Masy98 Masy98
mathiascode mathiascode
MaxwellScroggs
mborland mborland
mBornand mBornand
MeMuXin MeMuXin

View File

@ -44,7 +44,7 @@ public:
const Vector3i a_CursorPos const Vector3i a_CursorPos
) override ) override
{ {
cWindow * Window = new cAnvilWindow(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z); cWindow * Window = new cAnvilWindow(a_BlockPos);
a_Player.OpenWindow(*Window); a_Player.OpenWindow(*Window);
return true; return true;
} }

View File

@ -34,7 +34,7 @@ public:
const Vector3i a_CursorPos const Vector3i a_CursorPos
) override ) override
{ {
cWindow * Window = new cEnchantingWindow(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z); cWindow * Window = new cEnchantingWindow(a_BlockPos);
a_Player.OpenWindow(*Window); a_Player.OpenWindow(*Window);
return true; return true;
} }

View File

@ -34,7 +34,7 @@ public:
const Vector3i a_CursorPos const Vector3i a_CursorPos
) override ) override
{ {
cWindow * Window = new cCraftingWindow(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z); cWindow * Window = new cCraftingWindow();
a_Player.OpenWindow(*Window); a_Player.OpenWindow(*Window);
return true; return true;
} }

View File

@ -10,12 +10,10 @@
cAnvilWindow::cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : cAnvilWindow::cAnvilWindow(Vector3i a_BlockPos) :
cWindow(wtAnvil, "Repair"), cWindow(wtAnvil, "Repair"),
m_RepairedItemName(""), m_RepairedItemName(""),
m_BlockX(a_BlockX), m_BlockPos(a_BlockPos)
m_BlockY(a_BlockY),
m_BlockZ(a_BlockZ)
{ {
m_AnvilSlotArea = new cSlotAreaAnvil(*this); m_AnvilSlotArea = new cSlotAreaAnvil(*this);
m_SlotAreas.push_back(m_AnvilSlotArea); m_SlotAreas.push_back(m_AnvilSlotArea);
@ -49,17 +47,6 @@ void cAnvilWindow::SetRepairedItemName(const AString & a_Name, cPlayer * a_Playe
void cAnvilWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ)
{
a_PosX = m_BlockX;
a_PosY = m_BlockY;
a_PosZ = m_BlockZ;
}
void cAnvilWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) void cAnvilWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
{ {
cSlotAreas AreasInOrder; cSlotAreas AreasInOrder;

View File

@ -22,7 +22,7 @@ class cAnvilWindow:
public: public:
cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ); cAnvilWindow(Vector3i a_BlockPos);
/** Gets the repaired item name. */ /** Gets the repaired item name. */
AString GetRepairedItemName(void) const; AString GetRepairedItemName(void) const;
@ -31,14 +31,14 @@ public:
void SetRepairedItemName(const AString & a_Name, cPlayer * a_Player); void SetRepairedItemName(const AString & a_Name, cPlayer * a_Player);
/** Gets the Position from the Anvil */ /** Gets the Position from the Anvil */
void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ); const Vector3i & GetBlockPos() { return m_BlockPos; }
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override; virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
protected: protected:
cSlotAreaAnvil * m_AnvilSlotArea; cSlotAreaAnvil * m_AnvilSlotArea;
AString m_RepairedItemName; AString m_RepairedItemName;
int m_BlockX, m_BlockY, m_BlockZ; Vector3i m_BlockPos;
}; };

View File

@ -10,7 +10,7 @@
cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : cCraftingWindow::cCraftingWindow() :
cWindow(wtWorkbench, "Crafting Table") cWindow(wtWorkbench, "Crafting Table")
{ {
m_SlotAreas.push_back(new cSlotAreaCrafting(3, *this)); m_SlotAreas.push_back(new cSlotAreaCrafting(3, *this));

View File

@ -22,7 +22,7 @@ class cCraftingWindow:
public: public:
cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ); cCraftingWindow();
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override; virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
}; };

View File

@ -11,14 +11,12 @@
cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : cEnchantingWindow::cEnchantingWindow(Vector3i a_BlockPos) :
cWindow(wtEnchantment, "Enchant"), cWindow(wtEnchantment, "Enchant"),
m_SlotArea(), m_SlotArea(),
m_BlockX(a_BlockX), m_BlockPos(a_BlockPos)
m_BlockY(a_BlockY),
m_BlockZ(a_BlockZ)
{ {
m_SlotArea = new cSlotAreaEnchanting(*this, m_BlockX, m_BlockY, m_BlockZ); m_SlotArea = new cSlotAreaEnchanting(*this, m_BlockPos);
m_SlotAreas.push_back(m_SlotArea); m_SlotAreas.push_back(m_SlotArea);
m_SlotAreas.push_back(new cSlotAreaInventory(*this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this));
m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); m_SlotAreas.push_back(new cSlotAreaHotBar(*this));

View File

@ -22,7 +22,7 @@ class cEnchantingWindow:
public: public:
cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ); cEnchantingWindow(Vector3i a_BlockPos);
virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player) override; virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player) override;
@ -37,7 +37,7 @@ public:
protected: protected:
short m_PropertyValue[3]; short m_PropertyValue[3];
int m_BlockX, m_BlockY, m_BlockZ; Vector3i m_BlockPos;
}; };

View File

@ -996,14 +996,12 @@ void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player)
m_MaximumCost = 0; m_MaximumCost = 0;
static_cast<cAnvilWindow &>(m_ParentWindow).SetRepairedItemName("", nullptr); static_cast<cAnvilWindow &>(m_ParentWindow).SetRepairedItemName("", nullptr);
int PosX, PosY, PosZ; const Vector3i BlockPos = static_cast<cAnvilWindow &>(m_ParentWindow).GetBlockPos();
static_cast<cAnvilWindow &>(m_ParentWindow).GetBlockPos(PosX, PosY, PosZ);
BLOCKTYPE Block; BLOCKTYPE Block;
NIBBLETYPE BlockMeta; NIBBLETYPE BlockMeta;
a_Player.GetWorld()->GetBlockTypeMeta(PosX, PosY, PosZ, Block, BlockMeta); a_Player.GetWorld()->GetBlockTypeMeta(BlockPos, Block, BlockMeta);
const Vector3i BlockPos{PosX, PosY, PosZ};
if (!a_Player.IsGameModeCreative() && (Block == E_BLOCK_ANVIL) && GetRandomProvider().RandBool(0.12)) if (!a_Player.IsGameModeCreative() && (Block == E_BLOCK_ANVIL) && GetRandomProvider().RandBool(0.12))
{ {
NIBBLETYPE Orientation = BlockMeta & 0x3; NIBBLETYPE Orientation = BlockMeta & 0x3;
@ -1013,13 +1011,13 @@ void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player)
if (AnvilDamage > 2) if (AnvilDamage > 2)
{ {
// Anvil will break // Anvil will break
a_Player.GetWorld()->SetBlock(PosX, PosY, PosZ, E_BLOCK_AIR, 0); a_Player.GetWorld()->SetBlock(BlockPos, E_BLOCK_AIR, 0);
a_Player.GetWorld()->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_ANVIL_BREAK, BlockPos, 0); a_Player.GetWorld()->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_ANVIL_BREAK, BlockPos, 0);
a_Player.CloseWindow(false); a_Player.CloseWindow(false);
} }
else else
{ {
a_Player.GetWorld()->SetBlockMeta(PosX, PosY, PosZ, static_cast<NIBBLETYPE>(Orientation | (AnvilDamage << 2))); a_Player.GetWorld()->SetBlockMeta(BlockPos, static_cast<NIBBLETYPE>(Orientation | (AnvilDamage << 2)));
a_Player.GetWorld()->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_ANVIL_USE, BlockPos, 0); a_Player.GetWorld()->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_ANVIL_USE, BlockPos, 0);
} }
} }
@ -1407,11 +1405,9 @@ void cSlotAreaBeacon::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cSlotAreaEnchanting: // cSlotAreaEnchanting:
cSlotAreaEnchanting::cSlotAreaEnchanting(cWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ) : cSlotAreaEnchanting::cSlotAreaEnchanting(cWindow & a_ParentWindow, Vector3i a_BlockPos) :
cSlotAreaTemporary(2, a_ParentWindow), cSlotAreaTemporary(2, a_ParentWindow),
m_BlockX(a_BlockX), m_BlockPos(a_BlockPos)
m_BlockY(a_BlockY),
m_BlockZ(a_BlockZ)
{ {
} }
@ -1644,7 +1640,7 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld & a_World)
{ {
int Bookshelves = 0; int Bookshelves = 0;
cBlockArea Area; cBlockArea Area;
Area.Read(a_World, m_BlockX - 2, m_BlockX + 2, m_BlockY, m_BlockY + 1, m_BlockZ - 2, m_BlockZ + 2); Area.Read(a_World, m_BlockPos - Vector3i(2, 0, 2), m_BlockPos + Vector3i(2, 1, 2));
static const struct static const struct
{ {

View File

@ -381,7 +381,7 @@ class cSlotAreaEnchanting:
public: public:
cSlotAreaEnchanting(cWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ); cSlotAreaEnchanting(cWindow & a_ParentWindow, Vector3i a_BlockPos);
// cSlotArea overrides: // cSlotArea overrides:
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
@ -399,7 +399,7 @@ protected:
/** Handles a click in the item slot. */ /** Handles a click in the item slot. */
void UpdateResult(cPlayer & a_Player); void UpdateResult(cPlayer & a_Player);
int m_BlockX, m_BlockY, m_BlockZ; Vector3i m_BlockPos;
}; };