diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index caaa3b5ce..2a6294d0f 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -194,11 +194,12 @@ class BlockAPI{ for($count = $stack; $count > 0; ){ $data["stack"] = min(64, $count); $count -= $data["stack"]; - $e = $this->server->api->entity->add(ENTITY_ITEM, $block, $data); + $server = ServerAPI::request(); + $e = $server->api->entity->add(ENTITY_ITEM, $block, $data); //$e->speedX = mt_rand(-10, 10) / 100; //$e->speedY = mt_rand(0, 5) / 100; //$e->speedZ = mt_rand(-10, 10) / 100; - $this->server->api->entity->spawnToAll($e->eid); + $server->api->entity->spawnToAll($e->eid); } } } @@ -262,6 +263,10 @@ class BlockAPI{ if($block->y > 127 or $block->y < 0){ return false; } + + if($item->isActivable === true and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)){ + return $this->cancelAction($block); + } if($item->isPlaceable()){ $hand = $item->getBlock(); diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index ca4e083a6..17f093e7e 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -27,10 +27,15 @@ the Free Software Foundation, either version 3 of the License, or class ServerAPI{ var $restart = false; + private static $serverRequest = false; private $server; private $config; private $apiList = array(); + public static function request(){ + return self::$serverRequest; + } + public function run(){ $this->load(); return $this->init(); @@ -107,6 +112,7 @@ class ServerAPI{ $this->parseProperties(); define("DEBUG", $this->getProperty("debug")); $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), false, $this->getProperty("port"), $this->getProperty("server-id"), $this->getProperty("server-ip")); + self::$serverRequest = $this->server; $this->setProperty("server-id", $this->server->serverID); $this->server->api = $this; if($this->getProperty("upnp-forwarding") === true){ diff --git a/src/classes/material/Item.php b/src/classes/material/Item.php index d996527bd..e7931afc2 100644 --- a/src/classes/material/Item.php +++ b/src/classes/material/Item.php @@ -36,6 +36,7 @@ class Item{ WOODEN_DOOR => "WoodenDoorItem", IRON_DOOR => "IronDoorItem", BED => "BedItem", + PAINTING => "PaintingItem", ); protected $block; protected $id; @@ -44,6 +45,7 @@ class Item{ protected $maxStackSize = 64; protected $durability = 0; protected $name; + public $isActivable = false; public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){ $this->id = (int) $id; @@ -118,4 +120,8 @@ class Item{ return 1; } + public function onActivate(BlockAPI $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + return false; + } + } \ No newline at end of file diff --git a/src/classes/material/item/generic/Painting.php b/src/classes/material/item/generic/Painting.php new file mode 100644 index 000000000..dcd50a3bd --- /dev/null +++ b/src/classes/material/item/generic/Painting.php @@ -0,0 +1,50 @@ +isActivable = true; + } + + public function onActivate(BlockAPI $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + if($target->isTransparent === false and $face > 1){ + $data = array( + "x" => $target->x, + "y" => $target->y, + "z" => $target->z, + "yaw" => ($face % 4) * 90, + ); + $server = ServerAPI::request(); + $e = $server->api->entity->add(ENTITY_OBJECT, OBJECT_PAINTING, $data); + $server->api->entity->spawnToAll($e->eid); + return true; + } + return false; + } + +} \ No newline at end of file diff --git a/src/classes/network/CustomPacketHandler.php b/src/classes/network/CustomPacketHandler.php index 25867a893..94c769f14 100644 --- a/src/classes/network/CustomPacketHandler.php +++ b/src/classes/network/CustomPacketHandler.php @@ -226,7 +226,7 @@ class CustomPacketHandler{ $this->raw .= Utils::writeMetadata($this->data["metadata"]); } break; - case MC_ADD_ENTITY: + case MC_ADD_ENTITY: //Not used? if($this->c === false){ $this->data["eid"] = Utils::readInt($this->get(4)); $this->data["type"] = ord($this->get(1)); @@ -240,9 +240,6 @@ class CustomPacketHandler{ $this->raw .= Utils::writeFloat($this->data["y"]); $this->raw .= Utils::writeFloat($this->data["z"]); $this->raw .= Utils::hexToStr("000000020000ffd30000");//Utils::writeInt(0); - /*$this->raw .= Utils::writeShort(0); - $this->raw .= Utils::writeShort(0); - $this->raw .= Utils::writeShort(0);*/ } break; case MC_REMOVE_ENTITY: @@ -380,6 +377,23 @@ class CustomPacketHandler{ $this->raw .= chr($this->data["meta"]); } break; + case MC_ADD_PAINTING: + if($this->c === false){ + $this->data["eid"] = Utils::readInt($this->get(4)); + $this->data["x"] = Utils::readInt($this->get(4)); + $this->data["y"] = Utils::readInt($this->get(4)); + $this->data["z"] = Utils::readInt($this->get(4)); + $this->data["direction"] = Utils::readInt($this->get(4)); + $this->data["title"] = $this->get(Utils::readShort($this->get(2), false)); + }else{ + $this->raw .= Utils::writeInt($this->data["eid"]); + $this->raw .= Utils::writeInt($this->data["x"]); + $this->raw .= Utils::writeInt($this->data["y"]); + $this->raw .= Utils::writeInt($this->data["z"]); + $this->raw .= Utils::writeInt($this->data["direction"]); + $this->raw .= Utils::writeShort(strlen($this->data["title"])).$this->data["title"]; + } + break; case MC_EXPLOSION: if($this->c === false){ $this->data["x"] = Utils::readFloat($this->get(4)); diff --git a/src/classes/world/Entity.php b/src/classes/world/Entity.php index 9fe286235..9782ac5b0 100644 --- a/src/classes/world/Entity.php +++ b/src/classes/world/Entity.php @@ -123,6 +123,7 @@ class Entity extends stdClass{ //$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type)); break; case ENTITY_OBJECT: + $this->setHealth(1, "generic"); //$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type)); break; case ENTITY_PAINTING: @@ -392,7 +393,16 @@ class Entity extends stdClass{ )); break; case ENTITY_OBJECT: - //$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type)); + if($this->type === OBJECT_PAINTING){ + $player->dataPacket(MC_ADD_PAINTING, array( + "eid" => $this->eid, + "x" => (int) $this->x, + "y" => (int) $this->y, + "z" => (int) $this->z, + "direction" => $this->getDirection(), + "title" => "Creepers", + )); + } break; } } @@ -540,10 +550,12 @@ class Entity extends stdClass{ $this->crouched = false; $this->updateMetadata(); $this->dead = true; + $this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 3)); //Entity dead if($this->player instanceof Player){ $this->server->api->dhandle("player.death", array("name" => $this->name, "cause" => $cause)); + }else{ + $this->close(); } - $this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 3)); //Entity dead }elseif($this->health > 0){ $this->dead = false; } diff --git a/src/protocol/current.php b/src/protocol/current.php index 01c67e8e4..12388a493 100644 --- a/src/protocol/current.php +++ b/src/protocol/current.php @@ -56,7 +56,7 @@ define("MC_MOVE_PLAYER", 0x94); define("MC_PLACE_BLOCK", 0x95); define("MC_REMOVE_BLOCK", 0x96); define("MC_UPDATE_BLOCK", 0x97); -//define("MC_ADD_PAINTING", 0x98); +define("MC_ADD_PAINTING", 0x98); define("MC_EXPLOSION", 0x99); define("MC_LEVEL_EVENT", 0x9a); //define("MC_TILE_EVENT", 0x9b); diff --git a/src/protocol/dataName.php b/src/protocol/dataName.php index d5d0fccde..6a547b4bc 100644 --- a/src/protocol/dataName.php +++ b/src/protocol/dataName.php @@ -59,7 +59,7 @@ $dataName = array( MC_PLACE_BLOCK => "PlaceBlock", MC_REMOVE_BLOCK => "RemoveBlock", MC_UPDATE_BLOCK => "UpdateBlock", - + MC_ADD_PAINTING => "AddPainting", MC_EXPLOSION => "Explosion", MC_LEVEL_EVENT => "LevelEvent",