Merge pull request #1291 from mc-server/RedstoneCleanUp
Redstone clean up
This commit is contained in:
commit
eae42d91f9
@ -11,7 +11,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "BlockEntityWithItems.h"
|
#include "BlockEntityWithItems.h"
|
||||||
|
#include "RedstonePoweredEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -31,6 +31,9 @@ class cServer;
|
|||||||
// tolua_begin
|
// tolua_begin
|
||||||
class cDropSpenserEntity :
|
class cDropSpenserEntity :
|
||||||
public cBlockEntityWithItems
|
public cBlockEntityWithItems
|
||||||
|
// tolua_end
|
||||||
|
, public cRedstonePoweredEntity
|
||||||
|
// tolua_begin
|
||||||
{
|
{
|
||||||
typedef cBlockEntityWithItems super;
|
typedef cBlockEntityWithItems super;
|
||||||
|
|
||||||
@ -64,10 +67,10 @@ public:
|
|||||||
/// Sets the dropspenser to dropspense an item in the next tick
|
/// Sets the dropspenser to dropspense an item in the next tick
|
||||||
void Activate(void);
|
void Activate(void);
|
||||||
|
|
||||||
/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
|
|
||||||
void SetRedstonePower(bool a_IsPowered);
|
|
||||||
|
|
||||||
// tolua_end
|
// tolua_end
|
||||||
|
|
||||||
|
/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
|
||||||
|
virtual void SetRedstonePower(bool a_IsPowered) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_ShouldDropSpense; ///< If true, the dropspenser will dropspense an item in the next tick
|
bool m_ShouldDropSpense; ///< If true, the dropspenser will dropspense an item in the next tick
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "BlockEntity.h"
|
#include "BlockEntity.h"
|
||||||
|
#include "RedstonePoweredEntity.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Json
|
namespace Json
|
||||||
@ -30,6 +31,9 @@ enum ENUM_NOTE_INSTRUMENTS
|
|||||||
|
|
||||||
class cNoteEntity :
|
class cNoteEntity :
|
||||||
public cBlockEntity
|
public cBlockEntity
|
||||||
|
// tolua_end
|
||||||
|
, public cRedstonePoweredEntity
|
||||||
|
// tolua_begin
|
||||||
{
|
{
|
||||||
typedef cBlockEntity super;
|
typedef cBlockEntity super;
|
||||||
public:
|
public:
|
||||||
@ -38,6 +42,7 @@ public:
|
|||||||
|
|
||||||
/// Creates a new note entity. a_World may be NULL
|
/// Creates a new note entity. a_World may be NULL
|
||||||
cNoteEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
|
cNoteEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
|
||||||
|
virtual ~cNoteEntity() {}
|
||||||
|
|
||||||
bool LoadFromJson(const Json::Value & a_Value);
|
bool LoadFromJson(const Json::Value & a_Value);
|
||||||
virtual void SaveToJson(Json::Value & a_Value) override;
|
virtual void SaveToJson(Json::Value & a_Value) override;
|
||||||
@ -53,6 +58,14 @@ public:
|
|||||||
|
|
||||||
virtual void UsedBy(cPlayer * a_Player) override;
|
virtual void UsedBy(cPlayer * a_Player) override;
|
||||||
virtual void SendTo(cClientHandle &) override {}
|
virtual void SendTo(cClientHandle &) override {}
|
||||||
|
|
||||||
|
virtual void SetRedstonePower(bool a_Value)
|
||||||
|
{
|
||||||
|
if (a_Value)
|
||||||
|
{
|
||||||
|
MakeSound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static const char * GetClassStatic(void) { return "cNoteEntity"; }
|
static const char * GetClassStatic(void) { return "cNoteEntity"; }
|
||||||
|
|
||||||
|
13
src/BlockEntities/RedstonePoweredEntity.h
Normal file
13
src/BlockEntities/RedstonePoweredEntity.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Interface class representing a blockEntity that responds to redstone
|
||||||
|
class cRedstonePoweredEntity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~cRedstonePoweredEntity() {};
|
||||||
|
|
||||||
|
/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
|
||||||
|
virtual void SetRedstonePower(bool a_IsPowered) = 0;
|
||||||
|
};
|
@ -2127,6 +2127,41 @@ bool cChunk::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBloc
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cChunk::DoWithRedstonePoweredEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cRedstonePoweredCallback & 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;
|
||||||
|
}
|
||||||
|
switch ((*itr)->GetBlockType())
|
||||||
|
{
|
||||||
|
case E_BLOCK_DROPPER:
|
||||||
|
case E_BLOCK_DISPENSER:
|
||||||
|
case E_BLOCK_NOTE_BLOCK:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a_Callback.Item((cRedstonePoweredEntity *)*itr))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} // for itr - m_BlockEntitites[]
|
||||||
|
|
||||||
|
// Not found:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cChunk::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback)
|
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
|
// The blockentity list is locked by the parent chunkmap's CS
|
||||||
|
@ -43,6 +43,7 @@ class cBlockArea;
|
|||||||
class cFluidSimulatorData;
|
class cFluidSimulatorData;
|
||||||
class cMobCensus;
|
class cMobCensus;
|
||||||
class cMobSpawner;
|
class cMobSpawner;
|
||||||
|
class cRedstonePoweredEntity;
|
||||||
|
|
||||||
typedef std::list<cClientHandle *> cClientHandleList;
|
typedef std::list<cClientHandle *> cClientHandleList;
|
||||||
typedef cItemCallback<cEntity> cEntityCallback;
|
typedef cItemCallback<cEntity> cEntityCallback;
|
||||||
@ -54,6 +55,7 @@ typedef cItemCallback<cNoteEntity> cNoteBlockCallback;
|
|||||||
typedef cItemCallback<cCommandBlockEntity> cCommandBlockCallback;
|
typedef cItemCallback<cCommandBlockEntity> cCommandBlockCallback;
|
||||||
typedef cItemCallback<cMobHeadEntity> cMobHeadCallback;
|
typedef cItemCallback<cMobHeadEntity> cMobHeadCallback;
|
||||||
typedef cItemCallback<cFlowerPotEntity> cFlowerPotCallback;
|
typedef cItemCallback<cFlowerPotEntity> cFlowerPotCallback;
|
||||||
|
typedef cItemCallback<cRedstonePoweredEntity> cRedstonePoweredCallback;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -237,7 +239,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 */
|
/** 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
|
bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible
|
||||||
|
|
||||||
|
/** Calls the callback for the redstone powered entity at the specified coords; returns false if there's no redstone powered entity at those coords, true if found */
|
||||||
|
bool DoWithRedstonePoweredEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cRedstonePoweredCallback & a_Callback);
|
||||||
/** Calls the callback for the beacon at the specified coords; returns false if there's no beacon at those coords, true if found */
|
/** 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
|
bool DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback); // Lua-acessible
|
||||||
|
|
||||||
|
@ -3,11 +3,9 @@
|
|||||||
|
|
||||||
#include "IncrementalRedstoneSimulator.h"
|
#include "IncrementalRedstoneSimulator.h"
|
||||||
#include "BoundingBox.h"
|
#include "BoundingBox.h"
|
||||||
#include "../BlockEntities/DropSpenserEntity.h"
|
#include "../BlockEntities/RedstonePoweredEntity.h"
|
||||||
#include "../BlockEntities/NoteEntity.h"
|
|
||||||
#include "../BlockEntities/ChestEntity.h"
|
#include "../BlockEntities/ChestEntity.h"
|
||||||
#include "../BlockEntities/CommandBlockEntity.h"
|
#include "../BlockEntities/CommandBlockEntity.h"
|
||||||
#include "../Entities/TNTEntity.h"
|
|
||||||
#include "../Entities/Pickup.h"
|
#include "../Entities/Pickup.h"
|
||||||
#include "../Blocks/BlockTorch.h"
|
#include "../Blocks/BlockTorch.h"
|
||||||
#include "../Blocks/BlockDoor.h"
|
#include "../Blocks/BlockDoor.h"
|
||||||
@ -842,13 +840,13 @@ void cIncrementalRedstoneSimulator::HandlePiston(int a_RelBlockX, int a_RelBlock
|
|||||||
void cIncrementalRedstoneSimulator::HandleDropSpenser(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ)
|
void cIncrementalRedstoneSimulator::HandleDropSpenser(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ)
|
||||||
{
|
{
|
||||||
class cSetPowerToDropSpenser :
|
class cSetPowerToDropSpenser :
|
||||||
public cDropSpenserCallback
|
public cRedstonePoweredCallback
|
||||||
{
|
{
|
||||||
bool m_IsPowered;
|
bool m_IsPowered;
|
||||||
public:
|
public:
|
||||||
cSetPowerToDropSpenser(bool a_IsPowered) : m_IsPowered(a_IsPowered) {}
|
cSetPowerToDropSpenser(bool a_IsPowered) : m_IsPowered(a_IsPowered) {}
|
||||||
|
|
||||||
virtual bool Item(cDropSpenserEntity * a_DropSpenser) override
|
virtual bool Item(cRedstonePoweredEntity * a_DropSpenser) override
|
||||||
{
|
{
|
||||||
a_DropSpenser->SetRedstonePower(m_IsPowered);
|
a_DropSpenser->SetRedstonePower(m_IsPowered);
|
||||||
return false;
|
return false;
|
||||||
@ -857,7 +855,7 @@ void cIncrementalRedstoneSimulator::HandleDropSpenser(int a_RelBlockX, int a_Rel
|
|||||||
|
|
||||||
int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX;
|
int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX;
|
||||||
int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ;
|
int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ;
|
||||||
m_Chunk->DoWithDropSpenserAt(BlockX, a_RelBlockY, BlockZ, DrSpSP);
|
m_Chunk->DoWithRedstonePoweredEntityAt(BlockX, a_RelBlockY, BlockZ, DrSpSP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1034,25 +1032,21 @@ void cIncrementalRedstoneSimulator::HandleNoteBlock(int a_RelBlockX, int a_RelBl
|
|||||||
if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true))
|
if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true))
|
||||||
{
|
{
|
||||||
class cSetPowerToNoteBlock :
|
class cSetPowerToNoteBlock :
|
||||||
public cNoteBlockCallback
|
public cRedstonePoweredCallback
|
||||||
{
|
{
|
||||||
bool m_IsPowered;
|
|
||||||
public:
|
public:
|
||||||
cSetPowerToNoteBlock(bool a_IsPowered) : m_IsPowered(a_IsPowered) {}
|
cSetPowerToNoteBlock() {}
|
||||||
|
|
||||||
virtual bool Item(cNoteEntity * a_NoteBlock) override
|
virtual bool Item(cRedstonePoweredEntity * a_NoteBlock) override
|
||||||
{
|
{
|
||||||
if (m_IsPowered)
|
a_NoteBlock->SetRedstonePower(true);
|
||||||
{
|
|
||||||
a_NoteBlock->MakeSound();
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} NoteBlockSP(m_bAreCoordsPowered);
|
} NoteBlockSP;
|
||||||
|
|
||||||
int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX;
|
int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX;
|
||||||
int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ;
|
int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ;
|
||||||
m_Chunk->DoWithNoteBlockAt(BlockX, a_RelBlockY, BlockZ, NoteBlockSP);
|
m_Chunk->DoWithRedstonePoweredEntityAt(BlockX, a_RelBlockY, BlockZ, NoteBlockSP);
|
||||||
SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true);
|
SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user