Remove std::make_unique from redstone handler creation
This commit is contained in:
parent
6617d43983
commit
3143d6ce67
@ -3,6 +3,7 @@ target_sources(
|
|||||||
|
|
||||||
ForEachSourceCallback.cpp
|
ForEachSourceCallback.cpp
|
||||||
IncrementalRedstoneSimulator.cpp
|
IncrementalRedstoneSimulator.cpp
|
||||||
|
RedstoneHandler.cpp
|
||||||
|
|
||||||
CommandBlockHandler.h
|
CommandBlockHandler.h
|
||||||
DoorHandler.h
|
DoorHandler.h
|
||||||
@ -13,6 +14,7 @@ target_sources(
|
|||||||
RedstoneHandler.h
|
RedstoneHandler.h
|
||||||
RedstoneSimulatorChunkData.h
|
RedstoneSimulatorChunkData.h
|
||||||
RedstoneComparatorHandler.h
|
RedstoneComparatorHandler.h
|
||||||
|
RedstoneDataHelper.h
|
||||||
RedstoneRepeaterHandler.h
|
RedstoneRepeaterHandler.h
|
||||||
RedstoneBlockHandler.h
|
RedstoneBlockHandler.h
|
||||||
RedstoneTorchHandler.h
|
RedstoneTorchHandler.h
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../BlockEntities/CommandBlockEntity.h"
|
#include "../../BlockEntities/CommandBlockEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cCommandBlockHandler final : public cRedstoneHandler
|
namespace CommandBlockHandler
|
||||||
{
|
{
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
@ -21,7 +20,7 @@ class cCommandBlockHandler final : public cRedstoneHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating commander the cmdblck (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating commander the cmdblck (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ class cCommandBlockHandler final : public cRedstoneHandler
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../Blocks/BlockDoor.h"
|
#include "../../Blocks/BlockDoor.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cDoorHandler final : public cRedstoneHandler
|
namespace DoorHandler
|
||||||
{
|
{
|
||||||
// "Doormammu, I've come to bargain"
|
// "Doormammu, I've come to bargain"
|
||||||
|
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
@ -23,7 +22,7 @@ class cDoorHandler final : public cRedstoneHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating dori the door (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating dori the door (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ class cDoorHandler final : public cRedstoneHandler
|
|||||||
|
|
||||||
const auto TopPosition = a_Position + OffsetYP;
|
const auto TopPosition = a_Position + OffsetYP;
|
||||||
ForEachSourceCallback Callback(a_Chunk, TopPosition, a_BlockType);
|
ForEachSourceCallback Callback(a_Chunk, TopPosition, a_BlockType);
|
||||||
ForValidSourcePositions(a_Chunk, TopPosition, a_BlockType, a_Meta, Callback);
|
RedstoneHandler::ForValidSourcePositions(a_Chunk, TopPosition, a_BlockType, a_Meta, Callback);
|
||||||
|
|
||||||
// Factor in what the upper half is getting:
|
// Factor in what the upper half is getting:
|
||||||
a_PoweringData = std::max(a_PoweringData, Callback.Power);
|
a_PoweringData = std::max(a_PoweringData, Callback.Power);
|
||||||
@ -52,7 +51,7 @@ class cDoorHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../BlockEntities/DropSpenserEntity.h"
|
#include "../../BlockEntities/DropSpenserEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cDropSpenserHandler final : public cRedstoneHandler
|
namespace DropSpenserHandler
|
||||||
{
|
{
|
||||||
inline static bool IsActivated(NIBBLETYPE a_Meta)
|
inline bool IsActivated(NIBBLETYPE a_Meta)
|
||||||
{
|
{
|
||||||
return (a_Meta & E_META_DROPSPENSER_ACTIVATED) != 0;
|
return (a_Meta & E_META_DROPSPENSER_ACTIVATED) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static NIBBLETYPE SetActivationState(NIBBLETYPE a_Meta, bool IsOn)
|
inline NIBBLETYPE SetActivationState(NIBBLETYPE a_Meta, bool IsOn)
|
||||||
{
|
{
|
||||||
if (IsOn)
|
if (IsOn)
|
||||||
{
|
{
|
||||||
@ -27,7 +26,7 @@ class cDropSpenserHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
@ -38,7 +37,7 @@ class cDropSpenserHandler final : public cRedstoneHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating spencer the dropspenser (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating spencer the dropspenser (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -61,7 +60,7 @@ class cDropSpenserHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
|
||||||
#include "ForEachSourceCallback.h"
|
#include "ForEachSourceCallback.h"
|
||||||
#include "IncrementalRedstoneSimulator.h"
|
|
||||||
#include "../../BlockInfo.h"
|
#include "../../BlockInfo.h"
|
||||||
#include "../../Chunk.h"
|
#include "../../Chunk.h"
|
||||||
|
#include "IncrementalRedstoneSimulator.h"
|
||||||
|
#include "RedstoneHandler.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -67,16 +68,10 @@ void ForEachSourceCallback::operator()(Vector3i Location)
|
|||||||
|
|
||||||
PoweringData ForEachSourceCallback::QueryPower(const cChunk & Chunk, const Vector3i SourcePosition, const BLOCKTYPE SourceBlock, const Vector3i QueryPosition, const BLOCKTYPE QueryBlock, const bool IsLinked)
|
PoweringData ForEachSourceCallback::QueryPower(const cChunk & Chunk, const Vector3i SourcePosition, const BLOCKTYPE SourceBlock, const Vector3i QueryPosition, const BLOCKTYPE QueryBlock, const bool IsLinked)
|
||||||
{
|
{
|
||||||
const auto PotentialSourceHandler = cIncrementalRedstoneSimulator::GetComponentHandler(SourceBlock);
|
|
||||||
if (PotentialSourceHandler == nullptr)
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
SourceBlock,
|
SourceBlock,
|
||||||
PotentialSourceHandler->GetPowerDeliveredToPosition(
|
RedstoneHandler::GetPowerDeliveredToPosition(
|
||||||
Chunk, SourcePosition, SourceBlock,
|
Chunk, SourcePosition, SourceBlock,
|
||||||
QueryPosition, QueryBlock, IsLinked
|
QueryPosition, QueryBlock, IsLinked
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ForEachSourceCallback.h"
|
|
||||||
#include "RedstoneSimulatorChunkData.h"
|
#include "RedstoneSimulatorChunkData.h"
|
||||||
|
|
||||||
class ForEachSourceCallback
|
class ForEachSourceCallback
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../BlockEntities/HopperEntity.h"
|
#include "../../BlockEntities/HopperEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cHopperHandler final : public cRedstoneHandler
|
namespace HopperHandler
|
||||||
{
|
{
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
@ -21,7 +20,7 @@ class cHopperHandler final : public cRedstoneHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating holey the hopper (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating holey the hopper (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -38,7 +37,7 @@ class cHopperHandler final : public cRedstoneHandler
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
|
@ -2,122 +2,9 @@
|
|||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
|
||||||
#include "IncrementalRedstoneSimulator.h"
|
#include "IncrementalRedstoneSimulator.h"
|
||||||
|
#include "RedstoneHandler.h"
|
||||||
#include "ForEachSourceCallback.h"
|
#include "ForEachSourceCallback.h"
|
||||||
|
|
||||||
#include "CommandBlockHandler.h"
|
|
||||||
#include "DoorHandler.h"
|
|
||||||
#include "RedstoneTorchHandler.h"
|
|
||||||
#include "RedstoneWireHandler.h"
|
|
||||||
#include "RedstoneRepeaterHandler.h"
|
|
||||||
#include "RedstoneToggleHandler.h"
|
|
||||||
#include "RedstoneLampHandler.h"
|
|
||||||
#include "RedstoneBlockHandler.h"
|
|
||||||
#include "PistonHandler.h"
|
|
||||||
#include "SmallGateHandler.h"
|
|
||||||
#include "NoteBlockHandler.h"
|
|
||||||
#include "ObserverHandler.h"
|
|
||||||
#include "TNTHandler.h"
|
|
||||||
#include "PoweredRailHandler.h"
|
|
||||||
#include "PressurePlateHandler.h"
|
|
||||||
#include "TripwireHookHandler.h"
|
|
||||||
#include "DropSpenserHandler.h"
|
|
||||||
#include "RedstoneComparatorHandler.h"
|
|
||||||
#include "TrappedChestHandler.h"
|
|
||||||
#include "HopperHandler.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const cRedstoneHandler * cIncrementalRedstoneSimulator::GetComponentHandler(BLOCKTYPE a_BlockType)
|
|
||||||
{
|
|
||||||
struct sComponents :
|
|
||||||
public std::array<std::unique_ptr<cRedstoneHandler>, 256>
|
|
||||||
{
|
|
||||||
sComponents()
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i != 256; ++i)
|
|
||||||
{
|
|
||||||
(*this)[i] = cIncrementalRedstoneSimulator::CreateComponent(static_cast<BLOCKTYPE>(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static sComponents Components;
|
|
||||||
return Components[a_BlockType].get();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::unique_ptr<cRedstoneHandler> cIncrementalRedstoneSimulator::CreateComponent(BLOCKTYPE a_BlockType)
|
|
||||||
{
|
|
||||||
switch (a_BlockType)
|
|
||||||
{
|
|
||||||
case E_BLOCK_ACTIVATOR_RAIL:
|
|
||||||
case E_BLOCK_DETECTOR_RAIL:
|
|
||||||
case E_BLOCK_POWERED_RAIL: return std::make_unique<cPoweredRailHandler>();
|
|
||||||
|
|
||||||
case E_BLOCK_ACTIVE_COMPARATOR:
|
|
||||||
case E_BLOCK_INACTIVE_COMPARATOR: return std::make_unique<cRedstoneComparatorHandler>();
|
|
||||||
|
|
||||||
case E_BLOCK_DISPENSER:
|
|
||||||
case E_BLOCK_DROPPER: return std::make_unique<cDropSpenserHandler>();
|
|
||||||
|
|
||||||
case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE:
|
|
||||||
case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE:
|
|
||||||
case E_BLOCK_STONE_PRESSURE_PLATE:
|
|
||||||
case E_BLOCK_WOODEN_PRESSURE_PLATE: return std::make_unique<cPressurePlateHandler>();
|
|
||||||
|
|
||||||
case E_BLOCK_ACACIA_FENCE_GATE:
|
|
||||||
case E_BLOCK_BIRCH_FENCE_GATE:
|
|
||||||
case E_BLOCK_DARK_OAK_FENCE_GATE:
|
|
||||||
case E_BLOCK_FENCE_GATE:
|
|
||||||
case E_BLOCK_IRON_TRAPDOOR:
|
|
||||||
case E_BLOCK_JUNGLE_FENCE_GATE:
|
|
||||||
case E_BLOCK_SPRUCE_FENCE_GATE:
|
|
||||||
case E_BLOCK_TRAPDOOR: return std::make_unique<cSmallGateHandler>();
|
|
||||||
|
|
||||||
case E_BLOCK_REDSTONE_LAMP_OFF:
|
|
||||||
case E_BLOCK_REDSTONE_LAMP_ON: return std::make_unique<cRedstoneLampHandler>();
|
|
||||||
|
|
||||||
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
|
||||||
case E_BLOCK_REDSTONE_REPEATER_ON: return std::make_unique<cRedstoneRepeaterHandler>();
|
|
||||||
|
|
||||||
case E_BLOCK_REDSTONE_TORCH_OFF:
|
|
||||||
case E_BLOCK_REDSTONE_TORCH_ON: return std::make_unique<cRedstoneTorchHandler>();
|
|
||||||
|
|
||||||
case E_BLOCK_OBSERVER: return std::make_unique<cObserverHandler>();
|
|
||||||
|
|
||||||
case E_BLOCK_PISTON:
|
|
||||||
case E_BLOCK_STICKY_PISTON: return std::make_unique<cPistonHandler>();
|
|
||||||
|
|
||||||
case E_BLOCK_LEVER:
|
|
||||||
case E_BLOCK_STONE_BUTTON:
|
|
||||||
case E_BLOCK_WOODEN_BUTTON: return std::make_unique<cRedstoneToggleHandler>();
|
|
||||||
|
|
||||||
case E_BLOCK_BLOCK_OF_REDSTONE: return std::make_unique<cRedstoneBlockHandler>();
|
|
||||||
case E_BLOCK_COMMAND_BLOCK: return std::make_unique<cCommandBlockHandler>();
|
|
||||||
case E_BLOCK_HOPPER: return std::make_unique<cHopperHandler>();
|
|
||||||
case E_BLOCK_NOTE_BLOCK: return std::make_unique<cNoteBlockHandler>();
|
|
||||||
case E_BLOCK_REDSTONE_WIRE: return std::make_unique<cRedstoneWireHandler>();
|
|
||||||
case E_BLOCK_TNT: return std::make_unique<cTNTHandler>();
|
|
||||||
case E_BLOCK_TRAPPED_CHEST: return std::make_unique<cTrappedChestHandler>();
|
|
||||||
case E_BLOCK_TRIPWIRE_HOOK: return std::make_unique<cTripwireHookHandler>();
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
if (cBlockDoorHandler::IsDoorBlockType(a_BlockType))
|
|
||||||
{
|
|
||||||
return std::make_unique<cDoorHandler>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -168,19 +55,11 @@ void cIncrementalRedstoneSimulator::ProcessWorkItem(cChunk & Chunk, cChunk & Tic
|
|||||||
NIBBLETYPE CurrentMeta;
|
NIBBLETYPE CurrentMeta;
|
||||||
Chunk.GetBlockTypeMeta(Position, CurrentBlock, CurrentMeta);
|
Chunk.GetBlockTypeMeta(Position, CurrentBlock, CurrentMeta);
|
||||||
|
|
||||||
auto CurrentHandler = GetComponentHandler(CurrentBlock);
|
|
||||||
if (CurrentHandler == nullptr)
|
|
||||||
{
|
|
||||||
// Block at Position doesn't have a corresponding redstone handler
|
|
||||||
// ErasePowerData will have been called in AddBlock
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ForEachSourceCallback Callback(Chunk, Position, CurrentBlock);
|
ForEachSourceCallback Callback(Chunk, Position, CurrentBlock);
|
||||||
CurrentHandler->ForValidSourcePositions(Chunk, Position, CurrentBlock, CurrentMeta, Callback);
|
RedstoneHandler::ForValidSourcePositions(Chunk, Position, CurrentBlock, CurrentMeta, Callback);
|
||||||
|
|
||||||
// Inform the handler to update
|
// Inform the handler to update
|
||||||
CurrentHandler->Update(Chunk, TickingSource, Position, CurrentBlock, CurrentMeta, Callback.Power);
|
RedstoneHandler::Update(Chunk, TickingSource, Position, CurrentBlock, CurrentMeta, Callback.Power);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -189,14 +68,12 @@ void cIncrementalRedstoneSimulator::ProcessWorkItem(cChunk & Chunk, cChunk & Tic
|
|||||||
|
|
||||||
void cIncrementalRedstoneSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block)
|
void cIncrementalRedstoneSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block)
|
||||||
{
|
{
|
||||||
|
// Never update blocks without a handler:
|
||||||
if (!IsRedstone(a_Block))
|
if (!IsRedstone(a_Block))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never update blocks without a handler:
|
|
||||||
ASSERT(GetComponentHandler(a_Block) != nullptr);
|
|
||||||
|
|
||||||
auto & ChunkData = *static_cast<cIncrementalRedstoneSimulatorChunkData *>(a_Chunk.GetRedstoneSimulatorData());
|
auto & ChunkData = *static_cast<cIncrementalRedstoneSimulatorChunkData *>(a_Chunk.GetRedstoneSimulatorData());
|
||||||
|
|
||||||
if (IsAlwaysTicked(a_Block))
|
if (IsAlwaysTicked(a_Block))
|
||||||
@ -207,7 +84,7 @@ void cIncrementalRedstoneSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Positi
|
|||||||
// Temporary: in the absence of block state support calculate our own:
|
// Temporary: in the absence of block state support calculate our own:
|
||||||
if (a_Block == E_BLOCK_REDSTONE_WIRE)
|
if (a_Block == E_BLOCK_REDSTONE_WIRE)
|
||||||
{
|
{
|
||||||
static_cast<const cRedstoneWireHandler *>(GetComponentHandler(a_Block))->SetWireState(a_Chunk, a_Position);
|
RedstoneHandler::SetWireState(a_Chunk, a_Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always update redstone devices:
|
// Always update redstone devices:
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../RedstoneSimulator.h"
|
#include "../RedstoneSimulator.h"
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "RedstoneSimulatorChunkData.h"
|
#include "RedstoneSimulatorChunkData.h"
|
||||||
|
|
||||||
|
|
||||||
@ -18,8 +17,6 @@ public:
|
|||||||
|
|
||||||
using Super::cRedstoneSimulator;
|
using Super::cRedstoneSimulator;
|
||||||
|
|
||||||
static const cRedstoneHandler * GetComponentHandler(BLOCKTYPE a_BlockType);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** Returns if a redstone device is always ticked due to influence by its environment */
|
/** Returns if a redstone device is always ticked due to influence by its environment */
|
||||||
@ -110,8 +107,4 @@ private:
|
|||||||
virtual void AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) override;
|
virtual void AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) override;
|
||||||
virtual void WakeUp(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) override;
|
virtual void WakeUp(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) override;
|
||||||
virtual void WakeUp(cChunk & a_Chunk, Vector3i a_Position, Vector3i a_Offset, BLOCKTYPE a_Block) override;
|
virtual void WakeUp(cChunk & a_Chunk, Vector3i a_Position, Vector3i a_Offset, BLOCKTYPE a_Block) override;
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
static std::unique_ptr<cRedstoneHandler> CreateComponent(BLOCKTYPE a_BlockType);
|
|
||||||
} ;
|
} ;
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../BlockEntities/NoteEntity.h"
|
#include "../../BlockEntities/NoteEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cNoteBlockHandler: public cRedstoneHandler
|
namespace NoteBlockHandler
|
||||||
{
|
{
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
@ -21,7 +20,7 @@ class cNoteBlockHandler: public cRedstoneHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating sparky the magical note block (%d %d %d) %i", a_Position.x, a_Position.y, a_Position.z, a_PoweringData.PowerLevel);
|
// LOGD("Evaluating sparky the magical note block (%d %d %d) %i", a_Position.x, a_Position.y, a_Position.z, a_PoweringData.PowerLevel);
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ class cNoteBlockHandler: public cRedstoneHandler
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../Blocks/BlockObserver.h"
|
#include "../../Blocks/BlockObserver.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cObserverHandler final : public cRedstoneHandler
|
namespace ObserverHandler
|
||||||
{
|
{
|
||||||
inline static bool IsOn(NIBBLETYPE a_Meta)
|
inline bool IsOn(NIBBLETYPE a_Meta)
|
||||||
{
|
{
|
||||||
return (a_Meta & 0x8) == 0x8;
|
return (a_Meta & 0x8) == 0x8;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ShouldPowerOn(cChunk & Chunk, const Vector3i a_Position, NIBBLETYPE a_Meta, cIncrementalRedstoneSimulatorChunkData & a_Data)
|
inline bool ShouldPowerOn(cChunk & Chunk, const Vector3i a_Position, NIBBLETYPE a_Meta, cIncrementalRedstoneSimulatorChunkData & a_Data)
|
||||||
{
|
{
|
||||||
BLOCKTYPE BlockType;
|
BLOCKTYPE BlockType;
|
||||||
NIBBLETYPE BlockMeta;
|
NIBBLETYPE BlockMeta;
|
||||||
@ -32,13 +31,13 @@ class cObserverHandler final : public cRedstoneHandler
|
|||||||
return (Previous.PoweringBlock != Observed.PoweringBlock) || (Previous.PowerLevel != Observed.PowerLevel);
|
return (Previous.PoweringBlock != Observed.PoweringBlock) || (Previous.PowerLevel != Observed.PowerLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
const auto Meta = a_Chunk.GetMeta(a_Position);
|
const auto Meta = a_Chunk.GetMeta(a_Position);
|
||||||
return (IsOn(Meta) && (a_QueryPosition == (a_Position + cBlockObserverHandler::GetSignalOutputOffset(Meta)))) ? 15 : 0;
|
return (IsOn(Meta) && (a_QueryPosition == (a_Position + cBlockObserverHandler::GetSignalOutputOffset(Meta)))) ? 15 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating Lenny the observer (%i %i %i)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating Lenny the observer (%i %i %i)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -84,7 +83,7 @@ class cObserverHandler final : public cRedstoneHandler
|
|||||||
UpdateAdjustedRelative(a_Chunk, CurrentlyTicking, a_Position, cBlockObserverHandler::GetSignalOutputOffset(a_Meta));
|
UpdateAdjustedRelative(a_Chunk, CurrentlyTicking, a_Position, cBlockObserverHandler::GetSignalOutputOffset(a_Meta));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../Blocks/BlockPiston.h"
|
#include "../../Blocks/BlockPiston.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cPistonHandler final: public cRedstoneHandler
|
namespace PistonHandler
|
||||||
{
|
{
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
@ -21,7 +20,7 @@ class cPistonHandler final: public cRedstoneHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating pisty the piston (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating pisty the piston (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ class cPistonHandler final: public cRedstoneHandler
|
|||||||
// However, this delay is already present: as a side effect of the implementation of piston animation in Blocks\BlockPiston.cpp
|
// However, this delay is already present: as a side effect of the implementation of piston animation in Blocks\BlockPiston.cpp
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace PoweredRailHandler
|
||||||
class cPoweredRailHandler final : public cRedstoneHandler
|
|
||||||
{
|
{
|
||||||
static Vector3i GetPoweredRailAdjacentXZCoordinateOffset(NIBBLETYPE a_Meta) // Not in cBlockRailHandler since specific to powered rails
|
Vector3i GetPoweredRailAdjacentXZCoordinateOffset(NIBBLETYPE a_Meta) // Not in cBlockRailHandler since specific to powered rails
|
||||||
{
|
{
|
||||||
switch (a_Meta & 0x7)
|
switch (a_Meta & 0x7)
|
||||||
{
|
{
|
||||||
@ -27,7 +25,7 @@ class cPoweredRailHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
UNUSED(a_QueryBlockType);
|
UNUSED(a_QueryBlockType);
|
||||||
|
|
||||||
@ -41,7 +39,7 @@ class cPoweredRailHandler final : public cRedstoneHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTickingChunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTickingChunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating tracky the rail (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating tracky the rail (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -78,7 +76,7 @@ class cPoweredRailHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Meta);
|
UNUSED(a_Meta);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../BoundingBox.h"
|
#include "../../BoundingBox.h"
|
||||||
#include "../../Entities/Pickup.h"
|
#include "../../Entities/Pickup.h"
|
||||||
|
|
||||||
@ -9,20 +8,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cPressurePlateHandler final : public cRedstoneHandler
|
namespace PressurePlateHandler
|
||||||
{
|
{
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerLevel(const cChunk & Chunk, const Vector3i Position, const BLOCKTYPE BlockType)
|
||||||
{
|
|
||||||
UNUSED(a_BlockType);
|
|
||||||
UNUSED(a_QueryPosition);
|
|
||||||
UNUSED(a_QueryBlockType);
|
|
||||||
|
|
||||||
// Plates only link power blocks below
|
|
||||||
// Retrieve and return the cached power calculated by Update for performance:
|
|
||||||
return (IsLinked && (a_QueryPosition != (a_Position + OffsetYM))) ? 0 : DataForChunk(a_Chunk).GetCachedPowerData(a_Position).PowerLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned char GetPowerLevel(const cChunk & Chunk, const Vector3i Position, const BLOCKTYPE BlockType)
|
|
||||||
{
|
{
|
||||||
unsigned NumberOfEntities = 0;
|
unsigned NumberOfEntities = 0;
|
||||||
bool FoundPlayer = false;
|
bool FoundPlayer = false;
|
||||||
@ -69,7 +57,52 @@ class cPressurePlateHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline const char * GetClickOnSound(BLOCKTYPE a_BlockType)
|
||||||
|
{
|
||||||
|
// manage on-sound
|
||||||
|
switch (a_BlockType)
|
||||||
|
{
|
||||||
|
case E_BLOCK_STONE_PRESSURE_PLATE: return "block.stone_pressureplate.click_on";
|
||||||
|
case E_BLOCK_WOODEN_PRESSURE_PLATE: return "block.wood_pressureplate.click_on";
|
||||||
|
case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE:
|
||||||
|
case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: return "block.metal_pressureplate.click_on";
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
ASSERT(!"No on sound for this one!");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char * GetClickOffSound(BLOCKTYPE a_BlockType)
|
||||||
|
{
|
||||||
|
// manage off-sound
|
||||||
|
switch (a_BlockType)
|
||||||
|
{
|
||||||
|
case E_BLOCK_STONE_PRESSURE_PLATE: return "block.stone_pressureplate.click_off";
|
||||||
|
case E_BLOCK_WOODEN_PRESSURE_PLATE: return "block.wood_pressureplate.click_off";
|
||||||
|
case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE:
|
||||||
|
case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: return "block.metal_pressureplate.click_off";
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
ASSERT(!"No off sound for this one!");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
|
{
|
||||||
|
UNUSED(a_BlockType);
|
||||||
|
UNUSED(a_QueryPosition);
|
||||||
|
UNUSED(a_QueryBlockType);
|
||||||
|
|
||||||
|
// Plates only link power blocks below
|
||||||
|
// Retrieve and return the cached power calculated by Update for performance:
|
||||||
|
return (IsLinked && (a_QueryPosition != (a_Position + OffsetYM))) ? 0 : DataForChunk(a_Chunk).GetCachedPowerData(a_Position).PowerLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating clicky the pressure plate (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating clicky the pressure plate (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -171,7 +204,7 @@ class cPressurePlateHandler final : public cRedstoneHandler
|
|||||||
UpdateAdjustedRelatives(a_Chunk, CurrentlyTicking, a_Position, RelativeAdjacents);
|
UpdateAdjustedRelatives(a_Chunk, CurrentlyTicking, a_Position, RelativeAdjacents);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
@ -179,40 +212,4 @@ class cPressurePlateHandler final : public cRedstoneHandler
|
|||||||
UNUSED(a_Meta);
|
UNUSED(a_Meta);
|
||||||
UNUSED(Callback);
|
UNUSED(Callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
static const char * GetClickOnSound(BLOCKTYPE a_BlockType)
|
|
||||||
{
|
|
||||||
// manage on-sound
|
|
||||||
switch (a_BlockType)
|
|
||||||
{
|
|
||||||
case E_BLOCK_STONE_PRESSURE_PLATE: return "block.stone_pressureplate.click_on";
|
|
||||||
case E_BLOCK_WOODEN_PRESSURE_PLATE: return "block.wood_pressureplate.click_on";
|
|
||||||
case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE:
|
|
||||||
case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: return "block.metal_pressureplate.click_on";
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
ASSERT(!"No on sound for this one!");
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char * GetClickOffSound(BLOCKTYPE a_BlockType)
|
|
||||||
{
|
|
||||||
// manage off-sound
|
|
||||||
switch (a_BlockType)
|
|
||||||
{
|
|
||||||
case E_BLOCK_STONE_PRESSURE_PLATE: return "block.stone_pressureplate.click_off";
|
|
||||||
case E_BLOCK_WOODEN_PRESSURE_PLATE: return "block.wood_pressureplate.click_off";
|
|
||||||
case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE:
|
|
||||||
case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: return "block.metal_pressureplate.click_off";
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
ASSERT(!"No off sound for this one!");
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace RedstoneBlockHandler
|
||||||
class cRedstoneBlockHandler final : public cRedstoneHandler
|
|
||||||
{
|
{
|
||||||
public:
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
|
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
@ -21,12 +17,12 @@ public:
|
|||||||
return IsLinked ? 0 : 15;
|
return IsLinked ? 0 : 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating crimson the redstone block (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating crimson the redstone block (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../Blocks/BlockComparator.h"
|
#include "../../Blocks/BlockComparator.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cRedstoneComparatorHandler : public cRedstoneHandler
|
namespace RedstoneComparatorHandler
|
||||||
{
|
{
|
||||||
static unsigned char GetFrontPowerLevel(NIBBLETYPE a_Meta, unsigned char a_HighestSidePowerLevel, unsigned char a_HighestRearPowerLevel)
|
inline unsigned char GetFrontPowerLevel(NIBBLETYPE a_Meta, unsigned char a_HighestSidePowerLevel, unsigned char a_HighestRearPowerLevel)
|
||||||
{
|
{
|
||||||
if (cBlockComparatorHandler::IsInSubtractionMode(a_Meta))
|
if (cBlockComparatorHandler::IsInSubtractionMode(a_Meta))
|
||||||
{
|
{
|
||||||
@ -24,7 +23,7 @@ class cRedstoneComparatorHandler : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
UNUSED(a_QueryPosition);
|
UNUSED(a_QueryPosition);
|
||||||
UNUSED(a_QueryBlockType);
|
UNUSED(a_QueryBlockType);
|
||||||
@ -36,7 +35,7 @@ class cRedstoneComparatorHandler : public cRedstoneHandler
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char GetPowerLevel(cChunk & a_Chunk, Vector3i Position, BLOCKTYPE BlockType, NIBBLETYPE Meta)
|
inline unsigned char GetPowerLevel(cChunk & a_Chunk, Vector3i Position, BLOCKTYPE BlockType, NIBBLETYPE Meta)
|
||||||
{
|
{
|
||||||
UInt8 SignalStrength = 0;
|
UInt8 SignalStrength = 0;
|
||||||
auto RearCoordinate = cBlockComparatorHandler::GetRearCoordinate(Position, Meta & 0x3);
|
auto RearCoordinate = cBlockComparatorHandler::GetRearCoordinate(Position, Meta & 0x3);
|
||||||
@ -71,22 +70,16 @@ class cRedstoneComparatorHandler : public cRedstoneHandler
|
|||||||
});
|
});
|
||||||
|
|
||||||
const auto RearType = RearChunk->GetBlock(RearCoordinate);
|
const auto RearType = RearChunk->GetBlock(RearCoordinate);
|
||||||
const auto PotentialSourceHandler = cIncrementalRedstoneSimulator::GetComponentHandler(RearType);
|
|
||||||
if (PotentialSourceHandler == nullptr)
|
|
||||||
{
|
|
||||||
return SignalStrength;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::max(
|
return std::max(
|
||||||
SignalStrength,
|
SignalStrength,
|
||||||
PotentialSourceHandler->GetPowerDeliveredToPosition(
|
RedstoneHandler::GetPowerDeliveredToPosition(
|
||||||
*RearChunk, RearCoordinate, RearType,
|
*RearChunk, RearCoordinate, RearType,
|
||||||
cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(a_Chunk, *RearChunk, Position), BlockType, false
|
cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(a_Chunk, *RearChunk, Position), BlockType, false
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// Note that a_PoweringData here contains the maximum * side * power level, as specified by GetValidSourcePositions
|
// Note that a_PoweringData here contains the maximum * side * power level, as specified by GetValidSourcePositions
|
||||||
// LOGD("Evaluating ALU the comparator (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating ALU the comparator (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
@ -132,7 +125,7 @@ class cRedstoneComparatorHandler : public cRedstoneHandler
|
|||||||
UpdateAdjustedRelative(a_Chunk, CurrentlyTicking, a_Position, cBlockComparatorHandler::GetFrontCoordinate(a_Position, a_Meta & 0x3) - a_Position);
|
UpdateAdjustedRelative(a_Chunk, CurrentlyTicking, a_Position, cBlockComparatorHandler::GetFrontCoordinate(a_Position, a_Meta & 0x3) - a_Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../Chunk.h"
|
||||||
|
|
||||||
|
inline auto & DataForChunk(const cChunk & a_Chunk)
|
||||||
|
{
|
||||||
|
return *static_cast<cIncrementalRedstoneSimulatorChunkData *>(a_Chunk.GetRedstoneSimulatorData());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... ArrayTypes>
|
||||||
|
inline void UpdateAdjustedRelative(const cChunk & From, const cChunk & To, const Vector3i Position, const Vector3i Offset)
|
||||||
|
{
|
||||||
|
DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + Offset));
|
||||||
|
|
||||||
|
for (const auto LinkedOffset : cSimulator::GetLinkedOffsets(Offset))
|
||||||
|
{
|
||||||
|
DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + LinkedOffset));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ArrayType>
|
||||||
|
inline void UpdateAdjustedRelatives(const cChunk & From, const cChunk & To, const Vector3i Position, const ArrayType & Relative)
|
||||||
|
{
|
||||||
|
for (const auto Offset : Relative)
|
||||||
|
{
|
||||||
|
UpdateAdjustedRelative(From, To, Position, Offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ArrayType>
|
||||||
|
inline void InvokeForAdjustedRelatives(ForEachSourceCallback & Callback, const Vector3i Position, const ArrayType & Relative)
|
||||||
|
{
|
||||||
|
for (const auto Offset : Relative)
|
||||||
|
{
|
||||||
|
Callback(Position + Offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline constexpr Vector3i OffsetYP{ 0, 1, 0 };
|
||||||
|
|
||||||
|
inline constexpr Vector3i OffsetYM{ 0, -1, 0 };
|
||||||
|
|
||||||
|
inline constexpr std::array<Vector3i, 6> RelativeAdjacents
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{ 1, 0, 0 },
|
||||||
|
{ -1, 0, 0 },
|
||||||
|
{ 0, 1, 0 },
|
||||||
|
{ 0, -1, 0 },
|
||||||
|
{ 0, 0, 1 },
|
||||||
|
{ 0, 0, -1 },
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline constexpr std::array<Vector3i, 4> RelativeLaterals
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{ 1, 0, 0 },
|
||||||
|
{ -1, 0, 0 },
|
||||||
|
{ 0, 0, 1 },
|
||||||
|
{ 0, 0, -1 },
|
||||||
|
}
|
||||||
|
};
|
128
src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.cpp
Normal file
128
src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.cpp
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
|
||||||
|
#include "Globals.h"
|
||||||
|
|
||||||
|
#include "RedstoneHandler.h"
|
||||||
|
#include "RedstoneDataHelper.h"
|
||||||
|
#include "ForEachSourceCallback.h"
|
||||||
|
|
||||||
|
#include "CommandBlockHandler.h"
|
||||||
|
#include "DoorHandler.h"
|
||||||
|
#include "RedstoneTorchHandler.h"
|
||||||
|
#include "RedstoneWireHandler.h"
|
||||||
|
#include "RedstoneRepeaterHandler.h"
|
||||||
|
#include "RedstoneToggleHandler.h"
|
||||||
|
#include "RedstoneLampHandler.h"
|
||||||
|
#include "RedstoneBlockHandler.h"
|
||||||
|
#include "PistonHandler.h"
|
||||||
|
#include "SmallGateHandler.h"
|
||||||
|
#include "NoteBlockHandler.h"
|
||||||
|
#include "ObserverHandler.h"
|
||||||
|
#include "TNTHandler.h"
|
||||||
|
#include "PoweredRailHandler.h"
|
||||||
|
#include "PressurePlateHandler.h"
|
||||||
|
#include "TripwireHookHandler.h"
|
||||||
|
#include "DropSpenserHandler.h"
|
||||||
|
#include "RedstoneComparatorHandler.h"
|
||||||
|
#include "TrappedChestHandler.h"
|
||||||
|
#include "HopperHandler.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define INVOKE_FOR_HANDLERS(Callback) \
|
||||||
|
switch (BlockType) \
|
||||||
|
{ \
|
||||||
|
case E_BLOCK_ACTIVATOR_RAIL: \
|
||||||
|
case E_BLOCK_DETECTOR_RAIL: \
|
||||||
|
case E_BLOCK_POWERED_RAIL: return PoweredRailHandler::Callback; \
|
||||||
|
case E_BLOCK_ACTIVE_COMPARATOR: \
|
||||||
|
case E_BLOCK_INACTIVE_COMPARATOR: return RedstoneComparatorHandler::Callback; \
|
||||||
|
case E_BLOCK_DISPENSER: \
|
||||||
|
case E_BLOCK_DROPPER: return DropSpenserHandler::Callback; \
|
||||||
|
case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: \
|
||||||
|
case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: \
|
||||||
|
case E_BLOCK_STONE_PRESSURE_PLATE: \
|
||||||
|
case E_BLOCK_WOODEN_PRESSURE_PLATE: return PressurePlateHandler::Callback; \
|
||||||
|
case E_BLOCK_ACACIA_FENCE_GATE: \
|
||||||
|
case E_BLOCK_BIRCH_FENCE_GATE: \
|
||||||
|
case E_BLOCK_DARK_OAK_FENCE_GATE: \
|
||||||
|
case E_BLOCK_FENCE_GATE: \
|
||||||
|
case E_BLOCK_IRON_TRAPDOOR: \
|
||||||
|
case E_BLOCK_JUNGLE_FENCE_GATE: \
|
||||||
|
case E_BLOCK_SPRUCE_FENCE_GATE: \
|
||||||
|
case E_BLOCK_TRAPDOOR: return SmallGateHandler::Callback; \
|
||||||
|
case E_BLOCK_REDSTONE_LAMP_OFF: \
|
||||||
|
case E_BLOCK_REDSTONE_LAMP_ON: return RedstoneLampHandler::Callback; \
|
||||||
|
case E_BLOCK_REDSTONE_REPEATER_OFF: \
|
||||||
|
case E_BLOCK_REDSTONE_REPEATER_ON: return RedstoneRepeaterHandler::Callback; \
|
||||||
|
case E_BLOCK_REDSTONE_TORCH_OFF: \
|
||||||
|
case E_BLOCK_REDSTONE_TORCH_ON: return RedstoneTorchHandler::Callback; \
|
||||||
|
case E_BLOCK_OBSERVER: return ObserverHandler::Callback; \
|
||||||
|
case E_BLOCK_PISTON: \
|
||||||
|
case E_BLOCK_STICKY_PISTON: return PistonHandler::Callback; \
|
||||||
|
case E_BLOCK_LEVER: \
|
||||||
|
case E_BLOCK_STONE_BUTTON: \
|
||||||
|
case E_BLOCK_WOODEN_BUTTON: return RedstoneToggleHandler::Callback; \
|
||||||
|
case E_BLOCK_BLOCK_OF_REDSTONE: return RedstoneBlockHandler::Callback; \
|
||||||
|
case E_BLOCK_COMMAND_BLOCK: return CommandBlockHandler::Callback; \
|
||||||
|
case E_BLOCK_HOPPER: return HopperHandler::Callback; \
|
||||||
|
case E_BLOCK_NOTE_BLOCK: return NoteBlockHandler::Callback; \
|
||||||
|
case E_BLOCK_REDSTONE_WIRE: return RedstoneWireHandler::Callback; \
|
||||||
|
case E_BLOCK_TNT: return TNTHandler::Callback; \
|
||||||
|
case E_BLOCK_TRAPPED_CHEST: return TrappedChestHandler::Callback; \
|
||||||
|
case E_BLOCK_TRIPWIRE_HOOK: return TripwireHookHandler::Callback; \
|
||||||
|
default: \
|
||||||
|
{ \
|
||||||
|
if (cBlockDoorHandler::IsDoorBlockType(BlockType)) \
|
||||||
|
{ \
|
||||||
|
return DoorHandler::Callback; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace RedstoneHandler
|
||||||
|
{
|
||||||
|
unsigned char GetPowerDeliveredToPosition(const cChunk & Chunk, const Vector3i Position, const BLOCKTYPE BlockType, const Vector3i QueryPosition, const BLOCKTYPE QueryBlockType, const bool IsLinked)
|
||||||
|
{
|
||||||
|
INVOKE_FOR_HANDLERS(GetPowerDeliveredToPosition(Chunk, Position, BlockType, QueryPosition, QueryBlockType, IsLinked));
|
||||||
|
|
||||||
|
// Fell through the switch statement
|
||||||
|
// Block at Position doesn't have a corresponding redstone handler
|
||||||
|
// ErasePowerData will have been called in AddBlock
|
||||||
|
|
||||||
|
// Default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Update(cChunk & Chunk, cChunk & CurrentlyTicking, const Vector3i Position, const BLOCKTYPE BlockType, const NIBBLETYPE Meta, const PoweringData PoweringData)
|
||||||
|
{
|
||||||
|
INVOKE_FOR_HANDLERS(Update(Chunk, CurrentlyTicking, Position, BlockType, Meta, PoweringData));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ForValidSourcePositions(const cChunk & Chunk, const Vector3i Position, const BLOCKTYPE BlockType, const NIBBLETYPE Meta, ForEachSourceCallback & Callback)
|
||||||
|
{
|
||||||
|
INVOKE_FOR_HANDLERS(ForValidSourcePositions(Chunk, Position, BlockType, Meta, Callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SetWireState(const cChunk & Chunk, const Vector3i Position)
|
||||||
|
{
|
||||||
|
RedstoneWireHandler::SetWireState(Chunk, Position);
|
||||||
|
}
|
||||||
|
}
|
@ -1,89 +1,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../../Chunk.h"
|
|
||||||
#include "ForEachSourceCallback.h"
|
|
||||||
#include "RedstoneSimulatorChunkData.h"
|
#include "RedstoneSimulatorChunkData.h"
|
||||||
|
|
||||||
|
class cChunk;
|
||||||
|
class ForEachSourceCallback;
|
||||||
|
|
||||||
|
namespace RedstoneHandler
|
||||||
|
|
||||||
|
|
||||||
class cRedstoneHandler
|
|
||||||
{
|
{
|
||||||
public:
|
unsigned char GetPowerDeliveredToPosition(const cChunk & Chunk, Vector3i Position, BLOCKTYPE BlockType, Vector3i QueryPosition, BLOCKTYPE QueryBlockType, bool IsLinked);
|
||||||
|
|
||||||
cRedstoneHandler() = default;
|
void Update(cChunk & Chunk, cChunk & CurrentlyTicking, Vector3i Position, BLOCKTYPE BlockType, NIBBLETYPE Meta, PoweringData PoweringData);
|
||||||
DISALLOW_COPY_AND_ASSIGN(cRedstoneHandler);
|
|
||||||
|
|
||||||
using SourceCallback = ForEachSourceCallback &;
|
void ForValidSourcePositions(const cChunk & Chunk, Vector3i Position, BLOCKTYPE BlockType, NIBBLETYPE Meta, ForEachSourceCallback & Callback);
|
||||||
|
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const = 0;
|
void SetWireState(const cChunk & Chunk, Vector3i Position);
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const = 0;
|
}
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const = 0;
|
|
||||||
|
|
||||||
// Force a virtual destructor
|
|
||||||
virtual ~cRedstoneHandler() {}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
inline static auto & DataForChunk(const cChunk & a_Chunk)
|
|
||||||
{
|
|
||||||
return *static_cast<cIncrementalRedstoneSimulatorChunkData *>(a_Chunk.GetRedstoneSimulatorData());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... ArrayTypes>
|
|
||||||
static void UpdateAdjustedRelative(const cChunk & From, const cChunk & To, const Vector3i Position, const Vector3i Offset)
|
|
||||||
{
|
|
||||||
DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + Offset));
|
|
||||||
|
|
||||||
for (const auto LinkedOffset : cSimulator::GetLinkedOffsets(Offset))
|
|
||||||
{
|
|
||||||
DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + LinkedOffset));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename ArrayType>
|
|
||||||
static void UpdateAdjustedRelatives(const cChunk & From, const cChunk & To, const Vector3i Position, const ArrayType & Relative)
|
|
||||||
{
|
|
||||||
for (const auto Offset : Relative)
|
|
||||||
{
|
|
||||||
UpdateAdjustedRelative(From, To, Position, Offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename ArrayType>
|
|
||||||
static void InvokeForAdjustedRelatives(SourceCallback Callback, const Vector3i Position, const ArrayType & Relative)
|
|
||||||
{
|
|
||||||
for (const auto Offset : Relative)
|
|
||||||
{
|
|
||||||
Callback(Position + Offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static Vector3i OffsetYP{ 0, 1, 0 };
|
|
||||||
|
|
||||||
inline static Vector3i OffsetYM{ 0, -1, 0 };
|
|
||||||
|
|
||||||
inline static std::array<Vector3i, 6> RelativeAdjacents
|
|
||||||
{
|
|
||||||
{
|
|
||||||
{ 1, 0, 0 },
|
|
||||||
{ -1, 0, 0 },
|
|
||||||
{ 0, 1, 0 },
|
|
||||||
{ 0, -1, 0 },
|
|
||||||
{ 0, 0, 1 },
|
|
||||||
{ 0, 0, -1 },
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
inline static std::array<Vector3i, 4> RelativeLaterals
|
|
||||||
{
|
|
||||||
{
|
|
||||||
{ 1, 0, 0 },
|
|
||||||
{ -1, 0, 0 },
|
|
||||||
{ 0, 0, 1 },
|
|
||||||
{ 0, 0, -1 },
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
@ -5,19 +5,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cRedstoneLampHandler final : public cRedstoneHandler
|
namespace RedstoneLampHandler
|
||||||
{
|
{
|
||||||
inline static bool IsOn(BLOCKTYPE a_BlockType)
|
inline bool IsOn(BLOCKTYPE a_BlockType)
|
||||||
{
|
{
|
||||||
return (a_BlockType == E_BLOCK_REDSTONE_LAMP_ON);
|
return (a_BlockType == E_BLOCK_REDSTONE_LAMP_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating lamp (%i %i %i)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating lamp (%i %i %i)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ class cRedstoneLampHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Meta);
|
UNUSED(a_Meta);
|
||||||
|
@ -1,16 +1,87 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../Blocks/BlockRedstoneRepeater.h"
|
#include "../../Blocks/BlockRedstoneRepeater.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cRedstoneRepeaterHandler final : public cRedstoneHandler
|
namespace RedstoneRepeaterHandler
|
||||||
{
|
{
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline bool IsOn(BLOCKTYPE a_Block)
|
||||||
|
{
|
||||||
|
return (a_Block == E_BLOCK_REDSTONE_REPEATER_ON);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns a pair with first element indicating if the block at the given position is an activated repeater.
|
||||||
|
If it is activated, the second element is the repeater metadata. */
|
||||||
|
inline std::pair<bool, NIBBLETYPE> IsOnRepeater(cChunk & Chunk, const Vector3i a_Position)
|
||||||
|
{
|
||||||
|
BLOCKTYPE Type;
|
||||||
|
NIBBLETYPE Meta;
|
||||||
|
|
||||||
|
if (!Chunk.UnboundedRelGetBlock(a_Position, Type, Meta))
|
||||||
|
{
|
||||||
|
return std::make_pair(false, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_pair(IsOn(Type), Meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Determine, from the metadata of a repeater on our left side, if they lock us.
|
||||||
|
To test a repeater on our right, simply invert the order of arguments provided.
|
||||||
|
"Left" is relative to the direction the repeater output faces, naturally. */
|
||||||
|
inline bool DoesLhsLockMe(NIBBLETYPE a_MetaLhs, NIBBLETYPE a_MyMeta)
|
||||||
|
{
|
||||||
|
// Get the direction bits
|
||||||
|
a_MetaLhs &= E_META_REDSTONE_REPEATER_FACING_MASK;
|
||||||
|
a_MyMeta &= E_META_REDSTONE_REPEATER_FACING_MASK;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Check for a valid locking configuration, where they are perpendicular and one snuggles into the other.
|
||||||
|
|
||||||
|
Order of comparisons:
|
||||||
|
XP >^ ZM
|
||||||
|
ZP |_ XP
|
||||||
|
XM <| ZP
|
||||||
|
ZP ^< xM
|
||||||
|
|
||||||
|
Key:
|
||||||
|
^ Facing up
|
||||||
|
_ Facing right
|
||||||
|
| Facing down
|
||||||
|
< Facing left
|
||||||
|
*/
|
||||||
|
return
|
||||||
|
((a_MetaLhs == E_META_REDSTONE_REPEATER_FACING_XP) && (a_MyMeta == E_META_REDSTONE_REPEATER_FACING_ZM)) ||
|
||||||
|
((a_MetaLhs == E_META_REDSTONE_REPEATER_FACING_ZP) && (a_MyMeta == E_META_REDSTONE_REPEATER_FACING_XP)) ||
|
||||||
|
((a_MetaLhs == E_META_REDSTONE_REPEATER_FACING_XM) && (a_MyMeta == E_META_REDSTONE_REPEATER_FACING_ZP)) ||
|
||||||
|
((a_MetaLhs == E_META_REDSTONE_REPEATER_FACING_ZM) && (a_MyMeta == E_META_REDSTONE_REPEATER_FACING_XM))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Determine if a repeater is locked.
|
||||||
|
A locked repeater is one with another powered repeater facing them, to their immediate left or right sides.
|
||||||
|
"Left" is relative to the direction the repeater output faces, naturally. */
|
||||||
|
inline bool IsLocked(cChunk & Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta)
|
||||||
|
{
|
||||||
|
// The left hand side offset. Will be negated to get the rhs offset
|
||||||
|
const auto LhsOffset = cBlockRedstoneRepeaterHandler::GetLeftCoordinateOffset(a_Meta);
|
||||||
|
|
||||||
|
// Test the block to the left of us
|
||||||
|
const auto Lhs = IsOnRepeater(Chunk, LhsOffset + a_Position);
|
||||||
|
if (Lhs.first && DoesLhsLockMe(Lhs.second, a_Meta))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test the right side, flipping the argument order to DoesLhsLockMe
|
||||||
|
const auto Rhs = IsOnRepeater(Chunk, -LhsOffset + a_Position);
|
||||||
|
return Rhs.first && DoesLhsLockMe(a_Meta, Rhs.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
if (!IsOn(a_BlockType))
|
if (!IsOn(a_BlockType))
|
||||||
{
|
{
|
||||||
@ -27,7 +98,7 @@ class cRedstoneRepeaterHandler final : public cRedstoneHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating loopy the repeater (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating loopy the repeater (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -77,80 +148,8 @@ class cRedstoneRepeaterHandler final : public cRedstoneHandler
|
|||||||
UpdateAdjustedRelative(a_Chunk, CurrentlyTicking, a_Position, cBlockRedstoneRepeaterHandler::GetFrontCoordinateOffset(a_Meta));
|
UpdateAdjustedRelative(a_Chunk, CurrentlyTicking, a_Position, cBlockRedstoneRepeaterHandler::GetFrontCoordinateOffset(a_Meta));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
Callback(cBlockRedstoneRepeaterHandler::GetRearCoordinateOffset(a_Meta) + a_Position);
|
Callback(cBlockRedstoneRepeaterHandler::GetRearCoordinateOffset(a_Meta) + a_Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static bool IsOn(BLOCKTYPE a_Block)
|
|
||||||
{
|
|
||||||
return (a_Block == E_BLOCK_REDSTONE_REPEATER_ON);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns a pair with first element indicating if the block at the given position is an activated repeater.
|
|
||||||
If it is activated, the second element is the repeater metadata. */
|
|
||||||
static std::pair<bool, NIBBLETYPE> IsOnRepeater(cChunk & Chunk, const Vector3i a_Position)
|
|
||||||
{
|
|
||||||
BLOCKTYPE Type;
|
|
||||||
NIBBLETYPE Meta;
|
|
||||||
|
|
||||||
if (!Chunk.UnboundedRelGetBlock(a_Position, Type, Meta))
|
|
||||||
{
|
|
||||||
return std::make_pair(false, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::make_pair(IsOn(Type), Meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Determine if a repeater is locked.
|
|
||||||
A locked repeater is one with another powered repeater facing them, to their immediate left or right sides.
|
|
||||||
"Left" is relative to the direction the repeater output faces, naturally. */
|
|
||||||
inline static bool IsLocked(cChunk & Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta)
|
|
||||||
{
|
|
||||||
// The left hand side offset. Will be negated to get the rhs offset
|
|
||||||
const auto LhsOffset = cBlockRedstoneRepeaterHandler::GetLeftCoordinateOffset(a_Meta);
|
|
||||||
|
|
||||||
// Test the block to the left of us
|
|
||||||
const auto Lhs = IsOnRepeater(Chunk, LhsOffset + a_Position);
|
|
||||||
if (Lhs.first && DoesLhsLockMe(Lhs.second, a_Meta))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test the right side, flipping the argument order to DoesLhsLockMe
|
|
||||||
const auto Rhs = IsOnRepeater(Chunk, -LhsOffset + a_Position);
|
|
||||||
return Rhs.first && DoesLhsLockMe(a_Meta, Rhs.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Determine, from the metadata of a repeater on our left side, if they lock us.
|
|
||||||
To test a repeater on our right, simply invert the order of arguments provided.
|
|
||||||
"Left" is relative to the direction the repeater output faces, naturally. */
|
|
||||||
static bool DoesLhsLockMe(NIBBLETYPE a_MetaLhs, NIBBLETYPE a_MyMeta)
|
|
||||||
{
|
|
||||||
// Get the direction bits
|
|
||||||
a_MetaLhs &= E_META_REDSTONE_REPEATER_FACING_MASK;
|
|
||||||
a_MyMeta &= E_META_REDSTONE_REPEATER_FACING_MASK;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Check for a valid locking configuration, where they are perpendicular and one snuggles into the other.
|
|
||||||
|
|
||||||
Order of comparisons:
|
|
||||||
XP >^ ZM
|
|
||||||
ZP |_ XP
|
|
||||||
XM <| ZP
|
|
||||||
ZP ^< xM
|
|
||||||
|
|
||||||
Key:
|
|
||||||
^ Facing up
|
|
||||||
_ Facing right
|
|
||||||
| Facing down
|
|
||||||
< Facing left
|
|
||||||
*/
|
|
||||||
return
|
|
||||||
((a_MetaLhs == E_META_REDSTONE_REPEATER_FACING_XP) && (a_MyMeta == E_META_REDSTONE_REPEATER_FACING_ZM)) ||
|
|
||||||
((a_MetaLhs == E_META_REDSTONE_REPEATER_FACING_ZP) && (a_MyMeta == E_META_REDSTONE_REPEATER_FACING_XP)) ||
|
|
||||||
((a_MetaLhs == E_META_REDSTONE_REPEATER_FACING_XM) && (a_MyMeta == E_META_REDSTONE_REPEATER_FACING_ZP)) ||
|
|
||||||
((a_MetaLhs == E_META_REDSTONE_REPEATER_FACING_ZM) && (a_MyMeta == E_META_REDSTONE_REPEATER_FACING_XM))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../Blocks/BlockButton.h"
|
#include "../../Blocks/BlockButton.h"
|
||||||
#include "../../Blocks/BlockLever.h"
|
#include "../../Blocks/BlockLever.h"
|
||||||
|
|
||||||
@ -9,9 +8,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cRedstoneToggleHandler final : public cRedstoneHandler
|
namespace RedstoneToggleHandler
|
||||||
{
|
{
|
||||||
inline static Vector3i GetOffsetAttachedTo(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta)
|
inline Vector3i GetOffsetAttachedTo(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta)
|
||||||
{
|
{
|
||||||
switch (a_BlockType)
|
switch (a_BlockType)
|
||||||
{
|
{
|
||||||
@ -60,22 +59,7 @@ class cRedstoneToggleHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerLevel(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta)
|
||||||
{
|
|
||||||
UNUSED(a_QueryBlockType);
|
|
||||||
|
|
||||||
const auto Meta = a_Chunk.GetMeta(a_Position);
|
|
||||||
const auto QueryOffset = a_QueryPosition - a_Position;
|
|
||||||
|
|
||||||
if (IsLinked && (QueryOffset != GetOffsetAttachedTo(a_Position, a_BlockType, Meta)))
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GetPowerLevel(a_BlockType, Meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned char GetPowerLevel(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta)
|
|
||||||
{
|
{
|
||||||
switch (a_BlockType)
|
switch (a_BlockType)
|
||||||
{
|
{
|
||||||
@ -90,12 +74,27 @@ class cRedstoneToggleHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
|
{
|
||||||
|
UNUSED(a_QueryBlockType);
|
||||||
|
|
||||||
|
const auto Meta = a_Chunk.GetMeta(a_Position);
|
||||||
|
const auto QueryOffset = a_QueryPosition - a_Position;
|
||||||
|
|
||||||
|
if (IsLinked && (QueryOffset != GetOffsetAttachedTo(a_Position, a_BlockType, Meta)))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetPowerLevel(a_BlockType, Meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating templatio<> the lever/button (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating templatio<> the lever/button (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace RedstoneTorchHandler
|
||||||
class cRedstoneTorchHandler final : public cRedstoneHandler
|
|
||||||
{
|
{
|
||||||
inline static bool IsOn(BLOCKTYPE a_Block)
|
inline bool IsOn(BLOCKTYPE a_Block)
|
||||||
{
|
{
|
||||||
return (a_Block == E_BLOCK_REDSTONE_TORCH_ON);
|
return (a_Block == E_BLOCK_REDSTONE_TORCH_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static Vector3i GetOffsetAttachedTo(const NIBBLETYPE a_Meta)
|
inline Vector3i GetOffsetAttachedTo(const NIBBLETYPE a_Meta)
|
||||||
{
|
{
|
||||||
switch (a_Meta)
|
switch (a_Meta)
|
||||||
{
|
{
|
||||||
@ -31,7 +29,7 @@ class cRedstoneTorchHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
const auto QueryOffset = a_QueryPosition - a_Position;
|
const auto QueryOffset = a_QueryPosition - a_Position;
|
||||||
|
|
||||||
@ -47,7 +45,7 @@ class cRedstoneTorchHandler final : public cRedstoneHandler
|
|||||||
return 15;
|
return 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating torchy the redstone torch (%i %i %i)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating torchy the redstone torch (%i %i %i)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -88,7 +86,7 @@ class cRedstoneTorchHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cRedstoneWireHandler final : public cRedstoneHandler
|
namespace RedstoneWireHandler
|
||||||
{
|
{
|
||||||
/** A unified representation of wire direction. */
|
/** A unified representation of wire direction. */
|
||||||
enum class TemporaryDirection
|
enum class TemporaryDirection
|
||||||
@ -17,32 +17,10 @@ class cRedstoneWireHandler final : public cRedstoneHandler
|
|||||||
Side
|
Side
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Adjusts a given wire block so that the direction represented by Offset has state Direction. */
|
|
||||||
inline static void SetDirectionState(const Vector3i Offset, short & Block, TemporaryDirection Direction)
|
|
||||||
{
|
|
||||||
Block = DoWithDirectionState(Offset, Block, [Direction](auto, auto & Front, auto)
|
|
||||||
{
|
|
||||||
using FrontState = std::remove_reference_t<decltype(Front)>;
|
|
||||||
switch (Direction)
|
|
||||||
{
|
|
||||||
case TemporaryDirection::Up:
|
|
||||||
{
|
|
||||||
Front = FrontState::Up;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case TemporaryDirection::Side:
|
|
||||||
{
|
|
||||||
Front = FrontState::Side;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Invokes Callback with the wire's left, front, and right direction state corresponding to Offset.
|
/** Invokes Callback with the wire's left, front, and right direction state corresponding to Offset.
|
||||||
Returns a new block constructed from the directions that the callback may have modified. */
|
Returns a new block constructed from the directions that the callback may have modified. */
|
||||||
template <class OffsetCallback>
|
template <class OffsetCallback>
|
||||||
inline static short DoWithDirectionState(const Vector3i Offset, short Block, OffsetCallback Callback)
|
inline short DoWithDirectionState(const Vector3i Offset, short Block, OffsetCallback Callback)
|
||||||
{
|
{
|
||||||
auto North = Block::RedstoneWire::North(Block);
|
auto North = Block::RedstoneWire::North(Block);
|
||||||
auto South = Block::RedstoneWire::South(Block);
|
auto South = Block::RedstoneWire::South(Block);
|
||||||
@ -70,11 +48,58 @@ class cRedstoneWireHandler final : public cRedstoneHandler
|
|||||||
return Block::RedstoneWire::RedstoneWire(East, North, 0, South, West);
|
return Block::RedstoneWire::RedstoneWire(East, North, 0, South, West);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
/** Adjusts a given wire block so that the direction represented by Offset has state Direction. */
|
||||||
|
inline void SetDirectionState(const Vector3i Offset, short & Block, TemporaryDirection Direction)
|
||||||
|
{
|
||||||
|
Block = DoWithDirectionState(Offset, Block, [Direction](auto, auto & Front, auto)
|
||||||
|
{
|
||||||
|
using FrontState = std::remove_reference_t<decltype(Front)>;
|
||||||
|
switch (Direction)
|
||||||
|
{
|
||||||
|
case TemporaryDirection::Up:
|
||||||
|
{
|
||||||
|
Front = FrontState::Up;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case TemporaryDirection::Side:
|
||||||
|
{
|
||||||
|
Front = FrontState::Side;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool IsDirectlyConnectingMechanism(BLOCKTYPE a_Block, NIBBLETYPE a_BlockMeta, const Vector3i a_Offset)
|
||||||
|
{
|
||||||
|
switch (a_Block)
|
||||||
|
{
|
||||||
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
||||||
|
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
||||||
|
{
|
||||||
|
a_BlockMeta &= E_META_REDSTONE_REPEATER_FACING_MASK;
|
||||||
|
if ((a_BlockMeta == E_META_REDSTONE_REPEATER_FACING_XP) || (a_BlockMeta == E_META_REDSTONE_REPEATER_FACING_XM))
|
||||||
|
{
|
||||||
|
// Wire connects to repeater if repeater is aligned along X
|
||||||
|
// and wire is in front or behind it (#4639)
|
||||||
|
return a_Offset.x != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return a_Offset.z != 0;
|
||||||
|
}
|
||||||
|
case E_BLOCK_ACTIVE_COMPARATOR:
|
||||||
|
case E_BLOCK_INACTIVE_COMPARATOR:
|
||||||
|
case E_BLOCK_BLOCK_OF_REDSTONE:
|
||||||
|
case E_BLOCK_REDSTONE_TORCH_OFF:
|
||||||
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
||||||
|
case E_BLOCK_REDSTONE_WIRE: return true;
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Temporary. Discovers a wire's connection state, including terracing, storing the block inside redstone chunk data.
|
/** Temporary. Discovers a wire's connection state, including terracing, storing the block inside redstone chunk data.
|
||||||
TODO: once the server supports block states this should go in the block handler, with data saved in the world. */
|
TODO: once the server supports block states this should go in the block handler, with data saved in the world. */
|
||||||
void SetWireState(const cChunk & Chunk, const Vector3i Position) const
|
inline void SetWireState(const cChunk & Chunk, const Vector3i Position)
|
||||||
{
|
{
|
||||||
auto Block = Block::RedstoneWire::RedstoneWire();
|
auto Block = Block::RedstoneWire::RedstoneWire();
|
||||||
const auto YPTerraceBlock = Chunk.GetBlock(Position + OffsetYP);
|
const auto YPTerraceBlock = Chunk.GetBlock(Position + OffsetYP);
|
||||||
@ -164,36 +189,7 @@ public:
|
|||||||
DataForChunk(Chunk).WireStates[Position] = Block;
|
DataForChunk(Chunk).WireStates[Position] = Block;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
|
|
||||||
inline static bool IsDirectlyConnectingMechanism(BLOCKTYPE a_Block, NIBBLETYPE a_BlockMeta, const Vector3i a_Offset)
|
|
||||||
{
|
|
||||||
switch (a_Block)
|
|
||||||
{
|
|
||||||
case E_BLOCK_REDSTONE_REPEATER_ON:
|
|
||||||
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
|
||||||
{
|
|
||||||
a_BlockMeta &= E_META_REDSTONE_REPEATER_FACING_MASK;
|
|
||||||
if ((a_BlockMeta == E_META_REDSTONE_REPEATER_FACING_XP) || (a_BlockMeta == E_META_REDSTONE_REPEATER_FACING_XM))
|
|
||||||
{
|
|
||||||
// Wire connects to repeater if repeater is aligned along X
|
|
||||||
// and wire is in front or behind it (#4639)
|
|
||||||
return a_Offset.x != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return a_Offset.z != 0;
|
|
||||||
}
|
|
||||||
case E_BLOCK_ACTIVE_COMPARATOR:
|
|
||||||
case E_BLOCK_INACTIVE_COMPARATOR:
|
|
||||||
case E_BLOCK_BLOCK_OF_REDSTONE:
|
|
||||||
case E_BLOCK_REDSTONE_TORCH_OFF:
|
|
||||||
case E_BLOCK_REDSTONE_TORCH_ON:
|
|
||||||
case E_BLOCK_REDSTONE_WIRE: return true;
|
|
||||||
default: return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
|
||||||
{
|
{
|
||||||
// Starts off as the wire's meta value, modified appropriately and returned
|
// Starts off as the wire's meta value, modified appropriately and returned
|
||||||
auto Power = a_Chunk.GetMeta(a_Position);
|
auto Power = a_Chunk.GetMeta(a_Position);
|
||||||
@ -257,7 +253,7 @@ private:
|
|||||||
return Power;
|
return Power;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating dusty the wire (%d %d %d) %i", a_Position.x, a_Position.y, a_Position.z, a_PoweringData.PowerLevel);
|
// LOGD("Evaluating dusty the wire (%d %d %d) %i", a_Position.x, a_Position.y, a_Position.z, a_PoweringData.PowerLevel);
|
||||||
|
|
||||||
@ -280,7 +276,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
UNUSED(a_Meta);
|
UNUSED(a_Meta);
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace SmallGateHandler
|
||||||
class cSmallGateHandler final : public cRedstoneHandler
|
|
||||||
{
|
{
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
@ -20,7 +18,7 @@ class cSmallGateHandler final : public cRedstoneHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating gateydory the fence gate/trapdoor (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating gateydory the fence gate/trapdoor (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -33,7 +31,7 @@ class cSmallGateHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace TNTHandler
|
||||||
class cTNTHandler final : public cRedstoneHandler
|
|
||||||
{
|
{
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
@ -20,7 +18,7 @@ class cTNTHandler final : public cRedstoneHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating explodinator the trinitrotoluene (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating explodinator the trinitrotoluene (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
if (a_PoweringData.PowerLevel != 0)
|
if (a_PoweringData.PowerLevel != 0)
|
||||||
@ -30,7 +28,7 @@ class cTNTHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../BlockEntities/ChestEntity.h"
|
#include "../../BlockEntities/ChestEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cTrappedChestHandler final : public cRedstoneHandler
|
namespace TrappedChestHandler
|
||||||
{
|
{
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
{
|
{
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
UNUSED(a_QueryPosition);
|
UNUSED(a_QueryPosition);
|
||||||
@ -20,7 +19,7 @@ class cTrappedChestHandler final : public cRedstoneHandler
|
|||||||
return DataForChunk(a_Chunk).GetCachedPowerData(a_Position).PowerLevel;
|
return DataForChunk(a_Chunk).GetCachedPowerData(a_Position).PowerLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char GetPowerLevel(cChunk & a_Chunk, Vector3i a_Position)
|
inline unsigned char GetPowerLevel(cChunk & a_Chunk, Vector3i a_Position)
|
||||||
{
|
{
|
||||||
int NumberOfPlayers = 0;
|
int NumberOfPlayers = 0;
|
||||||
VERIFY(
|
VERIFY(
|
||||||
@ -35,7 +34,7 @@ class cTrappedChestHandler final : public cRedstoneHandler
|
|||||||
return static_cast<unsigned char>(std::min(NumberOfPlayers, 15));
|
return static_cast<unsigned char>(std::min(NumberOfPlayers, 15));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating tricky the trapped chest (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating tricky the trapped chest (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -48,7 +47,7 @@ class cTrappedChestHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_Position);
|
UNUSED(a_Position);
|
||||||
|
@ -1,25 +1,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RedstoneHandler.h"
|
|
||||||
#include "../../Blocks/BlockTripwireHook.h"
|
#include "../../Blocks/BlockTripwireHook.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cTripwireHookHandler final : public cRedstoneHandler
|
namespace TripwireHookHandler
|
||||||
{
|
{
|
||||||
virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
|
inline unsigned char GetPowerLevel(const cChunk & a_Chunk, Vector3i a_Position, NIBBLETYPE a_Meta)
|
||||||
{
|
|
||||||
UNUSED(a_BlockType);
|
|
||||||
UNUSED(a_QueryBlockType);
|
|
||||||
UNUSED(a_QueryPosition);
|
|
||||||
|
|
||||||
return (GetPowerLevel(a_Chunk, a_Position, a_Chunk.GetMeta(a_Position)) == 15) ? 15 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned char GetPowerLevel(const cChunk & a_Chunk, Vector3i a_Position, NIBBLETYPE a_Meta)
|
|
||||||
{
|
{
|
||||||
bool FoundActivated = false;
|
bool FoundActivated = false;
|
||||||
const auto FaceToGoTowards = cBlockTripwireHookHandler::MetadataToDirection(a_Meta);
|
const auto FaceToGoTowards = cBlockTripwireHookHandler::MetadataToDirection(a_Meta);
|
||||||
@ -70,7 +60,16 @@ class cTripwireHookHandler final : public cRedstoneHandler
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
||||||
|
{
|
||||||
|
UNUSED(a_BlockType);
|
||||||
|
UNUSED(a_QueryBlockType);
|
||||||
|
UNUSED(a_QueryPosition);
|
||||||
|
|
||||||
|
return (GetPowerLevel(a_Chunk, a_Position, a_Chunk.GetMeta(a_Position)) == 15) ? 15 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
|
||||||
{
|
{
|
||||||
// LOGD("Evaluating hooky the tripwire hook (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
// LOGD("Evaluating hooky the tripwire hook (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
||||||
|
|
||||||
@ -102,7 +101,7 @@ class cTripwireHookHandler final : public cRedstoneHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
||||||
{
|
{
|
||||||
UNUSED(a_Chunk);
|
UNUSED(a_Chunk);
|
||||||
UNUSED(a_BlockType);
|
UNUSED(a_BlockType);
|
||||||
|
Loading…
Reference in New Issue
Block a user