Skip to content

Commit

Permalink
Continue work on sheep drops
Browse files Browse the repository at this point in the history
More API for the InventoryHolder interface
  • Loading branch information
jasonw4331 committed May 31, 2019
1 parent c9ce782 commit e8fb668
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/jasonwynn10/VanillaEntityAI/entity/InventoryHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
30 changes: 29 additions & 1 deletion src/jasonwynn10/VanillaEntityAI/entity/hostile/Witch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
}
}
29 changes: 28 additions & 1 deletion src/jasonwynn10/VanillaEntityAI/entity/hostile/ZombiePigman.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
}
}
24 changes: 20 additions & 4 deletions src/jasonwynn10/VanillaEntityAI/entity/passive/Sheep.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit e8fb668

Please sign in to comment.