From 82aa76be17e87fc33cfd65980c827d649876f5aa Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 6 Jun 2013 23:02:44 +0200 Subject: [PATCH] Added Spawn Eggs --- src/API/BlockAPI.php | 7 +++- src/material/Item.php | 1 + src/material/item/generic/SpawnEgg.php | 54 ++++++++++++++++++++++++++ src/world/Entity.php | 2 +- 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/material/item/generic/SpawnEgg.php diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index cadeff35a..ab297d151 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -318,8 +318,11 @@ class BlockAPI{ return false; } - if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz)){ - return $this->cancelAction($block, $player); + if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){ + if($item->count <= 0){ + $player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false) + } + return false; } if($item->isPlaceable()){ diff --git a/src/material/Item.php b/src/material/Item.php index 2a9e90777..350ef44e3 100644 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -39,6 +39,7 @@ class Item{ PAINTING => "PaintingItem", COAL => "CoalItem", APPLE => "AppleItem", + SPAWN_EGG => "SpawnEggItem", DIAMOND => "DiamondItem", STICK => "StickItem", BOWL => "BowlItem", diff --git a/src/material/item/generic/SpawnEgg.php b/src/material/item/generic/SpawnEgg.php new file mode 100644 index 000000000..16faebad1 --- /dev/null +++ b/src/material/item/generic/SpawnEgg.php @@ -0,0 +1,54 @@ +meta = $meta; + $this->isActivable = true; + } + + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + switch($this->meta){ + case MOB_CHICKEN: + case MOB_SHEEP: + case MOB_COW: + case MOB_PIG: + $data = array( + "x" => $block->x + 0.5, + "y" => $block->y, + "z" => $block->z + 0.5, + ); + $e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data); + ServerAPI::request()->api->entity->spawnToAll($e); + --$this->count; + return true; + break; + } + return false; + } +} \ No newline at end of file diff --git a/src/world/Entity.php b/src/world/Entity.php index 0b85512db..b2091601f 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -116,7 +116,7 @@ class Entity extends Position{ $this->size = 0.5; break; case ENTITY_MOB: - $this->setHealth($this->data["Health"], "generic"); + $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic"); $this->update(); //$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type)); $this->size = 1;