mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
Fixed item in hand in creative mode, player files are now readable by Minecraft PC
This commit is contained in:
parent
a45f8782b1
commit
96445c4613
@ -1066,6 +1066,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
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
|
||||
*
|
||||
@ -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);
|
||||
$this->server->saveOfflinePlayerData($this->username, $nbt);
|
||||
parent::__construct($this->getLevel(), $nbt);
|
||||
$this->inventory->setHeldItemSlot($this->getCreativeBlock(Item::get(Item::STONE, 0, 1)));
|
||||
$this->loggedIn = true;
|
||||
|
||||
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"));
|
||||
if($ev->isCancelled()){
|
||||
$this->close($ev->getKickMessage(), "Plugin reason");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1537,19 +1544,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
|
||||
if(($this->gamemode & 0x01) === 1){ //Creative mode match
|
||||
$packet->slot = false;
|
||||
foreach(Block::$creative as $i => $d){
|
||||
if($d[0] === $packet->item and $d[1] === $packet->meta){
|
||||
$packet->slot = $i;
|
||||
$item = Item::get($d[0], $d[1], 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$item = Item::get($packet->item, $packet->meta, 1);
|
||||
$packet->slot = $this->getCreativeBlock($item);
|
||||
}else{
|
||||
$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);
|
||||
}else{
|
||||
$this->inventory->setHeldItemSlot($packet->slot);
|
||||
|
@ -674,6 +674,7 @@ class Server{
|
||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||
$nbt->setData($nbtTag);
|
||||
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
|
||||
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".raw.dat", $nbt->write());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,10 +135,7 @@ class DroppedItem extends Entity{
|
||||
$flags |= $this->fireTicks > 0 ? 1 : 0;
|
||||
|
||||
return [
|
||||
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)),
|
||||
0 => array("type" => 0, "value" => $flags)
|
||||
];
|
||||
}
|
||||
|
||||
@ -205,7 +202,6 @@ class DroppedItem extends Entity{
|
||||
$pk->pitch = $this->pitch;
|
||||
$pk->roll = 0;
|
||||
$pk->item = $this->getItem();
|
||||
$pk->metadata = $this->getData();
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket;
|
||||
|
@ -376,12 +376,7 @@ abstract class Entity extends Position implements Metadatable{
|
||||
}
|
||||
|
||||
$hasUpdate = false;
|
||||
$this->lastX = $this->x;
|
||||
$this->lastY = $this->y;
|
||||
$this->lastZ = $this->z;
|
||||
$this->lastMotionX = $this->motionX;
|
||||
$this->lastPitch = $this->pitch;
|
||||
$this->lastYaw = $this->yaw;
|
||||
$this->updateMovement();
|
||||
|
||||
if($this->handleWaterMovement()){
|
||||
$this->fallDistance = 0;
|
||||
@ -469,7 +464,6 @@ abstract class Entity extends Position implements Metadatable{
|
||||
}
|
||||
|
||||
$hasUpdate = $this->entityBaseTick();
|
||||
$this->updateMovement();
|
||||
|
||||
//if($this->isStatic())
|
||||
return true;
|
||||
|
@ -44,8 +44,6 @@ use pocketmine\utils\Binary;
|
||||
* Named Binary Tag encoder/decoder
|
||||
*/
|
||||
class NBT{
|
||||
const COMPRESSION_GZIP = 1;
|
||||
const COMPRESSION_ZLIB = 2;
|
||||
|
||||
const LITTLE_ENDIAN = 0;
|
||||
const BIG_ENDIAN = 1;
|
||||
@ -106,8 +104,8 @@ class NBT{
|
||||
$this->buffer = "";
|
||||
}
|
||||
|
||||
public function readCompressed($buffer, $compression = self::COMPRESSION_ZLIB){
|
||||
$this->read($compression === self::COMPRESSION_ZLIB ? zlib_decode($buffer) : zlib_decode($buffer));
|
||||
public function readCompressed($buffer, $compression = ZLIB_ENCODING_GZIP){
|
||||
$this->read(zlib_decode($buffer));
|
||||
}
|
||||
|
||||
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){
|
||||
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;
|
||||
|
@ -68,32 +68,32 @@ class Binary{
|
||||
public static function writeMetadata(array $data){
|
||||
$m = "";
|
||||
foreach($data as $bottom => $d){
|
||||
$m .= chr(($d[0] << 5) | ($bottom & 0x1F));
|
||||
switch($d[0]){
|
||||
$m .= chr(($d["type"] << 5) | ($bottom & 0x1F));
|
||||
switch($d["type"]){
|
||||
case 0:
|
||||
$m .= self::writeByte($d[1]);
|
||||
$m .= self::writeByte($d["value"]);
|
||||
break;
|
||||
case 1:
|
||||
$m .= self::writeLShort($d[1]);
|
||||
$m .= self::writeLShort($d["value"]);
|
||||
break;
|
||||
case 2:
|
||||
$m .= self::writeLInt($d[1]);
|
||||
$m .= self::writeLInt($d["value"]);
|
||||
break;
|
||||
case 3:
|
||||
$m .= self::writeLFloat($d[1]);
|
||||
$m .= self::writeLFloat($d["value"]);
|
||||
break;
|
||||
case 4:
|
||||
$m .= self::writeLShort(strlen($d[1])) . $d[1];
|
||||
$m .= self::writeLShort(strlen($d["value"])) . $d["value"];
|
||||
break;
|
||||
case 5:
|
||||
$m .= self::writeLShort($d[1][0]);
|
||||
$m .= self::writeByte($d[1][1]);
|
||||
$m .= self::writeLShort($d[1][2]);
|
||||
$m .= self::writeLShort($d["value"][0]);
|
||||
$m .= self::writeByte($d["value"][1]);
|
||||
$m .= self::writeLShort($d["value"][2]);
|
||||
break;
|
||||
case 6:
|
||||
$m .= self::writeLInt($d[1][0]);
|
||||
$m .= self::writeLInt($d[1][1]);
|
||||
$m .= self::writeLInt($d[1][2]);
|
||||
$m .= self::writeLInt($d["value"][0]);
|
||||
$m .= self::writeLInt($d["value"][1]);
|
||||
$m .= self::writeLInt($d["value"][2]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -158,10 +158,12 @@ class Binary{
|
||||
$offset += 4;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return [];
|
||||
|
||||
}
|
||||
if($types === true){
|
||||
$m[$bottom] = array($r, $type);
|
||||
$m[$bottom] = array("value" => $r, "type" => $type);
|
||||
}else{
|
||||
$m[$bottom] = $r;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user