summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/Bindings.cpp2
-rw-r--r--source/Defines.h6
-rw-r--r--source/PacketID.h2
-rw-r--r--source/cBlockToPickup.cpp4
-rw-r--r--source/cCavespider.cpp14
-rw-r--r--source/cChicken.cpp21
-rw-r--r--source/cClientHandle.cpp33
-rw-r--r--source/cCow.cpp20
-rw-r--r--source/cCraftingWindow.cpp5
-rw-r--r--source/cCreeper.cpp14
-rw-r--r--source/cEnderman.cpp13
-rw-r--r--source/cGhast.cpp14
-rw-r--r--source/cInventory.cpp2
-rw-r--r--source/cItem.cpp22
-rw-r--r--source/cItem.h4
-rw-r--r--source/cMonster.cpp17
-rw-r--r--source/cMonster.h4
-rw-r--r--source/cPickup.cpp6
-rw-r--r--source/cPig.cpp15
-rw-r--r--source/cPlayer.cpp10
-rw-r--r--source/cRecipeChecker.cpp4
-rw-r--r--source/cSheep.cpp17
-rw-r--r--source/cSilverfish.cpp11
-rw-r--r--source/cSkeleton.cpp14
-rw-r--r--source/cSlime.cpp15
-rw-r--r--source/cSpider.cpp14
-rw-r--r--source/cSquid.cpp13
-rw-r--r--source/cWindow.cpp12
-rw-r--r--source/cWolf.cpp11
-rw-r--r--source/cZombie.cpp13
-rw-r--r--source/cZombiepigman.cpp16
-rw-r--r--source/packets/cPacket_AddToInventory.cpp15
-rw-r--r--source/packets/cPacket_AddToInventory.h7
-rw-r--r--source/packets/cPacket_BlockPlace.cpp13
-rw-r--r--source/packets/cPacket_CreateInventoryAction.cpp101
-rw-r--r--source/packets/cPacket_CreateInventoryAction.h6
-rw-r--r--source/packets/cPacket_InventorySlot.cpp20
-rw-r--r--source/packets/cPacket_InventorySlot.h5
-rw-r--r--source/packets/cPacket_WholeInventory.cpp21
-rw-r--r--source/packets/cPacket_WholeInventory.h3
-rw-r--r--source/packets/cPacket_WindowClick.cpp26
-rw-r--r--source/packets/cPacket_WindowClick.h5
42 files changed, 315 insertions, 275 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 19cbf6651..187d9d34b 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -2483,7 +2483,7 @@ static int tolua_AllToLua_isValidItem00(lua_State* tolua_S)
{
int a_ItemID = ((int) tolua_tonumber(tolua_S,1,0));
{
- bool tolua_ret = (bool) isValidItem(a_ItemID);
+ bool tolua_ret = (bool) IsValidItem(a_ItemID);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
diff --git a/source/Defines.h b/source/Defines.h
index e40da0420..ba62a241e 100644
--- a/source/Defines.h
+++ b/source/Defines.h
@@ -29,9 +29,11 @@ inline bool IsValidBlock( int a_BlockID ) //tolua_export
return false;
} //tolua_export
-inline bool isValidItem( int a_ItemID ) //tolua_export
+// Was old :o
+// Changed to fit the style ;)
+inline bool IsValidItem( int a_ItemID ) //tolua_export
{ //tolua_export
- if( (a_ItemID >= 256 && a_ItemID <= 358)
+ if( (a_ItemID >= 256 && a_ItemID <= 383)
|| (a_ItemID == 2256 || a_ItemID == 2257) )
{
return true;
diff --git a/source/PacketID.h b/source/PacketID.h
index b346e4239..f19d7a795 100644
--- a/source/PacketID.h
+++ b/source/PacketID.h
@@ -19,7 +19,7 @@ enum ENUM_PACKET_ID
E_BLOCK_DIG = 0x0e,
E_BLOCK_PLACE = 0x0f,
E_ITEM_SWITCH = 0x10,
- E_ADD_TO_INV = 0x11,
+ E_ADD_TO_INV = 0x11, //TODO: Sure this is not Use Bed??
E_ANIMATION = 0x12,
E_PACKET_13 = 0x13,
E_NAMED_ENTITY_SPAWN= 0x14,
diff --git a/source/cBlockToPickup.cpp b/source/cBlockToPickup.cpp
index 75ba77f9a..7a80e4a97 100644
--- a/source/cBlockToPickup.cpp
+++ b/source/cBlockToPickup.cpp
@@ -1,5 +1,6 @@
#include "cBlockToPickup.h"
#include "BlockID.h"
+#include "stdlib.h"
ENUM_ITEM_ID cBlockToPickup::ToPickup( unsigned char a_BlockID, ENUM_ITEM_ID a_UsedItemID )
{
@@ -23,6 +24,8 @@ ENUM_ITEM_ID cBlockToPickup::ToPickup( unsigned char a_BlockID, ENUM_ITEM_ID a_U
if( a_UsedItemID == E_ITEM_SHEARS )
return E_ITEM_LEAVES;
else
+ if(rand() % 5 == 0)
+ return E_ITEM_SAPLING;
return E_ITEM_EMPTY;
case E_BLOCK_COAL_ORE:
return E_ITEM_COAL;
@@ -51,5 +54,6 @@ ENUM_ITEM_ID cBlockToPickup::ToPickup( unsigned char a_BlockID, ENUM_ITEM_ID a_U
default:
return (ENUM_ITEM_ID)a_BlockID;
}
+ //TODO: Whats that? :D
return E_ITEM_EMPTY;
}
diff --git a/source/cCavespider.cpp b/source/cCavespider.cpp
index a34f72465..dc0377edf 100644
--- a/source/cCavespider.cpp
+++ b/source/cCavespider.cpp
@@ -46,16 +46,10 @@ void cCavespider::Tick(float a_Dt)
void cCavespider::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ cMonster::RandomDropItem(E_ITEM_STRING, 0, 2);
+
+ cMonster::RandomDropItem(E_ITEM_SPIDER_EYE, 0, 1);
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cChicken.cpp b/source/cChicken.cpp
index ba534cc61..be740d6cd 100644
--- a/source/cChicken.cpp
+++ b/source/cChicken.cpp
@@ -20,6 +20,8 @@
#include <string>
+// TODO: Drop egg every 5-10 minutes
+
cChicken::cChicken()
: m_ChaseTime( 999999 )
@@ -49,16 +51,15 @@ void cChicken::Tick(float a_Dt)
void cChicken::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ //Drops 0-2 Feathers
+ cMonster::RandomDropItem(E_ITEM_FEATHER, 0, 2);
+
+ // Raw Chicken
+ // TODO: (Check wheather it is burning to drop cooked Chicken)
+ //Drops 0-2 Lether
+ cMonster::DropItem(E_ITEM_RAW_CHICKEN, 1);
+
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index d41759d09..a1e24c576 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -450,9 +450,9 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
cPacket_Chat Joined( m_pState->Username + " joined the game!");
cRoot::Get()->GetServer()->Broadcast( Joined, this );
}
- int posx = m_Player->GetPosX();
- int posy = m_Player->GetPosY();
- int posz = m_Player->GetPosZ();
+ int posx = (int) m_Player->GetPosX();
+ int posy = (int) m_Player->GetPosY();
+ int posz = (int) m_Player->GetPosZ();
// Now initialize player (adds to entity list etc.)
cWorld* PlayerWorld = cRoot::Get()->GetWorld( m_Player->GetLoadedWorldName() );
if( !PlayerWorld ) PlayerWorld = cRoot::Get()->GetDefaultWorld();
@@ -503,6 +503,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
m_Player->SetLastBlockActionCnt(LastActionCnt+1);
if (LastActionCnt > 3) { //kick if more than 3 interactions per .1 seconds
LOGWARN("Player %s tried to interact with a block too quickly! (could indicate bot) Was Kicked.", GetUsername() );
+ //To many false-positives :s for example on a minimal server lagg :s should be re checked
Kick("You're a baaaaaad boy!");
break;
}
@@ -812,6 +813,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
if( PacketData->m_Direction < 0 ) // clicked in air
break;
+ //TODO: Wrong Blocks!
int clickedBlock = (int)m_Player->GetWorld()->GetBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ );
char MetaData = (char)Equipped.m_ItemHealth;
bool LavaBucket = false;
@@ -820,6 +822,9 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
switch( PacketData->m_ItemType ) // Special handling for special items
{
case E_ITEM_BUCKET:
+ //TODO: Change this, it is just a small hack to get it working a little bit. seems like the Client sends the position from the first hitable block :s
+ clickedBlock = (int)m_Player->GetWorld()->GetBlock( PacketData->m_PosX, PacketData->m_PosY + 1, PacketData->m_PosZ );
+ LOG("Bucket Clicked BlockID: %d", clickedBlock);
switch (clickedBlock)
{
case E_BLOCK_WATER:
@@ -833,10 +838,24 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
}
break;
case E_ITEM_LAVA_BUCKET:
- PacketData->m_ItemType = E_BLOCK_LAVA;
+ if((m_Player->GetGameMode() == 1) || (m_Player->GetInventory().RemoveItem( Item )))
+ {
+ cItem NewItem;
+ NewItem.m_ItemID = E_ITEM_BUCKET;
+ NewItem.m_ItemCount = 1;
+ m_Player->GetInventory().AddItem( NewItem );
+ PacketData->m_ItemType = E_BLOCK_LAVA;
+ }
break;
case E_ITEM_WATER_BUCKET:
- PacketData->m_ItemType = E_BLOCK_WATER;
+ if((m_Player->GetGameMode() == 1) || (m_Player->GetInventory().RemoveItem( Item )))
+ {
+ cItem NewItem;
+ NewItem.m_ItemID = E_ITEM_BUCKET;
+ NewItem.m_ItemCount = 1;
+ m_Player->GetInventory().AddItem( NewItem );
+ PacketData->m_ItemType = E_BLOCK_WATER;
+ }
break;
case E_BLOCK_WHITE_CLOTH:
MetaData = (char)PacketData->m_Uses;
@@ -932,7 +951,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
NewItem.m_ItemID = E_ITEM_LAVA_BUCKET;
NewItem.m_ItemCount = 1;
m_Player->GetInventory().AddItem( NewItem );
- m_Player->GetWorld()->SetBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, E_BLOCK_AIR, 0 );
+ m_Player->GetWorld()->SetBlock( PacketData->m_PosX, PacketData->m_PosY + 1, PacketData->m_PosZ, E_BLOCK_AIR, 0 );
}
} else if (WaterBucket) {
@@ -942,7 +961,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
NewItem.m_ItemID = E_ITEM_WATER_BUCKET;
NewItem.m_ItemCount = 1;
m_Player->GetInventory().AddItem( NewItem );
- m_Player->GetWorld()->SetBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, E_BLOCK_AIR, 0 );
+ m_Player->GetWorld()->SetBlock( PacketData->m_PosX, PacketData->m_PosY + 1, PacketData->m_PosZ, E_BLOCK_AIR, 0 );
}
} else if( IsValidBlock( PacketData->m_ItemType) ) {
diff --git a/source/cCow.cpp b/source/cCow.cpp
index 517fa84d8..7ed21d504 100644
--- a/source/cCow.cpp
+++ b/source/cCow.cpp
@@ -19,7 +19,7 @@
#include <string>
-
+//TODO: Milk Cow
cCow::cCow()
: m_ChaseTime( 999999 )
@@ -49,16 +49,14 @@ void cCow::Tick(float a_Dt)
void cCow::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ //Drops 0-2 Lether
+ cMonster::RandomDropItem(E_ITEM_LEATHER, 0, 2);
+
+ //Drops 1-3 Raw beefs
+ cMonster::RandomDropItem(E_ITEM_LEATHER, 1, 3);
+
+ //TODO: Check wheather burning and drop 1-3 steak instead
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cCraftingWindow.cpp b/source/cCraftingWindow.cpp
index c8ddaa5d7..9e81b8ebe 100644
--- a/source/cCraftingWindow.cpp
+++ b/source/cCraftingWindow.cpp
@@ -73,7 +73,9 @@ void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_P
}
SendWholeWindow( a_Player.GetClientHandle() );
a_Player.GetInventory().SendWholeInventory( a_Player.GetClientHandle() );
- // Separate packet for result =/ Don't know why
+ //Separate packet for result =/ Don't know why
+
+
cPacket_InventorySlot Packet;
Packet.m_WindowID = (char)GetWindowID();
Packet.m_SlotNum = 0;
@@ -81,6 +83,7 @@ void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_P
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 )
diff --git a/source/cCreeper.cpp b/source/cCreeper.cpp
index 18f9a6730..e8410e142 100644
--- a/source/cCreeper.cpp
+++ b/source/cCreeper.cpp
@@ -45,16 +45,10 @@ void cCreeper::Tick(float a_Dt)
void cCreeper::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ cMonster::RandomDropItem(E_ITEM_GUNPOWDER, 0, 2);
+
+ //Todo: Check if killed by a skeleton then drop random music disk
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cEnderman.cpp b/source/cEnderman.cpp
index 166d05b20..a64b3122b 100644
--- a/source/cEnderman.cpp
+++ b/source/cEnderman.cpp
@@ -48,16 +48,9 @@ void cEnderman::Tick(float a_Dt)
void cEnderman::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ //Drops 0-1 Enderpearl
+ cMonster::RandomDropItem(E_ITEM_ENDER_PEARL, 0, 1);
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cGhast.cpp b/source/cGhast.cpp
index 3189e5d63..78306095a 100644
--- a/source/cGhast.cpp
+++ b/source/cGhast.cpp
@@ -45,16 +45,10 @@ void cGhast::Tick(float a_Dt)
void cGhast::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ cMonster::RandomDropItem(E_ITEM_GUNPOWDER, 0, 2);
+
+ cMonster::RandomDropItem(E_ITEM_GHAST_TEAR, 0, 1);
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cInventory.cpp b/source/cInventory.cpp
index 788d38eaa..68b8b431e 100644
--- a/source/cInventory.cpp
+++ b/source/cInventory.cpp
@@ -320,7 +320,7 @@ void cInventory::SendSlot( int a_SlotNum )
{
cPacket_InventorySlot InventorySlot;
InventorySlot.m_ItemCount = Item->m_ItemCount;
- InventorySlot.m_ItemID = (short)Item->m_ItemID;
+ InventorySlot.m_ItemID = Item->m_ItemID;
InventorySlot.m_ItemUses = (char)Item->m_ItemHealth;
InventorySlot.m_SlotNum = (short)a_SlotNum;
InventorySlot.m_WindowID = 0; // Inventory window ID
diff --git a/source/cItem.cpp b/source/cItem.cpp
index b91a7a316..20720a6e8 100644
--- a/source/cItem.cpp
+++ b/source/cItem.cpp
@@ -19,4 +19,26 @@ void cItem::FromJson( const Json::Value & a_Value )
m_ItemCount = (char)a_Value.get("Count", -1 ).asInt();
m_ItemHealth = (short)a_Value.get("Health", -1 ).asInt();
}
+}
+
+bool cItem::IsEnchantable(ENUM_ITEM_ID item)
+{
+ if(item >= 256 && item <= 259)
+ return true;
+ if(item >= 267 && item <= 279)
+ return true;
+ if(item >= 283 && item <= 286)
+ return true;
+ if(item >= 290 && item <= 294)
+ return true;
+ if(item >= 298 && item <= 317)
+ return true;
+ if(item >= 290 && item <= 294)
+ return true;
+
+ if(item == 346 || item == 359 || item == 261)
+ return true;
+
+
+ return false;
} \ No newline at end of file
diff --git a/source/cItem.h b/source/cItem.h
index dde0c649b..c58079e87 100644
--- a/source/cItem.h
+++ b/source/cItem.h
@@ -16,7 +16,7 @@ public:
, m_ItemCount ( a_ItemCount )
, m_ItemHealth ( a_ItemHealth )
{ //tolua_export
- if(!isValidItem( m_ItemID ) ) m_ItemID = E_ITEM_EMPTY;
+ if(!IsValidItem( m_ItemID ) ) m_ItemID = E_ITEM_EMPTY;
} //tolua_export
void Empty() //tolua_export
{ //tolua_export
@@ -35,6 +35,8 @@ public:
void GetJson( Json::Value & a_OutValue ); //tolua_export
void FromJson( const Json::Value & a_Value ); //tolua_export
+
+ static bool IsEnchantable(ENUM_ITEM_ID item);
ENUM_ITEM_ID m_ItemID; //tolua_export
char m_ItemCount; //tolua_export
diff --git a/source/cMonster.cpp b/source/cMonster.cpp
index 0eeac1409..0d99a2e7b 100644
--- a/source/cMonster.cpp
+++ b/source/cMonster.cpp
@@ -8,6 +8,8 @@
#include "cPlayer.h"
#include "BlockID.h"
#include "Defines.h"
+#include "cPickup.h"
+#include "cItem.h"
#include "packets/cPacket_SpawnMob.h"
#include "packets/cPacket_EntityLook.h"
@@ -607,3 +609,18 @@ void cMonster::SetAttackDamage(float ad) {
void cMonster::SetSightDistance(float sd) {
m_SightDistance = sd;
}
+
+
+void cMonster::DropItem(ENUM_ITEM_ID a_Item, unsigned int a_Count)
+{
+ if(a_Count > 0)
+ {
+ cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( a_Item, a_Count ) );
+ Pickup->Initialize( GetWorld() );
+ }
+}
+
+void cMonster::RandomDropItem(ENUM_ITEM_ID a_Item, unsigned int a_Min, unsigned int a_Max)
+{
+ return cMonster::DropItem(a_Item, rand() % (a_Max + 1) + a_Min);
+} \ No newline at end of file
diff --git a/source/cMonster.h b/source/cMonster.h
index b0cb19543..7ac8ef171 100644
--- a/source/cMonster.h
+++ b/source/cMonster.h
@@ -1,5 +1,6 @@
#pragma once
#include "cPawn.h"
+#include "BlockID.h"
class Vector3f;
class cClientHandle;
@@ -82,4 +83,7 @@ protected:
float m_AttackInterval;
float m_FireDamageInterval;
float m_BurnPeriod;
+
+ void DropItem(ENUM_ITEM_ID a_Item, unsigned int a_Count);
+ void RandomDropItem(ENUM_ITEM_ID a_Item, unsigned int a_Min, unsigned int a_Max);
}; //tolua_export
diff --git a/source/cPickup.cpp b/source/cPickup.cpp
index 10427f5b3..4788c2e1f 100644
--- a/source/cPickup.cpp
+++ b/source/cPickup.cpp
@@ -54,7 +54,8 @@ cPickup::cPickup(int a_X, int a_Y, int a_Z, const cItem & a_Item, float a_SpeedX
PickupSpawn.m_Rotation = (char)(m_Speed->x * 8);
PickupSpawn.m_Pitch = (char)(m_Speed->y * 8);
PickupSpawn.m_Roll = (char)(m_Speed->z * 8);
- cRoot::Get()->GetServer()->Broadcast( PickupSpawn );
+ if(PickupSpawn.m_Item != E_ITEM_EMPTY)
+ cRoot::Get()->GetServer()->Broadcast( PickupSpawn );
m_EntityType = E_PICKUP;
}
@@ -216,7 +217,8 @@ void cPickup::HandlePhysics(float a_Dt)
bool cPickup::CollectedBy( cPlayer* a_Dest )
{
if(m_bCollected) return false; // It's already collected!
- if(m_Timer < 800.f) return false; // Not old enough
+ // 800 is to long
+ if(m_Timer < 500.f) return false; // Not old enough
if( cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_COLLECT_ITEM, 2, this, a_Dest ) ) return false;
diff --git a/source/cPig.cpp b/source/cPig.cpp
index 424b2c53b..926bd8df0 100644
--- a/source/cPig.cpp
+++ b/source/cPig.cpp
@@ -49,16 +49,11 @@ void cPig::Tick(float a_Dt)
void cPig::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ //Drops 0-2 meat
+ cMonster::RandomDropItem(E_ITEM_RAW_MEAT, 0, 2);
+
+ //TODO: Check for burning state
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index 8238f327c..65b6187a6 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -325,11 +325,7 @@ void cPlayer::Heal( int a_Health )
{
if( m_Health < 20 )
{
- m_Health += (short)a_Health;
- if( m_Health > 20 )
- {
- m_Health = 20;
- }
+ m_Health = MIN(a_Health + m_Health, 20);
cPacket_UpdateHealth Health;
Health.m_Health = m_Health;
@@ -344,7 +340,9 @@ void cPlayer::TakeDamage( int a_Damage, cEntity* a_Instigator )
cPacket_UpdateHealth Health;
Health.m_Health = m_Health;
- m_ClientHandle->Send( Health );
+ //TODO: Causes problems sometimes O.o (E.G. Disconnecting when attacked)
+ if(m_ClientHandle != 0)
+ m_ClientHandle->Send( Health );
}
}
diff --git a/source/cRecipeChecker.cpp b/source/cRecipeChecker.cpp
index d85cb3c31..53a55b08b 100644
--- a/source/cRecipeChecker.cpp
+++ b/source/cRecipeChecker.cpp
@@ -195,7 +195,7 @@ void cRecipeChecker::ReloadRecipes()
if( c == '@' ) bLoadResult = true;
if( c != ',' ) bLoadSlot = false;
- if( !isValidItem( ItemID ) )
+ if( !IsValidItem( ItemID ) )
{
LOGERROR("Error in recipes file (%s): Invalid Item ID %i", a_File, ItemID );
bDontAddRecipe = true;
@@ -307,7 +307,7 @@ void cRecipeChecker::ReloadRecipes()
f >> c; if( c != ':' ) { bError=true; break; }
f >> Amount;
//LOG("%i %i", ItemID, Amount );
- if( !isValidItem( ItemID ) )
+ if( !IsValidItem( ItemID ) )
{
LOGERROR("Error in recipes file (%s): Invalid Item ID %i", a_File, ItemID );
bDontAddRecipe = true;
diff --git a/source/cSheep.cpp b/source/cSheep.cpp
index 2b3f93888..8c82faa1f 100644
--- a/source/cSheep.cpp
+++ b/source/cSheep.cpp
@@ -19,7 +19,7 @@
#include <string>
-
+//Todo: Implement color
cSheep::cSheep()
: m_ChaseTime( 999999 )
@@ -49,16 +49,11 @@ void cSheep::Tick(float a_Dt)
void cSheep::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ //Todo: Check wheather it is sheared
+ //Todo: Check color
+
+ cMonster::DropItem(E_ITEM_WHITE_CLOTH, 1);
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cSilverfish.cpp b/source/cSilverfish.cpp
index c1ebb9558..6083e2756 100644
--- a/source/cSilverfish.cpp
+++ b/source/cSilverfish.cpp
@@ -45,16 +45,7 @@ void cSilverfish::Tick(float a_Dt)
void cSilverfish::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cSkeleton.cpp b/source/cSkeleton.cpp
index 6cdb7b23b..8958e0c44 100644
--- a/source/cSkeleton.cpp
+++ b/source/cSkeleton.cpp
@@ -48,16 +48,10 @@ void cSkeleton::Tick(float a_Dt)
void cSkeleton::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ cMonster::RandomDropItem(E_ITEM_ARROW, 0, 2);
+
+ cMonster::RandomDropItem(E_ITEM_BONE, 0, 2);
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cSlime.cpp b/source/cSlime.cpp
index 90729e169..c2cf78061 100644
--- a/source/cSlime.cpp
+++ b/source/cSlime.cpp
@@ -18,6 +18,8 @@
#include <cstring>
#endif
+//TODO Implement sized slimes
+
cSlime::cSlime() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = AGGRESSIVE;
@@ -45,16 +47,9 @@ void cSlime::Tick(float a_Dt)
void cSlime::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ //TODO: only when tiny
+ cMonster::RandomDropItem(E_ITEM_SLIMEBALL, 0, 2);
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cSpider.cpp b/source/cSpider.cpp
index 7b7268e78..5249df6d0 100644
--- a/source/cSpider.cpp
+++ b/source/cSpider.cpp
@@ -46,16 +46,10 @@ void cSpider::Tick(float a_Dt)
void cSpider::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ cMonster::RandomDropItem(E_ITEM_STRING, 0, 2);
+
+ cMonster::RandomDropItem(E_ITEM_SPIDER_EYE, 0, 1);
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cSquid.cpp b/source/cSquid.cpp
index 2b519a5c7..97eba9808 100644
--- a/source/cSquid.cpp
+++ b/source/cSquid.cpp
@@ -49,16 +49,9 @@ void cSquid::Tick(float a_Dt)
void cSquid::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ //Drops 0-3 Ink Sacs
+ cMonster::RandomDropItem(E_ITEM_DYE, 0, 3);
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cWindow.cpp b/source/cWindow.cpp
index f3caa628c..3555c9c96 100644
--- a/source/cWindow.cpp
+++ b/source/cWindow.cpp
@@ -3,6 +3,7 @@
#include "cMCLogger.h"
#include "cClientHandle.h"
#include "cPlayer.h"
+#include "cPickup.h"
#include "cInventory.h"
#include "cWindowOwner.h"
@@ -195,6 +196,15 @@ void cWindow::Open( cPlayer & a_Player )
void cWindow::Close( cPlayer & a_Player )
{
+ //Checks wheather the player is still holding an item
+ if(m_DraggingItem && m_DraggingItem->m_ItemCount > 0)
+ {
+ LOG("Player holds item! Dropping it...");
+ a_Player.TossItem( true, m_DraggingItem->m_ItemCount );
+
+ }
+
+
cPacket_WindowClose WindowClose;
WindowClose.m_Close = (char)m_WindowID;
cClientHandle* ClientHandle = a_Player.GetClientHandle();
@@ -205,6 +215,8 @@ void cWindow::Close( cPlayer & a_Player )
{
Destroy();
}
+
+
}
void cWindow::OwnerDestroyed()
diff --git a/source/cWolf.cpp b/source/cWolf.cpp
index f504d79df..d317fe746 100644
--- a/source/cWolf.cpp
+++ b/source/cWolf.cpp
@@ -45,16 +45,7 @@ void cWolf::Tick(float a_Dt)
void cWolf::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cZombie.cpp b/source/cZombie.cpp
index 10fb609bb..5569b42ff 100644
--- a/source/cZombie.cpp
+++ b/source/cZombie.cpp
@@ -48,16 +48,9 @@ void cZombie::Tick(float a_Dt)
void cZombie::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ cMonster::RandomDropItem(E_ITEM_ROTTEN_FLESH, 0, 2);
+
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/cZombiepigman.cpp b/source/cZombiepigman.cpp
index da550d3df..79b84a4a7 100644
--- a/source/cZombiepigman.cpp
+++ b/source/cZombiepigman.cpp
@@ -48,16 +48,12 @@ void cZombiepigman::Tick(float a_Dt)
void cZombiepigman::KilledBy( cEntity* a_Killer )
{
- if( (rand() % 5) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
- if( (rand() % 1) == 0 )
- {
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
- Pickup->Initialize( GetWorld() );
- }
+ //Drops 0-1 Rottenflesh
+ cMonster::RandomDropItem(E_ITEM_ROTTEN_FLESH, 0, 2);
+
+ //Drops 0-1 gold nuggets
+ cMonster::RandomDropItem(E_ITEM_GOLD_NUGGET, 0, 2);
+
cMonster::KilledBy( a_Killer );
}
diff --git a/source/packets/cPacket_AddToInventory.cpp b/source/packets/cPacket_AddToInventory.cpp
index 5d3274229..0a9dad8c0 100644
--- a/source/packets/cPacket_AddToInventory.cpp
+++ b/source/packets/cPacket_AddToInventory.cpp
@@ -1,15 +1,22 @@
#include "cPacket_AddToInventory.h"
+#include "cPacket_WholeInventory.h"
+#include "cItem.h"
+#include "cPacket_ItemData.h"
bool cPacket_AddToInventory::Send( cSocket & a_Socket )
{
unsigned int TotalSize = c_Size;
+
+ cPacket_ItemData Item;
+
+ TotalSize += Item.GetSize(m_ItemType);
+
char* Message = new char[TotalSize];
unsigned int i = 0;
- AppendByte ( (char)m_PacketID, Message, i );
- AppendShort ( m_ItemType, Message, i );
- AppendByte ( m_Count, Message, i );
- AppendShort ( m_Life, Message, i );
+ AppendByte ( (char) m_PacketID, Message, i );
+
+ Item.AppendItem(Message, i, m_ItemType, m_Count, this->m_Life);
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
delete [] Message;
diff --git a/source/packets/cPacket_AddToInventory.h b/source/packets/cPacket_AddToInventory.h
index 8029a53d0..f6710e521 100644
--- a/source/packets/cPacket_AddToInventory.h
+++ b/source/packets/cPacket_AddToInventory.h
@@ -2,12 +2,13 @@
#include "cPacket.h"
#include "PacketID.h"
+#include "../BlockID.h"
class cPacket_AddToInventory : public cPacket
{
public:
cPacket_AddToInventory()
- : m_ItemType( 0 )
+ : m_ItemType( E_ITEM_EMPTY )
, m_Count( 0 )
, m_Life( 0 )
{ m_PacketID = E_ADD_TO_INV; }
@@ -16,8 +17,8 @@ public:
bool Parse( cSocket & a_Socket );
bool Send( cSocket & a_Socket );
- short m_ItemType;
+ ENUM_ITEM_ID m_ItemType;
char m_Count;
short m_Life;
- static const unsigned int c_Size = 1 + 2 + 1 + 2;
+ static const unsigned int c_Size = 1;
}; \ No newline at end of file
diff --git a/source/packets/cPacket_BlockPlace.cpp b/source/packets/cPacket_BlockPlace.cpp
index 08bc1c40c..9943ae38e 100644
--- a/source/packets/cPacket_BlockPlace.cpp
+++ b/source/packets/cPacket_BlockPlace.cpp
@@ -1,4 +1,5 @@
#include "cPacket_BlockPlace.h"
+#include "cPacket_ItemData.h"
bool cPacket_BlockPlace::Parse(cSocket & a_Socket)
{
@@ -8,11 +9,21 @@ bool cPacket_BlockPlace::Parse(cSocket & a_Socket)
if( !ReadInteger( m_PosZ ) ) return false;
if( !ReadByte ( m_Direction ) ) return false;
+ /*
if( !ReadShort ( m_ItemType ) ) return false;
if( m_ItemType > -1 )
{
if( !ReadByte ( m_Count ) ) return false;
if( !ReadShort ( m_Uses ) ) return false;
- }
+ }*/
+
+ cPacket_ItemData Item;
+
+ Item.Parse(m_Socket);
+
+ m_ItemType = Item.m_ItemID;
+ m_Count = Item.m_ItemCount;
+ m_Uses = Item.m_ItemUses;
+
return true;
} \ No newline at end of file
diff --git a/source/packets/cPacket_CreateInventoryAction.cpp b/source/packets/cPacket_CreateInventoryAction.cpp
index 40aad22e8..9ccc9f383 100644
--- a/source/packets/cPacket_CreateInventoryAction.cpp
+++ b/source/packets/cPacket_CreateInventoryAction.cpp
@@ -1,42 +1,59 @@
-#include "cPacket_CreateInventoryAction.h"
-
-cPacket_CreateInventoryAction::cPacket_CreateInventoryAction( const cPacket_CreateInventoryAction & a_Copy )
-{
- m_PacketID = E_CREATE_INVENTORY_ACTION;
- m_Slot = a_Copy.m_Slot;
- m_ItemID = a_Copy.m_ItemID;
- m_Quantity = 0;
- m_Damage = 0;
-}
-
-bool cPacket_CreateInventoryAction::Parse(cSocket & a_Socket)
-{
- m_Socket = a_Socket;
- if( !ReadShort ( m_Slot ) ) return false;
- if( !ReadShort ( m_ItemID ) ) return false;
- if( !ReadShort ( m_Quantity ) ) return false;
- if( !ReadShort ( m_Damage ) ) return false;
- return true;
-}
-
-bool cPacket_CreateInventoryAction::Send(cSocket & a_Socket)
-{
- //LOG("InventoryChange:");
- unsigned int TotalSize = c_Size;
- char* Message = new char[TotalSize];
-
- if( m_ItemID <= 0 ) m_ItemID = -1; // Fix, to make sure no invalid values are sent.
- // WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !!
- //LOG("cPacket_CreateInventoryAction: Sending Creative item ID: %i", m_ItemID );
-
- unsigned int i = 0;
- AppendByte ( (char)m_PacketID, Message, i );
- AppendShort ( m_Slot, Message, i );
- AppendShort ( m_ItemID, Message, i );
- AppendShort ( m_Quantity, Message, i );
- AppendShort ( m_Damage, Message, i );
-
- bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
- delete [] Message;
- return RetVal;
-}
+#include "cPacket_CreateInventoryAction.h"
+#include "cPacket_ItemData.h"
+
+cPacket_CreateInventoryAction::cPacket_CreateInventoryAction( const cPacket_CreateInventoryAction & a_Copy )
+{
+ m_PacketID = E_CREATE_INVENTORY_ACTION;
+ m_Slot = a_Copy.m_Slot;
+ m_ItemID = a_Copy.m_ItemID;
+ m_Quantity = 0;
+ m_Damage = 0;
+}
+
+bool cPacket_CreateInventoryAction::Parse(cSocket & a_Socket)
+{
+ m_Socket = a_Socket;
+ if( !ReadShort ( m_Slot ) ) return false;
+ /*
+ if( !ReadShort ( m_ItemID ) ) return false;
+ if( !ReadShort ( m_Quantity ) ) return false;
+ if( !ReadShort ( m_Damage ) ) return false;
+ */
+
+ cPacket_ItemData Item;
+
+ Item.Parse(m_Socket);
+
+ m_ItemID = Item.m_ItemID;
+ m_Quantity = Item.m_ItemCount;
+ m_Damage = Item.m_ItemUses;
+
+
+ return true;
+}
+
+bool cPacket_CreateInventoryAction::Send(cSocket & a_Socket)
+{
+ //LOG("InventoryChange:");
+ unsigned int TotalSize = c_Size;
+
+ cPacket_ItemData Item;
+
+ TotalSize += Item.GetSize(m_ItemID);
+
+ char* Message = new char[TotalSize];
+
+ if( m_ItemID <= 0 ) m_ItemID = -1; // Fix, to make sure no invalid values are sent.
+ // WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !!
+ //LOG("cPacket_CreateInventoryAction: Sending Creative item ID: %i", m_ItemID );
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendShort ( m_Slot, Message, i );
+
+ Item.AppendItem(Message, i, m_ItemID, m_Quantity, m_Damage);
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_CreateInventoryAction.h b/source/packets/cPacket_CreateInventoryAction.h
index 02af3a64e..083e05446 100644
--- a/source/packets/cPacket_CreateInventoryAction.h
+++ b/source/packets/cPacket_CreateInventoryAction.h
@@ -3,6 +3,8 @@
#include "cPacket.h"
#include "PacketID.h"
+//Sure itīs not Creative Inventory?
+
class cPacket_CreateInventoryAction : public cPacket
{
public:
@@ -20,8 +22,8 @@ public:
short m_Slot; // 0 = hold 1-4 = armor
short m_ItemID;
- short m_Quantity;
+ char m_Quantity; //Byte not short ;)
short m_Damage;
- static const unsigned int c_Size = 1 + 2 + 2 + 2 + 2;
+ static const unsigned int c_Size = 1 + 2;
};
diff --git a/source/packets/cPacket_InventorySlot.cpp b/source/packets/cPacket_InventorySlot.cpp
index 13b41b7b1..3c3a40210 100644
--- a/source/packets/cPacket_InventorySlot.cpp
+++ b/source/packets/cPacket_InventorySlot.cpp
@@ -1,21 +1,25 @@
#include "cPacket_InventorySlot.h"
+#include "cPacket_WholeInventory.h"
+#include "cPacket_ItemData.h"
bool cPacket_InventorySlot::Send(cSocket & a_Socket)
{
unsigned int TotalSize = c_Size;
- if( m_ItemID > -1 ) TotalSize += 1 + 2;
+
+ cPacket_ItemData Item;
+
+ TotalSize += Item.GetSize(m_ItemID);
+
char* Message = new char[TotalSize];
unsigned int i = 0;
- AppendByte ( (char)m_PacketID, Message, i );
+ AppendByte ( (char)m_PacketID, Message, i );
AppendByte ( m_WindowID, Message, i );
AppendShort ( m_SlotNum, Message, i );
- AppendShort ( m_ItemID, Message, i );
- if( m_ItemID > -1 )
- {
- AppendByte ( m_ItemCount, Message, i );
- AppendShort ( m_ItemUses, Message, i );
- }
+
+
+ Item.AppendItem(Message, i, m_ItemID, m_ItemCount, m_ItemUses);
+
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
delete [] Message;
diff --git a/source/packets/cPacket_InventorySlot.h b/source/packets/cPacket_InventorySlot.h
index 95711c98d..47672989e 100644
--- a/source/packets/cPacket_InventorySlot.h
+++ b/source/packets/cPacket_InventorySlot.h
@@ -2,6 +2,7 @@
#include "cPacket.h"
#include "PacketID.h"
+#include "../BlockID.h"
class cPacket_InventorySlot : public cPacket // Set item [S -> C] ?
{
@@ -9,7 +10,7 @@ public:
cPacket_InventorySlot()
: m_WindowID( 0 )
, m_SlotNum( 0 )
- , m_ItemID( 0 )
+ , m_ItemID( E_ITEM_EMPTY )
, m_ItemCount( 0 )
, m_ItemUses( 0 )
{ m_PacketID = E_INVENTORY_SLOT; }
@@ -30,5 +31,5 @@ public:
char m_ItemCount;
short m_ItemUses;
- static const unsigned int c_Size = 1 + 1 + 2 + 2; // Minimal size ( +1+1 = max)
+ static const unsigned int c_Size = 1 + 1 + 2; // Minimal size ( +1+1 = max)
}; \ No newline at end of file
diff --git a/source/packets/cPacket_WholeInventory.cpp b/source/packets/cPacket_WholeInventory.cpp
index 3ee047239..4bc68ed0b 100644
--- a/source/packets/cPacket_WholeInventory.cpp
+++ b/source/packets/cPacket_WholeInventory.cpp
@@ -2,6 +2,7 @@
#include "../cItem.h"
#include "../cInventory.h"
#include "../cWindow.h"
+#include "cPacket_ItemData.h"
cPacket_WholeInventory::cPacket_WholeInventory( const cPacket_WholeInventory & a_Clone )
{
@@ -39,11 +40,11 @@ bool cPacket_WholeInventory::Send(cSocket & a_Socket)
{
unsigned int TotalSize = c_Size;
+ cPacket_ItemData Item;
+
for(int i = 0; i < m_Count; i++)
{
- if( m_Items[i].m_ItemID > -1 )
- TotalSize+=3;
- TotalSize+=2;
+ TotalSize += Item.GetSize(m_Items[i].m_ItemID);
}
char* Message = new char[TotalSize];
@@ -51,18 +52,16 @@ bool cPacket_WholeInventory::Send(cSocket & a_Socket)
unsigned int i = 0;
AppendByte ( (char)m_PacketID, Message, i );
AppendByte ( m_WindowID, Message, i );
- AppendShort ( m_Count, Message, i );
+ AppendShort ( m_Count, Message, i );
+
for(int j = 0; j < m_Count; j++)
{
- AppendShort ( (short)m_Items[j].m_ItemID, Message, i );
- if( m_Items[j].m_ItemID > -1 )
- {
- AppendByte ( m_Items[j].m_ItemCount, Message, i );
- AppendShort ( m_Items[j].m_ItemHealth, Message, i );
- }
+ Item.AppendItem(Message, i, &(m_Items[j]));
}
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
delete [] Message;
return RetVal;
-} \ No newline at end of file
+}
+
+ \ No newline at end of file
diff --git a/source/packets/cPacket_WholeInventory.h b/source/packets/cPacket_WholeInventory.h
index a2e76658e..766342cd2 100644
--- a/source/packets/cPacket_WholeInventory.h
+++ b/source/packets/cPacket_WholeInventory.h
@@ -2,6 +2,7 @@
#include "cPacket.h"
#include "PacketID.h"
+#include "BlockID.h"
class cInventory;
class cWindow;
@@ -18,6 +19,8 @@ public:
, m_Count( 0 )
, m_Items( 0 )
{ m_PacketID = E_INVENTORY_WHOLE; }
+
+
virtual cPacket* Clone() const { return new cPacket_WholeInventory(*this); }
bool Send(cSocket & a_Socket);
diff --git a/source/packets/cPacket_WindowClick.cpp b/source/packets/cPacket_WindowClick.cpp
index 6b295b4d5..a84fbd34a 100644
--- a/source/packets/cPacket_WindowClick.cpp
+++ b/source/packets/cPacket_WindowClick.cpp
@@ -1,5 +1,6 @@
#include "cPacket_WindowClick.h"
-
+#include "cPacket_WholeInventory.h"
+#include "cPacket_ItemData.h"
bool cPacket_WindowClick::Parse(cSocket & a_Socket)
{
@@ -17,20 +18,15 @@ bool cPacket_WindowClick::Parse(cSocket & a_Socket)
// LOG("Right/Le: %i", m_RightMouse );
// LOG("NumClick: %i", m_NumClicks );
- if( !ReadShort(m_ItemID) ) return false;
-// LOG("ItemID: %i", m_ItemID );
- if( m_ItemID > -1 )
- {
- if( !ReadByte(m_ItemCount) ) return false;
- if( !ReadShort(m_ItemUses) ) return false;
-// LOG("Count : %i", m_ItemCount );
-// LOG("Uses : %i", m_ItemUses );
- }
- else
- {
- m_ItemCount = 0;
- m_ItemUses = 0;
- }
+ cPacket_ItemData Item;
+
+ Item.Parse(m_Socket);
+
+ m_ItemID = Item.m_ItemID;
+ m_ItemCount = Item.m_ItemCount;
+ m_ItemUses = Item.m_ItemUses;
+
+ m_EnchantNums = Item.m_EnchantNums;
return true;
} \ No newline at end of file
diff --git a/source/packets/cPacket_WindowClick.h b/source/packets/cPacket_WindowClick.h
index d6f38e9ab..e330584e1 100644
--- a/source/packets/cPacket_WindowClick.h
+++ b/source/packets/cPacket_WindowClick.h
@@ -15,6 +15,7 @@ public:
, m_ItemID( 0 )
, m_ItemCount( 0 )
, m_ItemUses( 0 )
+ , m_EnchantNums(-1)
{ m_PacketID = E_WINDOW_CLICK; }
virtual cPacket* Clone() const { return new cPacket_WindowClick(*this); }
@@ -30,12 +31,14 @@ public:
char m_RightMouse; // 0 = left 1 = Right mb
short m_NumClicks; // Num clicks
- bool m_Bool; // unkown????????????
+ bool m_Bool; // unkown???????????? SHIFT clicked
// Below = item
short m_ItemID; // if this is -1 the next stuff dont exist
char m_ItemCount;
short m_ItemUses;
+ short m_EnchantNums;
+
static const unsigned int c_Size = 1 + 1 + 2 + 1 + 2 + 2; // Minimal size ( +1+1 = max)
}; \ No newline at end of file