Fixed item in hand in creative mode, player files are now readable by Minecraft PC

This commit is contained in:
Shoghi Cervantes 2014-05-29 18:45:49 +02:00
parent a45f8782b1
commit 96445c4613
6 changed files with 36 additions and 44 deletions

View File

@ -1066,6 +1066,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return $this->lagStat * 1000; return $this->lagStat * 1000;
} }
protected function getCreativeBlock(Item $item){
foreach(Block::$creative as $i => $d){
if($d[0] === $item->getID() and $d[1] === $item->getDamage()){
return $i;
}
}
return -1;
}
/** /**
* WARNING: Experimental method * WARNING: Experimental method
* *
@ -1243,8 +1252,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
} }
} }
$this->updateMovement();
} }
/** /**
@ -1399,6 +1406,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$nbt["lastPlayed"] = floor(microtime(true) * 1000); $nbt["lastPlayed"] = floor(microtime(true) * 1000);
$this->server->saveOfflinePlayerData($this->username, $nbt); $this->server->saveOfflinePlayerData($this->username, $nbt);
parent::__construct($this->getLevel(), $nbt); parent::__construct($this->getLevel(), $nbt);
$this->inventory->setHeldItemSlot($this->getCreativeBlock(Item::get(Item::STONE, 0, 1)));
$this->loggedIn = true; $this->loggedIn = true;
if(($this->gamemode & 0x01) === 0x01){ if(($this->gamemode & 0x01) === 0x01){
@ -1411,7 +1419,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->server->getPluginManager()->callEvent($ev = new PlayerLoginEvent($this, "Plugin reason")); $this->server->getPluginManager()->callEvent($ev = new PlayerLoginEvent($this, "Plugin reason"));
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->close($ev->getKickMessage(), "Plugin reason"); $this->close($ev->getKickMessage(), "Plugin reason");
return; return;
} }
@ -1537,19 +1544,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
if(($this->gamemode & 0x01) === 1){ //Creative mode match if(($this->gamemode & 0x01) === 1){ //Creative mode match
$packet->slot = false; $item = Item::get($packet->item, $packet->meta, 1);
foreach(Block::$creative as $i => $d){ $packet->slot = $this->getCreativeBlock($item);
if($d[0] === $packet->item and $d[1] === $packet->meta){
$packet->slot = $i;
$item = Item::get($d[0], $d[1], 1);
break;
}
}
}else{ }else{
$item = $this->inventory->getItem($packet->slot); $item = $this->inventory->getItem($packet->slot);
} }
if(!isset($item) or $packet->slot === false){ if(!isset($item) or $packet->slot === -1){
$this->inventory->sendSlot($packet->slot, $this); $this->inventory->sendSlot($packet->slot, $this);
}else{ }else{
$this->inventory->setHeldItemSlot($packet->slot); $this->inventory->setHeldItemSlot($packet->slot);

View File

@ -674,6 +674,7 @@ class Server{
$nbt = new NBT(NBT::BIG_ENDIAN); $nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->setData($nbtTag); $nbt->setData($nbtTag);
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed()); file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".raw.dat", $nbt->write());
} }
/** /**

View File

@ -135,10 +135,7 @@ class DroppedItem extends Entity{
$flags |= $this->fireTicks > 0 ? 1 : 0; $flags |= $this->fireTicks > 0 ? 1 : 0;
return [ return [
0 => array("type" => 0, "value" => $flags), 0 => array("type" => 0, "value" => $flags)
1 => array("type" => 1, "value" => 0),
16 => array("type" => 0, "value" => 0),
17 => array("type" => 6, "value" => array(0, 0, 0)),
]; ];
} }
@ -205,7 +202,6 @@ class DroppedItem extends Entity{
$pk->pitch = $this->pitch; $pk->pitch = $this->pitch;
$pk->roll = 0; $pk->roll = 0;
$pk->item = $this->getItem(); $pk->item = $this->getItem();
$pk->metadata = $this->getData();
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = new SetEntityMotionPacket; $pk = new SetEntityMotionPacket;

View File

@ -376,12 +376,7 @@ abstract class Entity extends Position implements Metadatable{
} }
$hasUpdate = false; $hasUpdate = false;
$this->lastX = $this->x; $this->updateMovement();
$this->lastY = $this->y;
$this->lastZ = $this->z;
$this->lastMotionX = $this->motionX;
$this->lastPitch = $this->pitch;
$this->lastYaw = $this->yaw;
if($this->handleWaterMovement()){ if($this->handleWaterMovement()){
$this->fallDistance = 0; $this->fallDistance = 0;
@ -469,7 +464,6 @@ abstract class Entity extends Position implements Metadatable{
} }
$hasUpdate = $this->entityBaseTick(); $hasUpdate = $this->entityBaseTick();
$this->updateMovement();
//if($this->isStatic()) //if($this->isStatic())
return true; return true;

View File

@ -44,8 +44,6 @@ use pocketmine\utils\Binary;
* Named Binary Tag encoder/decoder * Named Binary Tag encoder/decoder
*/ */
class NBT{ class NBT{
const COMPRESSION_GZIP = 1;
const COMPRESSION_ZLIB = 2;
const LITTLE_ENDIAN = 0; const LITTLE_ENDIAN = 0;
const BIG_ENDIAN = 1; const BIG_ENDIAN = 1;
@ -106,8 +104,8 @@ class NBT{
$this->buffer = ""; $this->buffer = "";
} }
public function readCompressed($buffer, $compression = self::COMPRESSION_ZLIB){ public function readCompressed($buffer, $compression = ZLIB_ENCODING_GZIP){
$this->read($compression === self::COMPRESSION_ZLIB ? zlib_decode($buffer) : zlib_decode($buffer)); $this->read(zlib_decode($buffer));
} }
public function write(){ public function write(){
@ -121,9 +119,9 @@ class NBT{
} }
} }
public function writeCompressed($compression = self::COMPRESSION_ZLIB, $level = 7){ public function writeCompressed($compression = ZLIB_ENCODING_GZIP, $level = 7){
if(($write = $this->write()) !== false){ if(($write = $this->write()) !== false){
return $compression === self::COMPRESSION_ZLIB ? zlib_encode($write, 15, $level) : zlib_encode($write, 31, $level); return zlib_encode($write, ZLIB_ENCODING_GZIP, $level);
} }
return false; return false;

View File

@ -68,32 +68,32 @@ class Binary{
public static function writeMetadata(array $data){ public static function writeMetadata(array $data){
$m = ""; $m = "";
foreach($data as $bottom => $d){ foreach($data as $bottom => $d){
$m .= chr(($d[0] << 5) | ($bottom & 0x1F)); $m .= chr(($d["type"] << 5) | ($bottom & 0x1F));
switch($d[0]){ switch($d["type"]){
case 0: case 0:
$m .= self::writeByte($d[1]); $m .= self::writeByte($d["value"]);
break; break;
case 1: case 1:
$m .= self::writeLShort($d[1]); $m .= self::writeLShort($d["value"]);
break; break;
case 2: case 2:
$m .= self::writeLInt($d[1]); $m .= self::writeLInt($d["value"]);
break; break;
case 3: case 3:
$m .= self::writeLFloat($d[1]); $m .= self::writeLFloat($d["value"]);
break; break;
case 4: case 4:
$m .= self::writeLShort(strlen($d[1])) . $d[1]; $m .= self::writeLShort(strlen($d["value"])) . $d["value"];
break; break;
case 5: case 5:
$m .= self::writeLShort($d[1][0]); $m .= self::writeLShort($d["value"][0]);
$m .= self::writeByte($d[1][1]); $m .= self::writeByte($d["value"][1]);
$m .= self::writeLShort($d[1][2]); $m .= self::writeLShort($d["value"][2]);
break; break;
case 6: case 6:
$m .= self::writeLInt($d[1][0]); $m .= self::writeLInt($d["value"][0]);
$m .= self::writeLInt($d[1][1]); $m .= self::writeLInt($d["value"][1]);
$m .= self::writeLInt($d[1][2]); $m .= self::writeLInt($d["value"][2]);
break; break;
} }
} }
@ -158,10 +158,12 @@ class Binary{
$offset += 4; $offset += 4;
} }
break; break;
default:
return [];
} }
if($types === true){ if($types === true){
$m[$bottom] = array($r, $type); $m[$bottom] = array("value" => $r, "type" => $type);
}else{ }else{
$m[$bottom] = $r; $m[$bottom] = $r;
} }