mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
@ -35,7 +35,6 @@ use pocketmine\event\block\SignChangeEvent;
|
||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||
use pocketmine\event\entity\EntityDamageByEntityEvent;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||
use pocketmine\event\entity\EntityShootBowEvent;
|
||||
use pocketmine\event\entity\ProjectileLaunchEvent;
|
||||
use pocketmine\event\inventory\CraftItemEvent;
|
||||
@ -50,6 +49,7 @@ use pocketmine\event\player\PlayerChatEvent;
|
||||
use pocketmine\event\player\PlayerCommandPreprocessEvent;
|
||||
use pocketmine\event\player\PlayerDeathEvent;
|
||||
use pocketmine\event\player\PlayerDropItemEvent;
|
||||
use pocketmine\event\player\PlayerExhaustEvent;
|
||||
use pocketmine\event\player\PlayerGameModeChangeEvent;
|
||||
use pocketmine\event\player\PlayerInteractEvent;
|
||||
use pocketmine\event\player\PlayerItemConsumeEvent;
|
||||
@ -123,6 +123,7 @@ use pocketmine\network\protocol\SetTimePacket;
|
||||
use pocketmine\network\protocol\StartGamePacket;
|
||||
use pocketmine\network\protocol\TakeItemEntityPacket;
|
||||
use pocketmine\network\protocol\TextPacket;
|
||||
use pocketmine\network\protocol\UpdateAttributesPacket;
|
||||
use pocketmine\network\protocol\UpdateBlockPacket;
|
||||
use pocketmine\network\SourceInterface;
|
||||
use pocketmine\permission\PermissibleBase;
|
||||
@ -245,7 +246,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
/**
|
||||
* This might disappear in the future.
|
||||
* Please use getUniqueId() instead (IP + clientId + name combo, in the future it'll change to real UUID for online auth)
|
||||
* Please use getUniqueId() instead (IP + clientId + name combo, in the future it'll change to real UUID for online
|
||||
* auth)
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
@ -484,7 +486,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
return $this->perm->getEffectivePermissions();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param SourceInterface $interface
|
||||
* @param null $clientID
|
||||
@ -600,7 +601,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
public function isSleeping(){
|
||||
return $this->sleeping !== null;
|
||||
}
|
||||
|
||||
|
||||
public function getInAirTicks(){
|
||||
return $this->inAirTicks;
|
||||
}
|
||||
@ -855,7 +856,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
$this->loadQueue = $newOrder;
|
||||
|
||||
|
||||
Timings::$playerChunkOrderTimer->stopTiming();
|
||||
|
||||
return true;
|
||||
@ -986,12 +986,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
$this->level->sleepTicks = 60;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the spawnpoint of the player (and the compass direction) to a Vector3, or set it on another world with a Position object
|
||||
* Sets the spawnpoint of the player (and the compass direction) to a Vector3, or set it on another world with a
|
||||
* Position object
|
||||
*
|
||||
* @param Vector3|Position $pos
|
||||
*/
|
||||
@ -1017,7 +1017,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0]);
|
||||
$this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false);
|
||||
|
||||
|
||||
$this->level->sleepTicks = 0;
|
||||
|
||||
$pk = new AnimatePacket();
|
||||
@ -1025,7 +1024,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$pk->action = 3; //Wake up
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1213,6 +1211,23 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
return false;
|
||||
}
|
||||
|
||||
public function entityBaseTick($tickDiff = 1){
|
||||
$hasUpdate = parent::entityBaseTick($tickDiff);
|
||||
|
||||
$entries = $this->attributeMap->needSend();
|
||||
if(count($entries) > 0){
|
||||
$pk = new UpdateAttributesPacket();
|
||||
$pk->entityId = 0;
|
||||
$pk->entries = $entries;
|
||||
$this->dataPacket($pk);
|
||||
foreach($entries as $entry){
|
||||
$entry->markSynchronized();
|
||||
}
|
||||
}
|
||||
|
||||
return $hasUpdate;
|
||||
}
|
||||
|
||||
protected function checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz){
|
||||
if(!$this->onGround or $movY != 0){
|
||||
$bb = clone $this->boundingBox;
|
||||
@ -1448,7 +1463,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
}
|
||||
|
||||
protected function updateMovement(){
|
||||
|
||||
}
|
||||
|
||||
public function onUpdate($currentTick){
|
||||
@ -1531,7 +1545,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->server->batchPackets([$this], $this->batchedPackets, false);
|
||||
$this->batchedPackets = [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function canInteract(Vector3 $pos, $maxDistance, $maxDiff = 0.5){
|
||||
@ -1612,7 +1625,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
$this->allowFlight = $this->isCreative();
|
||||
|
||||
|
||||
if(($level = $this->server->getLevelByName($nbt["Level"])) === null){
|
||||
$this->setLevel($this->server->getDefaultLevel());
|
||||
$nbt["Level"] = $this->level->getName();
|
||||
@ -1631,7 +1643,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
$this->achievements = [];
|
||||
|
||||
/** @var Byte $achievement */
|
||||
/** @var ByteTag $achievement */
|
||||
foreach($nbt->Achievements as $achievement){
|
||||
$this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false;
|
||||
}
|
||||
@ -1752,7 +1764,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$timings = Timings::getReceiveDataPacketTimings($packet);
|
||||
|
||||
$timings->startTiming();
|
||||
@ -1950,7 +1961,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
|
||||
|
||||
if(!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()){
|
||||
|
||||
}elseif($this->isCreative()){
|
||||
$item = $this->inventory->getItemInHand();
|
||||
if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){
|
||||
@ -2082,7 +2092,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$nbt = new CompoundTag("", [
|
||||
"Pos" => new ListTag("Pos", [
|
||||
new DoubleTag("", $this->x),
|
||||
@ -2255,7 +2264,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
$vector = new Vector3($packet->x, $packet->y, $packet->z);
|
||||
|
||||
|
||||
if($this->isCreative()){
|
||||
$item = $this->inventory->getItemInHand();
|
||||
}else{
|
||||
@ -2270,6 +2278,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->inventory->setItemInHand($item);
|
||||
$this->inventory->sendHeldItem($this->hasSpawned);
|
||||
}
|
||||
|
||||
$this->exhaust(0.025, PlayerExhaustEvent::CAUSE_MINING);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -2309,7 +2319,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
if(
|
||||
$target instanceof Player and
|
||||
$this->server->getConfigBoolean("pvp", true) === false
|
||||
|
||||
){
|
||||
$cancelled = true;
|
||||
}
|
||||
@ -2407,16 +2416,19 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
break;
|
||||
}
|
||||
|
||||
if($item->isTool() and $this->isSurvival()){
|
||||
if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){
|
||||
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1));
|
||||
}else{
|
||||
$this->inventory->setItemInHand($item);
|
||||
if($this->isSurvival()){
|
||||
if($item->isTool()){
|
||||
if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){
|
||||
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1));
|
||||
}else{
|
||||
$this->inventory->setItemInHand($item);
|
||||
}
|
||||
}
|
||||
|
||||
$this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case ProtocolInfo::ANIMATE_PACKET:
|
||||
if($this->spawned === false or !$this->isAlive()){
|
||||
@ -2444,65 +2456,19 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); //TODO: check if this should be true
|
||||
|
||||
switch($packet->event){
|
||||
case 9: //Eating
|
||||
$items = [ //TODO: move this to item classes
|
||||
Item::APPLE => 4,
|
||||
Item::MUSHROOM_STEW => 10,
|
||||
Item::BEETROOT_SOUP => 10,
|
||||
Item::BREAD => 5,
|
||||
Item::RAW_PORKCHOP => 3,
|
||||
Item::COOKED_PORKCHOP => 8,
|
||||
Item::RAW_BEEF => 3,
|
||||
Item::STEAK => 8,
|
||||
Item::COOKED_CHICKEN => 6,
|
||||
Item::RAW_CHICKEN => 2,
|
||||
Item::MELON_SLICE => 2,
|
||||
Item::GOLDEN_APPLE => 10,
|
||||
Item::PUMPKIN_PIE => 8,
|
||||
Item::CARROT => 4,
|
||||
Item::POTATO => 1,
|
||||
Item::BAKED_POTATO => 6,
|
||||
Item::COOKIE => 2,
|
||||
Item::COOKED_FISH => [
|
||||
0 => 5,
|
||||
1 => 6
|
||||
],
|
||||
Item::RAW_FISH => [
|
||||
0 => 2,
|
||||
1 => 2,
|
||||
2 => 1,
|
||||
3 => 1
|
||||
],
|
||||
];
|
||||
case EntityEventPacket::USE_ITEM: //Eating
|
||||
$slot = $this->inventory->getItemInHand();
|
||||
if($this->getHealth() < $this->getMaxHealth() and isset($items[$slot->getId()])){
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $slot));
|
||||
if($ev->isCancelled()){
|
||||
|
||||
if($slot->canBeConsumed()){
|
||||
$ev = new PlayerItemConsumeEvent($this, $slot);
|
||||
if(!$slot->canBeConsumedBy($this)){
|
||||
$ev->setCancelled();
|
||||
}
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
if(!$ev->isCancelled()){
|
||||
$slot->onConsume($this);
|
||||
}else{
|
||||
$this->inventory->sendContents($this);
|
||||
break;
|
||||
}
|
||||
|
||||
$pk = new EntityEventPacket();
|
||||
$pk->eid = $this->getId();
|
||||
$pk->event = EntityEventPacket::USE_ITEM;
|
||||
$this->dataPacket($pk);
|
||||
Server::broadcastPacket($this->getViewers(), $pk);
|
||||
|
||||
$amount = $items[$slot->getId()];
|
||||
if(is_array($amount)){
|
||||
$amount = isset($amount[$slot->getDamage()]) ? $amount[$slot->getDamage()] : 0;
|
||||
}
|
||||
$ev = new EntityRegainHealthEvent($this, $amount, EntityRegainHealthEvent::CAUSE_EATING);
|
||||
$this->heal($ev->getAmount(), $ev);
|
||||
|
||||
--$slot->count;
|
||||
$this->inventory->setItemInHand($slot);
|
||||
if($slot->getId() === Item::MUSHROOM_STEW or $slot->getId() === Item::BEETROOT_SOUP){
|
||||
$this->inventory->addItem(Item::get(Item::BOWL, 0, 1));
|
||||
}elseif($slot->getId() === Item::RAW_FISH and $slot->getDamage() === 3){ //Pufferfish
|
||||
//$this->addEffect(Effect::getEffect(Effect::HUNGER)->setAmplifier(2)->setDuration(15 * 20));
|
||||
$this->addEffect(Effect::getEffect(Effect::NAUSEA)->setAmplifier(1)->setDuration(15 * 20));
|
||||
$this->addEffect(Effect::getEffect(Effect::POISON)->setAmplifier(3)->setDuration(60 * 20));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -2604,7 +2570,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
$canCraft = true;
|
||||
|
||||
|
||||
if($recipe instanceof ShapedRecipe){
|
||||
for($x = 0; $x < 3 and $canCraft; ++$x){
|
||||
for($y = 0; $y < 3; ++$y){
|
||||
@ -2792,7 +2757,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < (microtime(true) - 8)){
|
||||
if($this->currentTransaction !== null){
|
||||
foreach($this->currentTransaction->getInventories() as $inventory){
|
||||
@ -2934,7 +2898,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
return;
|
||||
}
|
||||
$message = $message->getText();
|
||||
|
||||
}
|
||||
|
||||
$mes = explode("\n", $this->server->getLanguage()->translateString($message));
|
||||
@ -3225,7 +3188,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
Entity::kill();
|
||||
@ -3246,7 +3208,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS);
|
||||
}
|
||||
|
||||
|
||||
$pk = new RespawnPacket();
|
||||
$pos = $this->getSpawn();
|
||||
$pk->x = $pos->x;
|
||||
@ -3288,6 +3249,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$pk->eid = 0;
|
||||
$pk->event = EntityEventPacket::HURT_ANIMATION;
|
||||
$this->dataPacket($pk);
|
||||
|
||||
if($this->isSurvival()){
|
||||
$this->exhaust(0.3, PlayerExhaustEvent::CAUSE_DAMAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3431,7 +3396,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->forceMovement = new Vector3($this->x, $this->y, $this->z);
|
||||
$this->sendPosition($this, $this->yaw, $this->pitch, 1);
|
||||
|
||||
|
||||
$this->resetFallDistance();
|
||||
$this->orderChunks();
|
||||
$this->nextChunkOrderRun = 0;
|
||||
@ -3439,7 +3403,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Inventory $inventory
|
||||
*
|
||||
@ -3507,25 +3470,20 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin);
|
||||
}
|
||||
|
||||
|
||||
public function onChunkChanged(FullChunk $chunk){
|
||||
$this->loadQueue[Level::chunkHash($chunk->getX(), $chunk->getZ())] = abs(($this->x >> 4) - $chunk->getX()) + abs(($this->z >> 4) - $chunk->getZ());
|
||||
}
|
||||
|
||||
public function onChunkLoaded(FullChunk $chunk){
|
||||
|
||||
}
|
||||
|
||||
public function onChunkPopulated(FullChunk $chunk){
|
||||
|
||||
}
|
||||
|
||||
public function onChunkUnloaded(FullChunk $chunk){
|
||||
|
||||
}
|
||||
|
||||
public function onBlockChanged(Vector3 $block){
|
||||
|
||||
}
|
||||
|
||||
public function getLoaderId(){
|
||||
@ -3537,9 +3495,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $chunkX
|
||||
* @param $chunkZ
|
||||
* @param $payload
|
||||
* @param int $chunkX
|
||||
* @param int $chunkZ
|
||||
* @param string $payload
|
||||
* @param int $ordering
|
||||
*
|
||||
* @return DataPacket
|
||||
*/
|
||||
|
Reference in New Issue
Block a user