Added Spawn Eggs

This commit is contained in:
Shoghi Cervantes 2013-06-06 23:02:44 +02:00
parent 7970b8aeed
commit 82aa76be17
4 changed files with 61 additions and 3 deletions

View File

@ -318,8 +318,11 @@ class BlockAPI{
return false; return false;
} }
if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz)){ if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){
return $this->cancelAction($block, $player); if($item->count <= 0){
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false)
}
return false;
} }
if($item->isPlaceable()){ if($item->isPlaceable()){

View File

@ -39,6 +39,7 @@ class Item{
PAINTING => "PaintingItem", PAINTING => "PaintingItem",
COAL => "CoalItem", COAL => "CoalItem",
APPLE => "AppleItem", APPLE => "AppleItem",
SPAWN_EGG => "SpawnEggItem",
DIAMOND => "DiamondItem", DIAMOND => "DiamondItem",
STICK => "StickItem", STICK => "StickItem",
BOWL => "BowlItem", BOWL => "BowlItem",

View File

@ -0,0 +1,54 @@
<?php
/*
-
/ \
/ \
/ PocketMine \
/ MP \
|\ @shoghicp /|
|. \ / .|
| .. \ / .. |
| .. | .. |
| .. | .. |
\ | /
\ | /
\ | /
\ | /
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/
class SpawnEggItem extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(SPAWN_EGG, 0, $count, "Spawn Egg");
$this->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;
}
}

View File

@ -116,7 +116,7 @@ class Entity extends Position{
$this->size = 0.5; $this->size = 0.5;
break; break;
case ENTITY_MOB: case ENTITY_MOB:
$this->setHealth($this->data["Health"], "generic"); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic");
$this->update(); $this->update();
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type)); //$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
$this->size = 1; $this->size = 1;