Exported the beacon.
This commit is contained in:
parent
89b1bbdc5f
commit
81e095adda
@ -47,6 +47,7 @@ $cfile "../Inventory.h"
|
||||
$cfile "../Enchantments.h"
|
||||
$cfile "../Item.h"
|
||||
$cfile "../ItemGrid.h"
|
||||
$cfile "../BlockEntities/BeaconEntity.h"
|
||||
$cfile "../BlockEntities/BlockEntity.h"
|
||||
$cfile "../BlockEntities/BlockEntityWithItems.h"
|
||||
$cfile "../BlockEntities/ChestEntity.h"
|
||||
|
@ -53,6 +53,7 @@ set(BINDING_DEPENDENCIES
|
||||
../Bindings/WebPlugin.h
|
||||
../BiomeDef.h
|
||||
../BlockArea.h
|
||||
../BlockEntities/BeaconEntity.h
|
||||
../BlockEntities/BlockEntity.h
|
||||
../BlockEntities/BlockEntityWithItems.h
|
||||
../BlockEntities/ChestEntity.h
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "../WebAdmin.h"
|
||||
#include "../ClientHandle.h"
|
||||
#include "../BlockArea.h"
|
||||
#include "../BlockEntities/BeaconEntity.h"
|
||||
#include "../BlockEntities/ChestEntity.h"
|
||||
#include "../BlockEntities/CommandBlockEntity.h"
|
||||
#include "../BlockEntities/DispenserEntity.h"
|
||||
@ -2996,6 +2997,7 @@ void ManualBindings::Bind(lua_State * tolua_S)
|
||||
tolua_beginmodule(tolua_S, "cWorld");
|
||||
tolua_function(tolua_S, "ChunkStay", tolua_cWorld_ChunkStay);
|
||||
tolua_function(tolua_S, "DoWithBlockEntityAt", tolua_DoWithXYZ<cWorld, cBlockEntity, &cWorld::DoWithBlockEntityAt>);
|
||||
tolua_function(tolua_S, "DoWithBeaconAt", tolua_DoWithXYZ<cWorld, cBeaconEntity, &cWorld::DoWithBeaconAt>);
|
||||
tolua_function(tolua_S, "DoWithChestAt", tolua_DoWithXYZ<cWorld, cChestEntity, &cWorld::DoWithChestAt>);
|
||||
tolua_function(tolua_S, "DoWithDispenserAt", tolua_DoWithXYZ<cWorld, cDispenserEntity, &cWorld::DoWithDispenserAt>);
|
||||
tolua_function(tolua_S, "DoWithDropSpenserAt", tolua_DoWithXYZ<cWorld, cDropSpenserEntity, &cWorld::DoWithDropSpenserAt>);
|
||||
|
@ -121,10 +121,8 @@ bool cBeaconEntity::IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLe
|
||||
|
||||
bool cBeaconEntity::SelectPrimaryPotion(cEntityEffect::eType a_Potion)
|
||||
{
|
||||
LOG("SelectPrimaryPotion!");
|
||||
if (!IsValidPotion(a_Potion, m_BeaconLevel))
|
||||
{
|
||||
LOG("FALLSE!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,10 @@
|
||||
// BeaconEntity.h
|
||||
|
||||
// Declares the cBeaconEntity class representing a single beacon in the world
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
@ -16,14 +23,26 @@ namespace Json
|
||||
|
||||
|
||||
|
||||
// tolua_begin
|
||||
class cBeaconEntity :
|
||||
public cBlockEntityWithItems
|
||||
{
|
||||
typedef cBlockEntityWithItems super;
|
||||
|
||||
public:
|
||||
// tolua_end
|
||||
|
||||
cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
|
||||
|
||||
bool LoadFromJson(const Json::Value & a_Value);
|
||||
// cBlockEntity overrides:
|
||||
virtual void SaveToJson(Json::Value& a_Value) override;
|
||||
virtual void SendTo(cClientHandle & a_Client) override;
|
||||
virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
|
||||
virtual void UsedBy(cPlayer * a_Player) override;
|
||||
|
||||
// tolua_begin
|
||||
|
||||
/** Is the beacon active? */
|
||||
bool IsActive(void) const { return m_IsActive; }
|
||||
|
||||
@ -45,33 +64,26 @@ public:
|
||||
/** Is the beacon blocked by non-transparent blocks that are higher than the beacon? */
|
||||
bool IsBeaconBlocked(void);
|
||||
|
||||
/** Returns true if the block is a diamond block, a golden block, an iron block or an emerald block. */
|
||||
static bool IsMineralBlock(BLOCKTYPE a_BlockType);
|
||||
|
||||
/** Returns true if the potion can be used. */
|
||||
static bool IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLevel);
|
||||
|
||||
/** Update the beacon. */
|
||||
void UpdateBeacon(void);
|
||||
|
||||
/** Give the near-players the effects. */
|
||||
void GiveEffects(void);
|
||||
|
||||
bool LoadFromJson(const Json::Value & a_Value);
|
||||
|
||||
// cBlockEntity overrides:
|
||||
virtual void SaveToJson(Json::Value& a_Value) override;
|
||||
virtual void SendTo(cClientHandle & a_Client) override;
|
||||
virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
|
||||
virtual void UsedBy(cPlayer * a_Player) override;
|
||||
/** Returns true if the block is a diamond block, a golden block, an iron block or an emerald block. */
|
||||
static bool IsMineralBlock(BLOCKTYPE a_BlockType);
|
||||
|
||||
/** Returns true if the potion can be used. */
|
||||
static bool IsValidPotion(cEntityEffect::eType a_Potion, char a_BeaconLevel);
|
||||
|
||||
// tolua_end
|
||||
|
||||
protected:
|
||||
bool m_IsActive;
|
||||
char m_BeaconLevel;
|
||||
|
||||
cEntityEffect::eType m_PrimaryPotion, m_SecondaryPotion;
|
||||
|
||||
} ;
|
||||
} ; // tolua_export
|
||||
|
||||
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "Server.h"
|
||||
#include "zlib/zlib.h"
|
||||
#include "Defines.h"
|
||||
#include "BlockEntities/BeaconEntity.h"
|
||||
#include "BlockEntities/ChestEntity.h"
|
||||
#include "BlockEntities/DispenserEntity.h"
|
||||
#include "BlockEntities/DropperEntity.h"
|
||||
@ -2126,6 +2127,38 @@ bool cChunk::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBloc
|
||||
|
||||
|
||||
|
||||
bool cChunk::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback)
|
||||
{
|
||||
// The blockentity list is locked by the parent chunkmap's CS
|
||||
for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2)
|
||||
{
|
||||
++itr2;
|
||||
if (((*itr)->GetPosX() != a_BlockX) || ((*itr)->GetPosY() != a_BlockY) || ((*itr)->GetPosZ() != a_BlockZ))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ((*itr)->GetBlockType() != E_BLOCK_BEACON)
|
||||
{
|
||||
// There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out
|
||||
return false;
|
||||
}
|
||||
|
||||
// The correct block entity is here
|
||||
if (a_Callback.Item((cBeaconEntity *)*itr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // for itr - m_BlockEntitites[]
|
||||
|
||||
// Not found:
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cChunk::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback)
|
||||
{
|
||||
// The blockentity list is locked by the parent chunkmap's CS
|
||||
|
@ -28,6 +28,7 @@ class cServer;
|
||||
class MTRand;
|
||||
class cPlayer;
|
||||
class cChunkMap;
|
||||
class cBeaconEntity;
|
||||
class cChestEntity;
|
||||
class cDispenserEntity;
|
||||
class cFurnaceEntity;
|
||||
@ -45,6 +46,7 @@ class cMobSpawner;
|
||||
|
||||
typedef std::list<cClientHandle *> cClientHandleList;
|
||||
typedef cItemCallback<cEntity> cEntityCallback;
|
||||
typedef cItemCallback<cBeaconEntity> cBeaconCallback;
|
||||
typedef cItemCallback<cChestEntity> cChestCallback;
|
||||
typedef cItemCallback<cDispenserEntity> cDispenserCallback;
|
||||
typedef cItemCallback<cFurnaceEntity> cFurnaceCallback;
|
||||
@ -236,6 +238,9 @@ public:
|
||||
/** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */
|
||||
bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible
|
||||
|
||||
/** Calls the callback for the beacon at the specified coords; returns false if there's no beacon at those coords, true if found */
|
||||
bool DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback); // Lua-acessible
|
||||
|
||||
/** Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found */
|
||||
bool DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback); // Lua-acessible
|
||||
|
||||
|
@ -2116,6 +2116,24 @@ bool cChunkMap::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cB
|
||||
|
||||
|
||||
|
||||
bool cChunkMap::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback)
|
||||
{
|
||||
int ChunkX, ChunkZ;
|
||||
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
|
||||
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
|
||||
cCSLock Lock(m_CSLayers);
|
||||
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
|
||||
if ((Chunk == NULL) || !Chunk->IsValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Chunk->DoWithBeaconAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cChunkMap::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback)
|
||||
{
|
||||
int ChunkX, ChunkZ;
|
||||
|
@ -19,6 +19,7 @@ class MTRand;
|
||||
class cChunkStay;
|
||||
class cChunk;
|
||||
class cPlayer;
|
||||
class cBeaconEntity;
|
||||
class cChestEntity;
|
||||
class cDispenserEntity;
|
||||
class cDropperEntity;
|
||||
@ -40,6 +41,7 @@ typedef std::list<cClientHandle *> cClientHandleList;
|
||||
typedef cChunk * cChunkPtr;
|
||||
typedef cItemCallback<cEntity> cEntityCallback;
|
||||
typedef cItemCallback<cBlockEntity> cBlockEntityCallback;
|
||||
typedef cItemCallback<cBeaconEntity> cBeaconCallback;
|
||||
typedef cItemCallback<cChestEntity> cChestCallback;
|
||||
typedef cItemCallback<cDispenserEntity> cDispenserCallback;
|
||||
typedef cItemCallback<cDropperEntity> cDropperCallback;
|
||||
@ -234,6 +236,9 @@ public:
|
||||
/** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */
|
||||
bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible
|
||||
|
||||
/** Calls the callback for the beacon at the specified coords; returns false if there's no beacon at those coords, true if found */
|
||||
bool DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback); // Lua-acessible
|
||||
|
||||
/** Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found */
|
||||
bool DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback); // Lua-acessible
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "Entities/TNTEntity.h"
|
||||
|
||||
#include "BlockEntities/CommandBlockEntity.h"
|
||||
#include "BlockEntities/BeaconEntity.h"
|
||||
|
||||
// Simulators:
|
||||
#include "Simulator/SimulatorManager.h"
|
||||
@ -1232,6 +1233,15 @@ bool cWorld::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBloc
|
||||
|
||||
|
||||
|
||||
bool cWorld::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback& a_Callback)
|
||||
{
|
||||
return m_ChunkMap->DoWithBeaconAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cWorld::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback)
|
||||
{
|
||||
return m_ChunkMap->DoWithChestAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
|
||||
|
@ -41,6 +41,7 @@ class cEntity;
|
||||
class cBlockEntity;
|
||||
class cWorldGenerator; // The generator that actually generates the chunks for a single world
|
||||
class cChunkGenerator; // The thread responsible for generating chunks
|
||||
class cBeaconEntity;
|
||||
class cChestEntity;
|
||||
class cDispenserEntity;
|
||||
class cFlowerPotEntity;
|
||||
@ -59,6 +60,7 @@ typedef std::vector<cSetChunkDataPtr> cSetChunkDataPtrs;
|
||||
|
||||
typedef cItemCallback<cPlayer> cPlayerListCallback;
|
||||
typedef cItemCallback<cEntity> cEntityCallback;
|
||||
typedef cItemCallback<cBeaconEntity> cBeaconCallback;
|
||||
typedef cItemCallback<cChestEntity> cChestCallback;
|
||||
typedef cItemCallback<cDispenserEntity> cDispenserCallback;
|
||||
typedef cItemCallback<cFurnaceEntity> cFurnaceCallback;
|
||||
@ -523,6 +525,9 @@ public:
|
||||
/** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */
|
||||
virtual bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback) override; // Exported in ManualBindings.cpp
|
||||
|
||||
/** Calls the callback for the beacon at the specified coords; returns false if there's no beacon at those coords, true if found */
|
||||
bool DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback); // Exported in ManualBindings.cpp
|
||||
|
||||
/** Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found */
|
||||
bool DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback); // Exported in ManualBindings.cpp
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user