Merge pull request #186 from tigerw/bugfixes

One feature and a few changes
master
Mattes D 2013-09-22 12:31:53 -07:00
commit 63c627f68f
15 changed files with 125 additions and 47 deletions

View File

@ -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"
>

View File

@ -0,0 +1,39 @@
#include "Globals.h"
#include "BlockButton.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);
}

View File

@ -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)
}
}
}
} ;

View File

@ -1,8 +1,6 @@
#include "Globals.h"
#include "BlockComparator.h"
#include "../Item.h"
#include "../World.h"
#include "../Simulator/RedstoneSimulator.h"
#include "../Entities/Player.h"
@ -32,16 +30,7 @@ void cBlockComparatorHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_Bl
{
NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
Meta ^= 0x04; // Toggle 3rd (addition/subtraction) bit with XOR
a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta);
}
void cBlockComparatorHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
{
OnUse(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NONE, 8, 8, 8);
a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta);
}

View File

@ -2,7 +2,6 @@
#pragma once
#include "BlockHandler.h"
#include "../World.h"
@ -15,7 +14,6 @@ public:
cBlockComparatorHandler(BLOCKTYPE a_BlockType);
virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override;
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;

View File

@ -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);

View File

@ -1,8 +1,6 @@
#include "Globals.h"
#include "BlockLever.h"
#include "../Item.h"
#include "../World.h"
#include "../Entities/Player.h"
#include "../Simulator/RedstoneSimulator.h"
@ -23,7 +21,8 @@ void cBlockLeverHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_BlockX,
{
// 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->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta);
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);
@ -37,12 +36,3 @@ void cBlockLeverHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_BlockX,
void cBlockLeverHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
{
OnUse(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NONE, 8, 8, 8);
}

View File

@ -1,7 +1,6 @@
#pragma once
#include "BlockHandler.h"
#include "../World.h"
#include "../Simulator/RedstoneSimulator.h"
@ -14,7 +13,6 @@ class cBlockLeverHandler :
public:
cBlockLeverHandler(BLOCKTYPE a_BlockType);
virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override;
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;

View File

@ -1,8 +1,6 @@
#include "Globals.h"
#include "BlockRedstoneRepeater.h"
#include "../Item.h"
#include "../World.h"
#include "../Simulator/RedstoneSimulator.h"
#include "../Entities/Player.h"
@ -30,16 +28,7 @@ void cBlockRedstoneRepeaterHandler::OnDestroyed(cWorld *a_World, int a_BlockX, i
void cBlockRedstoneRepeaterHandler::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)
{
a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f));
}
void cBlockRedstoneRepeaterHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
{
OnUse(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NONE, 8, 8, 8);
a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f));
}

View File

@ -2,7 +2,6 @@
#pragma once
#include "BlockHandler.h"
#include "../World.h"
@ -15,7 +14,6 @@ public:
cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockType);
virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override;
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;

View File

@ -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;

View File

@ -1918,7 +1918,7 @@ void cClientHandle::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType,
void cClientHandle::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) // VehicleTypeType is specific to Minecarts
void cClientHandle::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) // VehicleSubType is specific to Minecarts
{
m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType, a_VehicleSubType);
}

View File

@ -10,7 +10,6 @@
#pragma once
#include "Entity.h"
#include "../Item.h"

View File

@ -10,7 +10,6 @@
#pragma once
#include "Entity.h"
#include "../Item.h"

View File

@ -21,7 +21,7 @@ extern bool g_BlockPistonBreakable[];
/// Number of ticks that the piston extending / retracting waits before setting the block
const int PISTON_TICK_DELAY = 10;
const int PISTON_TICK_DELAY = 20;