mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 20:49:43 +00:00
feat: getProtocol()
This commit is contained in:
parent
896eb736f0
commit
5b4110b285
6 changed files with 41 additions and 12 deletions
|
|
@ -665,7 +665,7 @@ class BlockAPI{
|
||||||
|
|
||||||
private function cancelAction(Block $block, Player $player, $send = true){
|
private function cancelAction(Block $block, Player $player, $send = true){
|
||||||
$player->addBlockUpdateIntoQueue($block->x, $block->y, $block->z, $block->getID(), $block->getMetadata());
|
$player->addBlockUpdateIntoQueue($block->x, $block->y, $block->z, $block->getID(), $block->getMetadata());
|
||||||
if($send === true && $player->PROTOCOL >= ProtocolInfo12::CURRENT_PROTOCOL_11){
|
if($send === true && $player->getProtocol() >= ProtocolInfo12::CURRENT_PROTOCOL_11){
|
||||||
$player->sendInventory();
|
$player->sendInventory();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -533,7 +533,7 @@ class PlayerAPI{
|
||||||
public static function decodeProtocol($ip, $port){
|
public static function decodeProtocol($ip, $port){
|
||||||
foreach(ServerAPI::request()->clients as $p) {
|
foreach(ServerAPI::request()->clients as $p) {
|
||||||
if($p->ip == $ip && $p->port == $port){
|
if($p->ip == $ip && $p->port == $port){
|
||||||
return $p->PROTOCOL;
|
return $p->getProtocol();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ class Player{
|
||||||
public $CID;
|
public $CID;
|
||||||
public $MTU;
|
public $MTU;
|
||||||
public $spawned = false;
|
public $spawned = false;
|
||||||
public $PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL;
|
|
||||||
/**
|
/**
|
||||||
* Stores player inventory. Should not be accessed directly: use Player::addItem/Player::removeItem/Player::setSlot for setting and Player::getSlot for getting.
|
* Stores player inventory. Should not be accessed directly: use Player::addItem/Player::removeItem/Player::setSlot for setting and Player::getSlot for getting.
|
||||||
* @var array
|
* @var array
|
||||||
|
|
@ -86,6 +85,7 @@ class Player{
|
||||||
private $clientID;
|
private $clientID;
|
||||||
private $ip;
|
private $ip;
|
||||||
private $port;
|
private $port;
|
||||||
|
private $PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL;
|
||||||
private $counter = [0, 0, 0, 0];
|
private $counter = [0, 0, 0, 0];
|
||||||
public $username;
|
public $username;
|
||||||
public $iusername;
|
public $iusername;
|
||||||
|
|
@ -300,6 +300,35 @@ class Player{
|
||||||
return $this->spawnPosition;
|
return $this->spawnPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getVersion():string{
|
||||||
|
return match ($this->PROTOCOL) {
|
||||||
|
14 => "v 0.8.1 Alpha",
|
||||||
|
13 => "v 0.8.0 Alpha",
|
||||||
|
12 => "v 0.7.6 Alpha",
|
||||||
|
11 => "v 0.7.1 Alpha",
|
||||||
|
10 => "v 0.6.1 Alpha",
|
||||||
|
9 => "v 0.6.1 Alpha",
|
||||||
|
8 => "v 0.5.0j Alpha",
|
||||||
|
7 => "v 0.4.0 Alpha",
|
||||||
|
6 => "v 0.3.3 Alpha",
|
||||||
|
5 => "v 0.3.2 Alpha",
|
||||||
|
4 => "v 0.3.0 Alpha",
|
||||||
|
3 => "v 0.2.1 Alpha",
|
||||||
|
18 => "v 0.10.5 Alpha",
|
||||||
|
default => "v 0.8.1 Alpha",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getProtocol():int{
|
||||||
|
return $this->PROTOCOL;
|
||||||
|
}
|
||||||
|
|
||||||
public function setBedPosition(?Position $bedPos){
|
public function setBedPosition(?Position $bedPos){
|
||||||
if($bedPos != null) $this->bedPosition = [$bedPos->level->getName(), (int)$bedPos->x, (int)$bedPos->y, (int)$bedPos->z];
|
if($bedPos != null) $this->bedPosition = [$bedPos->level->getName(), (int)$bedPos->x, (int)$bedPos->y, (int)$bedPos->z];
|
||||||
else $this->bedPosition = null;
|
else $this->bedPosition = null;
|
||||||
|
|
|
||||||
|
|
@ -1634,7 +1634,7 @@ class Entity extends Position
|
||||||
$part->hurtAndBreak($v2, $this->player, helditem: false);
|
$part->hurtAndBreak($v2, $this->player, helditem: false);
|
||||||
if($part->count <= 0) $this->player->setArmor($slot, BlockAPI::getItem(0, 0, 0), send: false);
|
if($part->count <= 0) $this->player->setArmor($slot, BlockAPI::getItem(0, 0, 0), send: false);
|
||||||
}
|
}
|
||||||
if($this->player->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12 && $this->player->PROTOCOL > ProtocolInfo8::CURRENT_PROTOCOL_8){
|
if($this->player->getProtocol() < ProtocolInfo12::CURRENT_PROTOCOL_12 && $this->player->getProtocol() > ProtocolInfo8::CURRENT_PROTOCOL_8){
|
||||||
$pk = new HurtArmorPacket();
|
$pk = new HurtArmorPacket();
|
||||||
$pk->health = $v2; //TODO: Verify the real attack health for it
|
$pk->health = $v2; //TODO: Verify the real attack health for it
|
||||||
$this->player->entityQueueDataPacket($pk);
|
$this->player->entityQueueDataPacket($pk);
|
||||||
|
|
@ -1721,11 +1721,11 @@ class Entity extends Position
|
||||||
$this->updateMetadata();
|
$this->updateMetadata();
|
||||||
$this->dead = true;
|
$this->dead = true;
|
||||||
if($this->player instanceof Player){
|
if($this->player instanceof Player){
|
||||||
if($this->player->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){
|
if($this->player->getProtocol() < ProtocolInfo12::CURRENT_PROTOCOL_12){
|
||||||
$this->player->isWorkbench = false;
|
$this->player->isWorkbench = false;
|
||||||
$this->player->isStoneCutter = false;
|
$this->player->isStoneCutter = false;
|
||||||
if(!self::$keepInventory) {
|
if(!self::$keepInventory) {
|
||||||
if ($this->player->PROTOCOL <= ProtocolInfo8::CURRENT_PROTOCOL_8) {
|
if ($this->player->getProtocol() <= ProtocolInfo8::CURRENT_PROTOCOL_8) {
|
||||||
$pk = new EntityEventPacket;
|
$pk = new EntityEventPacket;
|
||||||
$pk->eid = $this->eid;
|
$pk->eid = $this->eid;
|
||||||
$pk->event = EntityEventPacket::ENTITY_DEAD;
|
$pk->event = EntityEventPacket::ENTITY_DEAD;
|
||||||
|
|
|
||||||
|
|
@ -739,13 +739,13 @@ class CraftingRecipes{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$craftneededItemCnt = self::getCraftNumber($craftItem, $type, $player->PROTOCOL);
|
$craftneededItemCnt = self::getCraftNumber($craftItem, $type, $player->getProtocol());
|
||||||
|
|
||||||
if(!$craftneededItemCnt){
|
if(!$craftneededItemCnt){
|
||||||
goto failed_to_craft;
|
goto failed_to_craft;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($player->PROTOCOL <= 6 && $type === self::TYPE_CRAFTIGTABLE && $items = self::getMCPE032CycleBlockType($player, $craftItem->getID(), $craftItem->getMetadata())){
|
if($player->getProtocol() <= 6 && $type === self::TYPE_CRAFTIGTABLE && $items = self::getMCPE032CycleBlockType($player, $craftItem->getID(), $craftItem->getMetadata())){
|
||||||
$itemsSolid = self::getMCPE032CycleBlockType($player, $craftItem->getID(), $craftItem->getMetadata(), true);
|
$itemsSolid = self::getMCPE032CycleBlockType($player, $craftItem->getID(), $craftItem->getMetadata(), true);
|
||||||
if(!isset($player->isOre[$itemsSolid->getID()]) && $itemsSolid->count){
|
if(!isset($player->isOre[$itemsSolid->getID()]) && $itemsSolid->count){
|
||||||
$player->isOre[$itemsSolid->getID()] = true;
|
$player->isOre[$itemsSolid->getID()] = true;
|
||||||
|
|
@ -807,7 +807,7 @@ class CraftingRecipes{
|
||||||
}elseif(self::getEnoughItem($player, $item[0], (($item[1] === "?") ? false : $item[1]), $needCraftCnt) !== false) {
|
}elseif(self::getEnoughItem($player, $item[0], (($item[1] === "?") ? false : $item[1]), $needCraftCnt) !== false) {
|
||||||
$slot = $player->hasItem($item[0], (($item[1] === "?") ? false : $item[1]));
|
$slot = $player->hasItem($item[0], (($item[1] === "?") ? false : $item[1]));
|
||||||
$player->addCraftingIngridient($slot, $item[0], ($item[1] === "?") ? 65535 : $item[1], $needCraftCnt);
|
$player->addCraftingIngridient($slot, $item[0], ($item[1] === "?") ? 65535 : $item[1], $needCraftCnt);
|
||||||
}elseif($player->PROTOCOL <= 6 && $type === CraftingRecipes::TYPE_CRAFTIGTABLE && ($items = self::getMCPE032CycleBlockType($player, $item[0], (($item[1] === "?") ? false : $item[1]))) !== false && ($player->getItemCount($item[0], (($item[1] === "?") ? false : $item[1])) || isset($player->isOre[$item[0]]) === true)) {
|
}elseif($player->getProtocol() <= 6 && $type === CraftingRecipes::TYPE_CRAFTIGTABLE && ($items = self::getMCPE032CycleBlockType($player, $item[0], (($item[1] === "?") ? false : $item[1]))) !== false && ($player->getItemCount($item[0], (($item[1] === "?") ? false : $item[1])) || isset($player->isOre[$item[0]]) === true)) {
|
||||||
$slot = $player->hasItem($item[0], (($item[1] === "?") ? false : $item[1]));
|
$slot = $player->hasItem($item[0], (($item[1] === "?") ? false : $item[1]));
|
||||||
$result = BlockAPI::getItem($item[0], ($item[1] === "?") ? 65535 : $item[1], $needCraftCnt-$items->count);
|
$result = BlockAPI::getItem($item[0], ($item[1] === "?") ? 65535 : $item[1], $needCraftCnt-$items->count);
|
||||||
self::tryCraft($player, $recipeItems, $result, $type, 1);
|
self::tryCraft($player, $recipeItems, $result, $type, 1);
|
||||||
|
|
@ -823,7 +823,7 @@ class CraftingRecipes{
|
||||||
$need = $item[2]*ceil($toCraftCnt/$craftneededItemCnt) - $cnt%$item[2];
|
$need = $item[2]*ceil($toCraftCnt/$craftneededItemCnt) - $cnt%$item[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($forwardResult = self::getRecipe(BlockAPI::getItem($item[0],(($item[1] === "?") ? false : $item[1]),$item[2]), $type, $player->PROTOCOL)) !== false){
|
if(($forwardResult = self::getRecipe(BlockAPI::getItem($item[0],(($item[1] === "?") ? false : $item[1]),$item[2]), $type, $player->getProtocol())) !== false){
|
||||||
$craftingItem = BlockAPI::getItem($item[0], (($item[1] === "?") ? false : $item[1]), $need);
|
$craftingItem = BlockAPI::getItem($item[0], (($item[1] === "?") ? false : $item[1]), $need);
|
||||||
if (self::tryCraft($player, $forwardResult, $craftingItem, $type, $depth)) {
|
if (self::tryCraft($player, $forwardResult, $craftingItem, $type, $depth)) {
|
||||||
$slot = $player->hasItem($craftingItem->getID(), (($item[1] === "?") ? false : $item[1]));
|
$slot = $player->hasItem($craftingItem->getID(), (($item[1] === "?") ? false : $item[1]));
|
||||||
|
|
@ -834,7 +834,7 @@ class CraftingRecipes{
|
||||||
}else{
|
}else{
|
||||||
goto failed_to_craft;
|
goto failed_to_craft;
|
||||||
}
|
}
|
||||||
}elseif (($forwardResult = self::getRecipe(BlockAPI::getItem($item[0],(($item[1] === "?") ? false : $item[1]),$item[2]), $type, $player->PROTOCOL)) !== false) {
|
}elseif (($forwardResult = self::getRecipe(BlockAPI::getItem($item[0],(($item[1] === "?") ? false : $item[1]),$item[2]), $type, $player->getProtocol())) !== false) {
|
||||||
$craftingItem = BlockAPI::getItem($item[0], (($item[1] === "?") ? false : $item[1]), $needCraftCnt);
|
$craftingItem = BlockAPI::getItem($item[0], (($item[1] === "?") ? false : $item[1]), $needCraftCnt);
|
||||||
if (self::tryCraft($player, $forwardResult, $craftingItem, $type, $depth)) {
|
if (self::tryCraft($player, $forwardResult, $craftingItem, $type, $depth)) {
|
||||||
$slot = $player->hasItem($craftingItem->getID(), (($item[1] === "?") ? false : $item[1]));
|
$slot = $player->hasItem($craftingItem->getID(), (($item[1] === "?") ? false : $item[1]));
|
||||||
|
|
|
||||||
|
|
@ -412,7 +412,7 @@ class Tile extends Position{
|
||||||
|
|
||||||
$nbt->write(chr(NBT::TAG_END));
|
$nbt->write(chr(NBT::TAG_END));
|
||||||
|
|
||||||
if($player->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){
|
if($player->getProtocol() < ProtocolInfo12::CURRENT_PROTOCOL_12){
|
||||||
$line1 = mb_substr($this->data["Text1"], 0, 15);
|
$line1 = mb_substr($this->data["Text1"], 0, 15);
|
||||||
$line2 = mb_substr($this->data["Text2"], 0, 15);
|
$line2 = mb_substr($this->data["Text2"], 0, 15);
|
||||||
$line3 = mb_substr($this->data["Text3"], 0, 15);
|
$line3 = mb_substr($this->data["Text3"], 0, 15);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue