From 52810a11baa9639e66ea9285c0b86e8601aca536 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Mon, 24 Dec 2012 03:04:06 +0100 Subject: [PATCH] Correct position for gates,doors,stairs,trapdoors + corrected cactus bug --- TODO.md | 2 -- classes/API/BlockAPI.php | 49 ++++++++++++++++++++++++++++++++++------ classes/Entity.class.php | 46 ++++++++++++++++++++++++++----------- 3 files changed, 75 insertions(+), 22 deletions(-) diff --git a/TODO.md b/TODO.md index 889b3c00..6759dac4 100644 --- a/TODO.md +++ b/TODO.md @@ -10,7 +10,6 @@ __Check Milestones [here](https://github.com/shoghicp/PocketMine-MP/issues/miles - Random Chunk Updates - Placing Half Slabs - Water/lava spread -- Door, trapdoor, stair, fence gate placement/orientation (+should need ground/wall beneath) - Opening/closing doors, fence gates, trapdoors (reflect it to all players) - Fix spawn position resetting - Correct block placement for beds @@ -18,7 +17,6 @@ __Check Milestones [here](https://github.com/shoghicp/PocketMine-MP/issues/miles - Bonemeal use - Hoes tilling dirt - Players can often hear "echos" of their own block interactions' SFX (torch placed, block destroyed, etc. most noticeable when moving around as you place.) -- BUG? Breaking redstone ore blocks not dropping TONS of redstone ore blocks (One-time occurrence... can't reproduce XD;) - Redstone ore blocks lighting up upon hit or contact - Cactus placement requirements (needs open blocks beside) - Sapling / flower placement requirements diff --git a/classes/API/BlockAPI.php b/classes/API/BlockAPI.php index ef1191ba..d27dc2e4 100644 --- a/classes/API/BlockAPI.php +++ b/classes/API/BlockAPI.php @@ -97,7 +97,7 @@ class BlockAPI{ return; } - $entity = $this->server->api->entity->get($this->eid); + $direction = $this->server->api->entity->get($data["eid"])->getDirection(); switch($data["block"]){ case 50: //Torch @@ -117,6 +117,41 @@ class BlockAPI{ } $data["meta"] = $faces[$data["face"]]; break; + case 53://Stairs + case 67: + case 108: + $faces = array( + 0 => 0, + 1 => 2, + 2 => 1, + 3 => 3, + ); + $data["meta"] = $faces[$direction] & 0x03; + break; + case 96: //trapdoor + if(isset(Material::$transparent[$target[0]])){ + return; + } + $faces = array( + 2 => 0, + 3 => 1, + 4 => 2, + 5 => 3, + ); + if(!isset($faces[$data["face"]])){ + return false; + } + $data["meta"] = $faces[$data["face"]] & 0x03; + break; + case 107: //Fence gate + $faces = array( + 0 => 3, + 1 => 0, + 2 => 1, + 3 => 2, + ); + $data["meta"] = $faces[$direction] & 0x03; + break; case 64://Door placing $blockUp = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]); $blockDown = $this->server->api->level->getBlock($data["x"], $data["y"] - 1, $data["z"]); @@ -124,8 +159,8 @@ class BlockAPI{ return; }else{ $data2 = $data; - $data2["meta"] = $data2["meta"] | 0x08; - $data["meta"] = $data["meta"] & 0x07; + $data2["meta"] = 0x08; + $data["meta"] = $direction & 0x03; ++$data2["y"]; $this->server->handle("player.block.place", $data2); } @@ -155,10 +190,10 @@ class BlockAPI{ 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"] + 1, $data["y"], $data["z"] + 1); - $block1 = $this->server->api->level->getBlock($data["x"] - 1, $data["y"], $data["z"] + 1); - $block2 = $this->server->api->level->getBlock($data["x"] + 1, $data["y"], $data["z"] - 1); - $block3 = $this->server->api->level->getBlock($data["x"] - 1, $data["y"], $data["z"] - 1); + $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 $block0[0] !== 0 or $block1[0] !== 0 or $block2[0] !== 0 or $block3[0] !== 0){ return; } diff --git a/classes/Entity.class.php b/classes/Entity.class.php index d980ad66..38649a2d 100644 --- a/classes/Entity.class.php +++ b/classes/Entity.class.php @@ -2,20 +2,20 @@ /* - - - / \ - / \ + - + / \ + / \ / PocketMine \ -/ MP \ -|\ @shoghicp /| -|. \ / .| -| .. \ / .. | -| .. | .. | -| .. | .. | -\ | / - \ | / - \ | / - \ | / +/ 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 @@ -74,6 +74,26 @@ class Entity extends stdClass{ } } + public function getDirection(){ + $rotation = ($this->yaw - 90) % 360; + if ($rotation < 0) { + $rotation += 360.0; + } + if(0 <= $rotation && $rotation < 45) { + return 2; + }elseif(45 <= $rotation && $rotation < 135) { + return 3; + }elseif(135 <= $rotation && $rotation < 225) { + return 0; + }elseif(225 <= $rotation && $rotation < 315) { + return 1; + }elseif(315 <= $rotation && $rotation < 360) { + return 2; + }else{ + return null; + } + } + public function spawn($player){ if(!is_object($player)){ $player = $this->server->api->player->get($player);