Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

Code Updates for PMMP 3.19.0, fix for #448 #449

Merged
merged 9 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: PureEntitiesX
main: revivalpmmp\pureentities\PureEntities
version: 0.6.9
api: [3.11.8]
version: 0.7.0
api: 3.19.0

load: STARTUP
authors: ["milk0417", "RevivalPMMP"]
authors: ["milk0417", "RevivalPMMP", "supercrafter333"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove your username from the authors list. There are a large number of contributors to this project and it is preferred that people look at Github to get a full list of everyone's contributions. That is why the website is included in the plugin details.

description: Implement all MCPE entities into your worlds
website: https://github.com/RevivalPMMP/PureEntitiesX

Expand Down
47 changes: 26 additions & 21 deletions src/revivalpmmp/pureentities/components/MobEquipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use pocketmine\item\IronHelmet;
use pocketmine\item\IronLeggings;
use pocketmine\item\Item;
use pocketmine\item\ItemIds;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the use of ItemIds to Item is not required to be compatible with 3.19.0. Please revert all related changes and open a separate PR to handle this.

use pocketmine\item\LeatherBoots;
use pocketmine\item\LeatherCap;
use pocketmine\item\LeatherPants;
Expand All @@ -54,6 +53,7 @@
use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket;
use pocketmine\network\mcpe\protocol\MobEquipmentPacket;
use pocketmine\network\mcpe\protocol\TakeItemActorPacket;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use pocketmine\Player;
use pocketmine\Server;
use revivalpmmp\pureentities\config\mobequipment\EntityConfig;
Expand Down Expand Up @@ -337,19 +337,19 @@ public function addLoot(array $existingDrops){
// see: http://minecraft.gamepedia.com/Sword (section: mobs)
if(mt_rand(0, 100) <= 9){
// drop all equipment
if($this->mainHand !== null && $this->mainHand->getId() !== ItemIds::AIR){
if($this->mainHand !== null && $this->mainHand->getId() !== Item::AIR){
array_push($existingDrops, $this->mainHand);
}
if($this->helmet !== null && $this->helmet->getId() !== ItemIds::AIR){
if($this->helmet !== null && $this->helmet->getId() !== Item::AIR){
array_push($existingDrops, $this->helmet);
}
if($this->boots !== null && $this->boots->getId() !== ItemIds::AIR){
if($this->boots !== null && $this->boots->getId() !== Item::AIR){
array_push($existingDrops, $this->boots);
}
if($this->chestplate !== null && $this->chestplate->getId() !== ItemIds::AIR){
if($this->chestplate !== null && $this->chestplate->getId() !== Item::AIR){
array_push($existingDrops, $this->chestplate);
}
if($this->leggings !== null && $this->leggings->getId() !== ItemIds::AIR){
if($this->leggings !== null && $this->leggings->getId() !== Item::AIR){
array_push($existingDrops, $this->leggings);
}
}
Expand Down Expand Up @@ -437,7 +437,7 @@ private function getWeaponDamage() : int{
private function getChestplateArmorPoints() : int{
$armor = 0;
$item = $this->getChestplate();
if($item !== null && $item->getId() !== ItemIds::AIR){
if($item !== null && $item->getId() !== Item::AIR){
if($item instanceof LeatherTunic){
$armor = 3;
}else if($item instanceof GoldChestplate){
Expand All @@ -461,7 +461,7 @@ private function getChestplateArmorPoints() : int{
private function getHelmetArmorPoints() : int{
$armor = 0;
$item = $this->getHelmet();
if($item !== null && $item->getId() !== ItemIds::AIR){
if($item !== null && $item->getId() !== Item::AIR){
if($item instanceof LeatherCap){
$armor = 1;
}else if($item instanceof GoldHelmet){
Expand All @@ -485,7 +485,7 @@ private function getHelmetArmorPoints() : int{
private function getBootsArmorPoints() : int{
$armor = 0;
$item = $this->getBoots();
if($item !== null && $item->getId() !== ItemIds::AIR){
if($item !== null && $item->getId() !== Item::AIR){
if($item instanceof LeatherBoots){
$armor = 1;
}else if($item instanceof GoldBoots){
Expand All @@ -509,7 +509,7 @@ private function getBootsArmorPoints() : int{
private function getLeggingsArmorPoints() : int{
$armor = 0;
$item = $this->getBoots();
if($item !== null && $item->getId() !== ItemIds::AIR){
if($item !== null && $item->getId() !== Item::AIR){
if($item instanceof LeatherPants){
$armor = 2;
}else if($item instanceof GoldLeggings){
Expand All @@ -529,7 +529,7 @@ private function getLeggingsArmorPoints() : int{
* @return bool
*/
private function isSwordWorn() : bool{
return $this->getMainHand() !== null and $this->getMainHand()->getId() !== ItemIds::AIR and
return $this->getMainHand() !== null and $this->getMainHand()->getId() !== Item::AIR and
($this->getMainHand() instanceof Sword);
}

Expand All @@ -539,22 +539,22 @@ private function storeToNBT(){
$armor[0] = new CompoundTag("0", [
"Count" => new IntTag("Count", 1),
"Damage" => new IntTag("Damage", 10),
"id" => new IntTag("id", $this->boots !== null ? $this->boots->getId() : ItemIds::AIR),
"id" => new IntTag("id", $this->boots !== null ? $this->boots->getId() : Item::AIR),
]);
$armor[1] = new CompoundTag("1", [
"Count" => new IntTag("Count", 1),
"Damage" => new IntTag("Damage", 10),
"id" => new IntTag("id", $this->leggings !== null ? $this->leggings->getId() : ItemIds::AIR),
"id" => new IntTag("id", $this->leggings !== null ? $this->leggings->getId() : Item::AIR),
]);
$armor[2] = new CompoundTag("2", [
"Count" => new IntTag("Count", 1),
"Damage" => new IntTag("Damage", 10),
"id" => new IntTag("id", $this->chestplate !== null ? $this->chestplate->getId() : ItemIds::AIR),
"id" => new IntTag("id", $this->chestplate !== null ? $this->chestplate->getId() : Item::AIR),
]);
$armor[3] = new CompoundTag("3", [
"Count" => new IntTag("Count", 1),
"Damage" => new IntTag("Damage", 10),
"id" => new IntTag("id", $this->helmet !== null ? $this->helmet->getId() : ItemIds::AIR),
"id" => new IntTag("id", $this->helmet !== null ? $this->helmet->getId() : Item::AIR),
]);
$armorItems = new ListTag(NBTConst::NBT_KEY_ARMOR_ITEMS, $armor);

Expand All @@ -565,7 +565,7 @@ private function storeToNBT(){
$hands[0] = new CompoundTag("0", [
"Count" => new ByteTag("Count", 1),
"Damage" => new IntTag("Damage", 10),
"id" => new IntTag("id", $this->getMainHand() !== null ? $this->getMainHand()->getId() : ItemIds::AIR),
"id" => new IntTag("id", $this->getMainHand() !== null ? $this->getMainHand()->getId() : Item::AIR),
]);
$this->entity->namedtag->setTag(new ListTag(NBTConst::NBT_KEY_HAND_ITEMS, $hands));
}
Expand Down Expand Up @@ -623,11 +623,12 @@ public function sendHandItemsToAllClients(){

private function createArmorEquipPacket() : MobArmorEquipmentPacket{
$pk = new MobArmorEquipmentPacket();
//ItemStackWrapper::legacy($this->helmet) ?? ItemStackWrapper::legacy(Item::get(Item::AIR));
$pk->entityRuntimeId = $this->entity->getId();
$pk->head = $this->helmet ?? Item::get(ItemIds::AIR);
$pk->chest = $this->chestplate ?? Item::get(ItemIds::AIR);
$pk->legs = $this->leggings ?? Item::get(ItemIds::AIR);
$pk->feet = $this->boots ?? Item::get(ItemIds::AIR);
$pk->head = $this->helmet ? ItemStackWrapper::legacy($this->helmet) : ItemStackWrapper::legacy(Item::get(Item::AIR));
$pk->chest = $this->helmet ? ItemStackWrapper::legacy($this->chestplate) : ItemStackWrapper::legacy(Item::get(Item::AIR));
$pk->legs = $this->helmet ? ItemStackWrapper::legacy($this->leggings) : ItemStackWrapper::legacy(Item::get(Item::AIR));
$pk->feet = $this->helmet ? ItemStackWrapper::legacy($this->boots) : ItemStackWrapper::legacy(Item::get(Item::AIR));
$pk->encode();
$pk->isEncoded = true;
return $pk;
Expand All @@ -636,7 +637,11 @@ private function createArmorEquipPacket() : MobArmorEquipmentPacket{
private function createHandItemsEquipPacket() : MobEquipmentPacket{
$pk = new MobEquipmentPacket();
$pk->entityRuntimeId = $this->entity->getId();
$pk->item = $this->mainHand !== null ? $this->mainHand : Item::get(ItemIds::AIR);
if ($this->mainHand instanceof Item) {
$pk->item = ItemStackWrapper::legacy($this->mainHand);
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shorthand could be maintained here by using $pk->item = $this->mainHand instanceof Item ? ItemStackWrapper::legacy($this->mainHand) : ItemStackWrapper::legacy(Item::get(Item::AIR));

$pk->item = ItemStackWrapper::legacy(Item::get(Item::AIR));
}
$pk->inventorySlot = 0;
$pk->hotbarSlot = 0;
return $pk;
Expand Down
2 changes: 1 addition & 1 deletion src/revivalpmmp/pureentities/event/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function dataPacketReceiveEvent(DataPacketReceiveEvent $event){
if($btnTxt === null){
return;
}
if($packet->transactionType !== InventoryTransactionPacket::TYPE_USE_ITEM_ON_ENTITY){
if($packet->trData !== InventoryTransactionPacket::TYPE_USE_ITEM_ON_ENTITY){
Copy link
Contributor

@TheNewHEROBRINEX TheNewHEROBRINEX Apr 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you should use !$packet->trData instanceof UseItemOnEntityTransactionData instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wtf... no

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read the changes carefully. He is right. You should use the
!$packet->trData instanceof UseItemOnEntityTransactionData

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works, that's the most important thing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most important thing is that the code is written correctly.

Copy link
Contributor

@TheNewHEROBRINEX TheNewHEROBRINEX Apr 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@supercrafter333 I made the requested changes for you, just review and merge my pull request into your branch supercrafter333#1

return;
}
$entity = $player->level->getEntity($packet->trData->entityRuntimeId);
Expand Down