From e8fb668f3880b2facd963235981f4543f965d91a Mon Sep 17 00:00:00 2001 From: jasonwynn10 Date: Fri, 31 May 2019 15:42:22 -0400 Subject: [PATCH] Continue work on sheep drops More API for the InventoryHolder interface --- .../entity/InventoryHolder.php | 10 +++++++ .../VanillaEntityAI/entity/hostile/Witch.php | 30 ++++++++++++++++++- .../entity/hostile/WitherSkeleton.php | 29 +++++++++++++++++- .../entity/hostile/ZombiePigman.php | 29 +++++++++++++++++- .../VanillaEntityAI/entity/passive/Sheep.php | 24 ++++++++++++--- 5 files changed, 115 insertions(+), 7 deletions(-) diff --git a/src/jasonwynn10/VanillaEntityAI/entity/InventoryHolder.php b/src/jasonwynn10/VanillaEntityAI/entity/InventoryHolder.php index a3ab824..b9b160f 100644 --- a/src/jasonwynn10/VanillaEntityAI/entity/InventoryHolder.php +++ b/src/jasonwynn10/VanillaEntityAI/entity/InventoryHolder.php @@ -32,4 +32,14 @@ public function checkItemValueToMainHand(Item $item) : bool; * @return bool */ public function checkItemValueToOffHand(Item $item) : bool; + + /** + * @return Item|null + */ + public function getMainHand() : ?Item; + + /** + * @return Item|null + */ + public function getOffHand() : ?Item; } \ No newline at end of file diff --git a/src/jasonwynn10/VanillaEntityAI/entity/hostile/Witch.php b/src/jasonwynn10/VanillaEntityAI/entity/hostile/Witch.php index 6b8403d..b136e3a 100644 --- a/src/jasonwynn10/VanillaEntityAI/entity/hostile/Witch.php +++ b/src/jasonwynn10/VanillaEntityAI/entity/hostile/Witch.php @@ -5,13 +5,15 @@ use jasonwynn10\VanillaEntityAI\entity\Collidable; use jasonwynn10\VanillaEntityAI\entity\CollisionCheckingTrait; use jasonwynn10\VanillaEntityAI\entity\CreatureBase; +use jasonwynn10\VanillaEntityAI\entity\InventoryHolder; use jasonwynn10\VanillaEntityAI\entity\ItemHolderTrait; use jasonwynn10\VanillaEntityAI\entity\MonsterBase; use pocketmine\entity\Entity; +use pocketmine\item\Item; use pocketmine\level\Position; use pocketmine\nbt\tag\CompoundTag; -class Witch extends MonsterBase implements Collidable { +class Witch extends MonsterBase implements Collidable, InventoryHolder { use CollisionCheckingTrait, ItemHolderTrait; public const NETWORK_ID = self::WITCH; public $width = 0.6; @@ -79,4 +81,30 @@ public static function spawnFromSpawner(Position $spawnPos, ?CompoundTag $spawnD public function onCollideWithEntity(Entity $entity) : void { // TODO: Implement onCollideWithEntity() method. } + + public function equipRandomItems() : void { + // TODO: Implement equipRandomItems() method. + } + + public function equipRandomArmour() : void { + // TODO: Implement equipRandomArmour() method. + } + + /** + * @param Item $item + * + * @return bool + */ + public function checkItemValueToMainHand(Item $item) : bool { + // TODO: Implement checkItemValueToMainHand() method. + } + + /** + * @param Item $item + * + * @return bool + */ + public function checkItemValueToOffHand(Item $item) : bool { + // TODO: Implement checkItemValueToOffHand() method. + } } \ No newline at end of file diff --git a/src/jasonwynn10/VanillaEntityAI/entity/hostile/WitherSkeleton.php b/src/jasonwynn10/VanillaEntityAI/entity/hostile/WitherSkeleton.php index e5dcce2..e66445b 100644 --- a/src/jasonwynn10/VanillaEntityAI/entity/hostile/WitherSkeleton.php +++ b/src/jasonwynn10/VanillaEntityAI/entity/hostile/WitherSkeleton.php @@ -5,6 +5,7 @@ use jasonwynn10\VanillaEntityAI\entity\Collidable; use jasonwynn10\VanillaEntityAI\entity\CollisionCheckingTrait; use jasonwynn10\VanillaEntityAI\entity\CreatureBase; +use jasonwynn10\VanillaEntityAI\entity\InventoryHolder; use jasonwynn10\VanillaEntityAI\entity\ItemHolderTrait; use jasonwynn10\VanillaEntityAI\entity\MonsterBase; use pocketmine\entity\Entity; @@ -13,7 +14,7 @@ use pocketmine\level\Position; use pocketmine\nbt\tag\CompoundTag; -class WitherSkeleton extends MonsterBase implements Collidable { +class WitherSkeleton extends MonsterBase implements Collidable, InventoryHolder { use CollisionCheckingTrait, ItemHolderTrait; public const NETWORK_ID = self::WITHER_SKELETON; public $width = 0.875; @@ -73,4 +74,30 @@ public static function spawnFromSpawner(Position $spawnPos, ?CompoundTag $spawnD public function onCollideWithEntity(Entity $entity) : void { // TODO: Implement onCollideWithEntity() method. } + + public function equipRandomItems() : void { + // TODO: Implement equipRandomItems() method. + } + + public function equipRandomArmour() : void { + // TODO: Implement equipRandomArmour() method. + } + + /** + * @param Item $item + * + * @return bool + */ + public function checkItemValueToMainHand(Item $item) : bool { + // TODO: Implement checkItemValueToMainHand() method. + } + + /** + * @param Item $item + * + * @return bool + */ + public function checkItemValueToOffHand(Item $item) : bool { + // TODO: Implement checkItemValueToOffHand() method. + } } \ No newline at end of file diff --git a/src/jasonwynn10/VanillaEntityAI/entity/hostile/ZombiePigman.php b/src/jasonwynn10/VanillaEntityAI/entity/hostile/ZombiePigman.php index e717aaf..cdb664a 100644 --- a/src/jasonwynn10/VanillaEntityAI/entity/hostile/ZombiePigman.php +++ b/src/jasonwynn10/VanillaEntityAI/entity/hostile/ZombiePigman.php @@ -6,6 +6,7 @@ use jasonwynn10\VanillaEntityAI\entity\Collidable; use jasonwynn10\VanillaEntityAI\entity\CollisionCheckingTrait; use jasonwynn10\VanillaEntityAI\entity\CreatureBase; +use jasonwynn10\VanillaEntityAI\entity\InventoryHolder; use jasonwynn10\VanillaEntityAI\entity\ItemHolderTrait; use jasonwynn10\VanillaEntityAI\entity\MonsterBase; use pocketmine\entity\Ageable; @@ -15,7 +16,7 @@ use pocketmine\level\Position; use pocketmine\nbt\tag\CompoundTag; -class ZombiePigman extends MonsterBase implements Ageable, Collidable { +class ZombiePigman extends MonsterBase implements Ageable, Collidable, InventoryHolder { use CollisionCheckingTrait, ItemHolderTrait, AgeableTrait; public const NETWORK_ID = self::ZOMBIE_PIGMAN; public $width = 2.0; @@ -90,4 +91,30 @@ public static function spawnFromSpawner(Position $spawnPos, ?CompoundTag $spawnD public function onCollideWithEntity(Entity $entity) : void { // TODO: Implement onCollideWithEntity() method. } + + public function equipRandomItems() : void { + // TODO: Implement equipRandomItems() method. + } + + public function equipRandomArmour() : void { + // TODO: Implement equipRandomArmour() method. + } + + /** + * @param Item $item + * + * @return bool + */ + public function checkItemValueToMainHand(Item $item) : bool { + // TODO: Implement checkItemValueToMainHand() method. + } + + /** + * @param Item $item + * + * @return bool + */ + public function checkItemValueToOffHand(Item $item) : bool { + // TODO: Implement checkItemValueToOffHand() method. + } } \ No newline at end of file diff --git a/src/jasonwynn10/VanillaEntityAI/entity/passive/Sheep.php b/src/jasonwynn10/VanillaEntityAI/entity/passive/Sheep.php index 8c2f135..0996483 100644 --- a/src/jasonwynn10/VanillaEntityAI/entity/passive/Sheep.php +++ b/src/jasonwynn10/VanillaEntityAI/entity/passive/Sheep.php @@ -5,10 +5,11 @@ use jasonwynn10\VanillaEntityAI\entity\AnimalBase; use jasonwynn10\VanillaEntityAI\entity\Collidable; use jasonwynn10\VanillaEntityAI\entity\Interactable; +use jasonwynn10\VanillaEntityAI\entity\InventoryHolder; use jasonwynn10\VanillaEntityAI\entity\passiveaggressive\Player; -use jasonwynn10\VanillaEntityAI\entity\Shearable; -use jasonwynn10\VanillaEntityAI\entity\ShearableTrait; use pocketmine\entity\Entity; +use pocketmine\event\entity\EntityDamageByEntityEvent; +use pocketmine\item\enchantment\Enchantment; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\item\Shears; @@ -35,9 +36,24 @@ public function entityBaseTick(int $tickDiff = 1) : bool { * @return array */ public function getDrops() : array { + $cause = $this->lastDamageCause; + $drops = []; + if($cause instanceof EntityDamageByEntityEvent) { + $entity = $cause->getDamager(); + if($entity instanceof Player) { + $item = $entity->getInventory()->getItemInHand(); + if($item->hasEnchantment(Enchantment::FIRE_ASPECT) or $item->hasEnchantment(Enchantment::FLAME)) + $drops[] = ItemFactory::get(Item::COOKED_MUTTON, 0, mt_rand(1, 3)); + }elseif($entity instanceof InventoryHolder) { + $item = $entity->getMainHand() ?? ItemFactory::get(Item::AIR); + if($item->hasEnchantment(Enchantment::FIRE_ASPECT) or $item->hasEnchantment(Enchantment::FLAME)) + $drops[] = ItemFactory::get(Item::COOKED_MUTTON, 0, mt_rand(1, 3)); + } + } if($this->isSheared()) - return []; - return [ItemFactory::get(Item::WOOL), ItemFactory::get(Item::MUTTON, 0, mt_rand(1,3))]; // TODO: Change the autogenerated stub + return $drops; + $drops[] = ItemFactory::get(Item::WOOL); // TODO: Change the autogenerated stub + return $drops; } /**