build 8, allow setting selected hotbar slot, auto_jump setting

This commit is contained in:
Shoghi Cervantes 2015-04-28 14:20:35 +02:00
parent 84d1f4596b
commit 8caf04ade5
4 changed files with 50 additions and 29 deletions

View File

@ -215,6 +215,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
protected $inAirTicks = 0; protected $inAirTicks = 0;
protected $autoJump = true;
private $needACK = []; private $needACK = [];
@ -285,6 +287,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return $this->namedtag instanceof Compound; return $this->namedtag instanceof Compound;
} }
public function setAutoJump($value){
$this->autoJump = $value;
$this->sendSettings();
}
public function hasAutoJump(){
return $this->autoJump;
}
/** /**
* @param Player $player * @param Player $player
*/ */
@ -458,7 +469,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->perm = new PermissibleBase($this); $this->perm = new PermissibleBase($this);
$this->namedtag = new Compound(); $this->namedtag = new Compound();
$this->server = Server::getInstance(); $this->server = Server::getInstance();
$this->lastBreak = microtime(true); $this->lastBreak = PHP_INT_MAX;
$this->ip = $ip; $this->ip = $ip;
$this->port = $port; $this->port = $port;
$this->clientID = $clientID; $this->clientID = $clientID;
@ -907,6 +918,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->level->sleepTicks = 0; $this->level->sleepTicks = 0;
$pk = new AnimatePacket();
$pk->eid = $this->getId();
$pk->action = 3; //Wake up
$this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
} }
} }
@ -1008,22 +1024,17 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
/** /**
* Sends all the option flags * Sends all the option flags
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param bool $nametags
*/ */
public function sendSettings($nametags = true){ public function sendSettings(){
/* /*
bit mask | flag name bit mask | flag name
0x00000001 world_inmutable 0x00000001 world_inmutable
0x00000002 - 0x00000002 no_pvp
0x00000004 - 0x00000004 no_pvm
0x00000008 - (autojump) 0x00000008 no_mvp
0x00000010 - 0x00000010 static_time
0x00000020 nametags_visible 0x00000020 nametags_visible
0x00000040 ? 0x00000040 auto_jump
0x00000080 ? 0x00000080 ?
0x00000100 ? 0x00000100 ?
0x00000200 ? 0x00000200 ?
@ -1055,8 +1066,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$flags |= 0x01; //Do not allow placing/breaking blocks, adventure mode $flags |= 0x01; //Do not allow placing/breaking blocks, adventure mode
} }
if($nametags !== false){ /*if($nametags !== false){
$flags |= 0x20; //Show Nametags $flags |= 0x20; //Show Nametags
}*/
if($this->autoJump){
$flags |= 0x40;
} }
$pk = new AdventureSettingsPacket(); $pk = new AdventureSettingsPacket();
@ -1686,9 +1701,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
break; break;
}elseif($this->isCreative()){ }elseif($this->isCreative()){
$this->inventory->setHeldItemIndex($packet->slot); $this->inventory->setHeldItemIndex($packet->selectedSlot);
$this->inventory->setHeldItemSlot($slot);
}else{ }else{
if($packet->selectedSlot >= 0 and $packet->selectedSlot < 9){ if($packet->selectedSlot >= 0 and $packet->selectedSlot < $this->inventory->getHotbarSize()){
$this->inventory->setHeldItemIndex($packet->selectedSlot); $this->inventory->setHeldItemIndex($packet->selectedSlot);
$this->inventory->setHeldItemSlot($slot); $this->inventory->setHeldItemSlot($slot);
}else{ }else{
@ -1728,7 +1744,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$item = $this->inventory->getItemInHand(); $item = $this->inventory->getItemInHand();
$oldItem = clone $item; $oldItem = clone $item;
//TODO: Implement adventure mode checks //TODO: Implement adventure mode checks
if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){ if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this)){
if(!$item->equals($oldItem, true) or $item->getCount() !== $oldItem->getCount()){ if(!$item->equals($oldItem, true) or $item->getCount() !== $oldItem->getCount()){
$this->inventory->setItemInHand($item, $this); $this->inventory->setItemInHand($item, $this);
$this->inventory->sendHeldItem($this->hasSpawned); $this->inventory->sendHeldItem($this->hasSpawned);

View File

@ -74,7 +74,7 @@ namespace pocketmine {
const VERSION = "1.5dev"; const VERSION = "1.5dev";
const API_VERSION = "1.12.0"; const API_VERSION = "1.12.0";
const CODENAME = "活発(Kappatsu)フグ(Fugu)"; const CODENAME = "活発(Kappatsu)フグ(Fugu)";
const MINECRAFT_VERSION = "v0.11.0 alpha build 7"; const MINECRAFT_VERSION = "v0.11.0 alpha build 8";
/* /*
* Startup code. Do not look at it, it may harm you. * Startup code. Do not look at it, it may harm you.

View File

@ -598,6 +598,13 @@ class Block extends Position implements Metadatable{
return 10; return 10;
} }
/**
* @return int
*/
public function getResistance(){
return 1;
}
/** /**
* @return float * @return float
*/ */

View File

@ -71,15 +71,12 @@ class PlayerInventory extends BaseInventory{
public function setHeldItemIndex($index){ public function setHeldItemIndex($index){
if($index >= 0 and $index < $this->getHotbarSize()){ if($index >= 0 and $index < $this->getHotbarSize()){
$this->itemInHandIndex = $index; $this->itemInHandIndex = $index;
$item = $this->getItemInHand();
$pk = new PlayerEquipmentPacket(); if($this->getHolder() instanceof Player){
$pk->eid = $this->getHolder()->getId(); $this->sendHeldItem($this->getHolder()->getViewers() + [$this->getHolder()]);
$pk->item = $item->getId(); }else{
$pk->meta = $item->getDamage(); $this->sendHeldItem($this->getHolder()->getViewers());
$pk->slot = $this->getHeldItemIndex(); }
Server::broadcastPacket($this->getHolder()->getViewers(), $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
} }
} }
@ -145,15 +142,16 @@ class PlayerInventory extends BaseInventory{
$pk->eid = $this->getHolder()->getId(); $pk->eid = $this->getHolder()->getId();
$pk->item = $item->getId(); $pk->item = $item->getId();
$pk->meta = $item->getDamage(); $pk->meta = $item->getDamage();
$pk->slot = 0; $pk->slot = $this->getHeldItemSlot();
$pk->selectedSlot = $this->getHeldItemIndex();
$pk->isEncoded = true; $pk->isEncoded = true;
$pk->encode();
Server::broadcastPacket($target, $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
foreach($target as $player){ foreach($target as $player){
if($player === $this->getHolder()){ if($player === $this->getHolder()){
$this->sendSlot($this->getHeldItemSlot(), $player); $this->sendSlot($this->getHeldItemSlot(), $player);
}else{ break;
$player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
} }
} }
} }