From 700314d75ae34f93718e0545463551f787028efe Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sat, 5 Jan 2013 22:13:10 +0100 Subject: [PATCH] Starting to support Chest windows --- src/API/BlockAPI.php | 10 ++++- src/classes/CustomPacketHandler.class.php | 35 +++++++++++++++++ src/classes/Entity.class.php | 28 ++++++------- src/classes/Packet.class.php | 2 +- src/classes/Player.class.php | 2 +- src/classes/SerializedPacketHandler.class.php | 2 +- src/classes/TileEntity.class.php | 36 +++++++++++++++++ src/classes/Window.class.php | 39 +++++++++++++++++++ src/common/dependencies.php | 2 + src/pstruct/dataName.php | 3 ++ src/pstruct/protocol.php | 3 ++ 11 files changed, 144 insertions(+), 18 deletions(-) create mode 100644 src/classes/TileEntity.class.php create mode 100644 src/classes/Window.class.php diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 4238043c77..44242f8943 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -69,7 +69,7 @@ class BlockAPI{ $meta = (int) $params[3]; } if(($player = $this->server->api->player->get($username)) !== false){ - $this->drop($player->entity->x, $player->entity->y, $player->entity->z, $block, $meta, $amount); + $this->drop($player->entity->x - 0.5, $player->entity->y, $player->entity->z - 0.5, $block, $meta, $amount); console("[INFO] Giving ".$amount." of ".$block.":".$meta." to ".$username); }else{ console("[INFO] Unknown player"); @@ -231,6 +231,14 @@ class BlockAPI{ $cancelPlace = false; if(isset(Material::$activable[$target[0]])){ switch($target[0]){ + case 54: + $this->server->api->player->getByEID($data["eid"])->dataPacket(MC_CONTAINER_OPEN, array( + "windowid" => 1, + "type" => WINDOW_CHEST, + "slots" => 27, + "title" => "Random Chest", + )); + break; case 6: if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal Sapling::growTree($this->server->api->level, $target, $target[1] & 0x03); diff --git a/src/classes/CustomPacketHandler.class.php b/src/classes/CustomPacketHandler.class.php index eb19008435..1f7056742e 100644 --- a/src/classes/CustomPacketHandler.class.php +++ b/src/classes/CustomPacketHandler.class.php @@ -505,6 +505,41 @@ class CustomPacketHandler{ $this->raw .= Utils::writeShort($this->data["meta"]); } break; + case MC_CONTAINER_OPEN: + if($this->c === false){ + $this->data["windowid"] = ord($this->get(1)); + $this->data["type"] = ord($this->get(1)); + $this->data["slots"] = Utils::readShort($this->get(2), false); + $this->data["title"] = $this->get(Utils::readShort($this->get(2), false)); + }else{ + $this->raw .= chr($this->data["windowid"]); + $this->raw .= chr($this->data["type"]); + $this->raw .= Utils::writeShort($this->data["slots"]); + $this->raw .= Utils::writeShort(strlen($this->data["title"])).$this->data["title"]; + } + break; + case MC_CONTAINER_CLOSE: + if($this->c === false){ + $this->data["windowid"] = ord($this->get(1)); + }else{ + $this->raw .= chr($this->data["windowid"]); + } + break; + case MC_CONTAINER_SET_SLOT: + if($this->c === false){ + $this->data["windowid"] = ord($this->get(1)); + $this->data["slot"] = Utils::readShort($this->get(2), false); + $this->data["block"] = Utils::readShort($this->get(2), false); + $this->data["stack"] = ord($this->get(1)); + $this->data["meta"] = Utils::readShort($this->get(2), false); + }else{ + $this->raw .= chr($this->data["windowid"]); + $this->raw .= Utils::writeShort($this->data["slot"]); + $this->raw .= Utils::writeShort($this->data["block"]); + $this->raw .= chr($this->data["stack"]); + $this->raw .= Utils::writeShort($this->data["meta"]); + } + break; case MC_CLIENT_MESSAGE: if($this->c === false){ $this->data["message"] = $this->get(Utils::readShort($this->get(2), false)); diff --git a/src/classes/Entity.class.php b/src/classes/Entity.class.php index 103008549b..a6ab290910 100644 --- a/src/classes/Entity.class.php +++ b/src/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 @@ -34,7 +34,7 @@ define("ENTITY_PAINTING", 4); class Entity extends stdClass{ var $eid, $type, $name, $x, $y, $z, $yaw, $pitch, $dead, $data, $class, $attach, $metadata, $closed, $player, $onTick; - private $ev, $server; + private $server; function __construct($server, $eid, $class, $type = 0, $data = array()){ $this->server = $server; $this->eid = (int) $eid; diff --git a/src/classes/Packet.class.php b/src/classes/Packet.class.php index e8524071c5..d5585f1ee4 100644 --- a/src/classes/Packet.class.php +++ b/src/classes/Packet.class.php @@ -75,7 +75,7 @@ class Packet{ case 0x40: $reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true); $this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3)); - $this->addRaw(Utils::writeTriad($this->data[$field]["count"])); + $this->addRaw(Utils::writeTriad(strrev($this->data[$field]["count"]))); $this->addRaw(chr($this->data[$field]["id"])); $this->addRaw($reply->raw); break; diff --git a/src/classes/Player.class.php b/src/classes/Player.class.php index 3f1a285397..40c3c3b146 100644 --- a/src/classes/Player.class.php +++ b/src/classes/Player.class.php @@ -398,7 +398,7 @@ class Player{ $this->server->api->block->drop($this->entity->x, $this->entity->y, $this->entity->z, $data["block"], $data["meta"], $data["stack"]); break; default: - console("[INTERNAL] Unhandled 0x".dechex($data["id"])." Data Packet for Client ID ".$this->clientID.": ".print_r($data, true), true, true, 3); + console("[DEBUG] Unhandled 0x".dechex($data["id"])." Data Packet for Client ID ".$this->clientID.": ".print_r($data, true), true, true, 2); break; } break; diff --git a/src/classes/SerializedPacketHandler.class.php b/src/classes/SerializedPacketHandler.class.php index f6afa4c812..0d92a201e2 100644 --- a/src/classes/SerializedPacketHandler.class.php +++ b/src/classes/SerializedPacketHandler.class.php @@ -62,7 +62,7 @@ class SerializedPacketHandler{ $len = ceil(Utils::readShort($this->get(2), false) / 8); //Utils::readShort($this->get(2), false) >> 3; if($pid !== 0x00){ - $c = Utils::readTriad($this->get(3)); + $c = Utils::readTriad(strrev($this->get(3))); } if($pid === 0x60 and $i === 0){ $this->data["unknown1"] = $this->get(4); diff --git a/src/classes/TileEntity.class.php b/src/classes/TileEntity.class.php new file mode 100644 index 0000000000..a62bfed57b --- /dev/null +++ b/src/classes/TileEntity.class.php @@ -0,0 +1,36 @@ + \ No newline at end of file diff --git a/src/classes/Window.class.php b/src/classes/Window.class.php new file mode 100644 index 0000000000..b964b52cc8 --- /dev/null +++ b/src/classes/Window.class.php @@ -0,0 +1,39 @@ + \ No newline at end of file diff --git a/src/common/dependencies.php b/src/common/dependencies.php index 730d179fc3..c6019f551e 100644 --- a/src/common/dependencies.php +++ b/src/common/dependencies.php @@ -92,6 +92,8 @@ require_once("classes/Utils.class.php"); require_once("classes/UDPSocket.class.php"); require_once("classes/Packet.class.php"); require_once("classes/Entity.class.php"); +require_once("classes/TileEntity.class.php"); +require_once("classes/Window.class.php"); require_once("classes/ChunkParser.class.php"); require_once("classes/NBT.class.php"); require_once("classes/Java.class.php"); diff --git a/src/pstruct/dataName.php b/src/pstruct/dataName.php index 7fc156a71c..930b44f4bb 100644 --- a/src/pstruct/dataName.php +++ b/src/pstruct/dataName.php @@ -76,6 +76,9 @@ $dataName = array( MC_RESPAWN => "Respawn", MC_DROP_ITEM => "DropItem", + MC_CONTAINER_OPEN => "ContainerOpen", + MC_CONTAINER_CLOSE => "ContainerClose", + MC_CONTAINER_SET_SLOT => "ContainerSetSlot", MC_CLIENT_MESSAGE => "ClientMessage", MC_SIGN_UPDATE => "SignUpdate", diff --git a/src/pstruct/protocol.php b/src/pstruct/protocol.php index 45ca0d35c8..dad9b8d97d 100644 --- a/src/pstruct/protocol.php +++ b/src/pstruct/protocol.php @@ -76,6 +76,9 @@ define("MC_ANIMATE", 0xa7); define("MC_RESPAWN", 0xa8); define("MC_DROP_ITEM", 0xaa); +define("MC_CONTAINER_OPEN", 0xab); +define("MC_CONTAINER_CLOSE", 0xac); +define("MC_CONTAINER_SET_SLOT", 0xad); define("MC_CLIENT_MESSAGE", 0xb1); define("MC_SIGN_UPDATE", 0xb2);