summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Blocks/BlockAnvil.h2
-rw-r--r--src/ClientHandle.cpp2
-rw-r--r--src/Simulator/SandSimulator.cpp4
-rw-r--r--src/UI/SlotArea.cpp164
-rw-r--r--src/UI/SlotArea.h9
-rw-r--r--src/UI/Window.cpp35
-rw-r--r--src/UI/Window.h12
7 files changed, 210 insertions, 18 deletions
diff --git a/src/Blocks/BlockAnvil.h b/src/Blocks/BlockAnvil.h
index c9eec961d..35a356678 100644
--- a/src/Blocks/BlockAnvil.h
+++ b/src/Blocks/BlockAnvil.h
@@ -27,7 +27,7 @@ public:
virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
- cWindow * Window = new cAnvilWindow();
+ cWindow * Window = new cAnvilWindow(a_BlockX, a_BlockY, a_BlockZ);
a_Player->OpenWindow(Window);
}
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index c0ddd1770..dbc07a96d 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -798,7 +798,7 @@ void cClientHandle::HandleAnvilItemName(const char * a_Data, unsigned int a_Leng
if (Name.length() <= 30)
{
- ((cAnvilWindow&)*m_Player->GetWindow()).SetRepairedItemName(Name);
+ ((cAnvilWindow&)*m_Player->GetWindow()).SetRepairedItemName(Name, m_Player);
}
}
diff --git a/src/Simulator/SandSimulator.cpp b/src/Simulator/SandSimulator.cpp
index f305ba61a..c4f57c86a 100644
--- a/src/Simulator/SandSimulator.cpp
+++ b/src/Simulator/SandSimulator.cpp
@@ -254,6 +254,10 @@ void cSandSimulator::FinishFalling(
{
// Rematerialize the material here:
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, a_FallingBlockType, a_FallingBlockMeta);
+ if (a_FallingBlockType == E_BLOCK_ANVIL)
+ {
+ a_World->BroadcastSoundParticleEffect(1022, a_BlockX, a_BlockY, a_BlockZ, 0);
+ }
return;
}
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index 2941982a7..1e488de62 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -610,8 +610,151 @@ cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) :
void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem)
{
- super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem);
- UpdateResult(a_Player);
+ ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots()));
+ if (a_SlotNum != 2)
+ {
+ super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem);
+ UpdateResult(a_Player);
+ return;
+ }
+
+ bool bAsync = false;
+ if (GetSlot(a_SlotNum, a_Player) == NULL)
+ {
+ LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum);
+ return;
+ }
+
+ if (a_ClickAction == caDblClick)
+ {
+ return;
+ }
+
+ cItem Slot(*GetSlot(a_SlotNum, a_Player));
+ if (!Slot.IsSameType(a_ClickedItem))
+ {
+ LOGWARNING("*** Window lost sync at item %d in SlotArea with %d items ***", a_SlotNum, m_NumSlots);
+ LOGWARNING("My item: %s", ItemToFullString(Slot).c_str());
+ LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str());
+ bAsync = true;
+ }
+ cItem & DraggingItem = a_Player.GetDraggingItem();
+
+ if (Slot.IsEmpty())
+ {
+ return;
+ }
+ if (!DraggingItem.IsEmpty())
+ {
+ if (!(DraggingItem.IsEqual(Slot) && ((DraggingItem.m_ItemCount + Slot.m_ItemCount) <= cItemHandler::GetItemHandler(Slot)->GetMaxStackSize())))
+ {
+ return;
+ }
+ }
+
+ if (!CanTakeResultItem(a_Player))
+ {
+ return;
+ }
+
+ cItem NewItem = cItem(Slot);
+ NewItem.m_ItemCount += DraggingItem.m_ItemCount;
+
+ Slot.Empty();
+ DraggingItem.Empty();
+ SetSlot(a_SlotNum, a_Player, Slot);
+
+ DraggingItem = NewItem;
+ OnTakeResult(a_Player, NewItem);
+
+ if (bAsync)
+ {
+ m_ParentWindow.BroadcastWholeWindow();
+ }
+}
+
+
+
+
+
+void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player, cItem a_ResultItem)
+{
+ if (!a_Player.IsGameModeCreative())
+ {
+ a_Player.DeltaExperience(cPlayer::XpForLevel(m_MaximumCost));
+ }
+ SetSlot(0, a_Player, cItem());
+
+ if (m_StackSizeToBeUsedInRepair > 0)
+ {
+ const cItem * Item = GetSlot(1, a_Player);
+ if (!Item->IsEmpty() && (Item->m_ItemCount > m_StackSizeToBeUsedInRepair))
+ {
+ cItem NewSecondItem(*Item);
+ NewSecondItem.m_ItemCount -= m_StackSizeToBeUsedInRepair;
+ SetSlot(1, a_Player, NewSecondItem);
+ }
+ else
+ {
+ SetSlot(1, a_Player, cItem());
+ }
+ }
+ else
+ {
+ SetSlot(1, a_Player, cItem());
+ }
+ m_ParentWindow.SetProperty(0, m_MaximumCost, a_Player);
+
+ m_MaximumCost = 0;
+ ((cAnvilWindow*)&m_ParentWindow)->SetRepairedItemName("", false);
+
+ int PosX, PosY, PosZ;
+ ((cAnvilWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ);
+
+ BLOCKTYPE Block;
+ NIBBLETYPE BlockMeta;
+ a_Player.GetWorld()->GetBlockTypeMeta(PosX, PosY, PosZ, Block, BlockMeta);
+
+ cFastRandom Random;
+ if (!a_Player.IsGameModeCreative() && (Block == E_BLOCK_ANVIL) && (Random.NextFloat(1.0F) < 0.12F))
+ {
+ NIBBLETYPE var4 = BlockMeta & 0x3;
+ NIBBLETYPE AnvilDamage = BlockMeta >> 2;
+ ++AnvilDamage;
+
+ if (AnvilDamage > 2)
+ {
+ // Anvil will break
+ a_Player.GetWorld()->SetBlock(PosX, PosY, PosZ, E_BLOCK_AIR, (NIBBLETYPE)0);
+ a_Player.GetWorld()->BroadcastSoundParticleEffect(1020, PosX, PosY, PosZ, 0);
+ a_Player.CloseWindow(false);
+ }
+ else
+ {
+ a_Player.GetWorld()->SetBlockMeta(PosX, PosY, PosZ, var4 | AnvilDamage << 2);
+ a_Player.GetWorld()->BroadcastSoundParticleEffect(1021, PosX, PosY, PosZ, 0);
+ }
+ }
+ else
+ {
+ a_Player.GetWorld()->BroadcastSoundParticleEffect(1021, PosX, PosY, PosZ, 0);
+ }
+}
+
+
+
+
+
+bool cSlotAreaAnvil::CanTakeResultItem(cPlayer & a_Player)
+{
+ return (
+ (
+ a_Player.IsGameModeCreative()
+ || a_Player.GetXpLevel() >= m_MaximumCost
+ )
+ && !GetSlot(2, a_Player)->IsEmpty()
+ && m_MaximumCost > 0
+ );
}
@@ -620,7 +763,7 @@ void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
void cSlotAreaAnvil::OnPlayerRemoved(cPlayer & a_Player)
{
- TossItems(a_Player, 0, 3);
+ TossItems(a_Player, 0, 2);
super::OnPlayerRemoved(a_Player);
}
@@ -641,7 +784,9 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
m_ParentWindow.SetProperty(0, 0, a_Player);
return;
}
-
+
+ m_MaximumCost = 0;
+ m_StackSizeToBeUsedInRepair = 0;
int RepairCost = cItemHandler::GetItemHandler(Input)->GetRepairCost();
int NeedExp = 0;
if (!SecondInput.IsEmpty())
@@ -670,6 +815,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
++x;
}
+ m_StackSizeToBeUsedInRepair = x;
}
else
{
@@ -731,18 +877,18 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
// TODO: Add enchantment exp cost.
- int MaximumCost = RepairCost + NeedExp;
+ m_MaximumCost = RepairCost + NeedExp;
if (NeedExp < 0)
{
Input.Empty();
}
- if (NameChangeExp == NeedExp && NameChangeExp > 0 && MaximumCost >= 40)
+ if (NameChangeExp == NeedExp && NameChangeExp > 0 && m_MaximumCost >= 40)
{
- MaximumCost = 39;
+ m_MaximumCost = 39;
}
- if (MaximumCost >= 40 && !a_Player.IsGameModeCreative())
+ if (m_MaximumCost >= 40 && !a_Player.IsGameModeCreative())
{
Input.Empty();
}
@@ -760,7 +906,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
}*/
SetSlot(2, a_Player, Input);
- m_ParentWindow.SetProperty(0, MaximumCost, a_Player);
+ m_ParentWindow.SetProperty(0, m_MaximumCost, a_Player);
}
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index 01dcb88ab..4f273ec65 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -274,12 +274,19 @@ public:
// cSlotAreaTemporary overrides:
virtual void OnPlayerRemoved(cPlayer & a_Player) override;
-protected:
+ bool CanTakeResultItem(cPlayer & a_Player);
+
+ void OnTakeResult(cPlayer & a_Player, cItem a_ResultItem);
+
/** Handles a click in the item slot. */
void UpdateResult(cPlayer & a_Player);
+protected:
/** The maximum cost of repairing/renaming in the anvil. */
int m_MaximumCost;
+
+ /** The stack size of the second item where was used for repair */
+ char m_StackSizeToBeUsedInRepair;
} ;
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index d6adbef8f..4991f0147 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -807,11 +807,15 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cAnvilWindow:
-cAnvilWindow::cAnvilWindow() :
+cAnvilWindow::cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
cWindow(wtAnvil, "Repair"),
- m_RepairedItemName("")
+ m_RepairedItemName(""),
+ m_BlockX(a_BlockX),
+ m_BlockY(a_BlockY),
+ m_BlockZ(a_BlockZ)
{
- m_SlotAreas.push_back(new cSlotAreaAnvil(*this));
+ m_AnvilSlotArea = new cSlotAreaAnvil(*this);
+ m_SlotAreas.push_back(m_AnvilSlotArea);
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
}
@@ -820,6 +824,31 @@ cAnvilWindow::cAnvilWindow() :
+void cAnvilWindow::SetRepairedItemName(const AString & a_Name, cPlayer * a_Player)
+{
+ m_RepairedItemName = a_Name;
+
+ if (a_Player != NULL)
+ {
+ m_AnvilSlotArea->UpdateResult(*a_Player);
+ }
+}
+
+
+
+
+
+void cAnvilWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ)
+{
+ a_PosX = m_BlockX;
+ a_PosY = m_BlockY;
+ a_PosZ = m_BlockZ;
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cEnchantingWindow:
diff --git a/src/UI/Window.h b/src/UI/Window.h
index 8f6f80a41..c87d9b174 100644
--- a/src/UI/Window.h
+++ b/src/UI/Window.h
@@ -24,6 +24,7 @@ class cEnderChestEntity;
class cFurnaceEntity;
class cHopperEntity;
class cSlotArea;
+class cSlotAreaAnvil;
class cWorld;
typedef std::list<cPlayer *> cPlayerList;
@@ -236,16 +237,21 @@ class cAnvilWindow :
{
typedef cWindow super;
public:
- cAnvilWindow();
+ cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ);
/** Gets the repaired item name. */
AString GetRepairedItemName(void) const { return m_RepairedItemName; }
/** Set the repaired item name. */
- void SetRepairedItemName(const AString & a_Name) { m_RepairedItemName = a_Name; }
+ void SetRepairedItemName(const AString & a_Name, cPlayer * a_Player);
+
+ /** Get the Position from the Enchantment Table */
+ void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ);
protected:
+ cSlotAreaAnvil * m_AnvilSlotArea;
AString m_RepairedItemName;
+ int m_BlockX, m_BlockY, m_BlockZ;
} ;
@@ -264,7 +270,7 @@ public:
/** Return the Value of a Property */
int GetPropertyValue(int a_Property);
- /** Set the Position Values to the Position of the Enchantment Table */
+ /** Get the Position from the Enchantment Table */
void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ);
cSlotArea * m_SlotArea;