used namespacer

This commit is contained in:
Shoghi Cervantes 2014-03-06 15:15:50 +01:00
parent 64a9650765
commit 2e0d9153b3
30 changed files with 155 additions and 107 deletions

View File

@ -249,12 +249,12 @@ class BlockAPI{
}
if(defined(strtoupper($b[0]))){
$item = Item\Item::get(constant(strtoupper($b[0])), $meta);
$item = ItemItem::get(constant(strtoupper($b[0])), $meta);
if($item->getID() === AIR and strtoupper($b[0]) !== "AIR"){
$item = Item\Item::get(((int) $b[0]) & 0xFFFF, $meta);
$item = ItemItem::get(((int) $b[0]) & 0xFFFF, $meta);
}
} else{
$item = Item\Item::get(((int) $b[0]) & 0xFFFF, $meta);
$item = ItemItem::get(((int) $b[0]) & 0xFFFF, $meta);
}
return $item;
@ -357,7 +357,7 @@ class BlockAPI{
if(($player->gamemode & 0x01) === 0x00 and count($drops) > 0){
foreach($drops as $drop){
echo "I dropped something\n";
//$this->server->api->entity->drop(new Position($target->x + 0.5, $target->y, $target->z + 0.5, $target->level), Item\Item::get($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2]));
//$this->server->api->entity->drop(new Position($target->x + 0.5, $target->y, $target->z + 0.5, $target->level), ItemItem::get($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2]));
}
}
@ -374,7 +374,7 @@ class BlockAPI{
if(($player->getGamemode() & 0x01) === 0){
$item = $player->getSlot($player->slot);
} else{
$item = Item\Item::get(BlockAPI::$creative[$player->slot][0], BlockAPI::$creative[$player->slot][1], 1);
$item = ItemItem::get(BlockAPI::$creative[$player->slot][0], BlockAPI::$creative[$player->slot][1], 1);
}
if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ //If no block exists or not allowed in CREATIVE
@ -410,7 +410,7 @@ class BlockAPI{
if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){
if($item->getCount() <= 0){
$player->setSlot($player->slot, Item\Item::get(AIR, 0, 0));
$player->setSlot($player->slot, ItemItem::get(AIR, 0, 0));
}
return false;
@ -464,7 +464,7 @@ class BlockAPI{
if(($player->getGamemode() & 0x01) === 0){
$item->setCount($item->getCount() - 1);
if($item->getCount() <= 0){
$player->setSlot($player->slot, Item\Item::get(AIR, 0, 0));
$player->setSlot($player->slot, ItemItem::get(AIR, 0, 0));
}
}

View File

@ -648,7 +648,7 @@ class Player extends RealHuman{
$pk = new Network\Protocol\ContainerSetSlotPacket;
$pk->windowid = 0;
$pk->slot = (int) $s;
$pk->item = Item\Item::get(AIR, 0, 0);
$pk->item = ItemItem::get(AIR, 0, 0);
$this->dataPacket($pk);
}
@ -914,15 +914,15 @@ class Player extends RealHuman{
$s = $this->getSlot($slot);
$s->setCount($s->getCount() - $item->getCount());
if($s->getCount() <= 0){
$this->setSlot($slot, Item\Item::get(AIR, 0, 0));
$this->setSlot($slot, ItemItem::get(AIR, 0, 0));
}
}
foreach($craft as $slot => $item){
$s = $this->getSlot($slot);
if($s->getCount() <= 0 or $s->getID() === AIR){
$this->setSlot($slot, Item\Item::get($item->getID(), $item->getMetadata(), $item->getCount()));
$this->setSlot($slot, ItemItem::get($item->getID(), $item->getMetadata(), $item->getCount()));
} else{
$this->setSlot($slot, Item\Item::get($item->getID(), $item->getMetadata(), $s->getCount() + $item->getCount()));
$this->setSlot($slot, ItemItem::get($item->getID(), $item->getMetadata(), $s->getCount() + $item->getCount()));
}
switch($item->getID()){
@ -957,7 +957,7 @@ class Player extends RealHuman{
$this->grantAchievement("diamond");
break;
case CAKE:
$this->addItem(Item\Item::get(BUCKET, 0, 3));
$this->addItem(ItemItem::get(BUCKET, 0, 3));
break;
}
@ -1454,7 +1454,7 @@ class Player extends RealHuman{
foreach(BlockAPI::$creative as $i => $d){
if($d[0] === $packet->item and $d[1] === $packet->meta){
$packet->slot = $i;
$item = Item\Item::get($d[0], $d[1], 1);
$item = ItemItem::get($d[0], $d[1], 1);
break;
}
}
@ -1670,13 +1670,13 @@ class Player extends RealHuman{
for($i = 0; $i < 4; ++$i){
$s = $packet->slots[$i];
if($s === 0 or $s === 255){
$s = Item\Item::get(AIR, 0, 0);
$s = ItemItem::get(AIR, 0, 0);
} else{
$s = Item\Item::get($s + 256, 0, 1);
$s = ItemItem::get($s + 256, 0, 1);
}
$slot = $this->getArmorSlot($i);
if($slot->getID() !== AIR and $s->getID() === AIR){
if($this->setArmorSlot($i, Item\Item::get(AIR, 0, 0)) === false){
if($this->setArmorSlot($i, ItemItem::get(AIR, 0, 0)) === false){
$this->sendArmor();
$this->sendInventory();
} else{
@ -1688,7 +1688,7 @@ class Player extends RealHuman{
$this->sendArmor();
$this->sendInventory();
} else{
$this->setSlot($sl, Item\Item::get(AIR, 0, 0));
$this->setSlot($sl, ItemItem::get(AIR, 0, 0));
}
} elseif($s->getID() !== AIR and $slot->getID() !== AIR and ($slot->getID() !== $s->getID() or $slot->getMetadata() !== $s->getMetadata()) and ($sl = $this->hasItem($s->getID())) !== false){
if($this->setArmorSlot($i, $this->getSlot($sl)) === false){
@ -1870,10 +1870,10 @@ class Player extends RealHuman{
$this->entity->heal($items[$slot->getID()], "eating");
//--$slot->count;
if($slot->getCount() <= 0){
$this->setSlot($this->slot, Item\Item::get(AIR, 0, 0));
$this->setSlot($this->slot, ItemItem::get(AIR, 0, 0));
}
if($slot->getID() === MUSHROOM_STEW or $slot->getID() === BEETROOT_SOUP){
$this->addItem(Item\Item::get(BOWL, 0, 1));
$this->addItem(ItemItem::get(BOWL, 0, 1));
}
}
break;
@ -1894,7 +1894,7 @@ class Player extends RealHuman{
$data["player"] = $this;
if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){
$this->server->api->entity->drop(new Position($this->entity->x - 0.5, $this->entity->y, $this->entity->z - 0.5, $this->level), $packet->item);
$this->setSlot($this->slot, Item\Item::get(AIR, 0, 0), false);
$this->setSlot($this->slot, ItemItem::get(AIR, 0, 0), false);
}
if($this->entity->inAction === true){
$this->entity->inAction = false;
@ -1975,22 +1975,22 @@ class Player extends RealHuman{
$craft = false;
$slot = $this->getSlot($packet->slot);
if($slot->getCount() >= $packet->item->getCount() and (($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()) or ($packet->item->getID() === AIR and $packet->item->getCount() === 0)) and !isset($this->craftingItems[$packet->slot])){ //Crafting recipe
$use = Item\Item::get($slot->getID(), $slot->getMetadata(), $slot->getCount() - $packet->item->getCount());
$use = ItemItem::get($slot->getID(), $slot->getMetadata(), $slot->getCount() - $packet->item->getCount());
$this->craftingItems[$packet->slot] = $use;
$craft = true;
} elseif($slot->getCount() <= $packet->item->getCount() and ($slot->getID() === AIR or ($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()))){ //Crafting final
$craftItem = Item\Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount() - $slot->getCount());
$craftItem = ItemItem::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount() - $slot->getCount());
if(count($this->toCraft) === 0){
$this->toCraft[-1] = 0;
}
$this->toCraft[$packet->slot] = $craftItem;
$craft = true;
} elseif(((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->getCount() > 0 and $slot->getID() > AIR and ($slot->getID() !== $packet->item->getID() or $slot->getMetadata() !== $packet->item->getMetadata())){ //Crafting final
$craftItem = Item\Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
$craftItem = ItemItem::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
if(count($this->toCraft) === 0){
$this->toCraft[-1] = 0;
}
$use = Item\Item::get($slot->getID(), $slot->getMetadata(), $slot->getCount());
$use = ItemItem::get($slot->getID(), $slot->getMetadata(), $slot->getCount());
$this->craftingItems[$packet->slot] = $use;
$this->toCraft[$packet->slot] = $craftItem;
$craft = true;
@ -2031,7 +2031,7 @@ class Player extends RealHuman{
break;
}
$item = Item\Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
$item = ItemItem::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
$slot = $tile->getSlot($slotn);
if($this->server->api->dhandle("player.container.slot", array(
@ -2085,7 +2085,7 @@ class Player extends RealHuman{
){
break;
}
$item = Item\Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
$item = ItemItem::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
$slot = $tile->getSlot($packet->slot);
if($this->server->api->dhandle("player.container.slot", array(

View File

@ -34,6 +34,8 @@ use PocketMine\Network\RCON\RCON as RCON;
use PocketMine\Network\Query\QueryHandler as QueryHandler;
use PocketMine\Recipes\Crafting as Crafting;
use PocketMine\Network\UPnP\RemovePortForward as RemovePortForward;
use PocketMine\Block\Block as Block;
use PocketMine\Item\Item as Item;
class ServerAPI{
public $restart = false;
@ -391,8 +393,8 @@ class ServerAPI{
$this->query = new QueryHandler();
}
Block\Block::init();
Item\Item::init();
Block::init();
Item::init();
Crafting::init();
$this->schedule(2, array($this, "checkTickUpdates"), array(), true);

View File

@ -195,6 +195,9 @@ const GLOWING_OBSIDIAN = 246;
const NETHER_REACTOR = 247;
use PocketMine;
use PocketMine\Level\Position as Position;
use PocketMine\Level\Level as Level;
use PocketMine\Item\Item as Item;
abstract class Block extends Position{
public static $list = array();
@ -348,7 +351,7 @@ abstract class Block extends Position{
}
}
public static function get($id, $meta = 0, Level\Position $pos = null){
public static function get($id, $meta = 0, Position $pos = null){
if(isset(self::$list[$id])){
$block = clone self::$list[$id];
$block->setMetadata($meta);
@ -397,7 +400,7 @@ abstract class Block extends Position{
}
public function getDrops(Item $item, Player $player){
if(!isset(Block::$class[$this->id])){ //Unknown blocks
if(!isset(self::$class[$this->id])){ //Unknown blocks
return array();
} else{
return array(
@ -416,7 +419,7 @@ abstract class Block extends Position{
public function getSide($side){
$v = parent::getSide($side);
if($this->level instanceof Level\Level){
if($this->level instanceof Level){
return $this->level->getBlock($v);
}
@ -427,13 +430,13 @@ abstract class Block extends Position{
return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")";
}
abstract function isBreakable(Item\Item $item, Player $player);
abstract function isBreakable(Item $item, Player $player);
abstract function onBreak(Item\Item $item, Player $player);
abstract function onBreak(Item $item, Player $player);
abstract function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz);
abstract function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz);
abstract function onActivate(Item\Item $item, Player $player);
abstract function onActivate(Item $item, Player $player);
abstract function onUpdate($type);
}

View File

@ -46,19 +46,19 @@ class Human extends Creature implements ProjectileSource, InventorySource{
}
$this->hotbar = array(-1, -1, -1, -1, -1, -1, -1, -1, -1);
$this->armor = array(
0 => Item\Item::get(AIR, 0, 0),
1 => Item\Item::get(AIR, 0, 0),
2 => Item\Item::get(AIR, 0, 0),
3 => Item\Item::get(AIR, 0, 0)
0 => ItemItem::get(AIR, 0, 0),
1 => ItemItem::get(AIR, 0, 0),
2 => ItemItem::get(AIR, 0, 0),
3 => ItemItem::get(AIR, 0, 0)
);
foreach($nbt->Inventory as $item){
if($item->Slot >= 0 and $item->Slot < 9){ //Hotbar
$this->hotbar[$item->Slot] = isset($item->TrueSlot) ? $item->TrueSlot : -1;
} elseif($item->Slot >= 100 and $item->Slot < 104){ //Armor
$this->armor[$item->Slot - 100] = Item\Item::get($item->id, $item->Damage, $item->Count);
$this->armor[$item->Slot - 100] = ItemItem::get($item->id, $item->Damage, $item->Count);
} else{
$this->inventory[$item->Slot - 9] = Item\Item::get($item->id, $item->Damage, $item->Count);
$this->inventory[$item->Slot - 9] = ItemItem::get($item->id, $item->Damage, $item->Count);
}
}
$this->slot = $this->hotbar[0];
@ -204,7 +204,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
public function getArmorSlot($slot){
$slot = (int) $slot;
if(!isset($this->armor[$slot])){
$this->armor[$slot] = Item\Item::get(AIR, 0, 0);
$this->armor[$slot] = ItemItem::get(AIR, 0, 0);
}
return $this->armor[$slot];
@ -216,7 +216,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
if(isset($this->armor[$i]) and ($this->armor[$i] instanceof Item) and $this->armor[$i]->getID() > AIR){
$slots[$i] = $this->armor[$i]->getID() !== AIR ? $this->armor[$i]->getID() - 256 : 0;
} else{
$this->armor[$i] = Item\Item::get(AIR, 0, 0);
$this->armor[$i] = ItemItem::get(AIR, 0, 0);
$slots[$i] = 255;
}
}
@ -354,7 +354,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
$i->setCount($i->getCount() - $item->getCount());
$this->setSlot($s, $i);
} else{
$this->setSlot($s, Item\Item::get(AIR, 0, 0));
$this->setSlot($s, ItemItem::get(AIR, 0, 0));
}
break;
}
@ -380,7 +380,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
public function getSlot($slot){
$slot = (int) $slot;
if(!isset($this->inventory[$slot])){
$this->inventory[$slot] = Item\Item::get(AIR, 0, 0);
$this->inventory[$slot] = ItemItem::get(AIR, 0, 0);
}
return $this->inventory[$slot];

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class Bed extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(BED_BLOCK);
$this->block = Block::get(BED_BLOCK);
parent::__construct(BED, 0, $count, "Bed");
$this->maxStackSize = 1;
}

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class BeetrootSeeds extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(BEETROOT_BLOCK);
$this->block = Block::get(BEETROOT_BLOCK);
parent::__construct(BEETROOT_SEEDS, 0, $count, "Beetroot Seeds");
}
}

View File

@ -21,9 +21,10 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as BlockBlock;
class Block extends Item{
public function __construct(Block\Block $block, $meta = 0, $count = 1){
public function __construct(BlockBlock $block, $meta = 0, $count = 1){
$this->block = clone $block;
parent::__construct($block->getID(), $block->getMetadata(), $count, $block->getName());
}

View File

@ -21,6 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Block\Block as Block;
use PocketMine\Block\Air as Air;
use PocketMine\Block\Water as Water;
use PocketMine\Block\Lava as Lava;
class Bucket extends Item{
public function __construct($meta = 0, $count = 1){
@ -29,20 +34,20 @@ class Bucket extends Item{
$this->maxStackSize = 1;
}
public function onActivate(Level\Level $level, Player $player, Block\Block $block, Block\Block $target, $face, $fx, $fy, $fz){
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($this->meta === AIR){
if($target instanceof Block\Liquid){
$level->setBlock($target, new Block\Air(), true, false, true);
$level->setBlock($target, new Air(), true, false, true);
if(($player->gamemode & 0x01) === 0){
$this->meta = ($target instanceof Block\Water) ? WATER : LAVA;
$this->meta = ($target instanceof Water) ? WATER : LAVA;
}
return true;
}
} elseif($this->meta === WATER){
//Support Make Non-Support Water to Support Water
if($block->getID() === AIR || ($block instanceof Block\Water && ($block->getMetadata() & 0x07) != 0x00)){
$water = new Block\Water();
if($block->getID() === AIR || ($block instanceof Water && ($block->getMetadata() & 0x07) != 0x00)){
$water = new Water();
$level->setBlock($block, $water, true, false, true);
$water->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz);
if(($player->gamemode & 0x01) === 0){
@ -53,7 +58,7 @@ class Bucket extends Item{
}
} elseif($this->meta === LAVA){
if($block->getID() === AIR){
$level->setBlock($block, new Block\Lava(), true, false, true);
$level->setBlock($block, new Lava(), true, false, true);
if(($player->gamemode & 0x01) === 0){
$this->meta = 0;
}

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class Cake extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(CAKE_BLOCK);
$this->block = Block::get(CAKE_BLOCK);
$this->maxStackSize = 1;
parent::__construct(CAKE, 0, $count, "Cake");
}

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class Carrot extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(CARROT_BLOCK);
$this->block = Block::get(CARROT_BLOCK);
parent::__construct(CARROT, 0, $count, "Carrot");
}
}

View File

@ -21,6 +21,9 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Block\Block as Block;
use PocketMine\Block\Fire as Fire;
class FlintSteel extends Item{
public function __construct($meta = 0, $count = 1){
@ -29,13 +32,13 @@ class FlintSteel extends Item{
$this->maxStackSize = 1;
}
public function onActivate(Level\Level $level, Player $player, Block\Block $block, Block\Block $target, $face, $fx, $fy, $fz){
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if(($player->gamemode & 0x01) === 0 and $this->useOn($block) and $this->getMetadata() >= $this->getMaxDurability()){
$player->setSlot($player->slot, new Item(AIR, 0, 0));
}
if($block->getID() === AIR and ($target instanceof Block\Solid)){
$level->setBlock($block, new Block\Fire(), true, false, true);
$level->setBlock($block, new Fire(), true, false, true);
return true;
}

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class IronDoor extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(IRON_DOOR_BLOCK);
$this->block = Block::get(IRON_DOOR_BLOCK);
parent::__construct(IRON_DOOR, 0, $count, "Iron Door");
$this->maxStackSize = 1;
}

View File

@ -345,6 +345,14 @@ const BEETROOT_SEEDS = 458;
const BEETROOT_SEED = 458;
const BEETROOT_SOUP = 459;
use PocketMine;
use PocketMine\Block\Block as Block;
use PocketMine\Item\Block as ItemBlock;
use PocketMine\Recipes\Fuel as Fuel;
use PocketMine\Recipes\Smelt as Smelt;
use PocketMine\Entity\Entity as Entity;
use PocketMine\Block\GRASS as GRASS;
use PocketMine\Block\DIRT as DIRT;
use PocketMine\Level\Level as Level;
class Item{
@ -397,8 +405,8 @@ class Item{
WOODEN_AXE => new WoodenAxe(),
FLINT_STEEL => new FlintSteel(),
);
foreach(Block\Block::$list as $id => $class){
self::$list[$id] = new Item\Block($class);
foreach(Block::$list as $id => $class){
self::$list[$id] = new ItemBlock($class);
}
}
@ -421,7 +429,7 @@ class Item{
$this->count = (int) $count;
$this->name = $name;
if(!isset($this->block) and $this->id <= 0xff and isset(Block::$class[$this->id])){
$this->block = Block\Block::get($this->id, $this->meta);
$this->block = Block::get($this->id, $this->meta);
$this->name = $this->block->getName();
}
if($this->isTool() !== false){
@ -443,14 +451,14 @@ class Item{
}
final public function isPlaceable(){
return (($this->block instanceof Block\Block) and $this->block->isPlaceable === true);
return (($this->block instanceof Block) and $this->block->isPlaceable === true);
}
public function getBlock(){
if($this->block instanceof Block\Block){
if($this->block instanceof Block){
return $this->block;
} else{
return Block\Block::get(AIR);
return Block::get(AIR);
}
}
@ -471,36 +479,36 @@ class Item{
}
final public function getFuelTime(){
if(!isset(Recipes\Fuel::$duration[$this->id])){
if(!isset(Fuel::$duration[$this->id])){
return false;
}
if($this->id !== BUCKET or $this->meta === 10){
return Recipes\Fuel::$duration[$this->id];
return Fuel::$duration[$this->id];
}
return false;
}
final public function getSmeltItem(){
if(!isset(Recipes\Smelt::$product[$this->id])){
if(!isset(Smelt::$product[$this->id])){
return false;
}
if(isset(Recipes\Smelt::$product[$this->id][0]) and !is_array(Recipes\Smelt::$product[$this->id][0])){
return Item\Item::get(Recipes\Smelt::$product[$this->id][0], Recipes\Smelt::$product[$this->id][1]);
if(isset(Smelt::$product[$this->id][0]) and !is_array(Smelt::$product[$this->id][0])){
return self::get(Smelt::$product[$this->id][0], Smelt::$product[$this->id][1]);
}
if(!isset(Recipes\Smelt::$product[$this->id][$this->meta])){
if(!isset(Smelt::$product[$this->id][$this->meta])){
return false;
}
return Item\Item::get(Recipes\Smelt::$product[$this->id][$this->meta][0], Recipes\Smelt::$product[$this->id][$this->meta][1]);
return self::get(Smelt::$product[$this->id][$this->meta][0], Smelt::$product[$this->id][$this->meta][1]);
}
public function useOn($object, $force = false){
if($this->isTool() or $force === true){
if(($object instanceof Entity\Entity) and !$this->isSword()){
if(($object instanceof Entity) and !$this->isSword()){
$this->meta += 2;
} else{
$this->meta++;
@ -508,7 +516,7 @@ class Item{
return true;
} elseif($this->isHoe()){
if(($object instanceof Block\Block) and ($object->getID() === Block\GRASS or $object->getID() === Block\DIRT)){
if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){
$this->meta++;
}
}
@ -644,7 +652,7 @@ class Item{
return 1;
}
public function onActivate(Level\Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
return false;
}

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class MelonSeeds extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(MELON_STEM);
$this->block = Block::get(MELON_STEM);
parent::__construct(MELON_SEEDS, 0, $count, "Melon Seeds");
}
}

View File

@ -21,6 +21,10 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Block\Block as Block;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine\Item\Item as Item;
class Painting extends Item{
public function __construct($meta = 0, $count = 1){
@ -28,7 +32,7 @@ class Painting extends Item{
$this->isActivable = true;
}
public function onActivate(Level\Level $level, Player $player, Block\Block $block, Block\Block $target, $face, $fx, $fy, $fz){
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($target->isTransparent === false and $face > 1 and $block->isSolid === false){
$server = ServerAPI::request();
$faces = array(

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class Potato extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(POTATO_BLOCK);
$this->block = Block::get(POTATO_BLOCK);
parent::__construct(POTATO, 0, $count, "Potato");
}
}

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class PumpkinSeeds extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(PUMPKIN_STEM);
$this->block = Block::get(PUMPKIN_STEM);
parent::__construct(PUMPKIN_SEEDS, 0, $count, "Pumpkin Seeds");
}
}

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class Sign extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(SIGN_POST);
$this->block = Block::get(SIGN_POST);
$this->maxStackSize = 16;
parent::__construct(SIGN, 0, $count, "Sign");
}

View File

@ -21,6 +21,9 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Level\Level as Level;
use PocketMine\Block\Block as Block;
use PocketMine\ServerAPI as ServerAPI;
class SpawnEgg extends Item{
public function __construct($meta = 0, $count = 1){
@ -29,7 +32,7 @@ class SpawnEgg extends Item{
$this->isActivable = true;
}
public function onActivate(Level\Level $level, Player $player, Block\Block $block, Block\Block $target, $face, $fx, $fy, $fz){
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
switch($this->meta){
case Entity\CHICKEN:
case Entity\SHEEP:

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class Sugarcane extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(SUGARCANE_BLOCK);
$this->block = Block::get(SUGARCANE_BLOCK);
parent::__construct(SUGARCANE, 0, $count, "Sugar Cane");
}
}

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class WheatSeeds extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(WHEAT_BLOCK);
$this->block = Block::get(WHEAT_BLOCK);
parent::__construct(WHEAT_SEEDS, 0, $count, "Wheat Seeds");
}
}

View File

@ -21,10 +21,11 @@
namespace PocketMine\Item;
use PocketMine;
use PocketMine\Block\Block as Block;
class WoodenDoor extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block\Block::get(WOODEN_DOOR_BLOCK);
$this->block = Block::get(WOODEN_DOOR_BLOCK);
parent::__construct(WOODEN_DOOR, 0, $count, "Wooden Door");
$this->maxStackSize = 1;
}

View File

@ -28,6 +28,8 @@ use PocketMine\Math\Vector3 as Vector3;
use PocketMine\BlockAPI as BlockAPI;
use PocketMine\Block\TNT as TNT;
use PocketMine\Player as Player;
use PocketMine\Block\Block as Block;
use PocketMine\Item\Item as Item;
class Explosion{
public static $specialDrops = array(
@ -75,7 +77,7 @@ class Explosion{
$blockID = $this->level->level->getBlockID($vBlock->x, $vBlock->y, $vBlock->z);
if($blockID > 0){
$block = Block\Block::get($blockID, 0);
$block = Block::get($blockID, 0);
$block->x = $vBlock->x;
$block->y = $vBlock->y;
$block->z = $vBlock->z;
@ -120,10 +122,10 @@ class Explosion{
} elseif(mt_rand(0, 10000) < ((1 / $this->size) * 10000)){
if(isset(self::$specialDrops[$block->getID()])){
//TODO
//$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), Item\Item::get(self::$specialDrops[$block->getID()], 0));
//$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), Item::get(self::$specialDrops[$block->getID()], 0));
} else{
//TODO
//$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), Item\Item::get($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z)));
//$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), Item::get($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z)));
}
}
$this->level->level->setBlockID($block->x, $block->y, $block->z, 0);

View File

@ -276,7 +276,7 @@ class Level{
public function getBlockRaw(Vector3 $pos){
$b = $this->level->getBlock($pos->x, $pos->y, $pos->z);
return Block\Block::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
return BlockBlock::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
}
public function getBlock(Vector3 $pos){
@ -285,7 +285,7 @@ class Level{
}
$b = $this->level->getBlock($pos->x, $pos->y, $pos->z);
return Block\Block::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
return BlockBlock::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
}
public function setBlockRaw(Vector3 $pos, Block $block, $direct = true, $send = true){

View File

@ -25,16 +25,17 @@ use PocketMine\Level;
use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\BlockAPI as BlockAPI;
use PocketMine\Block\Block as Block;
class TallGrass{
public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10){
$arr = array(
Block\Block::get(DANDELION, 0),
Block\Block::get(CYAN_FLOWER, 0),
Block\Block::get(TALL_GRASS, 1),
Block\Block::get(TALL_GRASS, 1),
Block\Block::get(TALL_GRASS, 1),
Block\Block::get(TALL_GRASS, 1)
Block::get(DANDELION, 0),
Block::get(CYAN_FLOWER, 0),
Block::get(TALL_GRASS, 1),
Block::get(TALL_GRASS, 1),
Block::get(TALL_GRASS, 1),
Block::get(TALL_GRASS, 1)
);
$arrC = count($arr) - 1;
for($c = 0; $c < $count; ++$c){

View File

@ -24,6 +24,7 @@ namespace PocketMine\Network\Protocol;
use PocketMine;
use PocketMine\Utils\Utils as Utils;
use PocketMine\BlockAPI as BlockAPI;
use PocketMine\Item\Item as Item;
abstract class DataPacket{
private $offset = 0;
@ -155,7 +156,7 @@ abstract class DataPacket{
$id = $this->getShort();
$cnt = $this->getByte();
return Item\Item::get(
return Item::get(
$id,
$this->getShort(),
$cnt

View File

@ -80,7 +80,7 @@ trait Container{
if($slot->getID() > AIR and $slot->getCount() > 0){
$slots[] = $slot;
} else{
$slots[] = Item\Item::get(AIR, 0, 0);
$slots[] = ItemItem::get(AIR, 0, 0);
}
}
}
@ -97,7 +97,7 @@ trait Container{
if($slot->getID() > AIR and $slot->getCount() > 0){
$slots[] = $slot;
} else{
$slots[] = Item\Item::get(AIR, 0, 0);
$slots[] = ItemItem::get(AIR, 0, 0);
}
}
}
@ -128,7 +128,7 @@ trait Container{
if($slot->getID() > AIR and $slot->getCount() > 0){
$slots[] = $slot;
} else{
$slots[] = Item\Item::get(AIR, 0, 0);
$slots[] = ItemItem::get(AIR, 0, 0);
}
}
$pk = new ContainerSetContentPacket;
@ -153,9 +153,9 @@ trait Container{
public function getSlot($s){
$i = $this->getSlotIndex($s);
if($i === false or $i < 0){
return Item\Item::get(AIR, 0, 0);
return ItemItem::get(AIR, 0, 0);
} else{
return Item\Item::get($this->namedtag->Items[$i]->id, $this->namedtag->Items[$i]->Damage, $this->namedtag->Items[$i]->Count);
return ItemItem::get($this->namedtag->Items[$i]->id, $this->namedtag->Items[$i]->Damage, $this->namedtag->Items[$i]->Count);
}
}

View File

@ -26,6 +26,8 @@ use PocketMine\Level\Level as Level;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\Tile\Tile as Tile;
use PocketMine\BlockAPI as BlockAPI;
use PocketMine\Item\Item as Item;
use PocketMine\Block\Block as Block;
class Furnace extends Tile{
use Container;
@ -68,12 +70,12 @@ class Furnace extends Tile{
$this->namedtag->BurnTicks = 0;
$fuel->setCount($fuel->getCount() - 1);
if($fuel->getCount() === 0){
$fuel = Item\Item::get(AIR, 0, 0);
$fuel = Item::get(AIR, 0, 0);
}
$this->setSlot(1, $fuel, false);
$current = $this->level->getBlock($this);
if($current->getID() === FURNACE){
$this->level->setBlock($this, Block\Block::get(BURNING_FURNACE, $current->getMetadata()), true, false, true);
$this->level->setBlock($this, Block::get(BURNING_FURNACE, $current->getMetadata()), true, false, true);
}
}
if($this->namedtag->BurnTime > 0){
@ -83,11 +85,11 @@ class Furnace extends Tile{
if($smelt !== false and $canSmelt){
$this->namedtag->CookTime += $ticks;
if($this->namedtag->CookTime >= 200){ //10 seconds
$product = Item\Item::get($smelt->getID(), $smelt->getMetadata(), $product->getCount() + 1);
$product = Item::get($smelt->getID(), $smelt->getMetadata(), $product->getCount() + 1);
$this->setSlot(2, $product, false);
$raw->setCount($raw->getCount() - 1);
if($raw->getCount() === 0){
$raw = Item\Item::get(AIR, 0, 0);
$raw = Item::get(AIR, 0, 0);
}
$this->setSlot(0, $raw, false);
$this->namedtag->CookTime -= 200;
@ -103,7 +105,7 @@ class Furnace extends Tile{
} else{
$current = $this->level->getBlock($this);
if($current->getID() === BURNING_FURNACE){
$this->level->setBlock($this, Block\Block::get(FURNACE, $current->getMetadata()), true, false, true);
$this->level->setBlock($this, Block::get(FURNACE, $current->getMetadata()), true, false, true);
}
$this->namedtag->CookTime = 0;
$this->namedtag->BurnTime = 0;

View File

@ -23,6 +23,7 @@ namespace PocketMine\Utils;
use PocketMine;
use PocketMine\BlockAPI as BlockAPI;
use PocketMine\Item\Item as Item;
class Utils{
const BIG_ENDIAN = 0x00;
@ -203,7 +204,7 @@ class Utils{
$id = Utils::readShort($ob->get(2));
$cnt = ord($ob->get(1));
return Item\Item::get(
return Item::get(
$id,
Utils::readShort($ob->get(2)),
$cnt