Entity: Moved and renamed entity\Item to entity\object\ItemEntity

This commit is contained in:
Dylan K. Taylor 2018-03-10 12:36:35 +00:00
parent bd3d2451bc
commit b39bbffdc5
14 changed files with 57 additions and 54 deletions

View File

@ -32,8 +32,8 @@ use pocketmine\entity\Effect;
use pocketmine\entity\EffectInstance; use pocketmine\entity\EffectInstance;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\entity\Human; use pocketmine\entity\Human;
use pocketmine\entity\Item as DroppedItem;
use pocketmine\entity\Living; use pocketmine\entity\Living;
use pocketmine\entity\object\ItemEntity;
use pocketmine\entity\projectile\Arrow; use pocketmine\entity\projectile\Arrow;
use pocketmine\entity\Skin; use pocketmine\entity\Skin;
use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageByBlockEvent;
@ -2461,7 +2461,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if(!$target->isAlive()){ if(!$target->isAlive()){
return true; return true;
} }
if($target instanceof DroppedItem or $target instanceof Arrow){ if($target instanceof ItemEntity or $target instanceof Arrow){
$this->kick("Attempting to attack an invalid entity"); $this->kick("Attempting to attack an invalid entity");
$this->server->getLogger()->warning($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidEntity", [$this->getName()])); $this->server->getLogger()->warning($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidEntity", [$this->getName()]));
return false; return false;

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\entity; namespace pocketmine\entity;
use pocketmine\item\Item;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
class DataPropertyManager{ class DataPropertyManager{
@ -138,20 +139,20 @@ class DataPropertyManager{
/** /**
* @param int $key * @param int $key
* *
* @return null|\pocketmine\item\Item * @return null|Item
*/ */
public function getItem(int $key) : ?\pocketmine\item\Item{ public function getItem(int $key) : ?Item{
$value = $this->getPropertyValue($key, Entity::DATA_TYPE_SLOT); $value = $this->getPropertyValue($key, Entity::DATA_TYPE_SLOT);
assert($value instanceof \pocketmine\item\Item or $value === null); assert($value instanceof \pocketmine\item\Item or $value === null);
return $value; return $value;
} }
/** /**
* @param int $key * @param int $key
* @param \pocketmine\item\Item $value * @param Item $value
* @param bool $force * @param bool $force
*/ */
public function setItem(int $key, \pocketmine\item\Item $value, bool $force = false) : void{ public function setItem(int $key, Item $value, bool $force = false) : void{
$this->setPropertyValue($key, Entity::DATA_TYPE_SLOT, $value, $force); $this->setPropertyValue($key, Entity::DATA_TYPE_SLOT, $value, $force);
} }

View File

@ -30,6 +30,7 @@ use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\BlockFactory;
use pocketmine\block\Water; use pocketmine\block\Water;
use pocketmine\entity\object\ExperienceOrb; use pocketmine\entity\object\ExperienceOrb;
use pocketmine\entity\object\ItemEntity;
use pocketmine\entity\object\Painting; use pocketmine\entity\object\Painting;
use pocketmine\entity\object\PaintingMotive; use pocketmine\entity\object\PaintingMotive;
use pocketmine\entity\projectile\Arrow; use pocketmine\entity\projectile\Arrow;
@ -237,7 +238,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
Entity::registerEntity(ExperienceBottle::class, false, ['ThrownExpBottle', 'minecraft:xp_bottle']); Entity::registerEntity(ExperienceBottle::class, false, ['ThrownExpBottle', 'minecraft:xp_bottle']);
Entity::registerEntity(ExperienceOrb::class, false, ['XPOrb', 'minecraft:xp_orb']); Entity::registerEntity(ExperienceOrb::class, false, ['XPOrb', 'minecraft:xp_orb']);
Entity::registerEntity(FallingSand::class, false, ['FallingSand', 'minecraft:falling_block']); Entity::registerEntity(FallingSand::class, false, ['FallingSand', 'minecraft:falling_block']);
Entity::registerEntity(Item::class, false, ['Item', 'minecraft:item']); Entity::registerEntity(ItemEntity::class, false, ['Item', 'minecraft:item']);
Entity::registerEntity(Painting::class, false, ['Painting', 'minecraft:painting']); Entity::registerEntity(Painting::class, false, ['Painting', 'minecraft:painting']);
Entity::registerEntity(PrimedTNT::class, false, ['PrimedTnt', 'PrimedTNT', 'minecraft:tnt']); Entity::registerEntity(PrimedTNT::class, false, ['PrimedTnt', 'PrimedTNT', 'minecraft:tnt']);
Entity::registerEntity(Snowball::class, false, ['Snowball', 'minecraft:snowball']); Entity::registerEntity(Snowball::class, false, ['Snowball', 'minecraft:snowball']);

View File

@ -33,7 +33,7 @@ use pocketmine\inventory\InventoryHolder;
use pocketmine\inventory\PlayerInventory; use pocketmine\inventory\PlayerInventory;
use pocketmine\item\Consumable; use pocketmine\item\Consumable;
use pocketmine\item\FoodSource; use pocketmine\item\FoodSource;
use pocketmine\item\Item as ItemItem; use pocketmine\item\Item;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\ByteArrayTag; use pocketmine\nbt\tag\ByteArrayTag;
@ -517,9 +517,9 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($slot >= 0 and $slot < 9){ //Hotbar if($slot >= 0 and $slot < 9){ //Hotbar
//Old hotbar saving stuff, ignore it //Old hotbar saving stuff, ignore it
}elseif($slot >= 100 and $slot < 104){ //Armor }elseif($slot >= 100 and $slot < 104){ //Armor
$this->armorInventory->setItem($slot - 100, ItemItem::nbtDeserialize($item)); $this->armorInventory->setItem($slot - 100, Item::nbtDeserialize($item));
}else{ }else{
$this->inventory->setItem($slot - 9, ItemItem::nbtDeserialize($item)); $this->inventory->setItem($slot - 9, Item::nbtDeserialize($item));
} }
} }
} }
@ -528,7 +528,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($enderChestInventoryTag !== null){ if($enderChestInventoryTag !== null){
/** @var CompoundTag $item */ /** @var CompoundTag $item */
foreach($enderChestInventoryTag as $i => $item){ foreach($enderChestInventoryTag as $i => $item){
$this->enderChestInventory->setItem($item->getByte("Slot"), ItemItem::nbtDeserialize($item)); $this->enderChestInventory->setItem($item->getByte("Slot"), Item::nbtDeserialize($item));
} }
} }

View File

@ -35,7 +35,7 @@ use pocketmine\inventory\ArmorInventory;
use pocketmine\item\Armor; use pocketmine\item\Armor;
use pocketmine\item\Consumable; use pocketmine\item\Consumable;
use pocketmine\item\enchantment\Enchantment; use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\Item as ItemItem; use pocketmine\item\Item;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\math\VoxelRayTrace; use pocketmine\math\VoxelRayTrace;
use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\ByteTag;
@ -751,7 +751,7 @@ abstract class Living extends Entity implements Damageable{
} }
/** /**
* @return ItemItem[] * @return Item[]
*/ */
public function getDrops() : array{ public function getDrops() : array{
return []; return [];

View File

@ -25,7 +25,7 @@ namespace pocketmine\entity;
use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item as ItemItem; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\network\mcpe\protocol\EntityEventPacket;
@ -123,7 +123,7 @@ class Squid extends WaterAnimal{
public function getDrops() : array{ public function getDrops() : array{
return [ return [
ItemFactory::get(ItemItem::DYE, 0, mt_rand(1, 3)) ItemFactory::get(Item::DYE, 0, mt_rand(1, 3))
]; ];
} }
} }

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\entity; namespace pocketmine\entity;
use pocketmine\item\Item as ItemItem; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
class Zombie extends Monster{ class Zombie extends Monster{
@ -38,19 +38,19 @@ class Zombie extends Monster{
public function getDrops() : array{ public function getDrops() : array{
$drops = [ $drops = [
ItemFactory::get(ItemItem::ROTTEN_FLESH, 0, mt_rand(0, 2)) ItemFactory::get(Item::ROTTEN_FLESH, 0, mt_rand(0, 2))
]; ];
if(mt_rand(0, 199) < 5){ if(mt_rand(0, 199) < 5){
switch(mt_rand(0, 2)){ switch(mt_rand(0, 2)){
case 0: case 0:
$drops[] = ItemFactory::get(ItemItem::IRON_INGOT, 0, 1); $drops[] = ItemFactory::get(Item::IRON_INGOT, 0, 1);
break; break;
case 1: case 1:
$drops[] = ItemFactory::get(ItemItem::CARROT, 0, 1); $drops[] = ItemFactory::get(Item::CARROT, 0, 1);
break; break;
case 2: case 2:
$drops[] = ItemFactory::get(ItemItem::POTATO, 0, 1); $drops[] = ItemFactory::get(Item::POTATO, 0, 1);
break; break;
} }
} }

View File

@ -21,18 +21,19 @@
declare(strict_types=1); declare(strict_types=1);
namespace pocketmine\entity; namespace pocketmine\entity\object;
use pocketmine\entity\Entity;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\ItemDespawnEvent; use pocketmine\event\entity\ItemDespawnEvent;
use pocketmine\event\entity\ItemSpawnEvent; use pocketmine\event\entity\ItemSpawnEvent;
use pocketmine\event\inventory\InventoryPickupItemEvent; use pocketmine\event\inventory\InventoryPickupItemEvent;
use pocketmine\item\Item as ItemItem; use pocketmine\item\Item;
use pocketmine\network\mcpe\protocol\AddItemEntityPacket; use pocketmine\network\mcpe\protocol\AddItemEntityPacket;
use pocketmine\network\mcpe\protocol\TakeItemEntityPacket; use pocketmine\network\mcpe\protocol\TakeItemEntityPacket;
use pocketmine\Player; use pocketmine\Player;
class Item extends Entity{ class ItemEntity extends Entity{
public const NETWORK_ID = self::ITEM; public const NETWORK_ID = self::ITEM;
/** @var string */ /** @var string */
@ -41,7 +42,7 @@ class Item extends Entity{
protected $thrower = ""; protected $thrower = "";
/** @var int */ /** @var int */
protected $pickupDelay = 0; protected $pickupDelay = 0;
/** @var ItemItem */ /** @var Item */
protected $item; protected $item;
public $width = 0.25; public $width = 0.25;
@ -70,7 +71,7 @@ class Item extends Entity{
return; return;
} }
$this->item = ItemItem::nbtDeserialize($itemTag); $this->item = Item::nbtDeserialize($itemTag);
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this)); $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
@ -142,9 +143,9 @@ class Item extends Entity{
} }
/** /**
* @return ItemItem * @return Item
*/ */
public function getItem() : ItemItem{ public function getItem() : Item{
return $this->item; return $this->item;
} }
@ -217,7 +218,7 @@ class Item extends Entity{
$item = $this->getItem(); $item = $this->getItem();
$playerInventory = $player->getInventory(); $playerInventory = $player->getInventory();
if(!($item instanceof ItemItem) or ($player->isSurvival() and !$playerInventory->canAddItem($item))){ if(!($item instanceof Item) or ($player->isSurvival() and !$playerInventory->canAddItem($item))){
return; return;
} }
@ -227,10 +228,10 @@ class Item extends Entity{
} }
switch($item->getId()){ switch($item->getId()){
case ItemItem::WOOD: case Item::WOOD:
$player->awardAchievement("mineWood"); $player->awardAchievement("mineWood");
break; break;
case ItemItem::DIAMOND: case Item::DIAMOND:
$player->awardAchievement("diamond"); $player->awardAchievement("diamond");
break; break;
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\event\entity;
use pocketmine\entity\Creature; use pocketmine\entity\Creature;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\entity\Human; use pocketmine\entity\Human;
use pocketmine\entity\Item; use pocketmine\entity\object\ItemEntity;
use pocketmine\entity\projectile\Projectile; use pocketmine\entity\projectile\Projectile;
use pocketmine\entity\Vehicle; use pocketmine\entity\Vehicle;
@ -86,7 +86,7 @@ class EntityDespawnEvent extends EntityEvent{
* @return bool * @return bool
*/ */
public function isItem() : bool{ public function isItem() : bool{
return $this->entity instanceof Item; return $this->entity instanceof ItemEntity;
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\event\entity;
use pocketmine\entity\Creature; use pocketmine\entity\Creature;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\entity\Human; use pocketmine\entity\Human;
use pocketmine\entity\Item; use pocketmine\entity\object\ItemEntity;
use pocketmine\entity\projectile\Projectile; use pocketmine\entity\projectile\Projectile;
use pocketmine\entity\Vehicle; use pocketmine\entity\Vehicle;
use pocketmine\level\Position; use pocketmine\level\Position;
@ -94,7 +94,7 @@ class EntitySpawnEvent extends EntityEvent{
* @return bool * @return bool
*/ */
public function isItem() : bool{ public function isItem() : bool{
return $this->entity instanceof Item; return $this->entity instanceof ItemEntity;
} }
} }

View File

@ -23,22 +23,22 @@ declare(strict_types=1);
namespace pocketmine\event\entity; namespace pocketmine\event\entity;
use pocketmine\entity\Item; use pocketmine\entity\object\ItemEntity;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
class ItemDespawnEvent extends EntityEvent implements Cancellable{ class ItemDespawnEvent extends EntityEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** /**
* @param Item $item * @param ItemEntity $item
*/ */
public function __construct(Item $item){ public function __construct(ItemEntity $item){
$this->entity = $item; $this->entity = $item;
} }
/** /**
* @return Item * @return ItemEntity
*/ */
public function getEntity(){ public function getEntity(){
return $this->entity; return $this->entity;

View File

@ -23,21 +23,21 @@ declare(strict_types=1);
namespace pocketmine\event\entity; namespace pocketmine\event\entity;
use pocketmine\entity\Item; use pocketmine\entity\object\ItemEntity;
class ItemSpawnEvent extends EntityEvent{ class ItemSpawnEvent extends EntityEvent{
public static $handlerList = null; public static $handlerList = null;
/** /**
* @param Item $item * @param ItemEntity $item
*/ */
public function __construct(Item $item){ public function __construct(ItemEntity $item){
$this->entity = $item; $this->entity = $item;
} }
/** /**
* @return Item * @return ItemEntity
*/ */
public function getEntity(){ public function getEntity(){
return $this->entity; return $this->entity;

View File

@ -23,29 +23,29 @@ declare(strict_types=1);
namespace pocketmine\event\inventory; namespace pocketmine\event\inventory;
use pocketmine\entity\Item; use pocketmine\entity\object\ItemEntity;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
use pocketmine\inventory\Inventory; use pocketmine\inventory\Inventory;
class InventoryPickupItemEvent extends InventoryEvent implements Cancellable{ class InventoryPickupItemEvent extends InventoryEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
/** @var Item */ /** @var ItemEntity */
private $item; private $item;
/** /**
* @param Inventory $inventory * @param Inventory $inventory
* @param Item $item * @param ItemEntity $item
*/ */
public function __construct(Inventory $inventory, Item $item){ public function __construct(Inventory $inventory, ItemEntity $item){
$this->item = $item; $this->item = $item;
parent::__construct($inventory); parent::__construct($inventory);
} }
/** /**
* @return Item * @return ItemEntity
*/ */
public function getItem() : Item{ public function getItem() : ItemEntity{
return $this->item; return $this->item;
} }

View File

@ -29,8 +29,8 @@ namespace pocketmine\level;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\BlockFactory;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\entity\Item as DroppedItem;
use pocketmine\entity\object\ExperienceOrb; use pocketmine\entity\object\ExperienceOrb;
use pocketmine\entity\object\ItemEntity;
use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent; use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\block\BlockUpdateEvent; use pocketmine\event\block\BlockUpdateEvent;
@ -1623,7 +1623,7 @@ class Level implements ChunkManager, Metadatable{
* @param Vector3 $motion * @param Vector3 $motion
* @param int $delay * @param int $delay
* *
* @return DroppedItem|null * @return ItemEntity|null
*/ */
public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, int $delay = 10){ public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, int $delay = 10){
$motion = $motion ?? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1); $motion = $motion ?? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1);
@ -1637,7 +1637,7 @@ class Level implements ChunkManager, Metadatable{
$nbt->setTag($itemTag); $nbt->setTag($itemTag);
$itemEntity = Entity::createEntity("Item", $this, $nbt); $itemEntity = Entity::createEntity("Item", $this, $nbt);
if($itemEntity instanceof DroppedItem){ if($itemEntity instanceof ItemEntity){
$itemEntity->spawnToAll(); $itemEntity->spawnToAll();
return $itemEntity; return $itemEntity;