mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
Merge pull request #64 from kotyaralih/entityandblockqueue
networking tweaks + pumpkin/melon growth fix
This commit is contained in:
commit
5fb979cb2d
62 changed files with 1191 additions and 417 deletions
|
|
@ -81,7 +81,7 @@ class AchievementAPI{
|
|||
],
|
||||
|
||||
];
|
||||
|
||||
/** @var PocketMinecraftServer */
|
||||
private $server;
|
||||
|
||||
function __construct(){
|
||||
|
|
@ -91,9 +91,9 @@ class AchievementAPI{
|
|||
/**
|
||||
* Add an achievement
|
||||
* @param string $achievementId
|
||||
* @param string $achievementName
|
||||
* @param array $requires
|
||||
* @return boolean
|
||||
* @param string $achievementName display name
|
||||
* @param array $requires a list of achievement ids, optional
|
||||
* @return boolean true if the achievement was added. false if the achievement with this id already exists.
|
||||
*/
|
||||
public static function addAchievement($achievementId, $achievementName, array $requires = []){
|
||||
if(!isset(self::$achievements[$achievementId])){
|
||||
|
|
@ -106,6 +106,12 @@ class AchievementAPI{
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the achievement to player
|
||||
* @param Player $player
|
||||
* @param string $achievementId
|
||||
* @return boolean
|
||||
*/
|
||||
public static function grantAchievement(Player $player, $achievementId){
|
||||
if(isset(self::$achievements[$achievementId]) and !self::hasAchievement($player, $achievementId)){
|
||||
foreach(self::$achievements[$achievementId]["requires"] as $requerimentId){
|
||||
|
|
@ -124,6 +130,11 @@ class AchievementAPI{
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param string $achievementId
|
||||
* @return boolean
|
||||
*/
|
||||
public static function hasAchievement(Player $player, $achievementId){
|
||||
if(!isset(self::$achievements[$achievementId]) or !isset($player->achievements)){
|
||||
$player->achievements = [];
|
||||
|
|
@ -136,6 +147,11 @@ class AchievementAPI{
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param string $achievementId
|
||||
* @return boolean
|
||||
*/
|
||||
public static function broadcastAchievement(Player $player, $achievementId){
|
||||
if(isset(self::$achievements[$achievementId])){
|
||||
$result = ServerAPI::request()->api->dhandle("achievement.broadcast", ["player" => $player, "achievementId" => $achievementId]);
|
||||
|
|
@ -151,6 +167,11 @@ class AchievementAPI{
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes achievement from player.
|
||||
* @param Player $player
|
||||
* @param string $achievementId
|
||||
*/
|
||||
public static function removeAchievement(Player $player, $achievementId){
|
||||
if(self::hasAchievement($player, $achievementId)){
|
||||
$player->achievements[$achievementId] = false;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
<?php
|
||||
|
||||
class BanAPI{
|
||||
|
||||
/** @var PocketMinecraftServer */
|
||||
private $server;
|
||||
/*
|
||||
* I would use PHPDoc Template here but PHPStorm does not recognise it. - @sekjun9878
|
||||
*/
|
||||
/** @var Config */
|
||||
private $whitelist;
|
||||
/** @var Config */
|
||||
|
|
@ -14,10 +11,14 @@ class BanAPI{
|
|||
private $ops;
|
||||
/** @var Config */
|
||||
private $bannedIPs;
|
||||
|
||||
public $cmdWhitelist = [];//Command WhiteList
|
||||
/**
|
||||
* Contains commands that can be used by anyone on the server.
|
||||
* Keys: lowercased command name. Values don't matter.
|
||||
* @var array
|
||||
*/
|
||||
public $cmdWhitelist = [];
|
||||
|
||||
function __construct(){
|
||||
public function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +57,6 @@ class BanAPI{
|
|||
/**
|
||||
* @param mixed $data
|
||||
* @param string $event
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function permissionsCheck($data, $event){
|
||||
|
|
@ -106,11 +106,11 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks is player op or not
|
||||
* @param string $username
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isOp($username){//Is a player op?
|
||||
public function isOp($username){
|
||||
$username = strtolower($username);
|
||||
if($this->server->api->dhandle("op.check", $username) === true){
|
||||
return true;
|
||||
|
|
@ -121,6 +121,7 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Bans a player.
|
||||
* @param string $username
|
||||
*/
|
||||
public function ban($username){
|
||||
|
|
@ -316,14 +317,16 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @param string $reason
|
||||
* Kicks a player
|
||||
* @param string $username - player's username
|
||||
* @param string $reason - kick reason, optional
|
||||
*/
|
||||
public function kick($username, $reason = "No Reason"){
|
||||
$this->commandHandler("kick", [$username, $reason], "console", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbans a player
|
||||
* @param string $username
|
||||
*/
|
||||
public function pardon($username){
|
||||
|
|
@ -331,6 +334,7 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Bans some ip
|
||||
* @param string $ip
|
||||
*/
|
||||
public function banIP($ip){
|
||||
|
|
@ -338,12 +342,16 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Unbans some ip
|
||||
* @param string $ip
|
||||
*/
|
||||
public function pardonIP($ip){
|
||||
$this->commandHandler("banip", ["pardon", $ip], "console", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Rereads ban list, kick list and banip list
|
||||
*/
|
||||
public function reload(){
|
||||
$this->commandHandler("ban", ["reload"], "console", "");
|
||||
$this->commandHandler("banip", ["reload"], "console", "");
|
||||
|
|
@ -351,8 +359,8 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks is ip banned or not
|
||||
* @param string $ip
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isIPBanned($ip){
|
||||
|
|
@ -366,8 +374,8 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks is username banned or not.
|
||||
* @param string $username
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isBanned($username){
|
||||
|
|
@ -382,8 +390,8 @@ class BanAPI{
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks is username in the whitelist or not
|
||||
* @param string $username
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function inWhitelist($username){
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
class EntityAPI{
|
||||
/**
|
||||
* @var Entity[]
|
||||
*/
|
||||
public $entities;
|
||||
private $server;
|
||||
private $eCnt = 1;
|
||||
|
|
@ -181,7 +184,11 @@ class EntityAPI{
|
|||
|
||||
public function spawnToAll(Entity $e){
|
||||
foreach($this->server->api->player->getAll($e->level) as $player){
|
||||
if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){
|
||||
if($player->eid != false and $player->eid != $e->eid and $e->class != ENTITY_PLAYER and $e instanceof Entity){
|
||||
if($e->closed !== false or ($player->level !== $e->level and $e->class !== ENTITY_PLAYER)){
|
||||
return false;
|
||||
}
|
||||
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
|
|
@ -193,6 +200,7 @@ class EntityAPI{
|
|||
|
||||
public function remove($eid){
|
||||
if(isset($this->entities[$eid])){
|
||||
$e = $this->entities[$eid];
|
||||
$level = $this->entities[$eid]->level;
|
||||
$this->entities[$eid]->closed = true;
|
||||
if($level instanceof Level){
|
||||
|
|
@ -210,11 +218,17 @@ class EntityAPI{
|
|||
$pk = new RemovePlayerPacket;
|
||||
$pk->eid = $eid;
|
||||
$pk->clientID = 0;
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll(), $pk);
|
||||
foreach($this->server->api->player->getAll() as $player){
|
||||
$player->entityQueueDataPacket(clone $pk);
|
||||
$player->removeEntity($e);
|
||||
}
|
||||
}else{
|
||||
$pk = new RemoveEntityPacket;
|
||||
$pk->eid = $eid;
|
||||
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
|
||||
foreach($this->entities[$eid]->level->players as $player){
|
||||
$player->entityQueueDataPacket(clone $pk);
|
||||
$player->removeEntity($e);
|
||||
}
|
||||
}
|
||||
$this->server->api->dhandle("entity.remove", $this->entities[$eid]);
|
||||
unset($this->entities[$eid]->level->entityList[$eid]);
|
||||
|
|
@ -222,6 +236,13 @@ class EntityAPI{
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Position $center
|
||||
* @param number $radius
|
||||
* @param boolean $class
|
||||
* @return Entity[]
|
||||
*/
|
||||
public function getRadius(Position $center, $radius = 15, $class = false){
|
||||
$minChunkX = ((int)($center->x - $radius)) >> 4;
|
||||
$minChunkZ = ((int)($center->z - $radius)) >> 4;
|
||||
|
|
|
|||
|
|
@ -148,8 +148,7 @@ class PlayerAPI{
|
|||
if($additional){
|
||||
$arqCnt = count($p->packetAlwaysRecoverQueue);
|
||||
$rqCnt = count($p->recoveryQueue);
|
||||
$emps = $p->entityMovementPacketsPerSecond;
|
||||
$additionalInfo = "ARQ/RQ/EMPS: $arqCnt/$rqCnt/$emps";
|
||||
$additionalInfo = "ARQ/RQ/EMPS: $arqCnt/$rqCnt";
|
||||
}
|
||||
$chunksCnt = count($p->chunkDataSent);
|
||||
return "{$p->username}'s ping: {$ping}ms, packet loss {$pkLoss}%, $transfer KB/s. Chunks: $chunksCnt/256\n$additionalInfo";
|
||||
|
|
@ -452,7 +451,7 @@ class PlayerAPI{
|
|||
$pk->z = -256;
|
||||
$pk->yaw = 0;
|
||||
$pk->pitch = 0;
|
||||
$player->dataPacketAlwaysRecover($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -489,7 +488,7 @@ class PlayerAPI{
|
|||
$pk->z = -256;
|
||||
$pk->yaw = 0;
|
||||
$pk->pitch = 0;
|
||||
$p->dataPacket($pk);
|
||||
$p->entityQueueDataPacket($pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
687
src/Player.php
687
src/Player.php
File diff suppressed because it is too large
Load diff
|
|
@ -3,11 +3,16 @@
|
|||
class PocketMinecraftServer{
|
||||
|
||||
public $tCnt, $ticks;
|
||||
public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
|
||||
public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
|
||||
/**
|
||||
* @var ServerAPI
|
||||
*/
|
||||
public $api;
|
||||
/**
|
||||
* @var Player[]
|
||||
*/
|
||||
public $clients;
|
||||
|
||||
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0;
|
||||
|
||||
public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread;
|
||||
|
|
@ -631,9 +636,6 @@ class PocketMinecraftServer{
|
|||
|
||||
foreach($this->clients as $client){
|
||||
$client->handlePacketQueues();
|
||||
if($this->ticks % 40 == 0){ //2s
|
||||
$client->sendPing();
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->api->level->levels as $l){
|
||||
|
|
|
|||
|
|
@ -57,12 +57,10 @@ abstract class Creature extends Living{
|
|||
return 0;
|
||||
}
|
||||
public function spawn($player){
|
||||
if(!($player instanceof Player)){
|
||||
$player = $this->server->api->player->get($player);
|
||||
}
|
||||
if($player->eid === $this->eid or $this->closed !== false or ($player->level !== $this->level and $this->class !== ENTITY_PLAYER)){
|
||||
return false;
|
||||
}
|
||||
$player->addEntity($this);
|
||||
$pk = new AddMobPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->type = $this->type;
|
||||
|
|
@ -72,18 +70,19 @@ abstract class Creature extends Living{
|
|||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$pk->metadata = $this->getMetadata();
|
||||
$player->dataPacketAlwaysRecover($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->speedX = $this->speedX;
|
||||
$pk->speedY = $this->speedY;
|
||||
$pk->speedZ = $this->speedZ;
|
||||
$player->dataPacket($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
|
||||
if($this->linkedEntity != 0 && $this->isRider){
|
||||
$player->eventHandler(["rider" => $this->eid, "riding" => $this->linkedEntity, "type" => 0], "entity.link");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ class Entity extends Position
|
|||
|
||||
public $moveStrafing, $moveForward;
|
||||
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = [])
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = [])
|
||||
{
|
||||
$this->random = new XorShift128Random();
|
||||
$this->last = [&$this->lastX, &$this->lastY, &$this->lastZ, &$this->lastYaw, &$this->lastPitch, &$this->lastTime]; //pointers to variables
|
||||
|
|
@ -202,6 +202,7 @@ class Entity extends Position
|
|||
$this->outOfWorld();
|
||||
}
|
||||
}
|
||||
|
||||
public function handlePrePlayerSearcher(){
|
||||
|
||||
}
|
||||
|
|
@ -997,8 +998,10 @@ class Entity extends Position
|
|||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$pk->bodyYaw = $this->yaw;
|
||||
$this->server->api->player->broadcastPacket($players, $pk);
|
||||
$pk->bodyYaw = $this->headYaw;
|
||||
foreach($players as $player){
|
||||
if($player->hasEntity($this) && !$this->player->isInvisibleFor($player)) $player->entityQueueDataPacket(clone $pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1132,11 +1135,12 @@ class Entity extends Position
|
|||
$this->server->api->dhandle("entity.metadata", $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @return boolean
|
||||
*/
|
||||
public function spawn($player)
|
||||
{
|
||||
if(! ($player instanceof Player)){
|
||||
$player = $this->server->api->player->get($player);
|
||||
}
|
||||
if($player->eid === $this->eid or $this->closed !== false or ($player->level !== $this->level and $this->class !== ENTITY_PLAYER)){
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1145,29 +1149,44 @@ class Entity extends Position
|
|||
if($this->player->connected !== true or $this->player->spawned === false){
|
||||
return false;
|
||||
}
|
||||
if($this->player->gamemode === SPECTATOR){
|
||||
break;
|
||||
}
|
||||
|
||||
$player->addEntity($this);
|
||||
if($this->level != $player->entity->level || $this->player->gamemode === SPECTATOR) $this->player->setInvisibleFor($player, true, send:false);
|
||||
$pk = new AddPlayerPacket();
|
||||
$pkm = new MovePlayerPacket();
|
||||
$pk->clientID = 0; // $this->player->clientID;
|
||||
$pk->username = $this->player->username;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->yaw = 0;
|
||||
$pk->pitch = 0;
|
||||
$pkm->eid = $pk->eid = $this->eid;
|
||||
|
||||
if($this->player->isInvisibleFor($player)){
|
||||
$pkm->x = $pk->x = -256;
|
||||
$pkm->y = $pk->y = 128;
|
||||
$pkm->z = $pk->z = -256;
|
||||
$pkm->yaw = $pk->yaw = 0;
|
||||
$pkm->pitch = $pk->pitch = 0;
|
||||
$pkm->bodyYaw = 0;
|
||||
}else{
|
||||
$pkm->x = $pk->x = $this->x;
|
||||
$pkm->y = $pk->y = $this->y;
|
||||
$pkm->z = $pk->z = $this->z;
|
||||
$pkm->yaw = $pk->yaw = $this->yaw;
|
||||
$pkm->pitch = $pk->pitch = $this->pitch;
|
||||
$pkm->bodyYaw = $this->headYaw;
|
||||
}
|
||||
|
||||
$pk->itemID = 0;
|
||||
$pk->itemAuxValue = 0;
|
||||
$pk->metadata = $this->getMetadata();
|
||||
$player->dataPacketAlwaysRecover($pk, 2, true);
|
||||
|
||||
$player->entityQueueDataPacket($pk);
|
||||
//AddPlayerPacket doesnt read yaw correctly in vanilla(uses PacketUtil::Rot_degreesToChar instead of PacketUtil::Rot_charToDegrees)
|
||||
$player->entityQueueDataPacket($pkm);
|
||||
|
||||
$pk = new PlayerEquipmentPacket();
|
||||
$pk->eid = $this->eid;
|
||||
$pk->item = $this->player->getSlot($this->player->slot)->getID();
|
||||
$pk->meta = $this->player->getSlot($this->player->slot)->getMetadata();
|
||||
$pk->slot = 0;
|
||||
$player->dataPacket($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
$this->player->sendArmor($player);
|
||||
break;
|
||||
}
|
||||
|
|
@ -1461,8 +1480,8 @@ class Entity extends Position
|
|||
if(isset($this->level->entityList[$this->linkedEntity])){
|
||||
$e = $this->level->entityList[$this->linkedEntity];
|
||||
if(!$e->dead && !$e->closed){
|
||||
$this->server->api->dhandle("entity.link", ["rider" => $this->eid, "riding" => -1, "type" => 1]);
|
||||
$this->server->api->dhandle("entity.link", ["rider" => $this->linkedEntity, "riding" => -1, "type" => 1]);
|
||||
$this->server->api->dhandle("entity.link", ["rider" => $this->eid, "riding" => 0, "type" => 1]);
|
||||
$this->server->api->dhandle("entity.link", ["rider" => $this->linkedEntity, "riding" => 0, "type" => 1]);
|
||||
$this->isRider = false;
|
||||
$this->linkedEntity = 0;
|
||||
$e->linkedEntity = 0;
|
||||
|
|
@ -1515,7 +1534,7 @@ class Entity extends Position
|
|||
public function sendMoveUpdate()
|
||||
{
|
||||
if($this->class === ENTITY_PLAYER){
|
||||
$this->player->teleport(new Vector3($this->x, $this->y, $this->z), false, false, true, false);
|
||||
//$this->player->teleport(new Vector3($this->x, $this->y, $this->z), false, false, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1597,20 +1616,14 @@ class Entity extends Position
|
|||
$pk->eid = $this->eid;
|
||||
$pk->event = EntityEventPacket::ENTITY_DAMAGE;
|
||||
foreach($this->level->players as $p){
|
||||
if(($p->entity instanceof Entity) && $p->entity->eid == $this->eid){
|
||||
$pk2 = clone $pk;
|
||||
$pk2->eid = 0;
|
||||
$p->dataPacket($pk2);
|
||||
}else{
|
||||
$p->dataPacket(clone $pk);
|
||||
}
|
||||
if($p->hasEntity($this)) $p->entityQueueDataPacket(clone $pk);
|
||||
}
|
||||
}
|
||||
|
||||
if($this->player instanceof Player){
|
||||
$pk = new SetHealthPacket();
|
||||
$pk->health = $this->health;
|
||||
$this->player->dataPacket($pk);
|
||||
if($this->player->hasEntity($this)) $this->player->entityQueueDataPacket($pk);
|
||||
}
|
||||
if($this->health <= 0 and $this->dead === false){
|
||||
$this->makeDead($cause);
|
||||
|
|
@ -1647,12 +1660,16 @@ class Entity extends Position
|
|||
$pk->z = -256;
|
||||
$pk->yaw = 0;
|
||||
$pk->pitch = 0;
|
||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
foreach($this->level->players as $player){
|
||||
if($player->hasEntity($this)) $player->entityQueueDataPacket(clone $pk);
|
||||
}
|
||||
}else{
|
||||
$pk = new EntityEventPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->event = EntityEventPacket::ENTITY_DEAD;
|
||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
foreach($this->level->players as $player){
|
||||
if($player->hasEntity($this)) $player->entityQueueDataPacket(clone $pk);
|
||||
}
|
||||
}
|
||||
|
||||
if($this->player instanceof Player){
|
||||
|
|
|
|||
|
|
@ -198,8 +198,11 @@ abstract class Projectile extends Entity{
|
|||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function spawn($player)
|
||||
{
|
||||
$player->addEntity($this);
|
||||
|
||||
$pk = new AddEntityPacket();
|
||||
$pk->eid = $this->eid;
|
||||
$pk->type = $this->type;
|
||||
|
|
@ -210,7 +213,8 @@ abstract class Projectile extends Entity{
|
|||
$pk->speedY = $this->speedY;
|
||||
$pk->speedZ = $this->speedZ;
|
||||
$pk->did = 0;
|
||||
$player->dataPacketAlwaysRecover($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,7 +5,9 @@ class TaskEatTileGoal extends TaskBase
|
|||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->selfCounter = 40;
|
||||
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, new EntityEventPacket($ai->entity->eid, EntityEventPacket::ENTITY_ANIM_10));
|
||||
foreach($ai->entity->level->players as $player){
|
||||
if($player->hasEntity($ai->entity)) $player->entityQueueDataPacket(new EntityEventPacket($ai->entity->eid, EntityEventPacket::ENTITY_ANIM_10));
|
||||
}
|
||||
}
|
||||
|
||||
public function onEnd(EntityAI $ai)
|
||||
|
|
|
|||
|
|
@ -47,16 +47,6 @@ class Arrow extends Entity{
|
|||
$data["shotByPlayer"] = $this->shotByPlayer;
|
||||
return $data;
|
||||
}
|
||||
public function handleUpdate(){
|
||||
$pk = new MoveEntityPacket_PosRot;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
}
|
||||
|
||||
public function shoot($d, $d1, $d2, $f, $f1){ //original name from 0.8.1 IDA decompilation, var names are taken from b1.7.3
|
||||
$f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2);
|
||||
|
|
@ -262,6 +252,7 @@ class Arrow extends Entity{
|
|||
|
||||
public function spawn($player){
|
||||
if($this->type === OBJECT_ARROW){
|
||||
$player->addEntity($this);
|
||||
$pk = new AddEntityPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->type = $this->type;
|
||||
|
|
@ -272,7 +263,7 @@ class Arrow extends Entity{
|
|||
$pk->speedX = $this->speedX;
|
||||
$pk->speedY = $this->speedY;
|
||||
$pk->speedZ = $this->speedZ;
|
||||
$player->dataPacketAlwaysRecover($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class FallingSand extends Entity{
|
|||
}
|
||||
public function spawn($player)
|
||||
{
|
||||
$player->addEntity($this);
|
||||
$pk = new AddEntityPacket();
|
||||
$pk->eid = $this->eid;
|
||||
$pk->type = $this->type;
|
||||
|
|
@ -31,7 +32,7 @@ class FallingSand extends Entity{
|
|||
$pk->speedY = $this->speedY;
|
||||
$pk->speedZ = $this->speedZ;
|
||||
$pk->did = -$this->data["Tile"];
|
||||
$player->dataPacketAlwaysRecover($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
}
|
||||
|
||||
public function update($now){
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class ItemEntity extends Entity{
|
|||
|
||||
public function spawn($player)
|
||||
{
|
||||
$player->addEntity($this);
|
||||
$pk = new AddItemEntityPacket();
|
||||
$pk->eid = $this->eid;
|
||||
$pk->x = $this->x;
|
||||
|
|
@ -54,14 +55,14 @@ class ItemEntity extends Entity{
|
|||
$pk->roll = 0;
|
||||
$pk->item = BlockAPI::getItem($this->itemID, $this->meta, $this->stack);
|
||||
$pk->metadata = $this->getMetadata();
|
||||
$player->dataPacketAlwaysRecover($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket();
|
||||
$pk->eid = $this->eid;
|
||||
$pk->speedX = $this->speedX;
|
||||
$pk->speedY = $this->speedY;
|
||||
$pk->speedZ = $this->speedZ;
|
||||
$player->dataPacket($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -427,6 +427,7 @@ class Minecart extends Vehicle{
|
|||
}
|
||||
|
||||
public function spawn($player){
|
||||
$player->addEntity($this);
|
||||
$pk = new AddEntityPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->type = $this->type;
|
||||
|
|
@ -435,14 +436,14 @@ class Minecart extends Vehicle{
|
|||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$player->dataPacketAlwaysRecover($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->speedX = $this->speedX;
|
||||
$pk->speedY = $this->speedY;
|
||||
$pk->speedZ = $this->speedZ;
|
||||
$player->dataPacket($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
|
|
|
|||
|
|
@ -198,6 +198,7 @@ class Painting extends Entity{
|
|||
}
|
||||
|
||||
public function spawn($player){
|
||||
$player->addEntity($this);
|
||||
$pk = new AddPaintingPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->x = (int) $this->xPos;
|
||||
|
|
@ -205,6 +206,6 @@ class Painting extends Entity{
|
|||
$pk->z = (int) $this->zPos;
|
||||
$pk->direction = $this->direction;
|
||||
$pk->title = $this->motive;
|
||||
$player->dataPacketAlwaysRecover($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ class PrimedTNT extends Entity{
|
|||
}
|
||||
|
||||
public function spawn($player){
|
||||
$player->addEntity($this);
|
||||
$pk = new AddEntityPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->type = $this->type;
|
||||
|
|
@ -76,6 +77,6 @@ class PrimedTNT extends Entity{
|
|||
$pk->speedX = $this->speedX;
|
||||
$pk->speedY = $this->speedY;
|
||||
$pk->speedZ = $this->speedZ;
|
||||
$player->dataPacketAlwaysRecover($pk);
|
||||
$player->entityQueueDataPacket($pk);
|
||||
}
|
||||
}
|
||||
|
|
@ -208,7 +208,7 @@ class DoorBlock extends TransparentBlock{
|
|||
$pk->z = $this->z;
|
||||
$pk->evid = 1003;
|
||||
$pk->data = 0;
|
||||
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
|
||||
ServerAPI::request()->api->player->broadcastPacket($players, $pk); //TODO use block queue?
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class FenceGateBlock extends TransparentBlock{
|
|||
$pk->z = $this->z;
|
||||
$pk->evid = 1003;
|
||||
$pk->data = 0;
|
||||
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
|
||||
ServerAPI::request()->api->player->broadcastPacket($players, $pk); //TODO use blok queue?
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ class BeetrootBlock extends FlowableBlock{
|
|||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ class CactusBlock extends TransparentBlock{
|
|||
$block3 = $this->getSide(5);
|
||||
if($block0->isFlowable === true and $block1->isFlowable === true and $block2->isFlowable === true and $block3->isFlowable === true){
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, BLOCK_UPDATE_NORMAL);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ class CarrotBlock extends FlowableBlock{
|
|||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -13,39 +13,83 @@ class MelonStemBlock extends FlowableBlock{
|
|||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getGrowthSpeed(Level $level, $x, $y, $z){
|
||||
$zneg = $level->level->getBlockID($x, $y, $z-1);
|
||||
$zpos = $level->level->getBlockID($x, $y, $z+1);
|
||||
$xneg = $level->level->getBlockID($x-1, $y, $z);
|
||||
$xpos = $level->level->getBlockID($x+1, $y, $z);
|
||||
$znxn = $level->level->getBlockID($x-1, $y, $z-1);
|
||||
$znxp = $level->level->getBlockID($x+1, $y, $z-1);
|
||||
$zpxp = $level->level->getBlockID($x+1, $y, $z+1);
|
||||
$zpxn = $level->level->getBlockID($x-1, $y, $z+1);
|
||||
$xEqual = $xneg == MELON_STEM || $xpos == MELON_STEM;
|
||||
$zEqual = $zneg == MELON_STEM || $zpos == MELON_STEM;
|
||||
$xzEqual = $znxn == MELON_STEM || $znxp == MELON_STEM || $zpxn == MELON_STEM || $zpxp == MELON_STEM;
|
||||
|
||||
$speed = 1;
|
||||
for($xx = $x-1; $xx >= $x+1; ++$xx){
|
||||
for($zz = $z-1; $zz >= $z+1; ++$zz){
|
||||
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
||||
$v18 = 0;
|
||||
if($id == FARMLAND) $v18 = $meta > 0 ? 3 : 1;
|
||||
if($xx != $x || $zz != $z) $v18 *= 0.25;
|
||||
$speed += $v18;
|
||||
}
|
||||
}
|
||||
if($xzEqual || ($xEqual && $zEqual)) return $speed*0.5;
|
||||
return $speed;
|
||||
}
|
||||
|
||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||
if(mt_rand(0, 2) == 1){
|
||||
$block = $level->level->getBlock($x, $y, $z);
|
||||
if($block[1] < 0x07){
|
||||
//++$this->meta;
|
||||
//$this->level->setBlock($this, $this, true, false, true);
|
||||
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
|
||||
}else{
|
||||
|
||||
$position = new AirBlock(); //feke block
|
||||
$position->x = $x;
|
||||
$position->y = $y;
|
||||
$position->z = $z;
|
||||
$position->level = $level;
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$b = $position->getSide($side);
|
||||
if($b->getID() === MELON_BLOCK){
|
||||
return;
|
||||
}
|
||||
}
|
||||
$side = $position->getSide(mt_rand(2,5));
|
||||
$d = $side->getSide(0);
|
||||
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
|
||||
$level->setBlock($side, new MelonBlock(), true, false, true);
|
||||
}
|
||||
//TODO checkAlive
|
||||
//if ( Level::getRawBrightness(a2, a3, a4 + 1, a5) > 8 ) TODO - skylight
|
||||
|
||||
$growSpeed = static::getGrowthSpeed($level, $x, $y, $z);
|
||||
$rand = mt_rand(0, (int)(25/$growSpeed));
|
||||
if($rand != 0) return;
|
||||
|
||||
$meta = $level->level->getBlockDamage($x, $y, $z);
|
||||
if($meta <= 6){
|
||||
$level->fastSetBlockUpdateMeta($x, $y, $z, $meta+1);
|
||||
return;
|
||||
}
|
||||
|
||||
$xn = $level->level->getBlockID($x-1, $y, $z);
|
||||
$xp = $level->level->getBlockID($x+1, $y, $z);
|
||||
$zn = $level->level->getBlockID($x, $y, $z-1);
|
||||
$zp = $level->level->getBlockID($x, $y, $z+1);
|
||||
if($xn != MELON_BLOCK && $xp != MELON_BLOCK && $zn != MELON_BLOCK && $zp != MELON_BLOCK){
|
||||
$below = $level->level->getBlockID($x-1, $y-1, $z);
|
||||
if($level->level->getBlockID($x-1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
|
||||
$level->fastSetBlockUpdate($x-1, $y, $z, MELON_BLOCK, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
$below = $level->level->getBlockID($x+1, $y-1, $z);
|
||||
if($level->level->getBlockID($x+1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
|
||||
$level->fastSetBlockUpdate($x+1, $y, $z, MELON_BLOCK, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
$below = $level->level->getBlockID($x, $y-1, $z-1);
|
||||
if($level->level->getBlockID($x, $y, $z-1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
|
||||
$level->fastSetBlockUpdate($x, $y, $z-1, MELON_BLOCK, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
$below = $level->level->getBlockID($x, $y-1, $z+1);
|
||||
if($level->level->getBlockID($x, $y, $z+1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
|
||||
$level->fastSetBlockUpdate($x, $y, $z+1, MELON_BLOCK, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
|
||||
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
|
||||
|
|
@ -68,14 +112,8 @@ class MelonStemBlock extends FlowableBlock{
|
|||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
$drops = [];
|
||||
if($this->meta >= 0x07){
|
||||
$drops[] = [MELON_SEEDS, 0, mt_rand(1, 2)];
|
||||
}
|
||||
elseif($this->meta >= 0x01 and $this->meta <= 0x07){
|
||||
$drops[] = [MELON_SEEDS, 0, 1];
|
||||
}
|
||||
else{
|
||||
$drops[] = [MELON_SEEDS, 0, 0];
|
||||
for($i = 0; $i < 3; ++$i){
|
||||
if(mt_rand(0, 15) <= $this->meta) $drops[] = [MELON_SEEDS, 0, 1];
|
||||
}
|
||||
return $drops;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ class PotatoBlock extends FlowableBlock{
|
|||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -10,39 +10,82 @@ class PumpkinStemBlock extends FlowableBlock{
|
|||
$this->material = Material::$plant;
|
||||
}
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getGrowthSpeed(Level $level, $x, $y, $z){
|
||||
$zneg = $level->level->getBlockID($x, $y, $z-1);
|
||||
$zpos = $level->level->getBlockID($x, $y, $z+1);
|
||||
$xneg = $level->level->getBlockID($x-1, $y, $z);
|
||||
$xpos = $level->level->getBlockID($x+1, $y, $z);
|
||||
$znxn = $level->level->getBlockID($x-1, $y, $z-1);
|
||||
$znxp = $level->level->getBlockID($x+1, $y, $z-1);
|
||||
$zpxp = $level->level->getBlockID($x+1, $y, $z+1);
|
||||
$zpxn = $level->level->getBlockID($x-1, $y, $z+1);
|
||||
$xEqual = $xneg == PUMPKIN_STEM || $xpos == PUMPKIN_STEM;
|
||||
$zEqual = $zneg == PUMPKIN_STEM || $zpos == PUMPKIN_STEM;
|
||||
$xzEqual = $znxn == PUMPKIN_STEM || $znxp == PUMPKIN_STEM || $zpxn == PUMPKIN_STEM || $zpxp == PUMPKIN_STEM;
|
||||
|
||||
$speed = 1;
|
||||
for($xx = $x-1; $xx >= $x+1; ++$xx){
|
||||
for($zz = $z-1; $zz >= $z+1; ++$zz){
|
||||
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
||||
if($id == FARMLAND) $v18 = $meta > 0 ? 3 : 1;
|
||||
else $v18 = 0;
|
||||
if($xx != $x || $zz != $z) $v18 *= 0.25;
|
||||
$speed += $v18;
|
||||
}
|
||||
}
|
||||
if($xzEqual || ($xEqual && $zEqual)) return $speed*0.5;
|
||||
return $speed;
|
||||
}
|
||||
|
||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||
if(mt_rand(0, 2) == 1){
|
||||
$block = $level->level->getBlock($x, $y, $z);
|
||||
if($block[1] < 0x07){
|
||||
//++$this->meta;
|
||||
//$this->level->setBlock($this, $this, true, false, true);
|
||||
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
|
||||
}else{
|
||||
|
||||
$position = new AirBlock(); //feke block
|
||||
$position->x = $x;
|
||||
$position->y = $y;
|
||||
$position->z = $z;
|
||||
$position->level = $level;
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$b = $position->getSide($side);
|
||||
if($b->getID() === PUMPKIN){
|
||||
return;
|
||||
}
|
||||
}
|
||||
$side = $position->getSide(mt_rand(2,5));
|
||||
$d = $side->getSide(0);
|
||||
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
|
||||
$level->setBlock($side, new PumpkinBlock(), true, false, true);
|
||||
}
|
||||
//TODO checkAlive
|
||||
//if ( Level::getRawBrightness(a2, a3, a4 + 1, a5) > 8 ) TODO - skylight
|
||||
|
||||
$growSpeed = static::getGrowthSpeed($level, $x, $y, $z);
|
||||
$rand = mt_rand(0, (int)(25/$growSpeed));
|
||||
if($rand != 0) return;
|
||||
|
||||
$meta = $level->level->getBlockDamage($x, $y, $z);
|
||||
if($meta <= 6){
|
||||
$level->fastSetBlockUpdateMeta($x, $y, $z, $meta+1);
|
||||
return;
|
||||
}
|
||||
|
||||
$xn = $level->level->getBlockID($x-1, $y, $z);
|
||||
$xp = $level->level->getBlockID($x+1, $y, $z);
|
||||
$zn = $level->level->getBlockID($x, $y, $z-1);
|
||||
$zp = $level->level->getBlockID($x, $y, $z+1);
|
||||
if($xn != PUMPKIN && $xp != PUMPKIN && $zn != PUMPKIN && $zp != PUMPKIN){
|
||||
$below = $level->level->getBlockID($x-1, $y-1, $z);
|
||||
if($level->level->getBlockID($x-1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
|
||||
$level->fastSetBlockUpdate($x-1, $y, $z, PUMPKIN, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
$below = $level->level->getBlockID($x+1, $y-1, $z);
|
||||
if($level->level->getBlockID($x+1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
|
||||
$level->fastSetBlockUpdate($x+1, $y, $z, PUMPKIN, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
$below = $level->level->getBlockID($x, $y-1, $z-1);
|
||||
if($level->level->getBlockID($x, $y, $z-1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
|
||||
$level->fastSetBlockUpdate($x, $y, $z-1, PUMPKIN, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
$below = $level->level->getBlockID($x, $y-1, $z+1);
|
||||
if($level->level->getBlockID($x, $y, $z+1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
|
||||
$level->fastSetBlockUpdate($x, $y, $z+1, PUMPKIN, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -68,14 +111,8 @@ class PumpkinStemBlock extends FlowableBlock{
|
|||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
$drops = [];
|
||||
if($this->meta >= 0x07){
|
||||
$drops[] = [PUMPKIN_SEEDS, 0, mt_rand(1, 2)];
|
||||
}
|
||||
elseif($this->meta >= 0x01 and $this->meta <= 0x07){
|
||||
$drops[] = [PUMPKIN_SEEDS, 0, 1];
|
||||
}
|
||||
else{
|
||||
$drops[] = [PUMPKIN_SEEDS, 0, 0];
|
||||
for($i = 0; $i < 3; ++$i){
|
||||
if(mt_rand(0, 15) <= $this->meta) $drops[] = [PUMPKIN_SEEDS, 0, 1];
|
||||
}
|
||||
return $drops;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ class SaplingBlock extends FlowableBlock{
|
|||
$down = $this->getSide(0);
|
||||
if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ class WheatBlock extends FlowableBlock{
|
|||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ class IceBlock extends TransparentBlock{
|
|||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,35 @@ abstract class ProtocolInfo{
|
|||
const ADVENTURE_SETTINGS_PACKET = 0xb7;
|
||||
const ENTITY_DATA_PACKET = 0xb8;
|
||||
const PLAYER_INPUT_PACKET = 0xb9;
|
||||
|
||||
|
||||
const EID_PACKETS = [
|
||||
self::ADD_MOB_PACKET => true,
|
||||
self::ADD_ITEM_ENTITY_PACKET => true,
|
||||
self::RESPAWN_PACKET => true,
|
||||
self::SET_ENTITY_MOTION_PACKET => true,
|
||||
self::USE_ITEM_PACKET => true,
|
||||
self::SET_ENTITY_DATA_PACKET => true,
|
||||
self::PLAYER_ARMOR_EQUIPMENT_PACKET => true,
|
||||
self::ROTATE_HEAD_PACKET => true,
|
||||
self::PLAYER_EQUIPMENT_PACKET => true,
|
||||
self::SEND_INVENTORY_PACKET => true,
|
||||
self::INTERACT_PACKET => true,
|
||||
self::ENTITY_EVENT_PACKET => true,
|
||||
self::PLAYER_ACTION_PACKET => true,
|
||||
self::REMOVE_ENTITY_PACKET => true,
|
||||
self::ANIMATE_PACKET => true,
|
||||
self::ADD_PLAYER_PACKET => true,
|
||||
self::TAKE_ITEM_ENTITY_PACKET => true,
|
||||
self::START_GAME_PACKET => true,
|
||||
self::ADD_PAINTING_PACKET => true,
|
||||
self::REMOVE_PLAYER_PACKET => true,
|
||||
self::MOVE_ENTITY_PACKET_POSROT => true,
|
||||
self::ADD_ENTITY_PACKET => true,
|
||||
self::REMOVE_BLOCK_PACKET => true,
|
||||
self::MOVE_PLAYER_PACKET => true,
|
||||
self::DROP_ITEM_PACKET => true,
|
||||
self::SET_ENTITY_LINK_PACKET => true
|
||||
];
|
||||
}
|
||||
/*Unused:
|
||||
* 0xb5
|
||||
|
|
|
|||
|
|
@ -33,5 +33,14 @@ class AddEntityPacket extends RakNetDataPacket{
|
|||
$this->putShort((int)($this->speedZ * 8000));
|
||||
}
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -29,5 +29,12 @@ class AddItemEntityPacket extends RakNetDataPacket{
|
|||
$this->putByte($this->pitch);
|
||||
$this->putByte($this->roll);
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -29,5 +29,13 @@ class AddMobPacket extends RakNetDataPacket{
|
|||
$this->putByte($this->pitch);
|
||||
$this->put(Utils::writeMetadata($this->metadata));
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -25,5 +25,13 @@ class AddPaintingPacket extends RakNetDataPacket{
|
|||
$this->putInt($this->direction);
|
||||
$this->putString($this->title);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -46,5 +46,13 @@ class AddPlayerPacket extends RakNetDataPacket{
|
|||
$this->putShort($this->itemAuxValue); //Example: bow shooting power
|
||||
$this->put(Utils::writeMetadata($this->metadata));
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -22,4 +22,21 @@ class AnimatePacket extends RakNetDataPacket{
|
|||
$this->putInt($this->eid);
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,5 +18,13 @@ class DropItemPacket extends RakNetDataPacket{
|
|||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,10 @@ class EntityEventPacket extends RakNetDataPacket{
|
|||
|
||||
const ENTITY_DAMAGE = 2;
|
||||
const ENTITY_DEAD = 3;
|
||||
/**
|
||||
* Works only for player entities
|
||||
*/
|
||||
const ENTITY_COMPLETE_USING_ITEM = 9;
|
||||
const ENTITY_ANIM_10 = 10;
|
||||
|
||||
public function __construct($eid = null, $event = null){
|
||||
|
|
@ -27,5 +31,21 @@ class EntityEventPacket extends RakNetDataPacket{
|
|||
$this->putInt($this->eid);
|
||||
$this->putByte($this->event);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,5 +24,24 @@ class InteractPacket extends RakNetDataPacket{
|
|||
$this->putInt($this->eid);
|
||||
$this->putInt($this->target);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
$this->target = $p->global2localEID[$this->target] ?? false;
|
||||
if($this->eid === false || $this->target === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
$this->target = $p->local2GlobalEID[$this->target] ?? false;
|
||||
if($this->eid === false || $this->target === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -32,4 +32,20 @@ class MoveEntityPacket_PosRot extends RakNetDataPacket{
|
|||
$this->putFloat($this->pitch);
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -34,4 +34,20 @@ class MovePlayerPacket extends RakNetDataPacket{
|
|||
$this->putFloat($this->bodyYaw);
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,5 +24,13 @@ class PlayerActionPacket extends RakNetDataPacket{
|
|||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,5 +24,22 @@ class PlayerArmorEquipmentPacket extends RakNetDataPacket{
|
|||
$this->putByte($this->slots[2]);
|
||||
$this->putByte($this->slots[3]);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,5 +24,22 @@ class PlayerEquipmentPacket extends RakNetDataPacket{
|
|||
$this->putShort($this->meta);
|
||||
$this->putByte($this->slot);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,4 +21,12 @@ class RemoveBlockPacket extends RakNetDataPacket{
|
|||
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,5 +15,13 @@ class RemoveEntityPacket extends RakNetDataPacket{
|
|||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,4 +18,12 @@ class RemovePlayerPacket extends RakNetDataPacket{
|
|||
$this->putLong($this->clientID);
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,5 +24,12 @@ class RespawnPacket extends RakNetDataPacket{
|
|||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -26,4 +26,21 @@ class RotateHeadPacket extends RakNetDataPacket{
|
|||
$this->putByte($this->rawYaw ? $this->yaw : ($this->yaw / 360 / 0.0039062)); //wraps 360 angle to 0xff
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -38,5 +38,23 @@ class SendInventoryPacket extends RakNetDataPacket{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -17,5 +17,13 @@ class SetEntityDataPacket extends RakNetDataPacket{
|
|||
$this->putInt($this->eid);
|
||||
$this->put(Utils::writeMetadata($this->metadata));
|
||||
}
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -28,4 +28,23 @@ class SetEntityLinkPacket extends RakNetDataPacket{
|
|||
return ProtocolInfo::SET_ENTITY_LINK_PACKET;
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->rider = $p->local2GlobalEID[$this->rider] ?? false;
|
||||
$this->riding = $p->local2GlobalEID[$this->riding] ?? false;
|
||||
if($this->rider === false || $this->riding === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->rider = $p->global2localEID[$this->rider] ?? false;
|
||||
$this->riding = $p->global2localEID[$this->riding] ?? false;
|
||||
if($this->rider === false || $this->riding === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,5 +21,12 @@ class SetEntityMotionPacket extends RakNetDataPacket{
|
|||
$this->putShort((int) ($this->speedY * 8000));
|
||||
$this->putShort((int) ($this->speedZ * 8000));
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -27,5 +27,13 @@ class StartGamePacket extends RakNetDataPacket{
|
|||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,4 +18,14 @@ class TakeItemEntityPacket extends RakNetDataPacket{
|
|||
$this->putInt($this->eid);
|
||||
}
|
||||
|
||||
//TODO convert
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
$this->target = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false || $this->target === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -38,5 +38,13 @@ class UseItemPacket extends RakNetDataPacket{
|
|||
public function encode(){
|
||||
|
||||
}
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,6 +106,9 @@ class RakNetCodec{
|
|||
or $pk->reliability === 7){
|
||||
$packet->buffer .= Utils::writeLTriad($pk->messageIndex);
|
||||
}
|
||||
if($pk->reliability == 1 || $pk->reliability == 4){
|
||||
$packet->buffer .= Utils::writeLTriad($pk->seqIndex);
|
||||
}
|
||||
|
||||
if($pk->reliability === 1
|
||||
or $pk->reliability === 3
|
||||
|
|
|
|||
|
|
@ -11,12 +11,21 @@ abstract class RakNetDataPacket extends stdClass{
|
|||
public $splitCount;
|
||||
public $splitID;
|
||||
public $splitIndex;
|
||||
public $seqIndex;
|
||||
private $offset = 0;
|
||||
|
||||
abstract public function encode();
|
||||
public abstract function encode();
|
||||
|
||||
abstract public function decode();
|
||||
public abstract function decode();
|
||||
|
||||
public $localEids = false;
|
||||
public function eidsToLocal(Player $p){
|
||||
return true;
|
||||
}
|
||||
public function eidsToGlobal(Player $p){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getBuffer(){
|
||||
return $this->buffer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
class RakNetPacket extends Packet{
|
||||
|
||||
public $packetID;
|
||||
|
||||
public $seqNumber;
|
||||
public $sendtime;
|
||||
|
||||
public function __construct($packetID){
|
||||
$this->packetID = (int) $packetID;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,12 @@ class RakNetParser{
|
|||
}else{
|
||||
$messageIndex = false;
|
||||
}
|
||||
if($reliability == 1 || $reliability == 4){
|
||||
$offset += 3;
|
||||
$seqIndex = Utils::readTriad(strrev(substr($buffer, $offset - 3, 3)));
|
||||
}else{
|
||||
$seqIndex = false;
|
||||
}
|
||||
|
||||
if($reliability == 1 ||$reliability == 3 || $reliability == 4 || $reliability == 7){
|
||||
$offset += 3;
|
||||
|
|
@ -228,6 +234,8 @@ class RakNetParser{
|
|||
$data->splitCount = $splitCount;
|
||||
$data->splitID = $splitID;
|
||||
$data->splitIndex = $splitIndex;
|
||||
$data->seqIndex = $seqIndex;
|
||||
$data->localEids = true;
|
||||
$data->setBuffer($buf);
|
||||
}
|
||||
return $data;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class PMFLevel extends PMF{
|
|||
@mkdir($dirname , 0755);
|
||||
}
|
||||
|
||||
$this->hasLight = str_repeat("\x00", 16*16);
|
||||
for($index = 0; $index < $cnt; ++$index){
|
||||
$this->chunks[$index] = false;
|
||||
$this->chunkChange[$index] = false;
|
||||
|
|
|
|||
|
|
@ -1,16 +1,10 @@
|
|||
<?php
|
||||
|
||||
class Explosion{
|
||||
|
||||
public static $specialDrops = [
|
||||
GRASS => DIRT,
|
||||
STONE => COBBLESTONE,
|
||||
COAL_ORE => COAL,
|
||||
DIAMOND_ORE => DIAMOND,
|
||||
REDSTONE_ORE => REDSTONE,
|
||||
];
|
||||
public static $enableExplosions = true;
|
||||
public $level; //Rays
|
||||
/** @var Level */
|
||||
public $level;
|
||||
/** @var Position */
|
||||
public $source;
|
||||
public $size;
|
||||
public $affectedBlocks = [];
|
||||
|
|
@ -91,18 +85,20 @@ class Explosion{
|
|||
$pk->speedX = $entity->speedX;
|
||||
$pk->speedY = $entity->speedY;
|
||||
$pk->speedZ = $entity->speedZ;
|
||||
$entity->player->dataPacket($pk);
|
||||
$entity->player->entityQueueDataPacket($pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$pk = new ExplodePacket; //sound fix
|
||||
$pk = new ExplodePacket;
|
||||
$pk->x = $this->source->x;
|
||||
$pk->y = $this->source->y;
|
||||
$pk->z = $this->source->z;
|
||||
$pk->radius = $this->size;
|
||||
$pk->records = [];
|
||||
$server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
$pk->records = []; //ExplodePacket doesnt seem to use the records provided by this packet, so no need to send more data
|
||||
foreach ($this->level->players as $player){
|
||||
$player->blockQueueDataPacket($pk);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", [
|
||||
|
|
@ -153,10 +149,7 @@ class Explosion{
|
|||
$this->sub_expl($i, $mRays, $j, $k);
|
||||
}
|
||||
}
|
||||
//if($i == 0 or $i == $mRays or $j == 0 or $j == $mRays or $k == 0 or $k == $mRays){
|
||||
|
||||
|
||||
$send = [];
|
||||
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
||||
$distance = $this->source->distance($entity);
|
||||
$distByRad = $distance / $this->size;
|
||||
|
|
@ -179,7 +172,7 @@ class Explosion{
|
|||
$pk->speedX = $entity->speedX;
|
||||
$pk->speedY = $entity->speedY;
|
||||
$pk->speedZ = $entity->speedZ;
|
||||
$entity->player->dataPacket($pk);
|
||||
$entity->player->entityQueueDataPacket($pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -191,7 +184,7 @@ class Explosion{
|
|||
$x = $xyz >> 16;
|
||||
$z = $xyz >> 8 & 0xff;
|
||||
$y = $xyz & 0xff;
|
||||
//console("$x $y $z $id $meta");
|
||||
|
||||
if($id === TNT){
|
||||
$data = [
|
||||
"x" => $x + 0.5,
|
||||
|
|
@ -212,14 +205,22 @@ class Explosion{
|
|||
}
|
||||
}
|
||||
$this->level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||
$send[] = $xyz;
|
||||
}
|
||||
|
||||
$pk = new ExplodePacket;
|
||||
$pk->x = $this->source->x;
|
||||
$pk->y = $this->source->y;
|
||||
$pk->z = $this->source->z;
|
||||
$pk->radius = $this->size;
|
||||
$pk->records = $send;
|
||||
$server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
$pk->records = []; //ExplodePacket doesnt seem to use the records provided by this packet, so no need to send more data
|
||||
foreach ($this->level->players as $player){
|
||||
$player->blockQueueDataPacket($pk);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated unused
|
||||
*/
|
||||
public static $specialDrops = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -395,7 +395,7 @@ class Level{
|
|||
$this->server->api->time->set("day", $this);
|
||||
}
|
||||
foreach($this->players as $p){
|
||||
$p->stopSleep();
|
||||
if($p->isSleeping) $p->stopSleep();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -817,6 +817,7 @@ class Level{
|
|||
|
||||
|
||||
foreach($this->players as $player){
|
||||
if(!$player->spawned) continue;
|
||||
foreach($post as $eid){
|
||||
$e = $this->entityList[$eid] ?? false;
|
||||
if(!($e instanceof Entity)){
|
||||
|
|
|
|||
|
|
@ -283,7 +283,10 @@ class Tile extends Position{
|
|||
$pk->z = $this->z;
|
||||
$pk->case1 = 1;
|
||||
$pk->case2 = 2;
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk);
|
||||
foreach($this->level->players as $player){
|
||||
$player->blockQueueDataPacket(clone $pk);
|
||||
}
|
||||
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s){
|
||||
$slot = $this->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
|
|
@ -297,7 +300,7 @@ class Tile extends Position{
|
|||
$pk = new ContainerSetContentPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->slots = $slots;
|
||||
$player->dataPacket($pk);
|
||||
$player->blockQueueDataPacket($pk);
|
||||
return true;
|
||||
}elseif($this->class === TILE_FURNACE){
|
||||
$player->windowCnt++;
|
||||
|
|
@ -311,7 +314,7 @@ class Tile extends Position{
|
|||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$player->dataPacket($pk);
|
||||
$player->blockQueueDataPacket($pk);
|
||||
|
||||
$slots = [];
|
||||
for($s = 0; $s < FURNACE_SLOTS; ++$s){
|
||||
|
|
@ -325,7 +328,7 @@ class Tile extends Position{
|
|||
$pk = new ContainerSetContentPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->slots = $slots;
|
||||
$player->dataPacket($pk);
|
||||
$player->blockQueueDataPacket($pk);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -375,7 +378,7 @@ class Tile extends Position{
|
|||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->namedtag = $nbt->binary;
|
||||
$player->dataPacketAlwaysRecover($pk);
|
||||
$player->blockQueueDataPacket($pk);
|
||||
break;
|
||||
case TILE_SIGN:
|
||||
$nbt = new NBT();
|
||||
|
|
@ -420,7 +423,7 @@ class Tile extends Position{
|
|||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->namedtag = $nbt->binary;
|
||||
$player->dataPacketAlwaysRecover($pk);
|
||||
$player->blockQueueDataPacket($pk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue