Bed placement

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-04 19:57:23 +01:00
parent 719dff6e3c
commit 565cb9781c
4 changed files with 65 additions and 1 deletions

View File

@ -322,7 +322,7 @@ class BlockAPI{
2 => 2,
3 => 5,
);
$next = $this->server->api->level->getBlockFace($block, $face[(($direction + 3) % 4)]);
$next = $level->getBlockFace($block, $face[(($direction + 3) % 4)]);
if(!isset(Material::$replaceable[$next[0]])){
return false;
}

View File

@ -35,6 +35,7 @@ class Item{
SIGN => "SignItem",
WOODEN_DOOR => "WoodenDoorItem",
IRON_DOOR => "IronDoorItem",
BED => "BedItem",
);
protected $block;
protected $id;

View File

@ -31,4 +31,34 @@ class BedBlock extends TransparentBlock{
$this->isActivable = true;
}
public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($block->inWorld === true){
$down = $level->getBlockFace($block, 0);
if($down->isTransparent === false){
$faces = array(
0 => 3,
1 => 4,
2 => 2,
3 => 5,
);
$d = $player->entity->getDirection();
$next = $level->getBlockFace($block, $faces[(($d + 3) % 4)]);
$downNext = $level->getBlockFace($next, 0);
if($next->isReplaceable === true and $downNext->isTransparent === false){
$meta = (($d + 3) % 4) & 0x03;
$level->setBlock($block, $this->id, $meta);
$level->setBlock($next, $this->id, $meta | 0x08);
return true;
}
}
}
return false;
}
public function getDrops(Item $item, Player $player){
return array(
array(BED, 0, 1),
);
}
}

View File

@ -0,0 +1,33 @@
<?php
/*
-
/ \
/ \
/ PocketMine \
/ MP \
|\ @shoghicp /|
|. \ / .|
| .. \ / .. |
| .. | .. |
| .. | .. |
\ | /
\ | /
\ | /
\ | /
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/
class BedItem extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = BlockAPI::get(BED_BLOCK);
parent::__construct(BED, 0, $count, "Bed");
}
}