mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 11:18:52 +00:00
Correct armor checks
This commit is contained in:
parent
e3e7919652
commit
45ee7ea7ae
@ -53,7 +53,7 @@ class Player{
|
|||||||
public $spawned = false;
|
public $spawned = false;
|
||||||
public $inventory;
|
public $inventory;
|
||||||
public $slot;
|
public $slot;
|
||||||
public $armor;
|
public $armor = array();
|
||||||
public $loggedIn = false;
|
public $loggedIn = false;
|
||||||
public $gamemode;
|
public $gamemode;
|
||||||
public $lastBreak;
|
public $lastBreak;
|
||||||
@ -95,7 +95,7 @@ class Player{
|
|||||||
$this->spawnPosition = $this->server->spawn;
|
$this->spawnPosition = $this->server->spawn;
|
||||||
$this->timeout = microtime(true) + 20;
|
$this->timeout = microtime(true) + 20;
|
||||||
$this->inventory = array();
|
$this->inventory = array();
|
||||||
$this->armor = array_fill(0, 4, array(AIR, 0, 0));
|
$this->armor = array();
|
||||||
$this->gamemode = $this->server->gamemode;
|
$this->gamemode = $this->server->gamemode;
|
||||||
$this->level = $this->server->api->level->getDefault();
|
$this->level = $this->server->api->level->getDefault();
|
||||||
$this->slot = 0;
|
$this->slot = 0;
|
||||||
@ -221,12 +221,16 @@ class Player{
|
|||||||
"z" => $this->spawnPosition->z,
|
"z" => $this->spawnPosition->z,
|
||||||
));
|
));
|
||||||
$inv = array();
|
$inv = array();
|
||||||
|
|
||||||
foreach($this->inventory as $slot => $item){
|
foreach($this->inventory as $slot => $item){
|
||||||
$inv[$slot] = array($item->getID(), $item->getMetadata(), $item->count);
|
$inv[$slot] = array($item->getID(), $item->getMetadata(), $item->count);
|
||||||
}
|
}
|
||||||
$this->data->set("inventory", $inv);
|
$this->data->set("inventory", $inv);
|
||||||
$this->data->set("armor", $this->armor);
|
|
||||||
|
$armor = array();
|
||||||
|
foreach($this->armor as $slot => $item){
|
||||||
|
$armor[$slot] = array($item->getID(), $item->getMetadata());
|
||||||
|
}
|
||||||
|
$this->data->set("armor", $armor);
|
||||||
$this->data->set("gamemode", $this->gamemode);
|
$this->data->set("gamemode", $this->gamemode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -378,7 +382,7 @@ class Player{
|
|||||||
public function hasItem($type, $damage = false){
|
public function hasItem($type, $damage = false){
|
||||||
foreach($this->inventory as $s => $item){
|
foreach($this->inventory as $s => $item){
|
||||||
if($item->getID() === $type and ($item->getMetadata() === $damage or $damage === false) and $item->count > 0){
|
if($item->getID() === $type and ($item->getMetadata() === $damage or $damage === false) and $item->count > 0){
|
||||||
return true;
|
return $s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -424,18 +428,10 @@ class Player{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "player.armor":
|
case "player.armor":
|
||||||
|
if($data["player"]->level === $this->level){
|
||||||
if($data["eid"] === $this->eid){
|
if($data["eid"] === $this->eid){
|
||||||
$data["eid"] = 0;
|
$data["eid"] = 0;
|
||||||
$this->armor = array();
|
|
||||||
for($i = 0; $i < 4; ++$i){
|
|
||||||
if($data["slot".$i] > 0){
|
|
||||||
$this->armor[$i] = array($data["slot".$i] + 256, 0, 1);
|
|
||||||
}else{
|
|
||||||
$this->armor[$i] = array(AIR, 0, 0);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$this->dataPacket(MC_PLAYER_ARMOR_EQUIPMENT, $data);
|
|
||||||
}elseif($data["player"]->level === $this->level){
|
|
||||||
$this->dataPacket(MC_PLAYER_ARMOR_EQUIPMENT, $data);
|
$this->dataPacket(MC_PLAYER_ARMOR_EQUIPMENT, $data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1017,7 +1013,10 @@ class Player{
|
|||||||
$this->inventory[$slot] = BlockAPI::getItem($item[0], $item[1], $item[2]);
|
$this->inventory[$slot] = BlockAPI::getItem($item[0], $item[1], $item[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->armor = $this->data->get("armor");
|
$this->armor = array();
|
||||||
|
foreach($this->data->get("armor") as $slot => $item){
|
||||||
|
$this->armor[$slot] = BlockAPI::getItem($item[0], $item[1], 1);
|
||||||
|
}
|
||||||
|
|
||||||
$this->data->set("lastIP", $this->ip);
|
$this->data->set("lastIP", $this->ip);
|
||||||
$this->data->set("lastID", $this->clientID);
|
$this->data->set("lastID", $this->clientID);
|
||||||
@ -1248,6 +1247,25 @@ class Player{
|
|||||||
$this->toCraft = array();
|
$this->toCraft = array();
|
||||||
$data["eid"] = $this->eid;
|
$data["eid"] = $this->eid;
|
||||||
$data["player"] = $this;
|
$data["player"] = $this;
|
||||||
|
for($i = 0; $i < 4; ++$i){
|
||||||
|
$s = $data["slot$i"];
|
||||||
|
if($s === 0){
|
||||||
|
$s = BlockAPI::getItem(AIR, 0, 0);
|
||||||
|
}else{
|
||||||
|
$s = BlockAPI::getItem($s + 256, 0, 1);
|
||||||
|
}
|
||||||
|
$slot = $this->armor[$i];
|
||||||
|
if($slot->getID() !== AIR and $s->getID() === AIR){
|
||||||
|
$this->addItem($slot->getID(), $slot->getMetadata(), 1);
|
||||||
|
$this->armor[$i] = BlockAPI::getItem(AIR, 0, 0);
|
||||||
|
}elseif($s->getID() !== AIR and $slot->getID() === AIR and ($sl = $this->hasItem($s->getID())) !== false){
|
||||||
|
$this->armor[$i] = $this->getSlot($sl);
|
||||||
|
$this->setSlot($sl, BlockAPI::getItem(AIR, 0, 0));
|
||||||
|
}else{
|
||||||
|
$data["slot$i"] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
$this->server->handle("player.armor", $data);
|
$this->server->handle("player.armor", $data);
|
||||||
if($this->entity->inAction === true){
|
if($this->entity->inAction === true){
|
||||||
$this->entity->inAction = false;
|
$this->entity->inAction = false;
|
||||||
@ -1581,8 +1599,24 @@ class Player{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendArmor(){
|
public function sendArmor($player = false){
|
||||||
$this->server->api->dhandle("player.armor", array("player" => $this, "eid" => $this->eid, "slot0" => ($this->armor[0][0] > 0 ? ($this->armor[0][0] - 256):AIR), "slot1" => ($this->armor[1][0] > 0 ? ($this->armor[1][0] - 256):AIR), "slot2" => ($this->armor[2][0] > 0 ? ($this->armor[2][0] - 256):AIR), "slot3" => ($this->armor[3][0] > 0 ? ($this->armor[3][0] - 256):AIR)));
|
$data = array(
|
||||||
|
"player" => $this,
|
||||||
|
"eid" => $this->eid
|
||||||
|
);
|
||||||
|
for($i = 0; $i < 4; ++$i){
|
||||||
|
if($this->armor[$i] instanceof Item){
|
||||||
|
$data["slot$i"] = $this->armor[$i]->getID() !== AIR ? $this->armor[$i]->getID() - 256:0;
|
||||||
|
}else{
|
||||||
|
$this->armor[$i] = BlockAPI::getItem(AIR, 0, 0);
|
||||||
|
$data["slot$i"] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($player instanceof Player){
|
||||||
|
$player->dataPacket(MC_PLAYER_ARMOR_EQUIPMENT, $data);
|
||||||
|
}else{
|
||||||
|
$this->server->api->dhandle("player.armor", $data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendInventory(){
|
public function sendInventory(){
|
||||||
|
@ -570,6 +570,7 @@ class Entity extends Position{
|
|||||||
"meta" => $this->player->getSlot($this->player->slot)->getMetadata(),
|
"meta" => $this->player->getSlot($this->player->slot)->getMetadata(),
|
||||||
"slot" => 0,
|
"slot" => 0,
|
||||||
));
|
));
|
||||||
|
$this->player->sendArmor($player);
|
||||||
break;
|
break;
|
||||||
case ENTITY_ITEM:
|
case ENTITY_ITEM:
|
||||||
$player->dataPacket(MC_ADD_ITEM_ENTITY, array(
|
$player->dataPacket(MC_ADD_ITEM_ENTITY, array(
|
||||||
@ -820,8 +821,8 @@ class Entity extends Position{
|
|||||||
DIAMOND_BOOTS => 3,
|
DIAMOND_BOOTS => 3,
|
||||||
);
|
);
|
||||||
foreach($this->player->armor as $part){
|
foreach($this->player->armor as $part){
|
||||||
if(isset($values[$part[0]])){
|
if($part instanceof Item and isset($values[$part->getID()])){
|
||||||
$points += $values[$part[0]];
|
$points += $values[$part->getID()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$dmg = (int) ($dmg - ($dmg * $points * 0.04));
|
$dmg = (int) ($dmg - ($dmg * $points * 0.04));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user