Added button placement handler
Also removed an unneeded variable in the stair handlermaster
parent
5c22a9f5f0
commit
a8a45a4afc
|
@ -2051,6 +2051,14 @@
|
|||
RelativePath="..\source\Blocks\BlockBrewingStand.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\Blocks\BlockButton.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\Blocks\BlockButton.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\blocks\BlockCactus.h"
|
||||
>
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
#include "Globals.h"
|
||||
#include "BlockButton.h"
|
||||
#include "../Simulator/RedstoneSimulator.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cBlockButtonHandler::cBlockButtonHandler(BLOCKTYPE a_BlockType)
|
||||
: cBlockHandler(a_BlockType)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cBlockButtonHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
|
||||
{
|
||||
// Flip the ON bit on/off. Using XOR bitwise operation to turn it on/off.
|
||||
NIBBLETYPE Meta = ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08) & 0x0f);
|
||||
a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta);
|
||||
|
||||
if (Meta & 0x08)
|
||||
{
|
||||
a_World->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f);
|
||||
}
|
||||
else
|
||||
{
|
||||
a_World->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
// Queue a button reset (unpress), with a GetBlock to prevent duplication of buttons (press, break, wait for reset)
|
||||
a_World->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ), ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08) & 0x0f), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 25);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#pragma once
|
||||
|
||||
#include "BlockHandler.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cBlockButtonHandler :
|
||||
public cBlockHandler
|
||||
{
|
||||
public:
|
||||
cBlockButtonHandler(BLOCKTYPE a_BlockType);
|
||||
|
||||
virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override;
|
||||
|
||||
|
||||
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
||||
{
|
||||
// Reset meta to 0
|
||||
a_Pickups.push_back(cItem(m_BlockType == E_BLOCK_WOODEN_BUTTON ? E_BLOCK_WOODEN_BUTTON : E_BLOCK_STONE_BUTTON, 1, 0));
|
||||
}
|
||||
|
||||
|
||||
virtual bool IsUseable(void) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual bool GetPlacementBlockTypeMeta(
|
||||
cWorld * a_World, cPlayer * a_Player,
|
||||
int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
|
||||
int a_CursorX, int a_CursorY, int a_CursorZ,
|
||||
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
||||
) override
|
||||
{
|
||||
a_BlockType = m_BlockType;
|
||||
a_BlockMeta = BlockFaceToMetaData(a_BlockFace);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual const char * GetStepSound(void) override
|
||||
{
|
||||
return m_BlockType == E_BLOCK_WOODEN_BUTTON ? "step.wood" : "step.stone";
|
||||
}
|
||||
|
||||
|
||||
inline static NIBBLETYPE BlockFaceToMetaData(char a_BlockFace)
|
||||
{
|
||||
switch (a_BlockFace)
|
||||
{
|
||||
case BLOCK_FACE_ZP: { return 0x4; }
|
||||
case BLOCK_FACE_ZM: { return 0x3; }
|
||||
case BLOCK_FACE_XP: { return 0x2; }
|
||||
case BLOCK_FACE_XM: { return 0x1; }
|
||||
default:
|
||||
{
|
||||
ASSERT(!"Unhandled block face!");
|
||||
return 0x0; // No idea, give a special meta (button in centre of block)
|
||||
}
|
||||
}
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
#include "../PluginManager.h"
|
||||
#include "BlockBed.h"
|
||||
#include "BlockBrewingStand.h"
|
||||
#include "BlockButton.h"
|
||||
#include "BlockCactus.h"
|
||||
#include "BlockCarpet.h"
|
||||
#include "BlockCauldron.h"
|
||||
|
@ -185,6 +186,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
|
|||
case E_BLOCK_STICKY_PISTON: return new cBlockPistonHandler (a_BlockType);
|
||||
case E_BLOCK_STONE: return new cBlockStoneHandler (a_BlockType);
|
||||
case E_BLOCK_STONE_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType);
|
||||
case E_BLOCK_STONE_BUTTON: return new cBlockButtonHandler (a_BlockType);
|
||||
case E_BLOCK_STONE_SLAB: return new cBlockSlabHandler (a_BlockType);
|
||||
case E_BLOCK_SUGARCANE: return new cBlockSugarcaneHandler (a_BlockType);
|
||||
case E_BLOCK_TALL_GRASS: return new cBlockTallGrassHandler (a_BlockType);
|
||||
|
@ -192,6 +194,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
|
|||
case E_BLOCK_VINES: return new cBlockVineHandler (a_BlockType);
|
||||
case E_BLOCK_WALLSIGN: return new cBlockSignHandler (a_BlockType);
|
||||
case E_BLOCK_WATER: return new cBlockFluidHandler (a_BlockType);
|
||||
case E_BLOCK_WOODEN_BUTTON: return new cBlockButtonHandler (a_BlockType);
|
||||
case E_BLOCK_WOODEN_DOOR: return new cBlockDoorHandler (a_BlockType);
|
||||
case E_BLOCK_WOODEN_SLAB: return new cBlockSlabHandler (a_BlockType);
|
||||
case E_BLOCK_WOODEN_STAIRS: return new cBlockStairsHandler (a_BlockType);
|
||||
|
|
|
@ -53,7 +53,6 @@ public:
|
|||
static NIBBLETYPE RotationToMetaData(double a_Rotation)
|
||||
{
|
||||
a_Rotation += 90 + 45; // So its not aligned with axis
|
||||
NIBBLETYPE result = 0x0;
|
||||
if (a_Rotation > 360)
|
||||
{
|
||||
a_Rotation -= 360;
|
||||
|
|
Loading…
Reference in New Issue