1
0

Fixed some small bugs :)

git-svn-id: http://mc-server.googlecode.com/svn/trunk@672 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
lapayo94@gmail.com 2012-07-16 13:30:33 +00:00
parent 14dce23845
commit ba70a15191
9 changed files with 103 additions and 38 deletions

View File

@ -34,10 +34,10 @@
#include "BlockCactus.h"
#include "BlockStems.h"
#include "BlockGlowstone.h"
#include "BlockRedstoneOre.h"
#include "BlockStone.h"
#include "BlockMelon.h"
#include "BlockIce.h"
#include "BlockOre.h"
bool cBlockHandler::m_HandlerInitialized = false;
cBlockHandler *cBlockHandler::m_BlockHandler[256];
@ -144,9 +144,15 @@ cBlockHandler *cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockID)
return new cBlockStemsHandler(a_BlockID);
case E_BLOCK_GLOWSTONE:
return new cBlockGlowstoneHandler(a_BlockID);
case E_BLOCK_DIAMOND_ORE:
case E_BLOCK_GOLD_ORE:
case E_BLOCK_REDSTONE_ORE:
case E_BLOCK_REDSTONE_ORE_GLOWING:
return new cBlockRedstoneOreHandler(a_BlockID);
case E_BLOCK_EMERALD_ORE:
case E_BLOCK_IRON_ORE:
case E_BLOCK_LAPIS_ORE:
case E_BLOCK_COAL_ORE:
return new cBlockOreHandler(a_BlockID);
case E_BLOCK_STONE:
case E_BLOCK_COBBLESTONE:
return new cBlockStoneHandler(a_BlockID);
@ -261,6 +267,11 @@ void cBlockHandler::DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z)
}
}
bool cBlockHandler::CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir)
{
return CanBeAt(a_World, a_X, a_Y, a_Z);
}
bool cBlockHandler::CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z)
{
return true;

View File

@ -28,7 +28,10 @@ public:
virtual bool NeedsRandomTicks();
//Item is -2 if it wasn´t a player
virtual void DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z);
//Checks if the block can stay at
virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z);
//Checks if the block can be placed at Default:CanBeAt(...) NOTE: In the block is not placed
virtual bool CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir);
//This gets called if the player tries to place a block ontop of this block (Only if he aims directly on this block)
virtual bool AllowBlockOnTop();
virtual bool IsUseable();

View File

@ -18,11 +18,17 @@ public:
OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
}
virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z)
virtual bool CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir) override
{
AddDirection( a_X, a_Y, a_Z, a_Dir, true );
return a_World->GetBlock( a_X, a_Y, a_Z ) != E_BLOCK_AIR;
}
virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
{
char Dir = cLadder::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
AddDirection( a_X, a_Y, a_Z, Dir, true );
return a_World->GetBlock( a_X, a_Y, a_Z ) != E_BLOCK_AIR;
return CanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir);
}
};

58
source/blocks/BlockOre.h Normal file
View File

@ -0,0 +1,58 @@
#pragma once
#include "Block.h"
#include "../MersenneTwister.h"
#include "../cWorld.h"
class cBlockOreHandler : public cBlockHandler
{
public:
cBlockOreHandler(BLOCKTYPE a_BlockID)
: cBlockHandler(a_BlockID)
{
}
virtual char GetDropCount() override
{
MTRand r1;
switch(m_BlockID)
{
case E_BLOCK_LAPIS_ORE:
return 4 + (char)r1.randInt(4);
case E_BLOCK_REDSTONE_ORE:
case E_BLOCK_REDSTONE_ORE_GLOWING:
return 4 + (char)r1.randInt(1);
default:
return 1;
}
}
virtual char GetDropMeta(char a_Meta) override
{
switch(m_BlockID)
{
case E_BLOCK_LAPIS_ORE:
return 4;
default:
return 0;
}
}
virtual int GetDropID() override
{
switch(m_BlockID)
{
case E_BLOCK_DIAMOND_ORE:
return E_ITEM_DIAMOND;
case E_BLOCK_REDSTONE_ORE:
case E_BLOCK_REDSTONE_ORE_GLOWING:
return E_ITEM_REDSTONE_DUST;
case E_BLOCK_EMERALD_ORE:
return E_ITEM_EMERALD;
case E_BLOCK_LAPIS_ORE:
return E_ITEM_DYE;
case E_BLOCK_COAL_ORE:
return E_ITEM_COAL;
}
return m_BlockID;
}
};

View File

@ -1,26 +0,0 @@
#pragma once
#include "Block.h"
#include "../MersenneTwister.h"
#include "../cWorld.h"
class cBlockRedstoneOreHandler : public cBlockHandler
{
public:
cBlockRedstoneOreHandler(BLOCKTYPE a_BlockID)
: cBlockHandler(a_BlockID)
{
}
virtual int GetDropID()
{
return E_ITEM_REDSTONE_DUST;
}
virtual char GetDropCount()
{
MTRand r1;
return 4 + r1.randInt(1);
}
};

View File

@ -11,11 +11,17 @@ public:
{
}
virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z)
virtual bool CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir) override
{
AddDirection( a_X, a_Y, a_Z, a_Dir, true );
return a_World->GetBlock( a_X, a_Y, a_Z ) != E_BLOCK_AIR;
}
virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
{
char Dir = cTorch::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
AddDirection( a_X, a_Y, a_Z, Dir, true );
return a_World->GetBlock( a_X, a_Y, a_Z ) != E_BLOCK_AIR;
return CanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir);
}
virtual int GetDropID()

View File

@ -16,10 +16,16 @@ public:
return false;
}
virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z)
virtual bool CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir) override
{
char Dir = cTorch::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
AddDirection( a_X, a_Y, a_Z, Dir, true );
AddDirection( a_X, a_Y, a_Z, a_Dir, true );
return a_World->GetBlock( a_X, a_Y, a_Z ) != E_BLOCK_AIR;
}
virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
{
char Dir = cTorch::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
return CanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir);
}
};

View File

@ -948,7 +948,7 @@ void cClientHandle::HandleBlockPlace(cPacket_BlockPlace * a_Packet)
if(Dir != 1 && !NewBlock->CanBePlacedOnSide())
return;
if(NewBlock->CanBeAt(World, X, Y, Z))
if(NewBlock->CanBePlacedAt(World, X, Y, Z, Dir))
{
ItemHandler->PlaceBlock(World, m_Player, &m_Player->GetInventory().GetEquippedItem(), X, Y, Z, a_Packet->m_Direction);
}else{

View File

@ -68,5 +68,6 @@ public:
case E_BLOCK_NETHER_BRICK_STAIRS:
return PickaxeLevel() >= 1;
}
return false;
}
};