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
Masy98
mathiascode
MaxwellScroggs
mborland
mBornand
MeMuXin

View File

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

View File

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

View File

@ -34,7 +34,7 @@ public:
const Vector3i a_CursorPos
) override
{
cWindow * Window = new cCraftingWindow(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z);
cWindow * Window = new cCraftingWindow();
a_Player.OpenWindow(*Window);
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"),
m_RepairedItemName(""),
m_BlockX(a_BlockX),
m_BlockY(a_BlockY),
m_BlockZ(a_BlockZ)
m_BlockPos(a_BlockPos)
{
m_AnvilSlotArea = new cSlotAreaAnvil(*this);
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)
{
cSlotAreas AreasInOrder;

View File

@ -22,7 +22,7 @@ class cAnvilWindow:
public:
cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ);
cAnvilWindow(Vector3i a_BlockPos);
/** Gets the repaired item name. */
AString GetRepairedItemName(void) const;
@ -31,14 +31,14 @@ public:
void SetRepairedItemName(const AString & a_Name, cPlayer * a_Player);
/** 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;
protected:
cSlotAreaAnvil * m_AnvilSlotArea;
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")
{
m_SlotAreas.push_back(new cSlotAreaCrafting(3, *this));

View File

@ -22,7 +22,7 @@ class cCraftingWindow:
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;
};

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"),
m_SlotArea(),
m_BlockX(a_BlockX),
m_BlockY(a_BlockY),
m_BlockZ(a_BlockZ)
m_BlockPos(a_BlockPos)
{
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(new cSlotAreaInventory(*this));
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));

View File

@ -22,7 +22,7 @@ class cEnchantingWindow:
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;
@ -37,7 +37,7 @@ public:
protected:
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;
static_cast<cAnvilWindow &>(m_ParentWindow).SetRepairedItemName("", nullptr);
int PosX, PosY, PosZ;
static_cast<cAnvilWindow &>(m_ParentWindow).GetBlockPos(PosX, PosY, PosZ);
const Vector3i BlockPos = static_cast<cAnvilWindow &>(m_ParentWindow).GetBlockPos();
BLOCKTYPE Block;
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))
{
NIBBLETYPE Orientation = BlockMeta & 0x3;
@ -1013,13 +1011,13 @@ void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player)
if (AnvilDamage > 2)
{
// 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.CloseWindow(false);
}
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);
}
}
@ -1407,11 +1405,9 @@ void cSlotAreaBeacon::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
////////////////////////////////////////////////////////////////////////////////
// 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),
m_BlockX(a_BlockX),
m_BlockY(a_BlockY),
m_BlockZ(a_BlockZ)
m_BlockPos(a_BlockPos)
{
}
@ -1644,7 +1640,7 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld & a_World)
{
int Bookshelves = 0;
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
{

View File

@ -381,7 +381,7 @@ class cSlotAreaEnchanting:
public:
cSlotAreaEnchanting(cWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ);
cSlotAreaEnchanting(cWindow & a_ParentWindow, Vector3i a_BlockPos);
// cSlotArea overrides:
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. */
void UpdateResult(cPlayer & a_Player);
int m_BlockX, m_BlockY, m_BlockZ;
Vector3i m_BlockPos;
};