mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 17:20:02 +00:00
Implement Armor changes as Transactions
This commit is contained in:
parent
f888acbd7c
commit
ee8ad6f92a
@ -57,6 +57,7 @@ use pocketmine\inventory\CraftingTransactionGroup;
|
|||||||
use pocketmine\inventory\FurnaceInventory;
|
use pocketmine\inventory\FurnaceInventory;
|
||||||
use pocketmine\inventory\Inventory;
|
use pocketmine\inventory\Inventory;
|
||||||
use pocketmine\inventory\InventoryHolder;
|
use pocketmine\inventory\InventoryHolder;
|
||||||
|
use pocketmine\inventory\PlayerInventory;
|
||||||
use pocketmine\inventory\SimpleTransactionGroup;
|
use pocketmine\inventory\SimpleTransactionGroup;
|
||||||
use pocketmine\inventory\StonecutterShapelessRecipe;
|
use pocketmine\inventory\StonecutterShapelessRecipe;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
@ -1709,50 +1710,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$tile->spawnTo($this);
|
$tile->spawnTo($this);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET:
|
case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET:
|
||||||
if($this->spawned === false or $this->blocked === true or $this->dead === true){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for($i = 0; $i < 4; ++$i){
|
|
||||||
$s = $packet->slots[$i];
|
|
||||||
if($s === 0 or $s === 255){
|
|
||||||
$s = Item::get(Item::AIR, 0, 1);
|
|
||||||
}else{
|
|
||||||
$s = Item::get($s + 256, 0, 1);
|
|
||||||
}
|
|
||||||
$slot = $this->inventory->getArmorItem($i);
|
|
||||||
if($slot->getID() !== Item::AIR and $s->getID() === Item::AIR){ //Removes a piece of armor
|
|
||||||
$this->inventory->setArmorItem($i, Item::get(Item::AIR, 0, 1), $this);
|
|
||||||
$sl = $this->inventory->firstEmpty();
|
|
||||||
if($sl === -1){
|
|
||||||
$this->inventory->sendContents($this);
|
|
||||||
}else{
|
|
||||||
$this->inventory->setItem($sl, $slot, $this);
|
|
||||||
}
|
|
||||||
$this->inventory->sendArmorContents($this);
|
|
||||||
}elseif($s->getID() !== Item::AIR and $slot->getID() === Item::AIR and ($sl = $this->inventory->first($s)) !== -1){
|
|
||||||
if($this->inventory->setArmorItem($i, $this->inventory->getItem($sl), $this) === false){
|
|
||||||
$this->inventory->sendArmorContents($this);
|
|
||||||
}else{
|
|
||||||
$this->inventory->setItem($sl, Item::get(Item::AIR, 0, 1), $this);
|
|
||||||
$this->inventory->sendArmorContents($this);
|
|
||||||
}
|
|
||||||
}elseif($s->getID() !== Item::AIR and $slot->getID() !== Item::AIR and ($slot->getID() !== $s->getID() or $slot->getDamage() !== $s->getDamage()) and ($sl = $this->inventory->first($s)) !== -1){
|
|
||||||
if($this->inventory->setArmorItem($i, $this->inventory->getItem($sl), $this) === false){
|
|
||||||
$this->inventory->sendArmorContents($this);
|
|
||||||
}else{
|
|
||||||
$this->inventory->setItem($sl, $slot, $this);
|
|
||||||
$this->inventory->sendArmorContents($this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this->inAction === true){
|
|
||||||
$this->inAction = false;
|
|
||||||
$this->sendMetadata($this->getViewers());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ProtocolInfo::INTERACT_PACKET:
|
case ProtocolInfo::INTERACT_PACKET:
|
||||||
if($this->spawned === false or $this->dead === true){
|
if($this->spawned === false or $this->dead === true){
|
||||||
break;
|
break;
|
||||||
@ -2047,7 +2008,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($packet->windowid === 0){ //Our inventory
|
if($packet->windowid === 0){ //Our inventory
|
||||||
if($packet->slot > $this->inventory->getSize()){
|
if($packet->slot >= $this->inventory->getSize()){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if($this->isCreative()){
|
if($this->isCreative()){
|
||||||
@ -2055,10 +2016,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$this->inventory->setItem($packet->slot, $packet->item);
|
$this->inventory->setItem($packet->slot, $packet->item);
|
||||||
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot); //links $hotbar[$packet->slot] to $slots[$packet->slot]
|
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot); //links $hotbar[$packet->slot] to $slots[$packet->slot]
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
|
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
|
||||||
|
}elseif($packet->windowid === 0x78){ //Our armor
|
||||||
|
if($packet->slot >= 4){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item);
|
||||||
}elseif(isset($this->windowIndex[$packet->windowid])){
|
}elseif(isset($this->windowIndex[$packet->windowid])){
|
||||||
$this->craftingType = 0;
|
$this->craftingType = 0;
|
||||||
$inv = $this->windowIndex[$packet->windowid];
|
$inv = $this->windowIndex[$packet->windowid];
|
||||||
@ -2077,6 +2042,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
if($this->currentTransaction instanceof SimpleTransactionGroup){
|
if($this->currentTransaction instanceof SimpleTransactionGroup){
|
||||||
foreach($this->currentTransaction->getInventories() as $inventory){
|
foreach($this->currentTransaction->getInventories() as $inventory){
|
||||||
$inventory->sendContents($inventory->getViewers());
|
$inventory->sendContents($inventory->getViewers());
|
||||||
|
if($inventory instanceof PlayerInventory){
|
||||||
|
$inventory->sendArmorContents($inventory->getViewers());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->currentTransaction = new SimpleTransactionGroup($this);
|
$this->currentTransaction = new SimpleTransactionGroup($this);
|
||||||
|
@ -293,13 +293,12 @@ class PlayerInventory extends BaseInventory{
|
|||||||
foreach($target as $player){
|
foreach($target as $player){
|
||||||
if($player === $this->getHolder()){
|
if($player === $this->getHolder()){
|
||||||
/** @var Player $player */
|
/** @var Player $player */
|
||||||
$pk2 = clone $pk;
|
//$pk2 = clone $pk;
|
||||||
$pk2->eid = 0;
|
//$pk2->eid = 0;
|
||||||
/*
|
|
||||||
$pk2 = new ContainerSetContentPacket;
|
$pk2 = new ContainerSetContentPacket;
|
||||||
$pk2->windowid = 0x78; //Armor window id constant
|
$pk2->windowid = 0x78; //Armor window id constant
|
||||||
$pk2->slots = $armor;
|
$pk2->slots = $armor;
|
||||||
*/
|
|
||||||
$player->dataPacket($pk2);
|
$player->dataPacket($pk2);
|
||||||
}else{
|
}else{
|
||||||
$player->dataPacket(clone $pk);
|
$player->dataPacket(clone $pk);
|
||||||
|
@ -143,6 +143,9 @@ class SimpleTransactionGroup implements TransactionGroup{
|
|||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
foreach($this->inventories as $inventory){
|
foreach($this->inventories as $inventory){
|
||||||
$inventory->sendContents($inventory->getViewers());
|
$inventory->sendContents($inventory->getViewers());
|
||||||
|
if($inventory instanceof PlayerInventory){
|
||||||
|
$inventory->sendArmorContents($inventory->getViewers());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user