summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-07-31 12:13:11 +0200
committerHowaner <franzi.moos@googlemail.com>2014-07-31 12:13:11 +0200
commit556fc908aedcc36388e9d859487b140045e5e33e (patch)
tree2dccc3b803528418ea3044a8cefe124028903447
parentAdded window update. (diff)
downloadcuberite-556fc908aedcc36388e9d859487b140045e5e33e.tar
cuberite-556fc908aedcc36388e9d859487b140045e5e33e.tar.gz
cuberite-556fc908aedcc36388e9d859487b140045e5e33e.tar.bz2
cuberite-556fc908aedcc36388e9d859487b140045e5e33e.tar.lz
cuberite-556fc908aedcc36388e9d859487b140045e5e33e.tar.xz
cuberite-556fc908aedcc36388e9d859487b140045e5e33e.tar.zst
cuberite-556fc908aedcc36388e9d859487b140045e5e33e.zip
Diffstat (limited to '')
-rw-r--r--src/BlockEntities/BeaconEntity.cpp78
-rw-r--r--src/BlockEntities/BeaconEntity.h12
-rw-r--r--src/ClientHandle.cpp24
-rw-r--r--src/Protocol/Protocol17x.cpp4
-rw-r--r--src/UI/Window.cpp4
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp4
-rw-r--r--src/WorldStorage/WSSAnvil.cpp4
-rw-r--r--src/WorldStorage/WSSCompact.cpp20
8 files changed, 84 insertions, 66 deletions
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp
index 30d927663..c94783ba8 100644
--- a/src/BlockEntities/BeaconEntity.cpp
+++ b/src/BlockEntities/BeaconEntity.cpp
@@ -13,8 +13,8 @@ cBeaconEntity::cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld *
: super(E_BLOCK_BEACON, a_BlockX, a_BlockY, a_BlockZ, 1, 1, a_World)
, m_IsActive(false)
, m_BeaconLevel(0)
- , m_PrimaryPotion(cEntityEffect::effNoEffect)
- , m_SecondaryPotion(cEntityEffect::effNoEffect)
+ , m_PrimaryEffect(cEntityEffect::effNoEffect)
+ , m_SecondaryEffect(cEntityEffect::effNoEffect)
{
UpdateBeacon();
}
@@ -62,9 +62,9 @@ char cBeaconEntity::CalculatePyramidLevel(void)
-bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLevel)
+bool cBeaconEntity::IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLevel)
{
- if (a_Potion == cEntityEffect::effNoEffect)
+ if (a_Effect == cEntityEffect::effNoEffect)
{
return true;
}
@@ -74,7 +74,7 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
case 4:
{
// Beacon level 4
- if (a_Potion == cEntityEffect::effRegeneration)
+ if (a_Effect == cEntityEffect::effRegeneration)
{
return true;
}
@@ -82,7 +82,7 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
case 3:
{
// Beacon level 3
- if (a_Potion == cEntityEffect::effStrength)
+ if (a_Effect == cEntityEffect::effStrength)
{
return true;
}
@@ -90,7 +90,7 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
case 2:
{
// Beacon level 2
- switch (a_Potion)
+ switch (a_Effect)
{
case cEntityEffect::effResistance:
case cEntityEffect::effJumpBoost:
@@ -102,7 +102,7 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
case 1:
{
// Beacon level 1
- switch (a_Potion)
+ switch (a_Effect)
{
case cEntityEffect::effSpeed:
case cEntityEffect::effHaste:
@@ -119,19 +119,19 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
-bool cBeaconEntity::SelectPrimaryPotion(cEntityEffect::eType a_Potion)
+bool cBeaconEntity::SelectPrimaryEffect(cEntityEffect::eType a_Effect)
{
- if (!IsValidPotion(a_Potion, m_BeaconLevel))
+ if (!IsValidEffect(a_Effect, m_BeaconLevel))
{
return false;
}
- m_PrimaryPotion = a_Potion;
+ m_PrimaryEffect = a_Effect;
// Send window update:
if (GetWindow() != NULL)
{
- GetWindow()->SetProperty(1, m_PrimaryPotion);
+ GetWindow()->SetProperty(1, m_PrimaryEffect);
}
return true;
}
@@ -140,19 +140,19 @@ bool cBeaconEntity::SelectPrimaryPotion(cEntityEffect::eType a_Potion)
-bool cBeaconEntity::SelectSecondaryPotion(cEntityEffect::eType a_Potion)
+bool cBeaconEntity::SelectSecondaryEffect(cEntityEffect::eType a_Effect)
{
- if (!IsValidPotion(a_Potion, m_BeaconLevel))
+ if (!IsValidEffect(a_Effect, m_BeaconLevel))
{
return false;
}
- m_SecondaryPotion = a_Potion;
+ m_SecondaryEffect = a_Effect;
// Send window update:
if (GetWindow() != NULL)
{
- GetWindow()->SetProperty(2, m_SecondaryPotion);
+ GetWindow()->SetProperty(2, m_SecondaryEffect);
}
return true;
}
@@ -163,17 +163,15 @@ bool cBeaconEntity::SelectSecondaryPotion(cEntityEffect::eType a_Potion)
bool cBeaconEntity::IsBeaconBlocked(void)
{
- bool IsBlocked = false;
for (int Y = m_PosY; Y < cChunkDef::Height; ++Y)
{
BLOCKTYPE Block = m_World->GetBlock(m_PosX, Y, m_PosZ);
if (!cBlockInfo::IsTransparent(Block))
{
- IsBlocked = true;
- break;
+ return true;
}
}
- return IsBlocked;
+ return false;
}
@@ -239,22 +237,22 @@ void cBeaconEntity::GiveEffects(void)
int Radius = m_BeaconLevel * 10 + 10;
short EffectLevel = 0;
- if ((m_BeaconLevel >= 4) && (m_PrimaryPotion == m_SecondaryPotion))
+ if ((m_BeaconLevel >= 4) && (m_PrimaryEffect == m_SecondaryEffect))
{
EffectLevel = 1;
}
- cEntityEffect::eType SecondaryPotion = cEntityEffect::effNoEffect;
- if ((m_BeaconLevel >= 4) && (m_PrimaryPotion != m_SecondaryPotion) && (m_SecondaryPotion > 0))
+ cEntityEffect::eType SecondaryEffect = cEntityEffect::effNoEffect;
+ if ((m_BeaconLevel >= 4) && (m_PrimaryEffect != m_SecondaryEffect) && (m_SecondaryEffect > 0))
{
- SecondaryPotion = m_SecondaryPotion;
+ SecondaryEffect = m_SecondaryEffect;
}
class cPlayerCallback : public cPlayerListCallback
{
int m_Radius;
int m_PosX, m_PosY, m_PosZ;
- cEntityEffect::eType m_PrimaryPotion, m_SecondaryPotion;
+ cEntityEffect::eType m_PrimaryEffect, m_SecondaryEffect;
short m_EffectLevel;
virtual bool Item(cPlayer * a_Player)
@@ -269,28 +267,28 @@ void cBeaconEntity::GiveEffects(void)
Vector3d BeaconPosition = Vector3d(m_PosX, m_PosY, m_PosZ);
if ((PlayerPosition - BeaconPosition).Length() <= m_Radius)
{
- a_Player->AddEntityEffect(m_PrimaryPotion, 180, m_EffectLevel);
+ a_Player->AddEntityEffect(m_PrimaryEffect, 180, m_EffectLevel);
- if (m_SecondaryPotion != cEntityEffect::effNoEffect)
+ if (m_SecondaryEffect != cEntityEffect::effNoEffect)
{
- a_Player->AddEntityEffect(m_SecondaryPotion, 180, 0);
+ a_Player->AddEntityEffect(m_SecondaryEffect, 180, 0);
}
}
return false;
}
public:
- cPlayerCallback(int a_Radius, int a_PosX, int a_PosY, int a_PosZ, cEntityEffect::eType a_PrimaryPotion, cEntityEffect::eType a_SecondaryPotion, short a_EffectLevel)
+ cPlayerCallback(int a_Radius, int a_PosX, int a_PosY, int a_PosZ, cEntityEffect::eType a_PrimaryEffect, cEntityEffect::eType a_SecondaryEffect, short a_EffectLevel)
: m_Radius(a_Radius)
, m_PosX(a_PosX)
, m_PosY(a_PosY)
, m_PosZ(a_PosZ)
- , m_PrimaryPotion(a_PrimaryPotion)
- , m_SecondaryPotion(a_SecondaryPotion)
+ , m_PrimaryEffect(a_PrimaryEffect)
+ , m_SecondaryEffect(a_SecondaryEffect)
, m_EffectLevel(a_EffectLevel)
{};
- } PlayerCallback(Radius, m_PosX, m_PosY, m_PosZ, m_PrimaryPotion, SecondaryPotion, EffectLevel);
+ } PlayerCallback(Radius, m_PosX, m_PosY, m_PosZ, m_PrimaryEffect, SecondaryEffect, EffectLevel);
GetWorld()->ForEachPlayer(PlayerCallback);
}
@@ -353,17 +351,17 @@ bool cBeaconEntity::LoadFromJson(const Json::Value & a_Value)
}
m_BeaconLevel = (char)a_Value.get("Level", 0).asInt();
- int PrimaryPotion = a_Value.get("PrimaryPotion", 0).asInt();
- int SecondaryPotion = a_Value.get("SecondaryPotion", 0).asInt();
+ int PrimaryEffect = a_Value.get("PrimaryEffect", 0).asInt();
+ int SecondaryEffect = a_Value.get("SecondaryEffect", 0).asInt();
- if ((PrimaryPotion >= 0) && (PrimaryPotion <= (int)cEntityEffect::effSaturation))
+ if ((PrimaryEffect >= 0) && (PrimaryEffect <= (int)cEntityEffect::effSaturation))
{
- m_PrimaryPotion = (cEntityEffect::eType)PrimaryPotion;
+ m_PrimaryEffect = (cEntityEffect::eType)PrimaryEffect;
}
- if ((SecondaryPotion >= 0) && (SecondaryPotion <= (int)cEntityEffect::effSaturation))
+ if ((SecondaryEffect >= 0) && (SecondaryEffect <= (int)cEntityEffect::effSaturation))
{
- m_SecondaryPotion = (cEntityEffect::eType)SecondaryPotion;
+ m_SecondaryEffect = (cEntityEffect::eType)SecondaryEffect;
}
return true;
@@ -390,8 +388,8 @@ void cBeaconEntity::SaveToJson(Json::Value& a_Value)
a_Value["Slots"] = AllSlots;
a_Value["Level"] = m_BeaconLevel;
- a_Value["PrimaryPotion"] = (int)m_PrimaryPotion;
- a_Value["SecondaryPotion"] = (int)m_SecondaryPotion;
+ a_Value["PrimaryEffect"] = (int)m_PrimaryEffect;
+ a_Value["SecondaryEffect"] = (int)m_SecondaryEffect;
}
diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h
index 59a4bdbd9..5cf8da24e 100644
--- a/src/BlockEntities/BeaconEntity.h
+++ b/src/BlockEntities/BeaconEntity.h
@@ -52,14 +52,14 @@ public:
/** Returns the beacon level. (0 - 4) */
char GetBeaconLevel(void) const { return m_BeaconLevel; }
- cEntityEffect::eType GetPrimaryPotion(void) const { return m_PrimaryPotion; }
- cEntityEffect::eType GetSecondaryPotion(void) const { return m_SecondaryPotion; }
+ cEntityEffect::eType GetPrimaryEffect(void) const { return m_PrimaryEffect; }
+ cEntityEffect::eType GetSecondaryEffect(void) const { return m_SecondaryEffect; }
/** Select the primary potion. Returns false when the potion is invalid.*/
- bool SelectPrimaryPotion(cEntityEffect::eType a_Potion);
+ bool SelectPrimaryEffect(cEntityEffect::eType a_Effect);
/** Select the secondary potion. Returns false when the potion is invalid. */
- bool SelectSecondaryPotion(cEntityEffect::eType a_Potion);
+ bool SelectSecondaryEffect(cEntityEffect::eType a_Effect);
/** Calculate the amount of layers the pyramid below the beacon has. */
char CalculatePyramidLevel(void);
@@ -77,7 +77,7 @@ public:
static bool IsMineralBlock(BLOCKTYPE a_BlockType);
/** Returns true if the potion can be used. */
- static bool IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLevel);
+ static bool IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLevel);
// tolua_end
@@ -85,7 +85,7 @@ protected:
bool m_IsActive;
char m_BeaconLevel;
- cEntityEffect::eType m_PrimaryPotion, m_SecondaryPotion;
+ cEntityEffect::eType m_PrimaryEffect, m_SecondaryEffect;
} ; // tolua_export
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 849de2ce1..e833f338a 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -7,6 +7,7 @@
#include "Bindings/PluginManager.h"
#include "Entities/Player.h"
#include "Inventory.h"
+#include "BlockEntities/BeaconEntity.h"
#include "BlockEntities/ChestEntity.h"
#include "BlockEntities/CommandBlockEntity.h"
#include "BlockEntities/SignEntity.h"
@@ -31,7 +32,6 @@
#include "Items/ItemSword.h"
#include "polarssl/md5.h"
-#include "BlockEntities/BeaconEntity.h"
@@ -775,25 +775,25 @@ void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length)
cByteBuffer Buffer(a_Length);
Buffer.Write(a_Data, a_Length);
- int PrimaryPotionID, SecondaryPotionID;
- Buffer.ReadBEInt(PrimaryPotionID);
- Buffer.ReadBEInt(SecondaryPotionID);
+ int PrimaryEffectID, SecondaryEffectID;
+ Buffer.ReadBEInt(PrimaryEffectID);
+ Buffer.ReadBEInt(SecondaryEffectID);
- cEntityEffect::eType PrimaryPotion = cEntityEffect::effNoEffect;
- if ((PrimaryPotionID >= 0) && (PrimaryPotionID <= (int)cEntityEffect::effSaturation))
+ cEntityEffect::eType PrimaryEffect = cEntityEffect::effNoEffect;
+ if ((PrimaryEffectID >= 0) && (PrimaryEffectID <= (int)cEntityEffect::effSaturation))
{
- PrimaryPotion = (cEntityEffect::eType)PrimaryPotionID;
+ PrimaryEffect = (cEntityEffect::eType)PrimaryEffectID;
}
- cEntityEffect::eType SecondaryPotion = cEntityEffect::effNoEffect;
- if ((SecondaryPotionID >= 0) && (SecondaryPotionID <= (int)cEntityEffect::effSaturation))
+ cEntityEffect::eType SecondaryEffect = cEntityEffect::effNoEffect;
+ if ((SecondaryEffectID >= 0) && (SecondaryEffectID <= (int)cEntityEffect::effSaturation))
{
- SecondaryPotion = (cEntityEffect::eType)SecondaryPotionID;
+ SecondaryEffect = (cEntityEffect::eType)SecondaryEffectID;
}
Window->SetSlot(*m_Player, 0, cItem());
- BeaconWindow->GetBeaconEntity()->SelectPrimaryPotion(PrimaryPotion);
- BeaconWindow->GetBeaconEntity()->SelectSecondaryPotion(SecondaryPotion);
+ BeaconWindow->GetBeaconEntity()->SelectPrimaryEffect(PrimaryEffect);
+ BeaconWindow->GetBeaconEntity()->SelectSecondaryEffect(SecondaryEffect);
}
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 8a68edd1f..8e31e211c 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -2590,8 +2590,8 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
Writer.AddInt("x", BeaconEntity.GetPosX());
Writer.AddInt("y", BeaconEntity.GetPosY());
Writer.AddInt("z", BeaconEntity.GetPosZ());
- Writer.AddInt("Primary", BeaconEntity.GetPrimaryPotion());
- Writer.AddInt("Secondary", BeaconEntity.GetSecondaryPotion());
+ Writer.AddInt("Primary", BeaconEntity.GetPrimaryEffect());
+ Writer.AddInt("Secondary", BeaconEntity.GetSecondaryEffect());
Writer.AddInt("Levels", BeaconEntity.GetBeaconLevel());
Writer.AddString("id", "Beacon"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
break;
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index aa129bfe8..8f4913030 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -863,8 +863,8 @@ void cBeaconWindow::OpenedByPlayer(cPlayer & a_Player)
super::OpenedByPlayer(a_Player);
a_Player.GetClientHandle()->SendWindowProperty(*this, 0, m_Beacon->GetBeaconLevel());
- a_Player.GetClientHandle()->SendWindowProperty(*this, 1, m_Beacon->GetPrimaryPotion());
- a_Player.GetClientHandle()->SendWindowProperty(*this, 2, m_Beacon->GetSecondaryPotion());
+ a_Player.GetClientHandle()->SendWindowProperty(*this, 1, m_Beacon->GetPrimaryEffect());
+ a_Player.GetClientHandle()->SendWindowProperty(*this, 2, m_Beacon->GetSecondaryEffect());
}
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 63387c33d..601cd8833 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -182,8 +182,8 @@ void cNBTChunkSerializer::AddBeaconEntity(cBeaconEntity * a_Entity)
m_Writer.BeginCompound("");
AddBasicTileEntity(a_Entity, "Beacon");
m_Writer.AddInt("Levels", a_Entity->GetBeaconLevel());
- m_Writer.AddInt("Primary", (int)a_Entity->GetPrimaryPotion());
- m_Writer.AddInt("Secondary", (int)a_Entity->GetSecondaryPotion());
+ m_Writer.AddInt("Primary", (int)a_Entity->GetPrimaryEffect());
+ m_Writer.AddInt("Secondary", (int)a_Entity->GetSecondaryEffect());
m_Writer.BeginList("Items", TAG_Compound);
AddItemGrid(a_Entity->GetContents());
m_Writer.EndList();
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 5a1972fd4..555ef410d 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -771,13 +771,13 @@ void cWSSAnvil::LoadBeaconFromNBT(cBlockEntityList & a_BlockEntities, const cPar
CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Primary");
if (CurrentLine >= 0)
{
- Beacon->SelectPrimaryPotion((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
+ Beacon->SelectPrimaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
}
CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Secondary");
if (CurrentLine >= 0)
{
- Beacon->SelectSecondaryPotion((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
+ Beacon->SelectSecondaryEffect((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
}
// We are better than mojang, we load/save the beacon inventory!
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index ee47047a0..58f9e3cab 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -9,6 +9,7 @@
#include "zlib/zlib.h"
#include "json/json.h"
#include "../StringCompression.h"
+#include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/CommandBlockEntity.h"
#include "../BlockEntities/DispenserEntity.h"
@@ -75,6 +76,7 @@ void cJsonChunkSerializer::BlockEntity(cBlockEntity * a_BlockEntity)
const char * SaveInto = NULL;
switch (a_BlockEntity->GetBlockType())
{
+ case E_BLOCK_BEACON: SaveInto = "Beacons"; break;
case E_BLOCK_CHEST: SaveInto = "Chests"; break;
case E_BLOCK_DISPENSER: SaveInto = "Dispensers"; break;
case E_BLOCK_DROPPER: SaveInto = "Droppers"; break;
@@ -268,6 +270,24 @@ bool cWSSCompact::EraseChunkData(const cChunkCoords & a_Chunk)
void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities, cWorld * a_World)
{
+ // Load beacon:
+ Json::Value AllBeacons = a_Value.get("Beacons", Json::nullValue);
+ if (!AllBeacons.empty())
+ {
+ for (Json::Value::iterator itr = AllBeacons.begin(); itr != AllBeacons.end(); ++itr)
+ {
+ std::auto_ptr<cBeaconEntity> BeaconEntity(new cBeaconEntity(0, 0, 0, a_World));
+ if (!BeaconEntity->LoadFromJson(*itr))
+ {
+ LOGWARNING("ERROR READING BEACON FROM JSON!");
+ }
+ else
+ {
+ a_BlockEntities.push_back(BeaconEntity.release());
+ }
+ } // for itr - AllBeacons[]
+ }
+
// Load chests:
Json::Value AllChests = a_Value.get("Chests", Json::nullValue);
if (!AllChests.empty())