summaryrefslogtreecommitdiffstats
path: root/source/cCraftingWindow.cpp
diff options
context:
space:
mode:
authorcedeel@gmail.com <cedeel@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-14 15:06:06 +0200
committercedeel@gmail.com <cedeel@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-14 15:06:06 +0200
commit92c59963f82f81aa3202657e7fdbb2592924ede3 (patch)
treeb7eb2474528a4998fa102e3ec9119b908cee08b4 /source/cCraftingWindow.cpp
parentAdded HOOK_WEATHER_CHANGE. (diff)
downloadcuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.gz
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.bz2
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.lz
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.xz
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.zst
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.zip
Diffstat (limited to 'source/cCraftingWindow.cpp')
-rw-r--r--source/cCraftingWindow.cpp262
1 files changed, 131 insertions, 131 deletions
diff --git a/source/cCraftingWindow.cpp b/source/cCraftingWindow.cpp
index 570f1ed9a..9e6b565c6 100644
--- a/source/cCraftingWindow.cpp
+++ b/source/cCraftingWindow.cpp
@@ -1,131 +1,131 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "cCraftingWindow.h"
-#include "cItem.h"
-#include "CraftingRecipes.h"
-#include "cPlayer.h"
-#include "cClientHandle.h"
-#include "cInventory.h"
-#include "cPickup.h"
-#include "cRoot.h"
-#include "cWorld.h"
-
-#include "packets/cPacket_WindowClick.h"
-#include "packets/cPacket_InventorySlot.h"
-
-
-
-
-
-cCraftingWindow::cCraftingWindow( cWindowOwner* a_Owner, bool a_bInventoryVisible )
- : cWindow( a_Owner, a_bInventoryVisible )
-{
- SetWindowID( 1 );
- SetWindowType( cWindow::Workbench ); // Workbench
-
- cItem* Slots = new cItem[10];
- SetSlots( Slots, 10 );
-}
-
-
-
-
-
-void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_Player )
-{
- bool bDontCook = false;
- // Override for craft result slot
- if( a_ClickPacket->m_SlotNum == 0 )
- {
- LOG("In craft slot: %i x %i !!", GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount );
- cItem* DraggingItem = GetDraggingItem( &a_Player );
- if( DraggingItem->m_ItemID <= 0 )
- {
- *DraggingItem = *GetSlot(0);
- GetSlot(0)->Empty();
- }
- else if( DraggingItem->Equals( *GetSlot(0) ) )
- {
- if( DraggingItem->m_ItemCount + GetSlot(0)->m_ItemCount <= 64 )
- {
- DraggingItem->m_ItemCount += GetSlot(0)->m_ItemCount;
- GetSlot(0)->Empty();
- }
- else
- {
- bDontCook = true;
- }
- }
- else
- {
- bDontCook = true;
- }
- LOG("Dragging Dish %i", DraggingItem->m_ItemCount );
- }
- else
- {
- cWindow::Clicked( a_ClickPacket, a_Player );
- }
-
- if ((a_ClickPacket->m_SlotNum >= 0) && (a_ClickPacket->m_SlotNum < 10))
- {
- cCraftingGrid Grid(GetSlots() + 1, 3, 3);
- cCraftingRecipe Recipe(Grid);
-
- cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe);
-
- if ((a_ClickPacket->m_SlotNum == 0) && !bDontCook)
- {
- // Consume the items from the crafting grid:
- Recipe.ConsumeIngredients(Grid);
-
- // Propagate grid back to m_Slots:
- Grid.CopyToItems(GetSlots() + 1);
-
- // Get the recipe for the new grid contents:
- cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe);
- }
- *GetSlot(0) = Recipe.GetResult();
- LOGD("%s cooked: %i x %i !!", a_Player.GetName().c_str(), GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount );
- }
- SendWholeWindow( a_Player.GetClientHandle() );
- a_Player.GetInventory().SendWholeInventory( a_Player.GetClientHandle() );
-
- // Separate packet for result =/ Don't know why
- cPacket_InventorySlot Packet;
- Packet.m_WindowID = (char)GetWindowID();
- Packet.m_SlotNum = 0;
- Packet.m_ItemID = (short)GetSlot(0)->m_ItemID;
- Packet.m_ItemCount = GetSlot(0)->m_ItemCount;
- Packet.m_ItemUses = (char)GetSlot(0)->m_ItemHealth;
- a_Player.GetClientHandle()->Send( Packet );
-}
-
-
-
-
-
-void cCraftingWindow::Close(cPlayer & a_Player)
-{
- // Start from slot 1, don't drop what's in the result slot
- cItems Drops;
- for( int i = 1; i < GetNumSlots(); i++ )
- {
- cItem * Item = GetSlot(i);
- if (!Item->IsEmpty())
- {
- Drops.push_back(*Item);
- }
- Item->Empty();
- }
- float vX = 0, vY = 0, vZ = 0;
- EulerToVector( -a_Player.GetRotation(), a_Player.GetPitch(), vZ, vX, vY);
- vY = -vY*2 + 1.f;
- a_Player.GetWorld()->SpawnItemPickups(Drops, a_Player.GetPosX(), a_Player.GetPosY() + 1.6f, a_Player.GetPosZ(), vX * 2, vY * 2, vZ * 2);
- cWindow::Close(a_Player);
-}
-
-
-
-
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "cCraftingWindow.h"
+#include "cItem.h"
+#include "CraftingRecipes.h"
+#include "cPlayer.h"
+#include "cClientHandle.h"
+#include "cInventory.h"
+#include "cPickup.h"
+#include "cRoot.h"
+#include "cWorld.h"
+
+#include "packets/cPacket_WindowClick.h"
+#include "packets/cPacket_InventorySlot.h"
+
+
+
+
+
+cCraftingWindow::cCraftingWindow( cWindowOwner* a_Owner, bool a_bInventoryVisible )
+ : cWindow( a_Owner, a_bInventoryVisible )
+{
+ SetWindowID( 1 );
+ SetWindowType( cWindow::Workbench ); // Workbench
+
+ cItem* Slots = new cItem[10];
+ SetSlots( Slots, 10 );
+}
+
+
+
+
+
+void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_Player )
+{
+ bool bDontCook = false;
+ // Override for craft result slot
+ if( a_ClickPacket->m_SlotNum == 0 )
+ {
+ LOG("In craft slot: %i x %i !!", GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount );
+ cItem* DraggingItem = GetDraggingItem( &a_Player );
+ if( DraggingItem->m_ItemID <= 0 )
+ {
+ *DraggingItem = *GetSlot(0);
+ GetSlot(0)->Empty();
+ }
+ else if( DraggingItem->Equals( *GetSlot(0) ) )
+ {
+ if( DraggingItem->m_ItemCount + GetSlot(0)->m_ItemCount <= 64 )
+ {
+ DraggingItem->m_ItemCount += GetSlot(0)->m_ItemCount;
+ GetSlot(0)->Empty();
+ }
+ else
+ {
+ bDontCook = true;
+ }
+ }
+ else
+ {
+ bDontCook = true;
+ }
+ LOG("Dragging Dish %i", DraggingItem->m_ItemCount );
+ }
+ else
+ {
+ cWindow::Clicked( a_ClickPacket, a_Player );
+ }
+
+ if ((a_ClickPacket->m_SlotNum >= 0) && (a_ClickPacket->m_SlotNum < 10))
+ {
+ cCraftingGrid Grid(GetSlots() + 1, 3, 3);
+ cCraftingRecipe Recipe(Grid);
+
+ cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe);
+
+ if ((a_ClickPacket->m_SlotNum == 0) && !bDontCook)
+ {
+ // Consume the items from the crafting grid:
+ Recipe.ConsumeIngredients(Grid);
+
+ // Propagate grid back to m_Slots:
+ Grid.CopyToItems(GetSlots() + 1);
+
+ // Get the recipe for the new grid contents:
+ cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe);
+ }
+ *GetSlot(0) = Recipe.GetResult();
+ LOGD("%s cooked: %i x %i !!", a_Player.GetName().c_str(), GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount );
+ }
+ SendWholeWindow( a_Player.GetClientHandle() );
+ a_Player.GetInventory().SendWholeInventory( a_Player.GetClientHandle() );
+
+ // Separate packet for result =/ Don't know why
+ cPacket_InventorySlot Packet;
+ Packet.m_WindowID = (char)GetWindowID();
+ Packet.m_SlotNum = 0;
+ Packet.m_ItemID = (short)GetSlot(0)->m_ItemID;
+ Packet.m_ItemCount = GetSlot(0)->m_ItemCount;
+ Packet.m_ItemUses = (char)GetSlot(0)->m_ItemHealth;
+ a_Player.GetClientHandle()->Send( Packet );
+}
+
+
+
+
+
+void cCraftingWindow::Close(cPlayer & a_Player)
+{
+ // Start from slot 1, don't drop what's in the result slot
+ cItems Drops;
+ for( int i = 1; i < GetNumSlots(); i++ )
+ {
+ cItem * Item = GetSlot(i);
+ if (!Item->IsEmpty())
+ {
+ Drops.push_back(*Item);
+ }
+ Item->Empty();
+ }
+ float vX = 0, vY = 0, vZ = 0;
+ EulerToVector( -a_Player.GetRotation(), a_Player.GetPitch(), vZ, vX, vY);
+ vY = -vY*2 + 1.f;
+ a_Player.GetWorld()->SpawnItemPickups(Drops, a_Player.GetPosX(), a_Player.GetPosY() + 1.6f, a_Player.GetPosZ(), vX * 2, vY * 2, vZ * 2);
+ cWindow::Close(a_Player);
+}
+
+
+
+