From 4f0517a5a765858805fb20aaae2e27fbfe9fb1b8 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Mon, 4 Feb 2013 19:35:11 +0100 Subject: [PATCH] Added Sign placement --- src/API/BlockAPI.php | 44 ++---------- src/classes/material/Item.php | 3 + src/classes/material/block/GenericBlock.php | 2 +- .../material/block/attachable/SignPost.php | 67 ++++++++++++++++++ .../material/block/attachable/Torch.php | 4 +- .../material/block/attachable/WallSign.php | 68 +++++++++++++++++++ .../generic/IronDoor.php} | 12 ++-- .../generic/SignItem.php} | 13 ++-- .../material/item/generic/WoodenDoor.php | 33 +++++++++ 9 files changed, 188 insertions(+), 58 deletions(-) create mode 100644 src/classes/material/block/attachable/SignPost.php create mode 100644 src/classes/material/block/attachable/WallSign.php rename src/classes/material/{block/solid/SignPost.php => item/generic/IronDoor.php} (69%) rename src/classes/material/{block/solid/WallSign.php => item/generic/SignItem.php} (69%) create mode 100644 src/classes/material/item/generic/WoodenDoor.php diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index ff0d16a4a..45347512c 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -63,9 +63,9 @@ class BlockAPI{ return $i; } - public function setBlock($block, $id, $meta){ + public function setBlock($block, $id, $meta, $update = true, $tiles = false){ if(($block instanceof Vector3) or (($block instanceof Block) and $block->inWorld === true)){ - $this->server->api->level->setBlock($block->x, $block->y, $block->z, (int) $id, (int) $meta); + $this->server->api->level->setBlock($block->x, $block->y, $block->z, (int) $id, (int) $meta, $update, $tiles); return true; } return false; @@ -307,12 +307,13 @@ class BlockAPI{ return $this->cancelAction($block); //Entity in block } - //$direction = $player->entity->getDirection(); - if($hand->place($this, $item, $player, $block, $target, $data["face"], $data["fx"], $data["fy"], $data["fz"]) === false){ return false; } - + if($hand->getID() === SIGN_POST or $hand->getID() === WALL_POST){ + $t = $this->server->api->tileentity->addSign($block->x, $block->y, $block->z); + $t->data["creator"] = $player->username; + } /*switch($data["block"]){ case 26: //bed $face = array( @@ -333,39 +334,6 @@ class BlockAPI{ $data2["z"] = $next[2][2]; $this->server->handle("player.block.place", $data2); break; - case 81: //Cactus - $blockDown = $this->server->api->level->getBlock($data["x"], $data["y"] - 1, $data["z"]); - $block0 = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"] + 1); - $block1 = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"] - 1); - $block2 = $this->server->api->level->getBlock($data["x"] + 1, $data["y"], $data["z"]); - $block3 = $this->server->api->level->getBlock($data["x"] - 1, $data["y"], $data["z"]); - if($blockDown[0] !== 12 or !isset(Material::$transparent[$block0[0]]) or !isset(Material::$transparent[$block1[0]]) or !isset(Material::$transparent[$block2[0]]) or !isset(Material::$transparent[$block3[0]])){ - return false; - } - break; - case 323: //Signs - $faces = array( - 2 => 2, - 3 => 3, - 4 => 4, - 5 => 5, - ); - if(!isset($faces[$data["face"]])){ - if($data["face"] === 1){ - $data["block"] = 63; - $data["meta"] = 0; - $t = $this->server->api->tileentity->addSign($data["x"], $data["y"], $data["z"]); - $t->data["creator"] = $entity->player->username; - }else{ - return false; - } - }else{ - $data["block"] = 68; - $data["meta"] = $faces[$data["face"]]; - $t = $this->server->api->tileentity->addSign($data["x"], $data["y"], $data["z"]); - $t->data["creator"] = $entity->player->username; - } - break; } */ if($this->server->gamemode === 0 or $this->server->gamemode === 2){ diff --git a/src/classes/material/Item.php b/src/classes/material/Item.php index d8246fd1a..9d8081e45 100644 --- a/src/classes/material/Item.php +++ b/src/classes/material/Item.php @@ -32,6 +32,9 @@ class Item{ SUGARCANE => "SugarcaneItem", WHEAT_SEEDS => "WheatSeedsItem", MELON_SEEDS => "MelonSeedsItem", + SIGN => "SignItem", + WOODEN_DOOR => "WoodenDoorItem", + IRON_DOOR => "IronDoorItem", ); protected $block; protected $id; diff --git a/src/classes/material/block/GenericBlock.php b/src/classes/material/block/GenericBlock.php index 04724756c..aba1b9336 100644 --- a/src/classes/material/block/GenericBlock.php +++ b/src/classes/material/block/GenericBlock.php @@ -40,7 +40,7 @@ class GenericBlock extends Block{ public function onBreak(BlockAPI $level, Item $item, Player $player){ if($this->inWorld === true){ - $level->setBlock($this, 0, 0); + $level->setBlock($this, AIR, 0); return true; } return false; diff --git a/src/classes/material/block/attachable/SignPost.php b/src/classes/material/block/attachable/SignPost.php new file mode 100644 index 000000000..1f30e2b3e --- /dev/null +++ b/src/classes/material/block/attachable/SignPost.php @@ -0,0 +1,67 @@ +inWorld === true and $face !== 0){ + if($face !== 0){ + $faces = array( + 2 => 2, + 3 => 3, + 4 => 4, + 5 => 5, + ); + if(!isset($faces[$face])){ + $level->setBlock($block, SIGN_POST, 0); + return true; + }else{ + $level->setBlock($block, WALL_SIGN, $faces[$face]); + return true; + } + } + } + return false; + } + + public function onBreak(BlockAPI $level, Item $item, Player $player){ + if($this->inWorld === true){ + $level->setBlock($this, 0, 0, true, true); + return true; + } + return false; + } + + public function getDrops(Item $item, Player $player){ + return array( + array(SIGN, 0, 1), + ); + } +} \ No newline at end of file diff --git a/src/classes/material/block/attachable/Torch.php b/src/classes/material/block/attachable/Torch.php index 0fb866057..2f775207c 100644 --- a/src/classes/material/block/attachable/Torch.php +++ b/src/classes/material/block/attachable/Torch.php @@ -31,8 +31,8 @@ class TorchBlock extends FlowableBlock{ } public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($block->inWorld === true){ - if($target->isTransparent === false and $face !== 0){ + if($block->inWorld === true and $face !== 0){ + if($target->isTransparent === false){ $faces = array( 1 => 5, 2 => 4, diff --git a/src/classes/material/block/attachable/WallSign.php b/src/classes/material/block/attachable/WallSign.php new file mode 100644 index 000000000..d68397054 --- /dev/null +++ b/src/classes/material/block/attachable/WallSign.php @@ -0,0 +1,68 @@ +inWorld === true and $face !== 0){ + if($face !== 0){ + $faces = array( + 2 => 2, + 3 => 3, + 4 => 4, + 5 => 5, + ); + if(!isset($faces[$face])){ + $level->setBlock($block, SIGN_POST, 0); + return true; + }else{ + $level->setBlock($block, WALL_SIGN, $faces[$face]); + return true; + } + } + } + return false; + } + + public function onBreak(BlockAPI $level, Item $item, Player $player){ + if($this->inWorld === true){ + $level->setBlock($this, AIR, 0, true, true); + return true; + } + return false; + } + + public function getDrops(Item $item, Player $player){ + return array( + array(SIGN, 0, 1), + ); + } + +} \ No newline at end of file diff --git a/src/classes/material/block/solid/SignPost.php b/src/classes/material/item/generic/IronDoor.php similarity index 69% rename from src/classes/material/block/solid/SignPost.php rename to src/classes/material/item/generic/IronDoor.php index fa0d3a2b0..14629bb8a 100644 --- a/src/classes/material/block/solid/SignPost.php +++ b/src/classes/material/item/generic/IronDoor.php @@ -25,13 +25,9 @@ the Free Software Foundation, either version 3 of the License, or */ -class SignPostBlock extends TransparentBlock{ - public function __construct($meta = 0){ - parent::__construct(SIGN_POST, $meta, "Sign Post"); +class IronDoorItem extends Item{ + public function __construct($meta = 0, $count = 1){ + $this->block = BlockAPI::get(IRON_DOOR_BLOCK); + parent::__construct(IRON_DOOR, 0, $count, "Iron Door"); } - public function getDrops(Item $item, Player $player){ - return array( - array(323, 0, 1), - ); - } } \ No newline at end of file diff --git a/src/classes/material/block/solid/WallSign.php b/src/classes/material/item/generic/SignItem.php similarity index 69% rename from src/classes/material/block/solid/WallSign.php rename to src/classes/material/item/generic/SignItem.php index 2d13b60ea..38f38b067 100644 --- a/src/classes/material/block/solid/WallSign.php +++ b/src/classes/material/item/generic/SignItem.php @@ -25,14 +25,9 @@ the Free Software Foundation, either version 3 of the License, or */ -class WallSignBlock extends TransparentBlock{ - public function __construct($meta = 0){ - parent::__construct(WALL_SIGN, $meta, "Wall Sign"); +class SignItem extends Item{ + public function __construct($meta = 0, $count = 1){ + $this->block = BlockAPI::get(SIGN_POST); + parent::__construct(SIGN, 0, $count, "Sign"); } - public function getDrops(Item $item, Player $player){ - return array( - array(323, 0, 1), - ); - } - } \ No newline at end of file diff --git a/src/classes/material/item/generic/WoodenDoor.php b/src/classes/material/item/generic/WoodenDoor.php new file mode 100644 index 000000000..ab249e1f8 --- /dev/null +++ b/src/classes/material/item/generic/WoodenDoor.php @@ -0,0 +1,33 @@ +block = BlockAPI::get(WOODEN_DOOR_BLOCK); + parent::__construct(WOODEN_DOOR, 0, $count, "Wooden Door"); + } +} \ No newline at end of file