Added sneaking, sprinting

This commit is contained in:
Shoghi Cervantes 2015-08-08 13:02:59 +02:00
parent b3efb733a2
commit d4163ea01c
5 changed files with 68 additions and 12 deletions

View File

@ -109,6 +109,7 @@ use pocketmine\network\protocol\DisconnectPacket;
use pocketmine\network\protocol\EntityEventPacket; use pocketmine\network\protocol\EntityEventPacket;
use pocketmine\network\protocol\FullChunkDataPacket; use pocketmine\network\protocol\FullChunkDataPacket;
use pocketmine\network\protocol\Info as ProtocolInfo; use pocketmine\network\protocol\Info as ProtocolInfo;
use pocketmine\network\protocol\PlayerActionPacket;
use pocketmine\network\protocol\PlayStatusPacket; use pocketmine\network\protocol\PlayStatusPacket;
use pocketmine\network\protocol\RespawnPacket; use pocketmine\network\protocol\RespawnPacket;
use pocketmine\network\protocol\TextPacket; use pocketmine\network\protocol\TextPacket;
@ -2078,7 +2079,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
break; break;
case ProtocolInfo::PLAYER_ACTION_PACKET: case ProtocolInfo::PLAYER_ACTION_PACKET:
if($this->spawned === false or $this->blocked === true or (!$this->isAlive() and $packet->action !== 7)){ if($this->spawned === false or $this->blocked === true or (!$this->isAlive() and $packet->action !== PlayerActionPacket::ACTION_RESPAWN and $packet->action !== PlayerActionPacket::ACTION_DIMENSION_CHANGE)){
break; break;
} }
@ -2086,7 +2087,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$pos = new Vector3($packet->x, $packet->y, $packet->z); $pos = new Vector3($packet->x, $packet->y, $packet->z);
switch($packet->action){ switch($packet->action){
case 0: //Start break case PlayerActionPacket::ACTION_START_BREAK:
if($this->lastBreak !== PHP_INT_MAX or $pos->distanceSquared($this) > 10000){ if($this->lastBreak !== PHP_INT_MAX or $pos->distanceSquared($this) > 10000){
break; break;
} }
@ -2099,10 +2100,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
$this->lastBreak = microtime(true); $this->lastBreak = microtime(true);
break; break;
case 1: //Abort! case PlayerActionPacket::ACTION_ABORT_BREAK:
$this->lastBreak = PHP_INT_MAX; $this->lastBreak = PHP_INT_MAX;
break; break;
case 5: //Shot arrow case PlayerActionPacket::ACTION_RELEASE_ITEM:
if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION)){ if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION)){
if($this->inventory->getItemInHand()->getId() === Item::BOW) { if($this->inventory->getItemInHand()->getId() === Item::BOW) {
$bow = $this->inventory->getItemInHand(); $bow = $this->inventory->getItemInHand();
@ -2194,10 +2195,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
} }
break; break;
case 6: //get out of the bed case PlayerActionPacket::ACTION_STOP_SLEEPING:
$this->stopSleep(); $this->stopSleep();
break; break;
case 7: //Respawn case PlayerActionPacket::ACTION_RESPAWN:
if($this->spawned === false or $this->isAlive() or !$this->isOnline()){ if($this->spawned === false or $this->isAlive() or !$this->isOnline()){
break; break;
} }
@ -2232,6 +2233,18 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->spawnToAll(); $this->spawnToAll();
$this->scheduleUpdate(); $this->scheduleUpdate();
break; break;
case PlayerActionPacket::ACTION_START_SPRINT:
$this->setSprinting(true);
break;
case PlayerActionPacket::ACTION_STOP_SPRINT:
$this->setSprinting(false);
break;
case PlayerActionPacket::ACTION_START_SNEAK:
$this->setSneaking(true);
break;
case PlayerActionPacket::ACTION_STOP_SNEAK:
$this->setSneaking(false);
break;
} }
$this->startAction = -1; $this->startAction = -1;

View File

@ -92,6 +92,7 @@ abstract class Entity extends Location implements Metadatable{
const DATA_FLAG_ONFIRE = 0; const DATA_FLAG_ONFIRE = 0;
const DATA_FLAG_SNEAKING = 1; const DATA_FLAG_SNEAKING = 1;
const DATA_FLAG_RIDING = 2; const DATA_FLAG_RIDING = 2;
const DATA_FLAG_SPRINTING = 3;
const DATA_FLAG_ACTION = 4; const DATA_FLAG_ACTION = 4;
const DATA_FLAG_INVISIBLE = 5; const DATA_FLAG_INVISIBLE = 5;
@ -302,6 +303,22 @@ abstract class Entity extends Location implements Metadatable{
$this->setDataProperty(self::DATA_SHOW_NAMETAG, self::DATA_TYPE_BYTE, $value ? 1 : 0); $this->setDataProperty(self::DATA_SHOW_NAMETAG, self::DATA_TYPE_BYTE, $value ? 1 : 0);
} }
public function isSneaking(){
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING);
}
public function setSneaking($value = true){
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING, (bool) $value);
}
public function isSprinting(){
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING);
}
public function setSprinting($value = true){
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING, (bool) $value);
}
/** /**
* @return Effect[] * @return Effect[]
*/ */
@ -433,8 +450,13 @@ abstract class Entity extends Location implements Metadatable{
public function saveNBT(){ public function saveNBT(){
if(!($this instanceof Player)){ if(!($this instanceof Player)){
$this->namedtag->id = new String("id", $this->getSaveId()); $this->namedtag->id = new String("id", $this->getSaveId());
$this->namedtag->CustomName = new String("CustomName", $this->getNameTag()); if($this->getNameTag() !== ""){
$this->namedtag->CustomNameVisible = new String("CustomNameVisible", $this->isNameTagVisible()); $this->namedtag->CustomName = new String("CustomName", $this->getNameTag());
$this->namedtag->CustomNameVisible = new String("CustomNameVisible", $this->isNameTagVisible());
}else{
unset($this->namedtag->CustomName);
unset($this->namedtag->CustomNameVisible);
}
} }
$this->namedtag->Pos = new Enum("Pos", [ $this->namedtag->Pos = new Enum("Pos", [
@ -495,7 +517,9 @@ abstract class Entity extends Location implements Metadatable{
if(isset($this->namedtag->CustomName)){ if(isset($this->namedtag->CustomName)){
$this->setNameTag($this->namedtag["CustomName"]); $this->setNameTag($this->namedtag["CustomName"]);
$this->setNameTagVisible($this->namedtag["CustomNameVisible"] > 0); if(isset($this->namedtag->CustomNameVisible)){
$this->setNameTagVisible($this->namedtag["CustomNameVisible"] > 0);
}
} }
$this->scheduleUpdate(); $this->scheduleUpdate();

View File

@ -29,6 +29,7 @@ use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Double; use pocketmine\nbt\tag\Double;
use pocketmine\nbt\tag\Enum; use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Float; use pocketmine\nbt\tag\Float;
use pocketmine\nbt\tag\String;
use pocketmine\Player; use pocketmine\Player;
class SpawnEgg extends Item{ class SpawnEgg extends Item{
@ -65,6 +66,10 @@ class SpawnEgg extends Item{
]), ]),
]); ]);
if($this->hasCustomName()){
$nbt->CustomName = new String("CustomName", $this->getCustomName());
}
$entity = Entity::createEntity($this->meta, $chunk, $nbt); $entity = Entity::createEntity($this->meta, $chunk, $nbt);
if($entity instanceof Entity){ if($entity instanceof Entity){
@ -72,7 +77,6 @@ class SpawnEgg extends Item{
--$this->count; --$this->count;
} }
$entity->spawnToAll(); $entity->spawnToAll();
return true; return true;
} }

View File

@ -1666,11 +1666,11 @@ class Level implements ChunkManager, Metadatable{
$this->server->getPluginManager()->callEvent($ev); $this->server->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$target->onUpdate(self::BLOCK_UPDATE_TOUCH); $target->onUpdate(self::BLOCK_UPDATE_TOUCH);
if($target->canBeActivated() === true and $target->onActivate($item, $player) === true){ if(!$player->isSneaking() and $target->canBeActivated() === true and $target->onActivate($item, $player) === true){
return true; return true;
} }
if($item->canBeActivated() and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)){ if(!$player->isSneaking() and $item->canBeActivated() and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)){
if($item->getCount() <= 0){ if($item->getCount() <= 0){
$item = Item::get(Item::AIR, 0, 0); $item = Item::get(Item::AIR, 0, 0);

View File

@ -27,6 +27,21 @@ namespace pocketmine\network\protocol;
class PlayerActionPacket extends DataPacket{ class PlayerActionPacket extends DataPacket{
const NETWORK_ID = Info::PLAYER_ACTION_PACKET; const NETWORK_ID = Info::PLAYER_ACTION_PACKET;
const ACTION_START_BREAK = 0;
const ACTION_ABORT_BREAK = 1;
const ACTION_STOP_BREAK = 2;
const ACTION_RELEASE_ITEM = 5;
const ACTION_STOP_SLEEPING = 6;
const ACTION_RESPAWN = 7;
const ACTION_JUMP = 8;
const ACTION_START_SPRINT = 9;
const ACTION_STOP_SPRINT = 10;
const ACTION_START_SNEAK = 11;
const ACTION_STOP_SNEAK = 12;
const ACTION_DIMENSION_CHANGE = 13;
public $eid; public $eid;
public $action; public $action;
public $x; public $x;