Added Block and Item namespaces

This commit is contained in:
Shoghi Cervantes 2014-03-06 17:14:15 +01:00
parent 2e0d9153b3
commit 6f74ef80f9
120 changed files with 1190 additions and 876 deletions

View File

@ -37,198 +37,197 @@ class BlockAPI{
private $scheduledUpdates = array();
private $randomUpdates = array();
public static $creative = array(
//Building
array(STONE, 0),
array(COBBLESTONE, 0),
array(STONE_BRICKS, 0),
array(STONE_BRICKS, 1),
array(STONE_BRICKS, 2),
array(MOSS_STONE, 0),
array(WOODEN_PLANKS, 0),
array(WOODEN_PLANKS, 1),
array(WOODEN_PLANKS, 2),
array(WOODEN_PLANKS, 3),
array(BRICKS, 0),
[Block\STONE, 0],
[Block\COBBLESTONE, 0],
[Block\STONE_BRICKS, 0],
[Block\STONE_BRICKS, 1],
[Block\STONE_BRICKS, 2],
[Block\MOSS_STONE, 0],
[Block\WOODEN_PLANKS, 0],
[Block\WOODEN_PLANKS, 1],
[Block\WOODEN_PLANKS, 2],
[Block\WOODEN_PLANKS, 3],
[Block\BRICKS, 0],
array(DIRT, 0),
array(GRASS, 0),
array(CLAY_BLOCK, 0),
array(SANDSTONE, 0),
array(SANDSTONE, 1),
array(SANDSTONE, 2),
array(SAND, 0),
array(GRAVEL, 0),
array(TRUNK, 0),
array(TRUNK, 1),
array(TRUNK, 2),
array(TRUNK, 3),
array(NETHER_BRICKS, 0),
array(NETHERRACK, 0),
array(BEDROCK, 0),
array(COBBLESTONE_STAIRS, 0),
array(OAK_WOODEN_STAIRS, 0),
array(SPRUCE_WOODEN_STAIRS, 0),
array(BIRCH_WOODEN_STAIRS, 0),
array(JUNGLE_WOODEN_STAIRS, 0),
array(BRICK_STAIRS, 0),
array(SANDSTONE_STAIRS, 0),
array(STONE_BRICK_STAIRS, 0),
array(NETHER_BRICKS_STAIRS, 0),
array(QUARTZ_STAIRS, 0),
array(SLAB, 0),
array(SLAB, 1),
array(WOODEN_SLAB, 0),
array(WOODEN_SLAB, 1),
array(WOODEN_SLAB, 2),
array(WOODEN_SLAB, 3),
array(SLAB, 3),
array(SLAB, 4),
array(SLAB, 5),
array(SLAB, 6),
array(QUARTZ_BLOCK, 0),
array(QUARTZ_BLOCK, 1),
array(QUARTZ_BLOCK, 2),
array(COAL_ORE, 0),
array(IRON_ORE, 0),
array(GOLD_ORE, 0),
array(DIAMOND_ORE, 0),
array(LAPIS_ORE, 0),
array(REDSTONE_ORE, 0),
array(OBSIDIAN, 0),
array(ICE, 0),
array(SNOW_BLOCK, 0),
[Block\DIRT, 0],
[Block\GRASS, 0],
[Block\CLAY_BLOCK, 0],
[Block\SANDSTONE, 0],
[Block\SANDSTONE, 1],
[Block\SANDSTONE, 2],
[Block\SAND, 0],
[Block\GRAVEL, 0],
[Block\TRUNK, 0],
[Block\TRUNK, 1],
[Block\TRUNK, 2],
[Block\TRUNK, 3],
[Block\NETHER_BRICKS, 0],
[Block\NETHERRACK, 0],
[Block\BEDROCK, 0],
[Block\COBBLESTONE_STAIRS, 0],
[Block\OAK_WOODEN_STAIRS, 0],
[Block\SPRUCE_WOODEN_STAIRS, 0],
[Block\BIRCH_WOODEN_STAIRS, 0],
[Block\JUNGLE_WOODEN_STAIRS, 0],
[Block\BRICK_STAIRS, 0],
[Block\SANDSTONE_STAIRS, 0],
[Block\STONE_BRICK_STAIRS, 0],
[Block\NETHER_BRICKS_STAIRS, 0],
[Block\QUARTZ_STAIRS, 0],
[Block\SLAB, 0],
[Block\SLAB, 1],
[Block\WOODEN_SLAB, 0],
[Block\WOODEN_SLAB, 1],
[Block\WOODEN_SLAB, 2],
[Block\WOODEN_SLAB, 3],
[Block\SLAB, 3],
[Block\SLAB, 4],
[Block\SLAB, 5],
[Block\SLAB, 6],
[Block\QUARTZ_BLOCK, 0],
[Block\QUARTZ_BLOCK, 1],
[Block\QUARTZ_BLOCK, 2],
[Block\COAL_ORE, 0],
[Block\IRON_ORE, 0],
[Block\GOLD_ORE, 0],
[Block\DIAMOND_ORE, 0],
[Block\LAPIS_ORE, 0],
[Block\REDSTONE_ORE, 0],
[Block\OBSIDIAN, 0],
[Block\ICE, 0],
[Block\SNOW_BLOCK, 0],
//Decoration
array(COBBLESTONE_WALL, 0),
array(COBBLESTONE_WALL, 1),
array(GOLD_BLOCK, 0),
array(IRON_BLOCK, 0),
array(DIAMOND_BLOCK, 0),
array(LAPIS_BLOCK, 0),
array(COAL_BLOCK, 0),
array(SNOW_LAYER, 0),
array(GLASS, 0),
array(GLOWSTONE_BLOCK, 0),
array(NETHER_REACTOR, 0),
array(WOOL, 0),
array(WOOL, 7),
array(WOOL, 6),
array(WOOL, 5),
array(WOOL, 4),
array(WOOL, 3),
array(WOOL, 2),
array(WOOL, 1),
array(WOOL, 15),
array(WOOL, 14),
array(WOOL, 13),
array(WOOL, 12),
array(WOOL, 11),
array(WOOL, 10),
array(WOOL, 9),
array(WOOL, 8),
array(LADDER, 0),
array(SPONGE, 0),
array(GLASS_PANE, 0),
array(WOODEN_DOOR, 0),
array(TRAPDOOR, 0),
array(FENCE, 0),
array(FENCE_GATE, 0),
array(IRON_BARS, 0),
array(BED, 0),
array(BOOKSHELF, 0),
array(PAINTING, 0),
array(WORKBENCH, 0),
array(STONECUTTER, 0),
array(CHEST, 0),
array(FURNACE, 0),
array(DANDELION, 0),
array(CYAN_FLOWER, 0),
array(BROWN_MUSHROOM, 0),
array(RED_MUSHROOM, 0),
array(CACTUS, 0),
array(MELON_BLOCK, 0),
array(PUMPKIN, 0),
array(LIT_PUMPKIN, 0),
array(COBWEB, 0),
array(HAY_BALE, 0),
array(TALL_GRASS, 1),
array(TALL_GRASS, 2),
array(DEAD_BUSH, 0),
array(SAPLING, 0),
array(SAPLING, 1),
array(SAPLING, 2),
array(SAPLING, 3),
array(LEAVES, 0),
array(LEAVES, 1),
array(LEAVES, 2),
array(LEAVES, 3),
array(CAKE, 0),
array(SIGN, 0),
array(CARPET, 0),
array(CARPET, 7),
array(CARPET, 6),
array(CARPET, 5),
array(CARPET, 4),
array(CARPET, 3),
array(CARPET, 2),
array(CARPET, 1),
array(CARPET, 15),
array(CARPET, 14),
array(CARPET, 13),
array(CARPET, 12),
array(CARPET, 11),
array(CARPET, 10),
array(CARPET, 9),
array(CARPET, 8),
[Block\COBBLESTONE_WALL, 0],
[Block\COBBLESTONE_WALL, 1],
[Block\GOLD_BLOCK, 0],
[Block\IRON_BLOCK, 0],
[Block\DIAMOND_BLOCK, 0],
[Block\LAPIS_BLOCK, 0],
[Block\COAL_BLOCK, 0],
[Block\SNOW_LAYER, 0],
[Block\GLASS, 0],
[Block\GLOWSTONE_BLOCK, 0],
[Block\NETHER_REACTOR, 0],
[Block\WOOL, 0],
[Block\WOOL, 7],
[Block\WOOL, 6],
[Block\WOOL, 5],
[Block\WOOL, 4],
[Block\WOOL, 3],
[Block\WOOL, 2],
[Block\WOOL, 1],
[Block\WOOL, 15],
[Block\WOOL, 14],
[Block\WOOL, 13],
[Block\WOOL, 12],
[Block\WOOL, 11],
[Block\WOOL, 10],
[Block\WOOL, 9],
[Block\WOOL, 8],
[Block\LADDER, 0],
[Block\SPONGE, 0],
[Block\GLASS_PANE, 0],
[Block\WOODEN_DOOR, 0],
[Block\TRAPDOOR, 0],
[Block\FENCE, 0],
[Block\FENCE_GATE, 0],
[Block\IRON_BARS, 0],
[Block\BED, 0],
[Block\BOOKSHELF, 0],
[Block\PAINTING, 0],
[Block\WORKBENCH, 0],
[Block\STONECUTTER, 0],
[Block\CHEST, 0],
[Block\FURNACE, 0],
[Block\DANDELION, 0],
[Block\CYAN_FLOWER, 0],
[Block\BROWN_MUSHROOM, 0],
[Block\RED_MUSHROOM, 0],
[Block\CACTUS, 0],
[Block\MELON_BLOCK, 0],
[Block\PUMPKIN, 0],
[Block\LIT_PUMPKIN, 0],
[Block\COBWEB, 0],
[Block\HAY_BALE, 0],
[Block\TALL_GRASS, 1],
[Block\TALL_GRASS, 2],
[Block\DEAD_BUSH, 0],
[Block\SAPLING, 0],
[Block\SAPLING, 1],
[Block\SAPLING, 2],
[Block\SAPLING, 3],
[Block\LEAVES, 0],
[Block\LEAVES, 1],
[Block\LEAVES, 2],
[Block\LEAVES, 3],
[Block\CAKE, 0],
[Block\SIGN, 0],
[Block\CARPET, 0],
[Block\CARPET, 7],
[Block\CARPET, 6],
[Block\CARPET, 5],
[Block\CARPET, 4],
[Block\CARPET, 3],
[Block\CARPET, 2],
[Block\CARPET, 1],
[Block\CARPET, 15],
[Block\CARPET, 14],
[Block\CARPET, 13],
[Block\CARPET, 12],
[Block\CARPET, 11],
[Block\CARPET, 10],
[Block\CARPET, 9],
[Block\CARPET, 8],
//Tools
//array(RAILS, 0),
//array(POWERED_RAILS, 0),
array(TORCH, 0),
array(BUCKET, 0),
array(BUCKET, 8),
array(BUCKET, 10),
array(TNT, 0),
array(IRON_HOE, 0),
array(IRON_SWORD, 0),
array(BOW, 0),
array(SHEARS, 0),
array(FLINT_AND_STEEL, 0),
array(CLOCK, 0),
array(COMPASS, 0),
array(MINECART, 0),
[Block\TORCH, 0],
[Block\BUCKET, 0],
[Block\BUCKET, 8],
[Block\BUCKET, 10],
[Block\TNT, 0],
[Block\IRON_HOE, 0],
[Block\IRON_SWORD, 0],
[Block\BOW, 0],
[Block\SHEARS, 0],
[Block\FLINT_AND_STEEL, 0],
[Block\CLOCK, 0],
[Block\COMPASS, 0],
[Block\MINECART, 0],
array(SPAWN_EGG, MOB_CHICKEN),
array(SPAWN_EGG, MOB_COW),
array(SPAWN_EGG, MOB_PIG),
array(SPAWN_EGG, MOB_SHEEP),
//Seeds
array(SUGARCANE, 0),
array(WHEAT, 0),
array(SEEDS, 0),
array(MELON_SEEDS, 0),
array(PUMPKIN_SEEDS, 0),
array(CARROT, 0),
array(POTATO, 0),
array(BEETROOT_SEEDS, 0),
array(EGG, 0),
array(DYE, 0),
array(DYE, 7),
array(DYE, 6),
array(DYE, 5),
array(DYE, 4),
array(DYE, 3),
array(DYE, 2),
array(DYE, 1),
array(DYE, 15),
array(DYE, 14),
array(DYE, 13),
array(DYE, 12),
array(DYE, 11),
array(DYE, 10),
array(DYE, 9),
array(DYE, 8),
[Block\SUGARCANE, 0],
[Block\WHEAT, 0],
[Block\SEEDS, 0],
[Block\MELON_SEEDS, 0],
[Block\PUMPKIN_SEEDS, 0],
[Block\CARROT, 0],
[Block\POTATO, 0],
[Block\BEETROOT_SEEDS, 0],
[Block\EGG, 0],
[Block\DYE, 0],
[Block\DYE, 7],
[Block\DYE, 6],
[Block\DYE, 5],
[Block\DYE, 4],
[Block\DYE, 3],
[Block\DYE, 2],
[Block\DYE, 1],
[Block\DYE, 15],
[Block\DYE, 14],
[Block\DYE, 13],
[Block\DYE, 12],
[Block\DYE, 11],
[Block\DYE, 10],
[Block\DYE, 9],
[Block\DYE, 8],
);
@ -249,12 +248,12 @@ class BlockAPI{
}
if(defined(strtoupper($b[0]))){
$item = ItemItem::get(constant(strtoupper($b[0])), $meta);
$item = Item::get(constant(strtoupper($b[0])), $meta);
if($item->getID() === AIR and strtoupper($b[0]) !== "AIR"){
$item = ItemItem::get(((int) $b[0]) & 0xFFFF, $meta);
$item = Item::get(((int) $b[0]) & 0xFFFF, $meta);
}
} else{
$item = ItemItem::get(((int) $b[0]) & 0xFFFF, $meta);
$item = Item::get(((int) $b[0]) & 0xFFFF, $meta);
}
return $item;
@ -357,7 +356,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), ItemItem::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), Item::get($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2]));
}
}
@ -374,7 +373,7 @@ class BlockAPI{
if(($player->getGamemode() & 0x01) === 0){
$item = $player->getSlot($player->slot);
} else{
$item = ItemItem::get(BlockAPI::$creative[$player->slot][0], BlockAPI::$creative[$player->slot][1], 1);
$item = Item::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 +409,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, ItemItem::get(AIR, 0, 0));
$player->setSlot($player->slot, Item::get(AIR, 0, 0));
}
return false;
@ -464,7 +463,7 @@ class BlockAPI{
if(($player->getGamemode() & 0x01) === 0){
$item->setCount($item->getCount() - 1);
if($item->getCount() <= 0){
$player->setSlot($player->slot, ItemItem::get(AIR, 0, 0));
$player->setSlot($player->slot, Item::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 = ItemItem::get(AIR, 0, 0);
$pk->item = Item::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, ItemItem::get(AIR, 0, 0));
$this->setSlot($slot, Item::get(AIR, 0, 0));
}
}
foreach($craft as $slot => $item){
$s = $this->getSlot($slot);
if($s->getCount() <= 0 or $s->getID() === AIR){
$this->setSlot($slot, ItemItem::get($item->getID(), $item->getMetadata(), $item->getCount()));
$this->setSlot($slot, Item::get($item->getID(), $item->getMetadata(), $item->getCount()));
} else{
$this->setSlot($slot, ItemItem::get($item->getID(), $item->getMetadata(), $s->getCount() + $item->getCount()));
$this->setSlot($slot, Item::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(ItemItem::get(BUCKET, 0, 3));
$this->addItem(Item::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 = ItemItem::get($d[0], $d[1], 1);
$item = Item::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 = ItemItem::get(AIR, 0, 0);
$s = Item::get(AIR, 0, 0);
} else{
$s = ItemItem::get($s + 256, 0, 1);
$s = Item::get($s + 256, 0, 1);
}
$slot = $this->getArmorSlot($i);
if($slot->getID() !== AIR and $s->getID() === AIR){
if($this->setArmorSlot($i, ItemItem::get(AIR, 0, 0)) === false){
if($this->setArmorSlot($i, Item::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, ItemItem::get(AIR, 0, 0));
$this->setSlot($sl, Item::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, ItemItem::get(AIR, 0, 0));
$this->setSlot($this->slot, Item::get(AIR, 0, 0));
}
if($slot->getID() === MUSHROOM_STEW or $slot->getID() === BEETROOT_SOUP){
$this->addItem(ItemItem::get(BOWL, 0, 1));
$this->addItem(Item::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, ItemItem::get(AIR, 0, 0), false);
$this->setSlot($this->slot, Item::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 = ItemItem::get($slot->getID(), $slot->getMetadata(), $slot->getCount() - $packet->item->getCount());
$use = Item::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 = ItemItem::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount() - $slot->getCount());
$craftItem = Item::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 = ItemItem::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
$craftItem = Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
if(count($this->toCraft) === 0){
$this->toCraft[-1] = 0;
}
$use = ItemItem::get($slot->getID(), $slot->getMetadata(), $slot->getCount());
$use = Item::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 = ItemItem::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
$item = Item::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 = ItemItem::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
$item = Item::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

@ -281,7 +281,7 @@ class PlayerAPI{
$player = Player::get($params[0]);
}
if($player instanceof Player){
$player->entity->harm(1000, "console", true);
$player->harm(1000, "console", true);
$player->sendChat("Ouch. That looks like it hurt.\n");
} else{
$output .= "Usage: /$cmd [player]\n";
@ -334,9 +334,9 @@ class PlayerAPI{
$player = Player::get($name);
if($player instanceof Player and $player->spawned === true){
$name = $player->getUsername();
$x = $x{0} === "~" ? $player->entity->x + floatval(substr($x, 1)) : floatval($x);
$y = $y{0} === "~" ? $player->entity->y + floatval(substr($y, 1)) : floatval($y);
$z = $z{0} === "~" ? $player->entity->z + floatval(substr($z, 1)) : floatval($z);
$x = $x{0} === "~" ? $player->x + floatval(substr($x, 1)) : floatval($x);
$y = $y{0} === "~" ? $player->y + floatval(substr($y, 1)) : floatval($y);
$z = $z{0} === "~" ? $player->z + floatval(substr($z, 1)) : floatval($z);
$player->teleport(new Vector3($x, $y, $z));
return true;

View File

@ -19,7 +19,10 @@
*
*/
class AirBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Air extends Transparent{
public function __construct(){
parent::__construct(AIR, 0, "Air");
$this->isActivable = false;

View File

@ -19,7 +19,10 @@
*
*/
class BedBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Bed extends Transparent{
public function __construct($type = 0){
parent::__construct(BED_BLOCK, $type, "Bed Block");
$this->isActivable = true;
@ -27,9 +30,9 @@ class BedBlock extends TransparentBlock{
$this->hardness = 1;
}
public function onActivate(Item $item, Player $player){
public function onActivate(Item\Item $item, Player $player){
if(ServerAPI::request()->api->time->getPhase($player->level) !== "night"){
$pk = new ChatPacket;
$pk = new Network\Protocol\ChatPacket;
$pk->message = "You can only sleep at night";
$player->dataPacket($pk);
@ -52,7 +55,7 @@ class BedBlock extends TransparentBlock{
} elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$b = $blockWest;
} else{
$pk = new ChatPacket;
$pk = new Network\Protocol\ChatPacket;
$pk->message = "This bed is incomplete";
$player->dataPacket($pk);
@ -61,7 +64,7 @@ class BedBlock extends TransparentBlock{
}
if($player->sleepOn($b) === false){
$pk = new ChatPacket;
$pk = new Network\Protocol\ChatPacket;
$pk->message = "This bed is occupied";
$player->dataPacket($pk);
}
@ -69,7 +72,7 @@ class BedBlock extends TransparentBlock{
return true;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->isTransparent === false){
$faces = array(
@ -78,13 +81,13 @@ class BedBlock extends TransparentBlock{
2 => 2,
3 => 5,
);
$d = $player->entity->getDirection();
$d = $player->getDirection();
$next = $this->getSide($faces[(($d + 3) % 4)]);
$downNext = $this->getSide(0);
if($next->isReplaceable === true and $downNext->isTransparent === false){
$meta = (($d + 3) % 4) & 0x03;
$this->level->setBlock($block, Block\Block::get($this->id, $meta), true, false, true);
$this->level->setBlock($next, Block\Block::get($this->id, $meta | 0x08), true, false, true);
$this->level->setBlock($block, Block::get($this->id, $meta), true, false, true);
$this->level->setBlock($next, Block::get($this->id, $meta | 0x08), true, false, true);
return true;
}
@ -93,7 +96,7 @@ class BedBlock extends TransparentBlock{
return false;
}
public function onBreak(Item $item, Player $player){
public function onBreak(Item\Item $item, Player $player){
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
$blockEast = $this->getSide(5);
@ -101,33 +104,33 @@ class BedBlock extends TransparentBlock{
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
$this->level->setBlock($blockNorth, new Air(), true, false, true);
} elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
$this->level->setBlock($blockSouth, new Air(), true, false, true);
} elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){
$this->level->setBlock($blockEast, new AirBlock(), true, false, true);
$this->level->setBlock($blockEast, new Air(), true, false, true);
} elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){
$this->level->setBlock($blockWest, new AirBlock(), true, false, true);
$this->level->setBlock($blockWest, new Air(), true, false, true);
}
} else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
$this->level->setBlock($blockNorth, new Air(), true, false, true);
} elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
$this->level->setBlock($blockSouth, new Air(), true, false, true);
} elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$this->level->setBlock($blockEast, new AirBlock(), true, false, true);
$this->level->setBlock($blockEast, new Air(), true, false, true);
} elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$this->level->setBlock($blockWest, new AirBlock(), true, false, true);
$this->level->setBlock($blockWest, new Air(), true, false, true);
}
}
$this->level->setBlock($this, new AirBlock(), true, false, true);
$this->level->setBlock($this, new Air(), true, false, true);
return true;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array(BED, 0, 1),
array(Item\BED, 0, 1),
);
}

View File

@ -19,14 +19,17 @@
*
*/
class BedrockBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Bedrock extends Solid{
public function __construct(){
parent::__construct(BEDROCK, 0, "Bedrock");
$this->breakable = false;
$this->hardness = 18000000;
}
public function isBreakable(Item $item, Player $player){
public function isBreakable(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return true;
}

View File

@ -19,27 +19,28 @@
*
*/
class BeetrootBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class Beetroot extends Flowable{
public function __construct($meta = 0){
parent::__construct(BEETROOT_BLOCK, $meta, "Beetroot Block");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
public function onActivate(Item\Item $item, Player $player){
if($item->getID() === Item\DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
@ -55,8 +56,9 @@ class BeetrootBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item\Item::get(BEETROOT_SEEDS, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true);
//TODO
//ServerAPI::request()->api->entity->drop($this, Item\Item::get(BEETROOT_SEEDS, 0, 1));
$this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
@ -76,13 +78,13 @@ class BeetrootBlock extends FlowableBlock{
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
$drops = array();
if($this->meta >= 0x07){
$drops[] = array(BEETROOT, 0, 1);
$drops[] = array(BEETROOT_SEEDS, 0, mt_rand(0, 3));
$drops[] = array(Item\BEETROOT, 0, 1);
$drops[] = array(Item\BEETROOT_SEEDS, 0, mt_rand(0, 3));
} else{
$drops[] = array(BEETROOT_SEEDS, 0, 1);
$drops[] = array(Item\BEETROOT_SEEDS, 0, 1);
}
return $drops;

View File

@ -19,12 +19,15 @@
*
*/
class BirchWoodStairsBlock extends StairBlock{
namespace PocketMine\Block;
use PocketMine;
class BirchWoodStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(BIRCH_WOOD_STAIRS, $meta, "Birch Wood Stairs");
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array($this->id, 0, 1),
);

View File

@ -350,7 +350,14 @@ abstract class Block extends Position{
);
}
}
/**
* @param int $id
* @param int $meta
* @param Position $pos
*
* @return Block
*/
public static function get($id, $meta = 0, Position $pos = null){
if(isset(self::$list[$id])){
$block = clone self::$list[$id];
@ -372,26 +379,46 @@ abstract class Block extends Position{
$this->hardness = 10;
}
/**
* @return int
*/
final public function getHardness(){
return ($this->hardness);
return $this->hardness;
}
/**
* @return string
*/
final public function getName(){
return $this->name;
}
/**
* @return int
*/
final public function getID(){
return $this->id;
}
/**
* @return int
*/
final public function getMetadata(){
return $this->meta;
}
/**
* @param int $meta
*/
final public function setMetadata($meta){
$this->meta = $meta & 0x0F;
}
/**
* Sets the block position to a new Position object
*
* @param Position $v
*/
final public function position(Position $v){
$this->level = $v->level;
$this->x = (int) $v->x;
@ -399,7 +426,15 @@ abstract class Block extends Position{
$this->z = (int) $v->z;
}
public function getDrops(Item $item, Player $player){
/**
* Returns an array of Item objects to be dropped
*
* @param Item\Item $item
* @param Player $player
*
* @return array
*/
public function getDrops(Item\Item $item, Player $player){
if(!isset(self::$class[$this->id])){ //Unknown blocks
return array();
} else{
@ -409,7 +444,16 @@ abstract class Block extends Position{
}
}
public function getBreakTime(Item $item, Player $player){
/**
* Returns the seconds that this block takes to be broken using an specific Item
*
* @param Item\Item $item
* @param Player $player
*
* @return float
*/
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.15;
}
@ -417,9 +461,16 @@ abstract class Block extends Position{
return $this->breakTime;
}
/**
* Returns the Block on the side $side, works like Vector3::side()
*
* @param int $side
*
* @return Block
*/
public function getSide($side){
$v = parent::getSide($side);
if($this->level instanceof Level){
if($this->level instanceof Level\Level){
return $this->level->getBlock($v);
}
@ -430,13 +481,58 @@ abstract class Block extends Position{
return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")";
}
abstract function isBreakable(Item $item, Player $player);
/**
* Returns if the item can be broken with an specific Item
*
* @param Item\Item $item
* @param Player $player
*
* @return bool
*/
abstract function isBreakable(Item\Item $item, Player $player);
abstract function onBreak(Item $item, Player $player);
/**
* Do the actions needed so the block is broken with the Item
*
* @param Item\Item $item
* @param Player $player
*
* @return mixed
*/
abstract function onBreak(Item\Item $item, Player $player);
abstract function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz);
/**
* Places the Block, using block space and block target, and side. Returns if the block has been placed.
*
* @param Item\Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param int $face
* @param float $fx
* @param float $fy
* @param float $fz
*
* @return bool
*/
abstract function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz);
abstract function onActivate(Item $item, Player $player);
/**
* Do actions when activated by Item. Returns if it has done anything
*
* @param Item\Item $item
* @param Player $player
*
* @return bool
*/
abstract function onActivate(Item\Item $item, Player $player);
/**
* Fires a block update on the Block
*
* @param int $type
*
* @return void
*/
abstract function onUpdate($type);
}

View File

@ -19,7 +19,10 @@
*
*/
class BookshelfBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Bookshelf extends Solid{
public function __construct(){
parent::__construct(BOOKSHELF, 0, "Bookshelf");
$this->hardness = 7.5;

View File

@ -19,7 +19,10 @@
*
*/
class BrickStairsBlock extends StairBlock{
namespace PocketMine\Block;
use PocketMine;
class BrickStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(BRICK_STAIRS, $meta, "Brick Stairs");
}

View File

@ -19,13 +19,16 @@
*
*/
class BricksBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Bricks extends Solid{
public function __construct(){
parent::__construct(BRICKS_BLOCK, 0, "Bricks");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -45,7 +48,7 @@ class BricksBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(BRICKS_BLOCK, 0, 1),

View File

@ -19,7 +19,10 @@
*
*/
class BrownMushroomBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class BrownMushroom extends Flowable{
public function __construct(){
parent::__construct(BROWN_MUSHROOM, 0, "Brown Mushroom");
$this->hardness = 0;
@ -28,8 +31,9 @@ class BrownMushroomBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true);
//TODO
//ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id));
$this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
@ -38,7 +42,7 @@ class BrownMushroomBlock extends FlowableBlock{
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->isTransparent === false){
$this->level->setBlock($block, $this, true, false, true);

View File

@ -19,57 +19,60 @@
*
*/
class BurningFurnaceBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class BurningFurnace extends Solid{
public function __construct($meta = 0){
parent::__construct(BURNING_FURNACE, $meta, "Burning Furnace");
$this->isActivable = true;
$this->hardness = 17.5;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
$this->meta = $faces[$player->entity->getDirection()];
$this->meta = $faces[$player->getDirection()];
$this->level->setBlock($block, $this, true, false, true);
$nbt = new NBT\Tag\Compound(false, array(
"Items" => new NBT\Tag\Enum("Items", array()),
"id" => new NBT\Tag\String("id", Tile::FURNACE),
"id" => new NBT\Tag\String("id", Tile\Tile::FURNACE),
"x" => new NBT\Tag\Int("x", $this->x),
"y" => new NBT\Tag\Int("y", $this->y),
"z" => new NBT\Tag\Int("z", $this->z)
));
$nbt->Items->setTagType(NBT\Tag_Compound);
$furnace = new Furnace($this->level, $nbt);
$furnace = new Tile\Furnace($this->level, $nbt);
return true;
}
public function onBreak(Item $item, Player $player){
$this->level->setBlock($this, new AirBlock(), true, true, true);
public function onBreak(Item\Item $item, Player $player){
$this->level->setBlock($this, new Air(), true, true, true);
return true;
}
public function onActivate(Item $item, Player $player){
public function onActivate(Item\Item $item, Player $player){
$t = $this->level->getTile($this);
$furnace = false;
if($t instanceof Furnace){
if($t instanceof Tile\Furnace){
$furnace = $t;
} else{
$nbt = new NBT\Tag\Compound(false, array(
"Items" => new NBT\Tag\Enum("Items", array()),
"id" => new NBT\Tag\String("id", Tile::FURNACE),
"id" => new NBT\Tag\String("id", Tile\Tile::FURNACE),
"x" => new NBT\Tag\Int("x", $this->x),
"y" => new NBT\Tag\Int("y", $this->y),
"z" => new NBT\Tag\Int("z", $this->z)
));
$nbt->Items->setTagType(NBT\Tag_Compound);
$furnace = new Furnace($this->level, $nbt);
$furnace = new Tile\Furnace($this->level, $nbt);
}
if(($player->gamemode & 0x01) === 0x01){
@ -81,7 +84,7 @@ class BurningFurnaceBlock extends SolidBlock{
return true;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -101,14 +104,14 @@ class BurningFurnaceBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
$drops = array();
if($item->isPickaxe() >= 1){
$drops[] = array(FURNACE, 0, 1);
}
$t = $this->level->getTile($this);
if($t instanceof Furnace){
for($s = 0; $s < Furnace::SLOTS; ++$s){
if($t instanceof Tile\Furnace){
for($s = 0; $s < Tile\Furnace::SLOTS; ++$s){
$slot = $t->getSlot($s);
if($slot->getID() > AIR and $slot->getCount() > 0){
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->getCount());

View File

@ -19,7 +19,10 @@
*
*/
class CactusBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Cactus extends Transparent{
public function __construct($meta = 0){
parent::__construct(CACTUS, $meta, "Cactus");
$this->isFullBlock = false;
@ -30,7 +33,7 @@ class CactusBlock extends TransparentBlock{
if($type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->getID() !== SAND and $down->getID() !== CACTUS){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false);
$this->level->setBlock($this, new Air(), false);
ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id));
return BLOCK_UPDATE_NORMAL;
@ -41,7 +44,7 @@ class CactusBlock extends TransparentBlock{
for($y = 1; $y < 3; ++$y){
$b = $this->level->getBlock(new Math\Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === AIR){
$this->level->setBlock($b, new CactusBlock(), true, false, true);
$this->level->setBlock($b, new Cactus(), true, false, true);
break;
}
}
@ -59,7 +62,7 @@ class CactusBlock extends TransparentBlock{
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === SAND or $down->getID() === CACTUS){
$block0 = $this->getSide(2);
@ -68,8 +71,6 @@ class CactusBlock extends TransparentBlock{
$block3 = $this->getSide(5);
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
$this->level->setBlock($this, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
}
@ -77,7 +78,7 @@ class CactusBlock extends TransparentBlock{
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array($this->id, 0, 1),
);

View File

@ -19,7 +19,10 @@
*
*/
class CakeBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Cake extends Transparent{
public function __construct($meta = 0){
parent::__construct(CAKE_BLOCK, 0, "Cake Block");
$this->isFullBlock = false;
@ -28,7 +31,7 @@ class CakeBlock extends TransparentBlock{
$this->hardness = 2.5;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() !== AIR){
$this->level->setBlock($block, $this, true, false, true);
@ -42,7 +45,7 @@ class CakeBlock extends TransparentBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), true, false, true);
$this->level->setBlock($this, new Air(), true, false, true);
return BLOCK_UPDATE_NORMAL;
}
@ -51,16 +54,16 @@ class CakeBlock extends TransparentBlock{
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array();
}
public function onActivate(Item $item, Player $player){
if($player->entity->getHealth() < 20){
public function onActivate(Item\Item $item, Player $player){
if($player->getHealth() < 20){
++$this->meta;
$player->entity->heal(3, "cake");
$player->heal(3, "cake");
if($this->meta >= 0x06){
$this->level->setBlock($this, new AirBlock(), true, false, true);
$this->level->setBlock($this, new Air(), true, false, true);
} else{
$this->level->setBlock($this, $this, true, false, true);
}

View File

@ -19,7 +19,10 @@
*
*/
class CarpetBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class Carpet extends Flowable{
public function __construct($meta = 0){
parent::__construct(CARPET, $meta, "Carpet");
$names = array(
@ -46,7 +49,7 @@ class CarpetBlock extends FlowableBlock{
$this->isSolid = true;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() !== AIR){
$this->level->setBlock($block, $this, true, false, true);
@ -60,8 +63,9 @@ class CarpetBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id, $this->meta, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true);
//TODO
//ServerAPI::request()->api->entity->drop($this, Item::get($this->id, $this->meta, 1));
$this->level->setBlock($this, new Air(), true, false, true);
return BLOCK_UPDATE_NORMAL;
}

View File

@ -19,18 +19,20 @@
*
*/
class CarrotBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class Carrot extends Flowable{
public function __construct($meta = 0){
parent::__construct(CARROT_BLOCK, $meta, "Carrot Block");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
@ -38,8 +40,8 @@ class CarrotBlock extends FlowableBlock{
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
public function onActivate(Item\Item $item, Player $player){
if($item->getID() === Item\DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
@ -55,8 +57,9 @@ class CarrotBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item\Item::get(CARROT, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true);
//TODO
//ServerAPI::request()->api->entity->drop($this, Item\Item::get(Item\CARROT, 0, 1));
$this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
@ -76,12 +79,12 @@ class CarrotBlock extends FlowableBlock{
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
$drops = array();
if($this->meta >= 0x07){
$drops[] = array(CARROT, 0, mt_rand(1, 4));
$drops[] = array(Item\CARROT, 0, mt_rand(1, 4));
} else{
$drops[] = array(CARROT, 0, 1);
$drops[] = array(Item\CARROT, 0, 1);
}
return $drops;

View File

@ -19,14 +19,17 @@
*
*/
class ChestBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Chest extends Transparent{
public function __construct($meta = 0){
parent::__construct(CHEST, $meta, "Chest");
$this->isActivable = true;
$this->hardness = 15;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(
0 => 4,
1 => 2,
@ -35,7 +38,7 @@ class ChestBlock extends TransparentBlock{
);
$chest = false;
$this->meta = $faces[$player->entity->getDirection()];
$this->meta = $faces[$player->getDirection()];
for($side = 2; $side <= 5; ++$side){
if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){
@ -44,8 +47,8 @@ class ChestBlock extends TransparentBlock{
continue;
}
$c = $this->getSide($side);
if(($c instanceof ChestBlock) and $c->getMetadata() === $this->meta){
if((($tile = $this->level->getTile($c)) instanceof Chest) and !$tile->isPaired()){
if(($c instanceof Tile\Chest) and $c->getMetadata() === $this->meta){
if((($tile = $this->level->getTile($c)) instanceof Tile\Chest) and !$tile->isPaired()){
$chest = $tile;
break;
}
@ -55,15 +58,15 @@ class ChestBlock extends TransparentBlock{
$this->level->setBlock($block, $this, true, false, true);
$nbt = new NBT\Tag\Compound(false, array(
"Items" => new NBT\Tag\Enum("Items", array()),
"id" => new NBT\Tag\String("id", Tile::CHEST),
"id" => new NBT\Tag\String("id", Tile\Tile::CHEST),
"x" => new NBT\Tag\Int("x", $this->x),
"y" => new NBT\Tag\Int("y", $this->y),
"z" => new NBT\Tag\Int("z", $this->z)
));
$nbt->Items->setTagType(NBT\Tag_Compound);
$tile = new Chest($this->level, $nbt);
$tile = new Tile\Chest($this->level, $nbt);
if($chest instanceof Chest){
if($chest instanceof Tile\Chest){
$chest->pairWith($tile);
$tile->pairWith($chest);
}
@ -71,17 +74,17 @@ class ChestBlock extends TransparentBlock{
return true;
}
public function onBreak(Item $item, Player $player){
public function onBreak(Item\Item $item, Player $player){
$t = $this->level->getTile($this);
if($t instanceof Chest){
if($t instanceof Tile\Chest){
$t->unpair();
}
$this->level->setBlock($this, new AirBlock(), true, true, true);
$this->level->setBlock($this, new Air(), true, true, true);
return true;
}
public function onActivate(Item $item, Player $player){
public function onActivate(Item\Item $item, Player $player){
$top = $this->getSide(1);
if($top->isTransparent !== true){
return true;
@ -89,18 +92,18 @@ class ChestBlock extends TransparentBlock{
$t = $this->level->getTile($this);
$chest = false;
if($t instanceof Chest){
if($t instanceof Tile\Chest){
$chest = $t;
} else{
$nbt = new NBT\Tag\Compound(false, array(
"Items" => new NBT\Tag\Enum("Items", array()),
"id" => new NBT\Tag\String("id", Tile::CHEST),
"id" => new NBT\Tag\String("id", Tile\Tile::CHEST),
"x" => new NBT\Tag\Int("x", $this->x),
"y" => new NBT\Tag\Int("y", $this->y),
"z" => new NBT\Tag\Int("z", $this->z)
));
$nbt->Items->setTagType(NBT\Tag_Compound);
$chest = new Chest($this->level, $nbt);
$chest = new Tile\Chest($this->level, $nbt);
}
@ -113,7 +116,7 @@ class ChestBlock extends TransparentBlock{
return true;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
$drops = array(
array($this->id, 0, 1),
);

View File

@ -19,15 +19,18 @@
*
*/
class ClayBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Clay extends Solid{
public function __construct(){
parent::__construct(CLAY_BLOCK, 0, "Clay Block");
$this->hardness = 3;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array(CLAY, 0, 4),
array(Item\CLAY, 0, 4),
);
}
}

View File

@ -19,13 +19,16 @@
*
*/
class CoalBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Coal extends Solid{
public function __construct(){
parent::__construct(COAL_BLOCK, 0, "Coal Block");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -45,7 +48,7 @@ class CoalBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(COAL_BLOCK, 0, 1),

View File

@ -19,13 +19,16 @@
*
*/
class CoalOreBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class CoalOre extends Solid{
public function __construct(){
parent::__construct(COAL_ORE, 0, "Coal Ore");
$this->hardness = 15;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -45,10 +48,10 @@ class CoalOreBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(COAL, 0, 1),
array(Item\COAL, 0, 1),
);
} else{
return array();

View File

@ -19,13 +19,16 @@
*
*/
class CobblestoneBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Cobblestone extends Solid{
public function __construct(){
parent::__construct(COBBLESTONE, 0, "Cobblestone");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -45,7 +48,7 @@ class CobblestoneBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(COBBLESTONE, 0, 1),

View File

@ -19,7 +19,10 @@
*
*/
class CobblestoneStairsBlock extends StairBlock{
namespace PocketMine\Block;
use PocketMine;
class CobblestoneStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(COBBLESTONE_STAIRS, $meta, "Cobblestone Stairs");
}

View File

@ -19,7 +19,10 @@
*
*/
class CobwebBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class Cobweb extends Flowable{
public function __construct(){
parent::__construct(COBWEB, 0, "Cobweb");
$this->isSolid = true;
@ -27,7 +30,7 @@ class CobwebBlock extends FlowableBlock{
$this->hardness = 25;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array();
}
}

View File

@ -19,13 +19,16 @@
*
*/
class CyanFlowerBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class CyanFlower extends Flowable{
public function __construct(){
parent::__construct(CYAN_FLOWER, 0, "Cyan Flower");
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
$this->level->setBlock($block, $this, true, false, true);
@ -39,8 +42,9 @@ class CyanFlowerBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true);
//TODO
//ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id));
$this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}

View File

@ -19,13 +19,16 @@
*
*/
class DandelionBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class Dandelion extends Flowable{
public function __construct(){
parent::__construct(DANDELION, 0, "Dandelion");
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
$this->level->setBlock($block, $this, true, false, true);
@ -39,8 +42,9 @@ class DandelionBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true);
//TODO
//ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id));
$this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}

View File

@ -19,7 +19,10 @@
*
*/
class DeadBushBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class DeadBush extends Flowable{
public function __construct(){
parent::__construct(DEAD_BUSH, 0, "Dead Bush");
//$this->isReplaceable = true;
@ -29,7 +32,7 @@ class DeadBushBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false, false, true);
$this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}

View File

@ -19,13 +19,16 @@
*
*/
class DiamondBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Diamond extends Solid{
public function __construct(){
parent::__construct(DIAMOND_BLOCK, 0, "Diamond Block");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -39,7 +42,7 @@ class DiamondBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 4){
return array(
array(DIAMOND_BLOCK, 0, 1),

View File

@ -19,13 +19,16 @@
*
*/
class DiamondOreBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class DiamondOre extends Solid{
public function __construct(){
parent::__construct(DIAMOND_ORE, 0, "Diamond Ore");
$this->hardness = 15;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -39,10 +42,10 @@ class DiamondOreBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 4){
return array(
array(DIAMOND, 0, 1),
array(Item\DIAMOND, 0, 1),
);
} else{
return array();

View File

@ -19,19 +19,22 @@
*
*/
class DirtBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Dirt extends Solid{
public function __construct(){
parent::__construct(DIRT, 0, "Dirt");
$this->isActivable = true;
$this->hardness = 2.5;
}
public function onActivate(Item $item, Player $player){
public function onActivate(Item\Item $item, Player $player){
if($item->isHoe()){
if(($player->gamemode & 0x01) === 0){
$item->useOn($this);
}
$this->level->setBlock($this, Block\Block::get(FARMLAND, 0), true, false, true);
$this->level->setBlock($this, Block::get(FARMLAND, 0), true, false, true);
return true;
}

View File

@ -19,28 +19,22 @@
*
*/
class DoorBlock extends TransparentBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
use PocketMine\Block;
use PocketMine;
abstract class Door extends Transparent{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isSolid = false;
}
/**
* @param int $type
*
* @return bool|int
*/
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false);
if($this->getSide(1) instanceof DoorBlock){
$this->level->setBlock($this->getSide(1), new AirBlock(), false);
$this->level->setBlock($this, new Air(), false);
if($this->getSide(1) instanceof Door){
$this->level->setBlock($this->getSide(1), new Air(), false);
}
return BLOCK_UPDATE_NORMAL;
@ -50,26 +44,14 @@ class DoorBlock extends TransparentBlock{
return false;
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param integer $face
* @param integer $fx
* @param integer $fy
* @param integer $fz
*
* @return boolean
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($face === 1){
$blockUp = $this->getSide(1);
$blockDown = $this->getSide(0);
if($blockUp->isReplaceable === false or $blockDown->isTransparent === true){
return false;
}
$direction = $player->entity->getDirection();
$direction = $player->getDirection();
$face = array(
0 => 3,
1 => 4,
@ -82,7 +64,7 @@ class DoorBlock extends TransparentBlock{
if($next->getID() === $this->id or ($next2->isTransparent === false and $next->isTransparent === true)){ //Door hinge
$metaUp |= 0x01;
}
$this->level->setBlock($blockUp, Block\Block::get($this->id, $metaUp), true, false, true); //Top
$this->level->setBlock($blockUp, Block::get($this->id, $metaUp), true, false, true); //Top
$this->meta = $direction & 0x03;
$this->level->setBlock($block, $this, true, false, true); //Bottom
@ -92,50 +74,38 @@ class DoorBlock extends TransparentBlock{
return false;
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onBreak(Item $item, Player $player){
public function onBreak(Item\Item $item, Player $player){
if(($this->meta & 0x08) === 0x08){
$down = $this->getSide(0);
if($down->getID() === $this->id){
$this->level->setBlock($down, new AirBlock(), true, false, true);
$this->level->setBlock($down, new Air(), true, false, true);
}
} else{
$up = $this->getSide(1);
if($up->getID() === $this->id){
$this->level->setBlock($up, new AirBlock(), true, false, true);
$this->level->setBlock($up, new Air(), true, false, true);
}
}
$this->level->setBlock($this, new AirBlock(), true, false, true);
$this->level->setBlock($this, new Air(), true, false, true);
return true;
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onActivate(Item $item, Player $player){
public function onActivate(Item\Item $item, Player $player){
if(($this->meta & 0x08) === 0x08){ //Top
$down = $this->getSide(0);
if($down->getID() === $this->id){
$meta = $down->getMetadata() ^ 0x04;
$this->level->setBlock($down, Block\Block::get($this->id, $meta), true, false, true);
$players = ServerAPI::request()->api->player->getAll($this->level);
$this->level->setBlock($down, Block::get($this->id, $meta), true, false, true);
$players = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4);
unset($players[$player->CID]);
$pk = new LevelEventPacket;
$pk = new Network\Protocol\LevelEventPacket;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->evid = 1003;
$pk->data = 0;
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
Player::broadcastPacket($players, $pk);
return true;
}
@ -144,15 +114,15 @@ class DoorBlock extends TransparentBlock{
} else{
$this->meta ^= 0x04;
$this->level->setBlock($this, $this, true, false, true);
$players = ServerAPI::request()->api->player->getAll($this->level);
$players = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4);
unset($players[$player->CID]);
$pk = new LevelEventPacket;
$pk = new Network\Protocol\LevelEventPacket;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->evid = 1003;
$pk->data = 0;
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
Player::broadcastPacket($players, $pk);
}
return true;

View File

@ -19,7 +19,10 @@
*
*/
class DoubleSlabBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class DoubleSlab extends Solid{
public function __construct($meta = 0){
parent::__construct(DOUBLE_SLAB, $meta, "Double Slab");
$names = array(
@ -35,7 +38,7 @@ class DoubleSlabBlock extends SolidBlock{
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -55,7 +58,7 @@ class DoubleSlabBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(SLAB, $this->meta & 0x07, 2),

View File

@ -19,7 +19,10 @@
*
*/
class DoubleWoodSlabBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class DoubleWoodSlab extends Solid{
public function __construct($meta = 0){
parent::__construct(DOUBLE_WOOD_SLAB, $meta, "Double Wooden Slab");
$names = array(
@ -32,7 +35,7 @@ class DoubleWoodSlabBlock extends SolidBlock{
$this->hardness = 15;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -52,7 +55,7 @@ class DoubleWoodSlabBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array(WOOD_SLAB, $this->meta & 0x07, 2),
);

View File

@ -19,30 +19,17 @@
*
*/
class FallableBlock extends SolidBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
namespace PocketMine\Block;
use PocketMine;
class Fallable extends Solid{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->hasPhysics = true;
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param int $face
* @param int $fx
* @param int $fy
* @param int $fz
*
* @return mixed
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL);

View File

@ -19,13 +19,16 @@
*
*/
class FarmlandBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Farmland extends Solid{
public function __construct($meta = 0){
parent::__construct(FARMLAND, $meta, "Farmland");
$this->hardness = 3;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array(DIRT, 0, 1),
);

View File

@ -19,7 +19,10 @@
*
*/
class FenceBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Fence extends Transparent{
public function __construct(){
parent::__construct(FENCE, 0, "Fence");
$this->isFullBlock = false;

View File

@ -19,7 +19,10 @@
*
*/
class FenceGateBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class FenceGate extends Transparent{
public function __construct($meta = 0){
parent::__construct(FENCE_GATE, $meta, "Fence Gate");
$this->isActivable = true;
@ -31,33 +34,33 @@ class FenceGateBlock extends TransparentBlock{
$this->hardness = 15;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(
0 => 3,
1 => 0,
2 => 1,
3 => 2,
);
$this->meta = $faces[$player->entity->getDirection()] & 0x03;
$this->meta = $faces[$player->getDirection()] & 0x03;
$this->level->setBlock($block, $this, true, false, true);
return true;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array($this->id, 0, 1),
);
}
public function onActivate(Item $item, Player $player){
public function onActivate(Item\Item $item, Player $player){
$faces = array(
0 => 3,
1 => 0,
2 => 1,
3 => 2,
);
$this->meta = ($faces[$player->entity->getDirection()] & 0x03) | ((~$this->meta) & 0x04);
$this->meta = ($faces[$player->getDirection()] & 0x03) | ((~$this->meta) & 0x04);
if(($this->meta & 0x04) === 0x04){
$this->isFullBlock = true;
} else{

View File

@ -19,7 +19,10 @@
*
*/
class FireBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class Fire extends Flowable{
public function __construct($meta = 0){
parent::__construct(FIRE, $meta, "Fire");
$this->isReplaceable = true;
@ -28,7 +31,7 @@ class FireBlock extends FlowableBlock{
$this->hardness = 0;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array();
}
@ -36,16 +39,16 @@ class FireBlock extends FlowableBlock{
if($type === BLOCK_UPDATE_NORMAL){
for($s = 0; $s <= 5; ++$s){
$side = $this->getSide($s);
if($side->getID() !== AIR and !($side instanceof LiquidBlock)){
if($side->getID() !== AIR and !($side instanceof Liquid)){
return false;
}
}
$this->level->setBlock($this, new AirBlock(), true, false, true);
$this->level->setBlock($this, new Air(), true, false, true);
return BLOCK_UPDATE_NORMAL;
} elseif($type === BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== NETHERRACK){
$this->level->setBlock($this, new AirBlock(), true, false, true);
$this->level->setBlock($this, new Air(), true, false, true);
return BLOCK_UPDATE_NORMAL;
}

View File

@ -19,12 +19,10 @@
*
*/
class FlowableBlock extends TransparentBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
namespace PocketMine\Block;
use PocketMine;
class Flowable extends Transparent{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isFlowable = true;

View File

@ -19,8 +19,11 @@
*
*/
namespace PocketMine\Block;
use PocketMine;
class FurnaceBlock extends BurningFurnaceBlock{
class Furnace extends BurningFurnace{
public function __construct($meta = 0){
parent::__construct($meta);
$this->id = FURNACE;

View File

@ -19,8 +19,11 @@
*
*/
namespace PocketMine\Block;
use PocketMine;
class Generic extends Block{
class GenericBlock extends Block{
/**
* @param int $id
* @param int $meta
@ -30,51 +33,22 @@ class GenericBlock extends Block{
parent::__construct($id, $meta, $name);
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param integer $face
* @param integer $fx
* @param integer $fy
* @param integer $fz
*
* @return mixed
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
return $this->level->setBlock($this, $this, true, false, true);
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function isBreakable(Item $item, Player $player){
return ($this->breakable);
public function isBreakable(Item\Item $item, Player $player){
return $this->breakable;
}
/**
* @param Item $item
* @param Player $player
*
* @return mixed
*/
public function onBreak(Item $item, Player $player){
return $this->level->setBlock($this, new AirBlock(), true, false, true);
public function onBreak(Item\Item $item, Player $player){
return $this->level->setBlock($this, new Air(), true, false, true);
}
/**
* @param integer $type
*
* @return boolean
*/
public function onUpdate($type){
if($this->hasPhysics === true and $type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->getID() === AIR or ($down instanceof LiquidBlock)){
if($down->getID() === AIR or ($down instanceof Liquid)){
$data = array(
"x" => $this->x + 0.5,
"y" => $this->y + 0.5,
@ -82,10 +56,10 @@ class GenericBlock extends Block{
"Tile" => $this->id,
);
$server = ServerAPI::request();
$this->level->setBlock($this, new AirBlock(), false, false, true);
$this->level->setBlock($this, new Air(), false, false, true);
//TODO
$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
$e->spawnToAll();
//$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
//$e->spawnToAll();
$server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1);
}
@ -95,13 +69,7 @@ class GenericBlock extends Block{
return false;
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
public function onActivate(Item $item, Player $player){
public function onActivate(Item\Item $item, Player $player){
return $this->isActivable;
}
}

View File

@ -19,13 +19,16 @@
*
*/
class GlassBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Glass extends Transparent{
public function __construct(){
parent::__construct(GLASS, 0, "Glass");
$this->hardness = 1.5;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array();
}
}

View File

@ -19,7 +19,10 @@
*
*/
class GlassPaneBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class GlassPane extends Transparent{
public function __construct(){
parent::__construct(GLASS_PANE, 0, "Glass Pane");
$this->isFullBlock = false;

View File

@ -19,7 +19,10 @@
*
*/
class GlowingObsidianBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class GlowingObsidian extends Solid{
public function __construct($meta = 0){
parent::__construct(GLOWING_OBSIDIAN, $meta, "Glowing Obsidian");
}

View File

@ -19,7 +19,10 @@
*
*/
class GlowingRedstoneOreBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class GlowingRedstoneOre extends Solid{
public function __construct(){
parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");
$this->hardness = 15;
@ -27,18 +30,18 @@ class GlowingRedstoneOreBlock extends SolidBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){
$this->level->setBlock($this, Block\Block::get(REDSTONE_ORE, $this->meta), false, false, true);
$this->level->setBlock($this, Block::get(REDSTONE_ORE, $this->meta), false, false, true);
return BLOCK_UPDATE_WEAK;
} else{
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
$this->level->scheduleBlockUpdate(new Level\Position($this, 0, 0, $this->level), Utils\Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
}
return false;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -52,10 +55,10 @@ class GlowingRedstoneOreBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 4){
return array(
array(REDSTONE_DUST, 0, mt_rand(4, 5)),
array(Item\REDSTONE_DUST, 0, mt_rand(4, 5)),
);
} else{
return array();

View File

@ -19,15 +19,18 @@
*
*/
class GlowstoneBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Glowstone extends Transparent{
public function __construct(){
parent::__construct(GLOWSTONE_BLOCK, 0, "Glowstone");
$this->hardness = 1.5;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array(GLOWSTONE_DUST, 0, mt_rand(2, 4)),
array(Item\GLOWSTONE_DUST, 0, mt_rand(2, 4)),
);
}
}

View File

@ -19,13 +19,16 @@
*
*/
class GoldBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Gold extends Solid{
public function __construct(){
parent::__construct(GOLD_BLOCK, 0, "Gold Block");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -39,7 +42,7 @@ class GoldBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 4){
return array(
array(GOLD_BLOCK, 0, 1),

View File

@ -19,13 +19,16 @@
*
*/
class GoldOreBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class GoldOre extends Solid{
public function __construct(){
parent::__construct(GOLD_ORE, 0, "Gold Ore");
$this->hardness = 15;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -39,7 +42,7 @@ class GoldOreBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 4){
return array(
array(GOLD_ORE, 0, 1),

View File

@ -19,32 +19,35 @@
*
*/
class GrassBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Grass extends Solid{
public function __construct(){
parent::__construct(GRASS, 0, "Grass");
$this->isActivable = true;
$this->hardness = 3;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array(DIRT, 0, 1),
);
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){
public function onActivate(Item\Item $item, Player $player){
if($item->getID() === Item\DYE and $item->getMetadata() === 0x0F){
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
TallGrassObject::growGrass($this->level, $this, new Random(), 8, 2);
Level\Generator\Object\TallGrass::growGrass($this->level, $this, new Utils\Random(), 8, 2);
return true;
} elseif($item->isHoe()){
if(($player->gamemode & 0x01) === 0){
$item->useOn($this);
}
$this->level->setBlock($this, new FarmlandBlock());
$this->level->setBlock($this, new Farmland());
return true;
}

View File

@ -19,16 +19,19 @@
*
*/
class GravelBlock extends FallableBlock{
namespace PocketMine\Block;
use PocketMine;
class Gravel extends Fallable{
public function __construct(){
parent::__construct(GRAVEL, 0, "Gravel");
$this->hardness = 3;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if(mt_rand(1, 10) === 1){
return array(
array(FLINT, 0, 1),
array(Item\FLINT, 0, 1),
);
}

View File

@ -19,13 +19,16 @@
*
*/
class HayBaleBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class HayBale extends Solid{
public function __construct($meta = 0){
parent::__construct(HAY_BALE, $meta, "Hay Bale");
$this->hardness = 10;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(
0 => 0,
1 => 0,
@ -41,7 +44,7 @@ class HayBaleBlock extends SolidBlock{
return true;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array($this->id, 0, 1),
);

View File

@ -19,23 +19,26 @@
*
*/
class IceBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Ice extends Transparent{
public function __construct(){
parent::__construct(ICE, 0, "Ice");
$this->hardness = 2.5;
}
public function onBreak(Item $item, Player $player){
public function onBreak(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0){
$this->level->setBlock($this, new WaterBlock(), true, false, true);
$this->level->setBlock($this, new Water(), true, false, true);
} else{
$this->level->setBlock($this, new AirBlock(), true, false, true);
$this->level->setBlock($this, new Air(), true, false, true);
}
return true;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -55,7 +58,7 @@ class IceBlock extends TransparentBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array();
}
}

View File

@ -19,13 +19,16 @@
*
*/
class IronBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Iron extends Solid{
public function __construct(){
parent::__construct(IRON_BLOCK, 0, "Iron Block");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -41,7 +44,7 @@ class IronBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 3){
return array(
array(IRON_BLOCK, 0, 1),

View File

@ -19,7 +19,10 @@
*
*/
class IronBarsBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class IronBars extends Transparent{
public function __construct(){
parent::__construct(IRON_BARS, 0, "Iron Bars");
$this->isFullBlock = false;

View File

@ -19,14 +19,17 @@
*
*/
class IronDoorBlock extends DoorBlock{
namespace PocketMine\Block;
use PocketMine;
class IronDoor extends Door{
public function __construct($meta = 0){
parent::__construct(IRON_DOOR_BLOCK, $meta, "Iron Door Block");
//$this->isActivable = true;
$this->hardness = 25;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -46,10 +49,10 @@ class IronDoorBlock extends DoorBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(IRON_DOOR, 0, 1),
array(Item\IRON_DOOR, 0, 1),
);
} else{
return array();

View File

@ -19,13 +19,16 @@
*
*/
class IronOreBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class IronOre extends Solid{
public function __construct(){
parent::__construct(IRON_ORE, 0, "Iron Ore");
$this->hardness = 15;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -41,7 +44,7 @@ class IronOreBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 3){
return array(
array(IRON_ORE, 0, 1),

View File

@ -19,12 +19,15 @@
*
*/
class JungleWoodStairsBlock extends StairBlock{
namespace PocketMine\Block;
use PocketMine;
class JungleWoodStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(JUNGLE_WOOD_STAIRS, $meta, "Jungle Wood Stairs");
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array($this->id, 0, 1),
);

View File

@ -19,7 +19,10 @@
*
*/
class LadderBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Ladder extends Transparent{
public function __construct($meta = 0){
parent::__construct(LADDER, $meta, "Ladder");
$this->isSolid = false;
@ -27,7 +30,7 @@ class LadderBlock extends TransparentBlock{
$this->hardness = 2;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($target->isTransparent === false){
$faces = array(
2 => 2,
@ -50,7 +53,7 @@ class LadderBlock extends TransparentBlock{
if($type === BLOCK_UPDATE_NORMAL){
/*if($this->getSide(0)->getID() === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item\Item::get(LADDER, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, true, true);
$this->level->setBlock($this, new Air(), true, true, true);
return BLOCK_UPDATE_NORMAL;
}*/
}
@ -58,7 +61,7 @@ class LadderBlock extends TransparentBlock{
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array($this->id, 0, 1),
);

View File

@ -19,13 +19,16 @@
*
*/
class LapisBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Lapis extends Solid{
public function __construct(){
parent::__construct(LAPIS_BLOCK, 0, "Lapis Block");
$this->hardness = 15;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -41,7 +44,7 @@ class LapisBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 3){
return array(
array(LAPIS_BLOCK, 0, 1),

View File

@ -19,13 +19,16 @@
*
*/
class LapisOreBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class LapisOre extends Solid{
public function __construct(){
parent::__construct(LAPIS_ORE, 0, "Lapis Ore");
$this->hardness = 15;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -41,10 +44,10 @@ class LapisOreBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 3){
return array(
array(DYE, 4, mt_rand(4, 8)),
array(Item\DYE, 4, mt_rand(4, 8)),
);
} else{
return array();

View File

@ -19,13 +19,16 @@
*
*/
class LavaBlock extends LiquidBlock{
namespace PocketMine\Block;
use PocketMine;
class Lava extends Liquid{
public function __construct($meta = 0){
parent::__construct(LAVA, $meta, "Lava");
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, BLOCK_UPDATE_NORMAL);
@ -35,7 +38,7 @@ class LavaBlock extends LiquidBlock{
public function getSourceCount(){
$count = 0;
for($side = 2; $side <= 5; ++$side){
if($this->getSide($side) instanceof LavaBlock){
if($this->getSide($side) instanceof Lava){
$b = $this->getSide($side);
$level = $b->meta & 0x07;
if($level == 0x00){
@ -50,12 +53,12 @@ class LavaBlock extends LiquidBlock{
public function checkWater(){
for($side = 1; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b instanceof WaterBlock){
if($b instanceof Water){
$level = $this->meta & 0x07;
if($level == 0x00){
$this->level->setBlock($this, new ObsidianBlock(), false, false, true);
$this->level->setBlock($this, new Obsidian(), false, false, true);
} else{
$this->level->setBlock($this, new CobblestoneBlock(), false, false, true);
$this->level->setBlock($this, new Cobblestone(), false, false, true);
}
}
}
@ -64,7 +67,7 @@ class LavaBlock extends LiquidBlock{
public function getFrom(){
for($side = 0; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b instanceof LavaBlock){
if($b instanceof Lava){
$tlevel = $b->meta & 0x07;
$level = $this->meta & 0x07;
if(($tlevel + 2) == $level || ($side == 0x01 && $level == 0x01) || ($tlevel == 6 && $level == 7)){
@ -94,17 +97,17 @@ class LavaBlock extends LiquidBlock{
$from = $this->getFrom();
if($from !== null || $level == 0x00){
if($level !== 0x07){
if($down instanceof AirBlock || $down instanceof LavaBlock){
$this->level->setBlock($down, new LavaBlock(0x01), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
if($down instanceof Air || $down instanceof Lava){
$this->level->setBlock($down, new Lava(0x01), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Level\Position($down, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
} else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b instanceof LavaBlock){
if($b instanceof Lava){
} elseif($b->isFlowable === true){
$this->level->setBlock($b, new LavaBlock(min($level + 2, 7)), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
$this->level->setBlock($b, new Lava(min($level + 2, 7)), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Level\Position($b, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
}
}
}
@ -113,31 +116,31 @@ class LavaBlock extends LiquidBlock{
//Extend Remove for Left Lavas
for($side = 2; $side <= 5; ++$side){
$sb = $this->getSide($side);
if($sb instanceof LavaBlock){
if($sb instanceof Lava){
$tlevel = $sb->meta & 0x07;
if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Level\Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($sb, new AirBlock(), false, false, true);
$this->level->setBlock($sb, new Air(), false, false, true);
}
}
$b = $this->getSide(0)->getSide($side);
if($b instanceof LavaBlock){
if($b instanceof Lava){
$tlevel = $b->meta & 0x07;
if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Level\Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($b, new AirBlock(), false, false, true);
$this->level->setBlock($b, new Air(), false, false, true);
}
}
//ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($this, new AirBlock(), false, false, true);
$this->level->setBlock($this, new Air(), false, false, true);
}
return false;

View File

@ -19,18 +19,22 @@
*
*/
class LeavesBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Leaves extends Transparent{
const OAK = 0;
const SPRUCE = 1;
const BIRCH = 2;
const JUNGLE = 3;
public function __construct($meta = 0){
parent::__construct(LEAVES, $meta, "Leaves");
$names = array(
LeavesBlock::OAK => "Oak Leaves",
LeavesBlock::SPRUCE => "Spruce Leaves",
LeavesBlock::BIRCH => "Birch Leaves",
3 => "",
self::OAK => "Oak Leaves",
self::SPRUCE => "Spruce Leaves",
self::BIRCH => "Birch Leaves",
self::JUNGLE => "Jungle Leaves",
);
$this->name = $names[$this->meta & 0x03];
$this->hardness = 1;
@ -115,12 +119,12 @@ class LeavesBlock extends TransparentBlock{
if($this->findLog($this, $visited, 0, $check) === true){
$this->level->setBlock($this, $this, false, false, true);
} else{
$this->level->setBlock($this, new AirBlock(), false, false, true);
$this->level->setBlock($this, new Air(), false, false, true);
if(mt_rand(1, 20) === 1){ //Saplings
//TODO
ServerAPI::request()->api->entity->drop($this, Item\Item::get(SAPLING, $this->meta & 0x03, 1));
}
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1, 200) === 1){ //Apples
if(($this->meta & 0x03) === self::OAK and mt_rand(1, 200) === 1){ //Apples
//TODO
ServerAPI::request()->api->entity->drop($this, Item\Item::get(APPLE, 0, 1));
}
@ -133,21 +137,21 @@ class LeavesBlock extends TransparentBlock{
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$this->meta |= 0x04;
$this->level->setBlock($this, $this, true, false, true);
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
$drops = array();
if($item->isShears()){
$drops[] = array(LEAVES, $this->meta & 0x03, 1);
} else{
if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = array(SAPLING, $this->meta & 0x03, 1);
$drops[] = array(Item\SAPLING, $this->meta & 0x03, 1);
}
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1, 200) === 1){ //Apples
$drops[] = array(APPLE, 0, 1);
if(($this->meta & 0x03) === self::OAK and mt_rand(1, 200) === 1){ //Apples
$drops[] = array(Item\APPLE, 0, 1);
}
}

View File

@ -19,12 +19,10 @@
*
*/
class LiquidBlock extends TransparentBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
namespace PocketMine\Block;
use PocketMine;
class Liquid extends Transparent{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isLiquid = true;

View File

@ -19,20 +19,23 @@
*
*/
class LitPumpkinBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class LitPumpkin extends Solid{
public function __construct(){
parent::__construct(LIT_PUMPKIN, "Jack o'Lantern");
$this->hardness = 5;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(
0 => 4,
1 => 2,
2 => 5,
3 => 3,
);
$this->meta = $faces[$player->entity->getDirection()];
$this->meta = $faces[$player->getDirection()];
$this->level->setBlock($block, $this, true, false, true);
return true;

View File

@ -19,15 +19,18 @@
*
*/
class MelonBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Melon extends Transparent{
public function __construct(){
parent::__construct(MELON_BLOCK, 0, "Melon Block");
$this->hardness = 5;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array(MELON_SLICE, 0, mt_rand(3, 7)),
array(Item\MELON_SLICE, 0, mt_rand(3, 7)),
);
}
}

View File

@ -19,18 +19,20 @@
*
*/
class MelonStemBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class MelonStem extends Flowable{
public function __construct($meta = 0){
parent::__construct(MELON_STEM, $meta, "Melon Stem");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
@ -41,8 +43,9 @@ class MelonStemBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item\Item::get(MELON_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new AirBlock(), false, false, true);
//TODO
//ServerAPI::request()->api->entity->drop($this, Item\Item::get(MELON_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
@ -63,7 +66,7 @@ class MelonStemBlock extends FlowableBlock{
$side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$this->level->setBlock($side, new MelonBlock(), true, false, true);
$this->level->setBlock($side, new Melon(), true, false, true);
}
}
}
@ -74,8 +77,8 @@ class MelonStemBlock extends FlowableBlock{
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
public function onActivate(Item\Item $item, Player $player){
if($item->getID() === Item\DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
@ -88,9 +91,9 @@ class MelonStemBlock extends FlowableBlock{
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array(MELON_SEEDS, 0, mt_rand(0, 2)),
array(Item\MELON_SEEDS, 0, mt_rand(0, 2)),
);
}
}

View File

@ -19,13 +19,16 @@
*
*/
class MossStoneBlock extends SolidBlock{
public function __construct(){
parent::__construct(MOSS_STONE, 0, "Moss Stone");
namespace PocketMine\Block;
use PocketMine;
class MossStone extends Solid{
public function __construct($meta){
parent::__construct(MOSS_STONE, $meta, "Moss Stone");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -45,10 +48,10 @@ class MossStoneBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(MOSS_STONE, 0, 1),
array(MOSS_STONE, $this->meta, 1),
);
} else{
return array();

View File

@ -19,13 +19,16 @@
*
*/
class NetherBricksBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class NetherBricks extends Solid{
public function __construct(){
parent::__construct(NETHER_BRICKS, 0, "Nether Bricks");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -45,7 +48,7 @@ class NetherBricksBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(NETHER_BRICKS, 0, 1),

View File

@ -19,7 +19,10 @@
*
*/
class NetherBricksStairsBlock extends StairBlock{
namespace PocketMine\Block;
use PocketMine;
class NetherBricksStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(NETHER_BRICKS_STAIRS, $meta, "Nether Bricks Stairs");
}

View File

@ -19,7 +19,10 @@
*
*/
class NetherReactorBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class NetherReactor extends Solid{
public function __construct($meta = 0){
parent::__construct(NETHER_REACTOR, $meta, "Nether Reactor");
$this->isActivable = true;

View File

@ -19,13 +19,16 @@
*
*/
class NetherrackBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Netherrack extends Solid{
public function __construct(){
parent::__construct(NETHERRACK, 0, "Netherrack");
$this->hardness = 2;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -45,7 +48,7 @@ class NetherrackBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(NETHERRACK, 0, 1),

View File

@ -19,13 +19,16 @@
*
*/
class ObsidianBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Obsidian extends Solid{
public function __construct(){
parent::__construct(OBSIDIAN, 0, "Obsidian");
$this->hardness = 6000;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -36,7 +39,7 @@ class ObsidianBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 5){
return array(
array(OBSIDIAN, 0, 1),

View File

@ -19,7 +19,10 @@
*
*/
class PlanksBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Planks extends Solid{
public function __construct($meta = 0){
parent::__construct(PLANKS, $meta, "Wooden Planks");
$names = array(

View File

@ -19,18 +19,20 @@
*
*/
class PotatoBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class Potato extends Flowable{
public function __construct($meta = 0){
parent::__construct(POTATO_BLOCK, $meta, "Potato Block");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
@ -38,8 +40,8 @@ class PotatoBlock extends FlowableBlock{
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
public function onActivate(Item\Item $item, Player $player){
if($item->getID() === Item\DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
@ -55,8 +57,9 @@ class PotatoBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item\Item::get(POTATO, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true);
//TODO
//ServerAPI::request()->api->entity->drop($this, Item\Item::get(POTATO, 0, 1));
$this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
@ -76,12 +79,12 @@ class PotatoBlock extends FlowableBlock{
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
$drops = array();
if($this->meta >= 0x07){
$drops[] = array(POTATO, 0, mt_rand(1, 4));
$drops[] = array(Item\POTATO, 0, mt_rand(1, 4));
} else{
$drops[] = array(POTATO, 0, 1);
$drops[] = array(Item\POTATO, 0, 1);
}
return $drops;

View File

@ -19,7 +19,10 @@
*
*/
class PumpkinBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Pumpkin extends Solid{
public function __construct(){
parent::__construct(PUMPKIN, "Pumpkin");
$this->hardness = 5;

View File

@ -19,18 +19,20 @@
*
*/
class PumpkinStemBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class PumpkinStem extends Flowable{
public function __construct($meta = 0){
parent::__construct(PUMPKIN_STEM, $meta, "Pumpkin Stem");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
@ -41,8 +43,9 @@ class PumpkinStemBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item\Item::get(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new AirBlock(), false, false, true);
//TODO
//ServerAPI::request()->api->entity->drop($this, Item\Item::get(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
@ -63,7 +66,7 @@ class PumpkinStemBlock extends FlowableBlock{
$side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$this->level->setBlock($side, new PumpkinBlock(), true, false, true);
$this->level->setBlock($side, new Pumpkin(), true, false, true);
}
}
}
@ -74,8 +77,8 @@ class PumpkinStemBlock extends FlowableBlock{
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
public function onActivate(Item\Item $item, Player $player){
if($item->getID() === Item\DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta = 0x07;
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
@ -88,9 +91,9 @@ class PumpkinStemBlock extends FlowableBlock{
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array(PUMPKIN_SEEDS, 0, mt_rand(0, 2)),
array(Item\PUMPKIN_SEEDS, 0, mt_rand(0, 2)),
);
}
}

View File

@ -19,7 +19,10 @@
*
*/
class QuartzBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Quartz extends Solid{
public function __construct($meta = 0){
parent::__construct(QUARTZ_BLOCK, $meta, "Quartz Block");
$names = array(
@ -31,7 +34,7 @@ class QuartzBlock extends SolidBlock{
$this->name = $names[$this->meta & 0x03];
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -51,7 +54,7 @@ class QuartzBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(QUARTZ_BLOCK, $this->meta & 0x03, 1),

View File

@ -19,7 +19,10 @@
*
*/
class QuartzStairsBlock extends StairBlock{
namespace PocketMine\Block;
use PocketMine;
class QuartzStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(QUARTZ_STAIRS, $meta, "Quartz Stairs");
}

View File

@ -19,7 +19,10 @@
*
*/
class RedMushroomBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class RedMushroom extends Flowable{
public function __construct(){
parent::__construct(RED_MUSHROOM, 0, "Red Mushroom");
$this->hardness = 0;
@ -29,8 +32,8 @@ class RedMushroomBlock extends FlowableBlock{
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO
ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id));
$this->level->setBlock($this, new AirBlock(), false);
//ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id));
$this->level->setBlock($this, new Air(), false);
return BLOCK_UPDATE_NORMAL;
}
@ -39,7 +42,7 @@ class RedMushroomBlock extends FlowableBlock{
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->isTransparent === false){
$this->level->setBlock($block, $this, true, false, true);

View File

@ -19,7 +19,10 @@
*
*/
class RedstoneOreBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class RedstoneOre extends Solid{
public function __construct(){
parent::__construct(REDSTONE_ORE, 0, "Redstone Ore");
$this->hardness = 15;
@ -27,7 +30,7 @@ class RedstoneOreBlock extends SolidBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){
$this->level->setBlock($this, Block\Block::get(GLOWING_REDSTONE_ORE, $this->meta), false, false, true);
$this->level->setBlock($this, Block::get(GLOWING_REDSTONE_ORE, $this->meta), false, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return BLOCK_UPDATE_WEAK;
@ -36,10 +39,10 @@ class RedstoneOreBlock extends SolidBlock{
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 2){
return array(
array(REDSTONE_DUST, 0, mt_rand(4, 5)),
array(Redstone\REDSTONE_DUST, 0, mt_rand(4, 5)),
);
} else{
return array();

View File

@ -19,7 +19,10 @@
*
*/
class SandBlock extends FallableBlock{
namespace PocketMine\Block;
use PocketMine;
class Sand extends Fallable{
public function __construct(){
parent::__construct(SAND, 0, "Sand");
$this->hardness = 2.5;

View File

@ -19,7 +19,10 @@
*
*/
class SandstoneBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Sandstone extends Solid{
public function __construct($meta = 0){
parent::__construct(SANDSTONE, $meta, "Sandstone");
$names = array(
@ -31,7 +34,7 @@ class SandstoneBlock extends SolidBlock{
$this->hardness = 4;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -51,7 +54,7 @@ class SandstoneBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(SANDSTONE, $this->meta & 0x03, 1),

View File

@ -19,7 +19,10 @@
*
*/
class SandstoneStairsBlock extends StairBlock{
namespace PocketMine\Block;
use PocketMine;
class SandstoneStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(SANDSTONE_STAIRS, $meta, "Sandstone Stairs");
}

View File

@ -19,7 +19,10 @@
*
*/
class SaplingBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class Sapling extends Flowable{
const OAK = 0;
const SPRUCE = 1;
const BIRCH = 2;
@ -39,11 +42,10 @@ class SaplingBlock extends FlowableBlock{
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
@ -51,9 +53,9 @@ class SaplingBlock extends FlowableBlock{
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
public function onActivate(Item\Item $item, Player $player){
if($item->getID() === Item\DYE and $item->getMetadata() === 0x0F){ //Bonemeal
Level\Generator\Object\Tree::growTree($this->level, $this, new Utils\Random(), $this->meta & 0x03);
if(($player->gamemode & 0x01) === 0){
$item->count--;
}
@ -68,15 +70,15 @@ class SaplingBlock extends FlowableBlock{
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO
ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true);
//ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id));
$this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
} elseif($type === BLOCK_UPDATE_RANDOM){ //Growth
if(mt_rand(1, 7) === 1){
if(($this->meta & 0x08) === 0x08){
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
Level\Generator\Object\Tree::growTree($this->level, $this, new Utils\Random(), $this->meta & 0x03);
} else{
$this->meta |= 0x08;
$this->level->setBlock($this, $this, true, false, true);
@ -91,7 +93,7 @@ class SaplingBlock extends FlowableBlock{
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array($this->id, $this->meta & 0x03, 1),
);

View File

@ -19,7 +19,10 @@
*
*/
class SignPostBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class SignPost extends Transparent{
public function __construct($meta = 0){
parent::__construct(SIGN_POST, $meta, "Sign Post");
$this->isSolid = false;
@ -27,7 +30,7 @@ class SignPostBlock extends TransparentBlock{
$this->hardness = 5;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($face !== 0){
$faces = array(
2 => 2,
@ -36,13 +39,13 @@ class SignPostBlock extends TransparentBlock{
5 => 5,
);
if(!isset($faces[$face])){
$this->meta = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F;
$this->level->setBlock($block, Block\Block::get(SIGN_POST, $this->meta), true, false, true);
$this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0F;
$this->level->setBlock($block, Block::get(SIGN_POST, $this->meta), true, false, true);
return true;
} else{
$this->meta = $faces[$face];
$this->level->setBlock($block, Block\Block::get(WALL_SIGN, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(WALL_SIGN, $this->meta), true, false, true);
return true;
}
@ -54,8 +57,9 @@ class SignPostBlock extends TransparentBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item\Item::get(SIGN, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, true, true);
//TODO
//ServerAPI::request()->api->entity->drop($this, Item\Item::get(SIGN, 0, 1));
$this->level->setBlock($this, new Air(), true, true, true);
return BLOCK_UPDATE_NORMAL;
}
@ -64,15 +68,15 @@ class SignPostBlock extends TransparentBlock{
return false;
}
public function onBreak(Item $item, Player $player){
$this->level->setBlock($this, new AirBlock(), true, true, true);
public function onBreak(Item\Item $item, Player $player){
$this->level->setBlock($this, new Air(), true, true, true);
return true;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array(SIGN, 0, 1),
array(Item\SIGN, 0, 1),
);
}
}

View File

@ -19,7 +19,10 @@
*
*/
class SlabBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class Slab extends Transparent{
public function __construct($meta = 0){
parent::__construct(SLAB, $meta, "Slab");
$names = array(
@ -41,15 +44,15 @@ class SlabBlock extends TransparentBlock{
$this->hardness = 30;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$this->meta &= 0x07;
if($face === 0){
if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, Block\Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
$this->level->setBlock($target, Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
} elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, Block\Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
} else{
@ -57,18 +60,18 @@ class SlabBlock extends TransparentBlock{
}
} elseif($face === 1){
if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, Block\Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
$this->level->setBlock($target, Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
} elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, Block\Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}
} elseif(!$player->entity->inBlock($block)){
} elseif(!$player->inBlock($block)){
if($block->getID() === SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, Block\Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}
@ -90,7 +93,7 @@ class SlabBlock extends TransparentBlock{
return true;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -110,7 +113,7 @@ class SlabBlock extends TransparentBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array($this->id, $this->meta & 0x07, 1),

View File

@ -19,7 +19,10 @@
*
*/
class SnowBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Snow extends Solid{
public function __construct(){
parent::__construct(SNOW_BLOCK, 0, "Snow Block");
$this->hardness = 1;

View File

@ -19,7 +19,10 @@
*
*/
class SnowLayerBlock extends FlowableBlock{
namespace PocketMine\Block;
use PocketMine;
class SnowLayer extends Flowable{
public function __construct($meta = 0){
parent::__construct(SNOW_LAYER, $meta, "Snow Layer");
$this->isReplaceable = true;
@ -28,9 +31,9 @@ class SnowLayerBlock extends FlowableBlock{
$this->hardness = 0.5;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down instanceof SolidBlock){
if($down instanceof Solid){
$this->level->setBlock($block, $this, true, false, true);
return true;
@ -42,7 +45,7 @@ class SnowLayerBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), true, false, true);
$this->level->setBlock($this, new Air(), true, false, true);
return BLOCK_UPDATE_NORMAL;
}
@ -51,10 +54,10 @@ class SnowLayerBlock extends FlowableBlock{
return false;
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isShovel() !== false){
return array(
array(SNOWBALL, 0, 1),
array(Item\SNOWBALL, 0, 1),
);
}

View File

@ -19,12 +19,11 @@
*
*/
class SolidBlock extends GenericBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
namespace PocketMine\Block;
use PocketMine;
class Solid extends Generic{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isSolid = true;

View File

@ -19,7 +19,10 @@
*
*/
class SoulSandBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class SoulSand extends Solid{
public function __construct(){
parent::__construct(SOUL_SAND, 0, "Soul Sand");
$this->hardness = 2.5;

View File

@ -19,7 +19,10 @@
*
*/
class SpongeBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Sponge extends Solid{
public function __construct(){
parent::__construct(SPONGE, "Sponge");
$this->hardness = 3;

View File

@ -19,12 +19,15 @@
*
*/
class SpruceWoodStairsBlock extends StairBlock{
namespace PocketMine\Block;
use PocketMine;
class SpruceWoodStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(SPRUCE_WOOD_STAIRS, $meta, "Spruce Wood Stairs");
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
return array(
array($this->id, 0, 1),
);

View File

@ -19,12 +19,11 @@
*
*/
class StairBlock extends TransparentBlock{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
namespace PocketMine\Block;
use PocketMine;
class Stair extends Transparent{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
if(($this->meta & 0x04) === 0x04){
@ -35,26 +34,14 @@ class StairBlock extends TransparentBlock{
$this->hardness = 30;
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param int $face
* @param int $fx
* @param int $fy
* @param int $fz
*
* @return bool|mixed
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(
0 => 0,
1 => 2,
2 => 1,
3 => 3,
);
$this->meta = $faces[$player->entity->getDirection()] & 0x03;
$this->meta = $faces[$player->getDirection()] & 0x03;
if(($fy > 0.5 and $face !== 1) or $face === 0){
$this->meta |= 0x04; //Upside-down stairs
}
@ -63,13 +50,7 @@ class StairBlock extends TransparentBlock{
return true;
}
/**
* @param Item $item
* @param Player $player
*
* @return array
*/
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array($this->id, 0, 1),

View File

@ -19,7 +19,10 @@
*
*/
class StillLavaBlock extends LiquidBlock{
namespace PocketMine\Block;
use PocketMine;
class StillLava extends Liquid{
public function __construct($meta = 0){
parent::__construct(STILL_LAVA, $meta, "Still Lava");
$this->hardness = 500;

View File

@ -19,7 +19,10 @@
*
*/
class StillWaterBlock extends WaterBlock{
namespace PocketMine\Block;
use PocketMine;
class StillWater extends Water{
public function __construct($meta = 0){
LiquidBlock::__construct(STILL_WATER, $meta, "Still Water");
$this->hardness = 500;

View File

@ -19,13 +19,16 @@
*
*/
class StoneBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class Stone extends Solid{
public function __construct(){
parent::__construct(STONE, 0, "Stone");
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -45,7 +48,7 @@ class StoneBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(COBBLESTONE, 0, 1),

View File

@ -19,7 +19,10 @@
*
*/
class StoneBrickStairsBlock extends StairBlock{
namespace PocketMine\Block;
use PocketMine;
class StoneBrickStairs extends Stair{
public function __construct($meta = 0){
parent::__construct(STONE_BRICK_STAIRS, $meta, "Stone Brick Stairs");
}

View File

@ -19,7 +19,10 @@
*
*/
class StoneBricksBlock extends SolidBlock{
namespace PocketMine\Block;
use PocketMine;
class StoneBricks extends Solid{
public function __construct($meta = 0){
parent::__construct(STONE_BRICKS, $meta, "Stone Bricks");
$names = array(
@ -32,7 +35,7 @@ class StoneBricksBlock extends SolidBlock{
$this->hardness = 30;
}
public function getBreakTime(Item $item, Player $player){
public function getBreakTime(Item\Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
@ -52,7 +55,7 @@ class StoneBricksBlock extends SolidBlock{
}
}
public function getDrops(Item $item, Player $player){
public function getDrops(Item\Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(STONE_BRICKS, $this->meta & 0x03, 1),

View File

@ -19,7 +19,10 @@
*
*/
class StoneWallBlock extends TransparentBlock{
namespace PocketMine\Block;
use PocketMine;
class StoneWall extends Transparent{
public function __construct($meta = 0){
$meta &= 0x01;
parent::__construct(STONE_WALL, $meta, "Cobblestone Wall");

Some files were not shown because too many files have changed in this diff Show More