mirror of
https://github.com/xtreme8000/CavEX.git
synced 2025-01-22 09:11:55 -05:00
Allow doors to be opened/closed
This commit is contained in:
parent
a610fef0f1
commit
2cce3a45ae
2 changed files with 32 additions and 3 deletions
|
@ -17,6 +17,7 @@
|
|||
along with CavEX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../network/server_local.h"
|
||||
#include "blocks.h"
|
||||
|
||||
static enum block_material getMaterial1(struct block_info* this) {
|
||||
|
@ -76,8 +77,35 @@ static uint8_t getTextureIndex2(struct block_info* this, enum side side) {
|
|||
|
||||
static size_t getDroppedItem(struct block_info* this, struct item_data* it,
|
||||
struct random_gen* g) {
|
||||
// TODO
|
||||
return 0;
|
||||
if(it) {
|
||||
it->id = (this->block->type == BLOCK_WOODEN_DOOR) ? ITEM_DOOR_WOOD :
|
||||
ITEM_DOOR_IRON;
|
||||
it->durability = 0;
|
||||
it->count = 1;
|
||||
}
|
||||
|
||||
// drop item only for top block
|
||||
return (this->block->metadata & 0x08) ? 1 : 0;
|
||||
}
|
||||
|
||||
static void onRightClick(struct server_local* s, struct item_data* it,
|
||||
struct block_info* where, struct block_info* on,
|
||||
enum side on_side) {
|
||||
bool is_top = on->block->metadata & 0x08;
|
||||
struct block_data other;
|
||||
|
||||
if(!server_world_get_block(&s->world, on->x, is_top ? on->y - 1 : on->y + 1,
|
||||
on->z, &other)
|
||||
|| on->block->type != other.type)
|
||||
return;
|
||||
|
||||
// flip open/closed state
|
||||
on->block->metadata ^= 0x04;
|
||||
other.metadata ^= 0x04;
|
||||
|
||||
server_world_set_block(&s->world, on->x, on->y, on->z, *on->block);
|
||||
server_world_set_block(&s->world, on->x, is_top ? on->y - 1 : on->y + 1,
|
||||
on->z, other);
|
||||
}
|
||||
|
||||
struct block block_wooden_door = {
|
||||
|
@ -88,7 +116,7 @@ struct block block_wooden_door = {
|
|||
.getTextureIndex = getTextureIndex1,
|
||||
.getDroppedItem = getDroppedItem,
|
||||
.onRandomTick = NULL,
|
||||
.onRightClick = NULL,
|
||||
.onRightClick = onRightClick,
|
||||
.transparent = false,
|
||||
.renderBlock = render_block_door,
|
||||
.renderBlockAlways = NULL,
|
||||
|
|
|
@ -94,6 +94,7 @@ enum block_type {
|
|||
BLOCK_DIAMOND_CAST = 57,
|
||||
BLOCK_WORKBENCH = 58,
|
||||
BLOCK_FURNACE = 61,
|
||||
BLOCK_WOODEN_DOOR = 64,
|
||||
BLOCK_LADDER = 65,
|
||||
BLOCK_RAIL = 66,
|
||||
BLOCK_STONE_STAIRS = 67,
|
||||
|
|
Loading…
Reference in a new issue