Pocketmine-mp: DroppedItem->getItem() not equal Item::get()

Created on 27 Jun 2017  路  6Comments  路  Source: pmmp/PocketMine-MP

Issue description



Write a short description about the issue
I was writing a plugin to check the item the player picked up, then noticed that they are not equal even though they are created the same way

If you are reporting a regression or unexpected behaviour, please include the below information:
Expected result: The 2 items should be equal
Actual result: They are not

Steps to reproduce the issue

Create a plugin with below code
Tap any block, it should drop a stone block, pick it up, notice the message "Pickup Item", i was expecting "Pickup HELLO Stone" since they are the same item?

OS and versions

-->

  • PocketMine-MP:4a7c40e
  • PHP:7
  • Server OS:Win 8.1
  • Game version: PE

Plugins

  • Test on a clean server without plugins: is the issue reproducible without any plugins loaded? No

If the issue is not reproducible without plugins:
It is not a plugin issue, plugin is needed to demostrate

Crashdump, backtrace or other files

public function PlayerInteractEven(PlayerInteractEvent $event){
    $event->getPlayer()->getLevel()->dropItem($event->getPlayer(),Item::get(1)->setCustomName("HELLO"));
}
public function InventoryPickupItemEvent(InventoryPickupItemEvent $event){
    $p = $event->getInventory()->getHolder();
    $item = $event->getItem()->getItem();
    if($item->equals(Item::get(1)->setCustomName("HELLO")))
        $p->sendMessage("Pickup HELLO Stone");
    else $p->sendMessage("Pickup Item");
}
API Fixed

All 6 comments

The name should replaced with getEntityItem() in my opinion.

For fix that, use ...->getItem()->getItem()

Huh? I dont understand

This should be moved to the forums tbh.
But why are you doing $event->getItem()->getItem()? It should be $event->getItem() if I'm correct.

@SalmonDE Referring to this line, the first getItem() is pocketmine\event\InventoryPickupItemEvent::getItem() : pocketmine\entity\Item while the second one is pocketmine\entity\Item::getItem() : pocketmine\item\Item.

@SalmonDE InventoryPickupItemEvent::getItem() returns a entity\Item not item\Item

I agree the entity\Item is very confusing to code with, and annoying when using both item\Item and entity\Item. It wouldn't be a bad idea to change that in my opinion.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arfianadam picture arfianadam  路  3Comments

nmo0ory picture nmo0ory  路  3Comments

jasonwynn10 picture jasonwynn10  路  3Comments

SuperAdam47 picture SuperAdam47  路  3Comments

sergeysova picture sergeysova  路  3Comments