From bef84b4821724c7119a3cb007d9e1265a56a27f0 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 28 Jun 2014 12:59:09 +0200 Subject: Fix sheep color's, add shear sound. --- src/Mobs/Monster.cpp | 2 +- src/Mobs/Sheep.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- src/Mobs/Sheep.h | 2 +- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 5843ca5a6..5ffd645b3 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -900,7 +900,7 @@ cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType) case mtMooshroom: toReturn = new cMooshroom(); break; case mtOcelot: toReturn = new cOcelot(); break; case mtPig: toReturn = new cPig(); break; - case mtSheep: toReturn = new cSheep (Random.NextInt(15)); break; // Colour parameter + case mtSheep: toReturn = new cSheep(); break; case mtSilverfish: toReturn = new cSilverfish(); break; case mtSnowGolem: toReturn = new cSnowGolem(); break; case mtSpider: toReturn = new cSpider(); break; diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index 5a6b760af..cc7315a86 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -5,6 +5,7 @@ #include "../BlockID.h" #include "../Entities/Player.h" #include "../World.h" +#include "FastRandom.h" @@ -16,6 +17,43 @@ cSheep::cSheep(int a_Color) : m_WoolColor(a_Color), m_TimeToStopEating(-1) { + // Generate random wool color. + if (m_WoolColor == -1) + { + cFastRandom Random; + int Chance = Random.NextInt(101); + + if (Chance <= 81) + { + // White + m_WoolColor = 0; + } + else if (Chance <= 86) + { + // Black + m_WoolColor = 15; + } + else if (Chance <= 91) + { + // Grey + m_WoolColor = 7; + } + else if (Chance <= 96) + { + // Light grey + m_WoolColor = 8; + } + else if (Chance <= 99) + { + // Brown + m_WoolColor = 12; + } + else + { + // Pink + m_WoolColor = 6; + } + } } @@ -37,7 +75,7 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSheep::OnRightClicked(cPlayer & a_Player) { const cItem & EquippedItem = a_Player.GetEquippedItem(); - if ((EquippedItem.m_ItemType == E_ITEM_SHEARS) && (!m_IsSheared)) + if ((EquippedItem.m_ItemType == E_ITEM_SHEARS) && !IsSheared() && !IsBaby()) { m_IsSheared = true; m_World->BroadcastEntityMetadata(*this); @@ -51,6 +89,7 @@ void cSheep::OnRightClicked(cPlayer & a_Player) int NumDrops = m_World->GetTickRandomNumber(2) + 1; Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor)); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + m_World->BroadcastSoundEffect("mob.sheep.shear", POSX_TOINT * 8, POSY_TOINT * 8, POSZ_TOINT * 8, 1.0f, 1.0f); } else if ((EquippedItem.m_ItemType == E_ITEM_DYE) && (m_WoolColor != 15 - EquippedItem.m_ItemDamage)) { diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h index 402e8e61c..14da81364 100644 --- a/src/Mobs/Sheep.h +++ b/src/Mobs/Sheep.h @@ -13,7 +13,7 @@ class cSheep : typedef cPassiveMonster super; public: - cSheep(int a_Color); + cSheep(int a_Color = -1); CLASS_PROTODEF(cSheep); -- cgit v1.2.3 From 11d02a447e45e96e4652f25afc6d040597ad2064 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 28 Jun 2014 13:19:32 +0200 Subject: Save IsSheared from Sheep. --- src/Mobs/Sheep.h | 3 +++ src/WorldStorage/WSSAnvil.cpp | 15 +++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h index 14da81364..21dca7787 100644 --- a/src/Mobs/Sheep.h +++ b/src/Mobs/Sheep.h @@ -24,7 +24,10 @@ public: virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } bool IsSheared(void) const { return m_IsSheared; } + void SetSheared(bool a_IsSheared) { m_IsSheared = a_IsSheared; } + int GetFurColor(void) const { return m_WoolColor; } + void SetFurColor(bool a_WoolColor) { m_WoolColor = a_WoolColor; } private: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 9870c144a..5c209c7fa 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2073,10 +2073,11 @@ void cWSSAnvil::LoadPigFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { int ColorIdx = a_NBT.FindChildByName(a_TagIdx, "Color"); - - if (ColorIdx < 0) { return; } - - int Color = (int)a_NBT.GetByte(ColorIdx); + int Color = -1; + if (ColorIdx > 0) + { + Color = (int)a_NBT.GetByte(ColorIdx); + } std::auto_ptr Monster(new cSheep(Color)); if (!LoadEntityBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) @@ -2089,6 +2090,12 @@ void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ return; } + int ShearedIdx = a_NBT.FindChildByName(a_TagIdx, "Sheared"); + if (ShearedIdx > 0) + { + Monster.get()->SetSheared((bool)a_NBT.GetByte(ShearedIdx)); + } + a_Entities.push_back(Monster.release()); } -- cgit v1.2.3 From 20b32fc44e69ef317dea7536eb8e31bc3fe6c562 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 29 Jun 2014 01:01:10 +0200 Subject: Code fixes. --- src/WorldStorage/WSSAnvil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 5c209c7fa..b22454cdf 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2093,7 +2093,7 @@ void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ int ShearedIdx = a_NBT.FindChildByName(a_TagIdx, "Sheared"); if (ShearedIdx > 0) { - Monster.get()->SetSheared((bool)a_NBT.GetByte(ShearedIdx)); + Monster->SetSheared(a_NBT.GetByte(ShearedIdx) != 0); } a_Entities.push_back(Monster.release()); -- cgit v1.2.3 From c3cde6232fae96a1c196d6bdf63b17ae996aee24 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 30 Jun 2014 20:23:17 +0200 Subject: Moved the random code to a function (cSheep::GenerateNaturalRandomColor()) --- src/Mobs/Sheep.cpp | 72 ++++++++++++++++++++++++++++++------------------------ src/Mobs/Sheep.h | 11 ++++++--- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index cc7315a86..e208aa891 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -20,39 +20,12 @@ cSheep::cSheep(int a_Color) : // Generate random wool color. if (m_WoolColor == -1) { - cFastRandom Random; - int Chance = Random.NextInt(101); + m_WoolColor = GenerateNaturalRandomColor(); + } - if (Chance <= 81) - { - // White - m_WoolColor = 0; - } - else if (Chance <= 86) - { - // Black - m_WoolColor = 15; - } - else if (Chance <= 91) - { - // Grey - m_WoolColor = 7; - } - else if (Chance <= 96) - { - // Light grey - m_WoolColor = 8; - } - else if (Chance <= 99) - { - // Brown - m_WoolColor = 12; - } - else - { - // Pink - m_WoolColor = 6; - } + if ((m_WoolColor < 0) || (m_WoolColor > 15)) + { + m_WoolColor = 0; } } @@ -148,3 +121,38 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk) } } + + + + +NIBBLETYPE cSheep::GenerateNaturalRandomColor(void) +{ + cFastRandom Random; + int Chance = Random.NextInt(101); + + if (Chance <= 81) + { + return E_META_WOOL_WHITE; + } + else if (Chance <= 86) + { + return E_META_WOOL_BLACK; + } + else if (Chance <= 91) + { + return E_META_WOOL_GRAY; + } + else if (Chance <= 96) + { + return E_META_WOOL_LIGHTGRAY; + } + else if (Chance <= 99) + { + return E_META_WOOL_BROWN; + } + else + { + return E_META_WOOL_PINK; + } +} + diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h index 21dca7787..41de7924f 100644 --- a/src/Mobs/Sheep.h +++ b/src/Mobs/Sheep.h @@ -13,24 +13,27 @@ class cSheep : typedef cPassiveMonster super; public: + + /** Use -1 for random color. */ cSheep(int a_Color = -1); - + CLASS_PROTODEF(cSheep); - + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void OnRightClicked(cPlayer & a_Player) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } + static NIBBLETYPE GenerateNaturalRandomColor(void); + bool IsSheared(void) const { return m_IsSheared; } void SetSheared(bool a_IsSheared) { m_IsSheared = a_IsSheared; } int GetFurColor(void) const { return m_WoolColor; } - void SetFurColor(bool a_WoolColor) { m_WoolColor = a_WoolColor; } + void SetFurColor(int a_WoolColor) { m_WoolColor = a_WoolColor; } private: - bool m_IsSheared; int m_WoolColor; int m_TimeToStopEating; -- cgit v1.2.3 From 68007ab3e5aba33fb3a8e34c0301401aef594737 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 1 Jul 2014 20:42:23 +0200 Subject: Add doxy-comments. --- src/Mobs/Sheep.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h index 41de7924f..36d7df826 100644 --- a/src/Mobs/Sheep.h +++ b/src/Mobs/Sheep.h @@ -14,7 +14,9 @@ class cSheep : public: - /** Use -1 for random color. */ + /** The number is the color of the sheep. + 0-15 are the normal colors, if you type -1 the server + automatically chooses the right color for the sheep when spawned. */ cSheep(int a_Color = -1); CLASS_PROTODEF(cSheep); @@ -25,6 +27,7 @@ public: virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } + /** Generates a random color for the sheep, like Mojang it does. */ static NIBBLETYPE GenerateNaturalRandomColor(void); bool IsSheared(void) const { return m_IsSheared; } -- cgit v1.2.3 From 905fed09a64667f6f9cebf353dc65e6f094fbc72 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 13 Jul 2014 00:51:42 +0200 Subject: Fixed wrong types. (BLOCKTYPE -> NIBBLETYPE) --- src/BlockArea.cpp | 2 +- src/ChunkMap.cpp | 4 ++-- src/ChunkMap.h | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 185582ba3..0e4c42f0f 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -59,7 +59,7 @@ void InternalMergeBlocks( } else { - BLOCKTYPE FakeDestMeta = 0; + NIBBLETYPE FakeDestMeta = 0; Combinator(a_DstTypes[DstIdx], a_SrcTypes[SrcIdx], FakeDestMeta, (NIBBLETYPE)0); } ++DstIdx; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 35d55d396..4040fff9f 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1278,7 +1278,7 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP -void cChunkMap::SetBlock(cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, bool a_SendToClients) +void cChunkMap::SetBlock(cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_SendToClients) { cChunkInterface ChunkInterface(this); if (a_BlockType == E_BLOCK_AIR) @@ -1303,7 +1303,7 @@ void cChunkMap::SetBlock(cWorldInterface & a_WorldInterface, int a_BlockX, int a -void cChunkMap::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType) +void cChunkMap::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType) { int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ; cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 4daa85ebd..973d0d219 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -154,9 +154,9 @@ public: NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ); NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ); NIBBLETYPE GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_BlockZ); - void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockMeta); - void SetBlock (cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, bool a_SendToClients = true); - void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR); + void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta); + void SetBlock (cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_SendToClients = true); + void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR); bool GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); bool GetBlockInfo (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight); -- cgit v1.2.3 From dc5c43c0aa3ffb8ddaa0871ccf76d872d2393cdb Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 13 Jul 2014 01:04:43 +0200 Subject: Changed comments. --- src/Mobs/Sheep.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h index 36d7df826..5ffd3e4fe 100644 --- a/src/Mobs/Sheep.h +++ b/src/Mobs/Sheep.h @@ -15,8 +15,9 @@ class cSheep : public: /** The number is the color of the sheep. - 0-15 are the normal colors, if you type -1 the server - automatically chooses the right color for the sheep when spawned. */ + Use E_META_WOOL_* constants for the wool color. + If you type -1, the server will generate a random color + with the GenerateNaturalRandomColor() function. */ cSheep(int a_Color = -1); CLASS_PROTODEF(cSheep); @@ -27,7 +28,8 @@ public: virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } - /** Generates a random color for the sheep, like Mojang it does. */ + /** Generates a random color for the sheep like the vanilla server. + The percent's where used are from the wiki: http://minecraft.gamepedia.com/Sheep#Breeding */ static NIBBLETYPE GenerateNaturalRandomColor(void); bool IsSheared(void) const { return m_IsSheared; } -- cgit v1.2.3 From f1491ad1d1df3e0b4d22af8329c95106e794ba01 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 13 Jul 2014 01:18:41 +0200 Subject: Fixed diamond mover plugin --- MCServer/Plugins/DiamondMover/DiamondMover.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/MCServer/Plugins/DiamondMover/DiamondMover.lua b/MCServer/Plugins/DiamondMover/DiamondMover.lua index 0fdd32250..d3e70acfc 100644 --- a/MCServer/Plugins/DiamondMover/DiamondMover.lua +++ b/MCServer/Plugins/DiamondMover/DiamondMover.lua @@ -22,6 +22,8 @@ function Initialize(Plugin) Plugin:SetVersion(1); cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_USED_ITEM, OnPlayerUsedItem); + + LOG("Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()); return true; end @@ -36,8 +38,8 @@ function OnPlayerUsedItem(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, Cu return false; end; - if (Player:HasPermission("diamondmover.move") == false) then - return true; + if (not Player:HasPermission("diamondmover.move")) then + return false; end; -- Rclk with a diamond to push in the direction the player is facing @@ -56,7 +58,7 @@ function OnPlayerUsedItem(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, Cu if (PlayerPitch > 70) then -- looking down BlockY = BlockY - 1; else - local PlayerRot = Player:GetRotation() + 180; -- Convert [-180, 180] into [0, 360] for simpler conditions + local PlayerRot = Player:GetYaw() + 180; -- Convert [-180, 180] into [0, 360] for simpler conditions if ((PlayerRot < 45) or (PlayerRot > 315)) then BlockZ = BlockZ - 1; else -- cgit v1.2.3