diff options
author | Tycho <work.tycho+git@gmail.com> | 2014-02-02 15:56:07 +0100 |
---|---|---|
committer | Tycho <work.tycho+git@gmail.com> | 2014-02-02 15:56:07 +0100 |
commit | 0b0aa5554fbb0179e108f0473f4bf732340d1b95 (patch) | |
tree | 36239f98c1c8417483af6a13fed586c32dda811c | |
parent | Changed Signiture of OnUpdate (diff) | |
parent | Fixed #620 (diff) | |
download | cuberite-0b0aa5554fbb0179e108f0473f4bf732340d1b95.tar cuberite-0b0aa5554fbb0179e108f0473f4bf732340d1b95.tar.gz cuberite-0b0aa5554fbb0179e108f0473f4bf732340d1b95.tar.bz2 cuberite-0b0aa5554fbb0179e108f0473f4bf732340d1b95.tar.lz cuberite-0b0aa5554fbb0179e108f0473f4bf732340d1b95.tar.xz cuberite-0b0aa5554fbb0179e108f0473f4bf732340d1b95.tar.zst cuberite-0b0aa5554fbb0179e108f0473f4bf732340d1b95.zip |
-rw-r--r-- | CONTRIBUTORS | 1 | ||||
-rw-r--r-- | MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua | 23 | ||||
-rw-r--r-- | src/Bindings/Plugin.h | 1 | ||||
-rw-r--r-- | src/Bindings/PluginLua.cpp | 20 | ||||
-rw-r--r-- | src/Bindings/PluginLua.h | 1 | ||||
-rw-r--r-- | src/Bindings/PluginManager.cpp | 21 | ||||
-rw-r--r-- | src/Bindings/PluginManager.h | 2 | ||||
-rw-r--r-- | src/Blocks/BlockTorch.h | 3 | ||||
-rw-r--r-- | src/Entities/Player.cpp | 2 | ||||
-rw-r--r-- | src/Mobs/Monster.cpp | 2 | ||||
-rw-r--r-- | src/Mobs/Wolf.cpp | 1 | ||||
-rw-r--r-- | src/WorldStorage/NBTChunkSerializer.cpp | 4 | ||||
-rw-r--r-- | src/WorldStorage/WSSAnvil.cpp | 18 |
13 files changed, 96 insertions, 3 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 2392d8523..8b10525da 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -23,6 +23,7 @@ Sxw1212 Taugeshtu tigerw (Tiger Wang) tonibm19 +UltraCoderRU worktycho xoft diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua new file mode 100644 index 000000000..8e503658c --- /dev/null +++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerDestroyed.lua @@ -0,0 +1,23 @@ +return +{ + HOOK_PLAYER_DESTROYED = + { + CalledWhen = "A player is about to get destroyed.", + DefaultFnName = "OnPlayerDestroyed", -- also used as pagename + Desc = [[ + This function is called when a {{cPlayer|player}} is about to get destroyed. But the player isn't already destroyed. + ]], + Params = + { + { Name = "Player", Type = "{{cPlayer}}", Notes = "The destroyed player" }, + }, + Returns = [[ + It's only for notification. Can't be returned. + ]], + }, -- HOOK_PLAYER_DESTROYED +} + + + + + diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index f4a117721..949e4693a 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -67,6 +67,7 @@ public: virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; + virtual bool OnPlayerDestroyed (cPlayer & a_Player) = 0; virtual bool OnPlayerEating (cPlayer & a_Player) = 0; virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) = 0; virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 7b2362887..773d522c4 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -641,6 +641,26 @@ bool cPluginLua::OnPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX, int a_Blo +bool cPluginLua::OnPlayerDestroyed(cPlayer & a_Player) +{ + cCSLock Lock(m_CriticalSection); + bool res = false; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_DESTROYED]; + for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) + { + m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res); + if (res) + { + return true; + } + } + return false; +} + + + + + bool cPluginLua::OnPlayerEating(cPlayer & a_Player) { cCSLock Lock(m_CriticalSection); diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index c13f31424..ad0cfbe5a 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -64,6 +64,7 @@ public: virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; + virtual bool OnPlayerDestroyed (cPlayer & a_Player) override; virtual bool OnPlayerEating (cPlayer & a_Player) override; virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) override; virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index e582fde86..a20583550 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -673,6 +673,27 @@ bool cPluginManager::CallHookPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX, +bool cPluginManager::CallHookPlayerDestroyed(cPlayer & a_Player) +{ + HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_DESTROYED); + if (Plugins == m_Hooks.end()) + { + return false; + } + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnPlayerDestroyed(a_Player)) + { + return true; + } + } + return false; +} + + + + + bool cPluginManager::CallHookPlayerEating(cPlayer & a_Player) { HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_EATING); diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index d8b838d80..c78bceda1 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -79,6 +79,7 @@ public: // tolua_export HOOK_LOGIN, HOOK_PLAYER_BREAKING_BLOCK, HOOK_PLAYER_BROKEN_BLOCK, + HOOK_PLAYER_DESTROYED, HOOK_PLAYER_EATING, HOOK_PLAYER_FISHED, HOOK_PLAYER_FISHING, @@ -174,6 +175,7 @@ public: // tolua_export bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation); bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + bool CallHookPlayerDestroyed (cPlayer & a_Player); bool CallHookPlayerEating (cPlayer & a_Player); bool CallHookPlayerFished (cPlayer & a_Player, const cItems a_Reward); bool CallHookPlayerFishing (cPlayer & a_Player, cItems a_Reward); diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 33cafbddc..c3b25c899 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -38,9 +38,10 @@ public: else { // Not top or bottom faces, try to preserve whatever face was clicked - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); // Set to clicked block if (!CanBePlacedOn(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ), a_BlockFace)) { + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, false); // Reset to torch block // Torch couldn't be placed on whatever face was clicked, last ditch resort - find another face a_BlockFace = FindSuitableFace(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); if (a_BlockFace == BLOCK_FACE_NONE) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 82e31ae65..8c37fdc8d 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -130,6 +130,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) cPlayer::~cPlayer(void) { + cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this); + LOGD("Deleting cPlayer \"%s\" at %p, ID %d", m_PlayerName.c_str(), this, GetUniqueID()); // Notify the server that the player is being destroyed diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 42c7d2899..283ef36e6 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -276,7 +276,7 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) { Distance.y = 0; Distance.Normalize(); - Distance *= 3; + Distance *= 5; SetSpeedX(Distance.x); SetSpeedZ(Distance.z); diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index c0c7892e3..ff324d073 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -204,6 +204,7 @@ void cWolf::TickFollowPlayer() { if (!IsSitting()) { + Callback.OwnerPos.y = FindFirstNonAirBlockPosition(Callback.OwnerPos.x, Callback.OwnerPos.z); TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z); } } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 9c454c028..c6250f393 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -455,7 +455,9 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) case cMonster::mtWolf: { m_Writer.AddString("Owner", ((const cWolf *)a_Monster)->GetOwner()); - m_Writer.AddByte("Sitting", ((const cWolf *)a_Monster)->IsSitting()); + m_Writer.AddByte("Sitting", (((const cWolf *)a_Monster)->IsSitting() ? 1 : 0)); + m_Writer.AddByte("Angry", (((const cWolf *)a_Monster)->IsAngry() ? 1 : 0)); + m_Writer.AddInt("CollarColor", ((const cWolf *)a_Monster)->GetCollarColor()); break; } case cMonster::mtZombie: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 02396bb16..d72165c46 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1886,6 +1886,24 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N Monster->SetIsTame(true); } } + int SittingIdx = a_NBT.FindChildByName(a_TagIdx, "Sitting"); + if (SittingIdx > 0) + { + bool Sitting = ((a_NBT.GetByte(SittingIdx) == 1) ? true : false); + Monster->SetIsSitting(Sitting); + } + int AngryIdx = a_NBT.FindChildByName(a_TagIdx, "Angry"); + if (AngryIdx > 0) + { + bool Angry = ((a_NBT.GetByte(AngryIdx) == 1) ? true : false); + Monster->SetIsAngry(Angry); + } + int CollarColorIdx = a_NBT.FindChildByName(a_TagIdx, "CollarColor"); + if (CollarColorIdx > 0) + { + int CollarColor = a_NBT.GetInt(CollarColorIdx); + Monster->SetCollarColor(CollarColor); + } a_Entities.push_back(Monster.release()); } |