Skip to content

Commit

Permalink
Fix/Add braces and coding style for block code.
Browse files Browse the repository at this point in the history
  • Loading branch information
joehillen committed Feb 28, 2011
1 parent 5a00fad commit 045711e
Show file tree
Hide file tree
Showing 17 changed files with 710 additions and 550 deletions.
103 changes: 59 additions & 44 deletions src/blocks/basic.cpp
Expand Up @@ -44,26 +44,26 @@ bool BlockBasic::isBlockStackable(const uint8_t block)
/* Check block below allows blocks placed on top */
switch(block)
{
case BLOCK_WORKBENCH:
case BLOCK_CHEST:
case BLOCK_JUKEBOX:
case BLOCK_TORCH:
case BLOCK_REDSTONE_TORCH_OFF:
case BLOCK_REDSTONE_TORCH_ON:
case BLOCK_WATER:
case BLOCK_STATIONARY_WATER:
case BLOCK_LAVA:
case BLOCK_STATIONARY_LAVA:
case BLOCK_AIR:
case BLOCK_MINECART_TRACKS:
case BLOCK_WOODEN_DOOR:
case BLOCK_IRON_DOOR:
case BLOCK_ICE:
case BLOCK_CAKE:
return false;
break;
default:
break;
case BLOCK_WORKBENCH:
case BLOCK_CHEST:
case BLOCK_JUKEBOX:
case BLOCK_TORCH:
case BLOCK_REDSTONE_TORCH_OFF:
case BLOCK_REDSTONE_TORCH_ON:
case BLOCK_WATER:
case BLOCK_STATIONARY_WATER:
case BLOCK_LAVA:
case BLOCK_STATIONARY_LAVA:
case BLOCK_AIR:
case BLOCK_MINECART_TRACKS:
case BLOCK_WOODEN_DOOR:
case BLOCK_IRON_DOOR:
case BLOCK_ICE:
case BLOCK_CAKE:
return false;
break;
default:
break;
}

return true;
Expand Down Expand Up @@ -92,30 +92,31 @@ bool BlockBasic::translateDirection(int32_t *x, int8_t *y, int32_t *z, int map,c
{
uint8_t block, meta;
Mineserver::get()->map(map)->getBlock(*x,*y,*z,&block,&meta);
if(block != BLOCK_SNOW){
if (block != BLOCK_SNOW)
{
switch(direction)
{
case BLOCK_SOUTH:
*x-=1;
break;
case BLOCK_NORTH:
*x+=1;
break;
case BLOCK_EAST:
*z+=1;
break;
case BLOCK_WEST:
*z-=1;
break;
case BLOCK_TOP:
*y+=1;
break;
case BLOCK_BOTTOM:
*y-=1;
break;
default:
return false;
break;
case BLOCK_SOUTH:
*x-=1;
break;
case BLOCK_NORTH:
*x+=1;
break;
case BLOCK_EAST:
*z+=1;
break;
case BLOCK_WEST:
*z-=1;
break;
case BLOCK_TOP:
*y+=1;
break;
case BLOCK_BOTTOM:
*y-=1;
break;
default:
return false;
break;
}
}
return true;
Expand All @@ -125,7 +126,8 @@ bool BlockBasic::isBlockEmpty(const int32_t x, const int8_t y, const int32_t z,
{
uint8_t block;
uint8_t meta;
if(!Mineserver::get()->map(map)->getBlock(x, y, z, &block, &meta)){
if(!Mineserver::get()->map(map)->getBlock(x, y, z, &block, &meta))
{
return false;
}
return (block == BLOCK_AIR || block == BLOCK_WATER || block == BLOCK_STATIONARY_WATER || block == BLOCK_LAVA || block == BLOCK_STATIONARY_LAVA || block == BLOCK_SNOW);
Expand Down Expand Up @@ -163,6 +165,9 @@ void BlockBasic::notifyNeighbours(const int32_t x, const int8_t y, const int32_t
{
uint8_t block;
uint8_t meta;

//why is this commented out?

/* Function::invoker_type inv(user, oldblock, x, y, z, 0);
if (ignore_direction != BLOCK_SOUTH && Mineserver::get()->map(map)->getBlock(x+1, y, z, &block, &meta) && block != BLOCK_AIR)
Expand Down Expand Up @@ -205,12 +210,15 @@ void BlockBasic::notifyNeighbours(const int32_t x, const int8_t y, const int32_t
void BlockBasic::onStartedDigging(User* user, int8_t status, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
}

void BlockBasic::onDigging(User* user, int8_t status, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
}

void BlockBasic::onStoppedDigging(User* user, int8_t status, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
}

bool BlockBasic::onBroken(User* user, int8_t status, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
//Clear block on destroy
Expand All @@ -221,28 +229,35 @@ bool BlockBasic::onBroken(User* user, int8_t status, int32_t x, int8_t y, int32_
spawnBlockItem(x, y, z, map, block, meta);
return false;
}

void BlockBasic::onNeighbourBroken(User* user, int16_t oldblock, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
}

bool BlockBasic::onPlace(User* user, int16_t newblock, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
return false;
}

void BlockBasic::onNeighbourPlace(User* user, int16_t newblock, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
}

void BlockBasic::onReplace(User* user, int16_t newblock, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
}

void BlockBasic::onNeighbourMove(User* user, int16_t oldblock, int32_t x, int8_t y, int32_t z, int8_t direction)
{
}

bool BlockBasic::onInteract(User* user, int32_t x, int8_t y, int32_t z, int map)
{
return false;
}

void BlockBasic::revertBlock(User* user, int32_t x, int8_t y, int32_t z, int map){
void BlockBasic::revertBlock(User* user, int32_t x, int8_t y, int32_t z, int map)
{
unsigned char block, meta;
Mineserver::get()->map(map)->getBlock((int)x, (int)y, (int)z, &block, &meta);
user->buffer << PACKET_BLOCK_CHANGE << (int32_t)x << (int8_t)y << (int32_t)z << (int8_t)block << (int8_t)meta;
Expand Down
16 changes: 14 additions & 2 deletions src/blocks/blockfurnace.cpp
Expand Up @@ -48,26 +48,36 @@ bool BlockFurnace::onPlace(User* user, int16_t newblock, int32_t x, int8_t y, in
uint8_t oldmeta;

if (!Mineserver::get()->map(map)->getBlock(x, y, z, &oldblock, &oldmeta))
{
revertBlock(user,x,y,z,map);
return true;
}

/* Check block below allows blocks placed on top */
if (!this->isBlockStackable(oldblock))
{
revertBlock(user,x,y,z,map);
return true;
}

/* move the x,y,z coords dependent upon placement direction */
if (!this->translateDirection(&x,&y,&z,map,direction))
{
revertBlock(user,x,y,z,map);
return true;
}

if (this->isUserOnBlock(x,y,z,map))
{
revertBlock(user,x,y,z,map);
return true;
return true;
}

if (!this->isBlockEmpty(x,y,z,map))
{
revertBlock(user,x,y,z,map);
return true;
return true;
}

direction = user->relativeToBlock(x, y, z);

Expand Down Expand Up @@ -110,7 +120,9 @@ bool BlockFurnace::onBroken(User* user, int8_t status, int32_t x, int8_t y, int3
uint8_t meta;

if (!Mineserver::get()->map(map)->getBlock(x, y, z, &block, &meta))
{
return true;
}

bool destroy = false;

Expand Down
28 changes: 15 additions & 13 deletions src/blocks/cake.cpp
Expand Up @@ -35,9 +35,9 @@ bool BlockCake::affectedBlock(int block)
{
switch(block)
{
case BLOCK_CAKE:
case ITEM_CAKE:
return true;
case BLOCK_CAKE:
case ITEM_CAKE:
return true;
}
return false;
}
Expand Down Expand Up @@ -95,28 +95,30 @@ bool BlockCake::onInteract(User* user, int32_t x, int8_t y, int32_t z, int map)

if(metadata < 6)
{
if(newhealth > 20)
newhealth=20;
user->sethealth(newhealth);
Mineserver::get()->map(map)->setBlock(x, y, z, block, metadata);
Mineserver::get()->map(map)->sendBlockChange(x, y, z, (char)block, metadata);
if(newhealth > 20)
newhealth=20;
user->sethealth(newhealth);
Mineserver::get()->map(map)->setBlock(x, y, z, block, metadata);
Mineserver::get()->map(map)->sendBlockChange(x, y, z, (char)block, metadata);
}
else
{
if(newhealth > 20)
newhealth=20;
user->sethealth(newhealth);
Mineserver::get()->map(map)->setBlock(x, y, z, BLOCK_AIR, 0);
Mineserver::get()->map(map)->sendBlockChange(x, y, z, BLOCK_AIR, 0);
if(newhealth > 20)
newhealth=20;
user->sethealth(newhealth);
Mineserver::get()->map(map)->setBlock(x, y, z, BLOCK_AIR, 0);
Mineserver::get()->map(map)->sendBlockChange(x, y, z, BLOCK_AIR, 0);
}
return false;
}
void BlockCake::onStartedDigging(User* user, int8_t status, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
}

void BlockCake::onDigging(User* user, int8_t status, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
}

bool BlockCake::onBroken(User* user, int8_t status, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
uint8_t block;
Expand Down
18 changes: 14 additions & 4 deletions src/blocks/chest.cpp
Expand Up @@ -201,26 +201,36 @@ bool BlockChest::onPlace(User* user, int16_t newblock, int32_t x, int8_t y, int3
uint8_t oldmeta;

if (!Mineserver::get()->map(map)->getBlock(x, y, z, &oldblock, &oldmeta))
{
revertBlock(user,x,y,z,map);
return true;
}

/* Check block below allows blocks placed on top */
if (!this->isBlockStackable(oldblock))
{
revertBlock(user,x,y,z,map);
return true;
}

/* move the x,y,z coords dependent upon placement direction */
if (!this->translateDirection(&x,&y,&z,map,direction))
{
revertBlock(user,x,y,z,map);
return true;
}

if (this->isUserOnBlock(x,y,z,map))
{
revertBlock(user,x,y,z,map);
return true;
return true;
}

if (!this->isBlockEmpty(x,y,z,map))
{
revertBlock(user,x,y,z,map);
return true;
return true;
}

direction = user->relativeToBlock(x, y, z);

Expand All @@ -244,7 +254,7 @@ void BlockChest::onNeighbourMove(User* user, int16_t oldblock, int32_t x, int8_t

bool BlockChest::onInteract(User* user, int32_t x, int8_t y, int32_t z, int map)
{
//ToDo: check for large chest!
Mineserver::get()->inventory()->windowOpen(user,WINDOW_CHEST,x, y, z);
//ToDo: check for large chest!
Mineserver::get()->inventory()->windowOpen(user,WINDOW_CHEST,x, y, z);
return true;
}

2 comments on commit 045711e

@winex
Copy link
Contributor

@winex winex commented on 045711e Mar 1, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, code bodies under cases never needed braces and never will.
also, 'case ID:' is kinda special - similar to labels for goto, so it doesn't need increasing indent level.
(and yes, using labels/gotos in some cases makes code much more readable)

i don't get why upstream merged that much...

@joehillen
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I thought case needed the braces. Oh well.

I was probably a bit liberal with my styling changes.

Please sign in to comment.