diff --git a/src/BlockAPI.php b/src/BlockAPI.php index 7ee2cd7da..baf393e6a 100644 --- a/src/BlockAPI.php +++ b/src/BlockAPI.php @@ -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)); } } diff --git a/src/Player.php b/src/Player.php index 50fb6a739..454d4af46 100644 --- a/src/Player.php +++ b/src/Player.php @@ -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( diff --git a/src/PlayerAPI.php b/src/PlayerAPI.php index 80ff65eda..7ef5e36c1 100644 --- a/src/PlayerAPI.php +++ b/src/PlayerAPI.php @@ -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; diff --git a/src/block/Air.php b/src/block/Air.php index 9ce4a13b2..d37688c81 100644 --- a/src/block/Air.php +++ b/src/block/Air.php @@ -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; diff --git a/src/block/Bed.php b/src/block/Bed.php index 478e461cc..181e83ecf 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -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), ); } diff --git a/src/block/Bedrock.php b/src/block/Bedrock.php index 9f397d83b..b48b2da52 100644 --- a/src/block/Bedrock.php +++ b/src/block/Bedrock.php @@ -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; } diff --git a/src/block/Beetroot.php b/src/block/Beetroot.php index a6a5deb32..30a66f421 100644 --- a/src/block/Beetroot.php +++ b/src/block/Beetroot.php @@ -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; diff --git a/src/block/BirchWoodStairs.php b/src/block/BirchWoodStairs.php index f52f600cf..754fa9641 100644 --- a/src/block/BirchWoodStairs.php +++ b/src/block/BirchWoodStairs.php @@ -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), ); diff --git a/src/block/Block.php b/src/block/Block.php index 7bf716210..b33ffb1b7 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -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); } diff --git a/src/block/Bookshelf.php b/src/block/Bookshelf.php index 8884ed392..a207d9641 100644 --- a/src/block/Bookshelf.php +++ b/src/block/Bookshelf.php @@ -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; diff --git a/src/block/BrickStairs.php b/src/block/BrickStairs.php index dcd6f180b..51b3d0487 100644 --- a/src/block/BrickStairs.php +++ b/src/block/BrickStairs.php @@ -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"); } diff --git a/src/block/Bricks.php b/src/block/Bricks.php index 075761374..1fa8fdbda 100644 --- a/src/block/Bricks.php +++ b/src/block/Bricks.php @@ -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), diff --git a/src/block/BrownMushroom.php b/src/block/BrownMushroom.php index 430075cad..3fdc8a0d4 100644 --- a/src/block/BrownMushroom.php +++ b/src/block/BrownMushroom.php @@ -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); diff --git a/src/block/BurningFurnace.php b/src/block/BurningFurnace.php index 284e2d07a..f4396e5bb 100644 --- a/src/block/BurningFurnace.php +++ b/src/block/BurningFurnace.php @@ -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()); diff --git a/src/block/Cactus.php b/src/block/Cactus.php index 9efca6aaa..296e4eee5 100644 --- a/src/block/Cactus.php +++ b/src/block/Cactus.php @@ -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), ); diff --git a/src/block/Cake.php b/src/block/Cake.php index b2e434844..18f320286 100644 --- a/src/block/Cake.php +++ b/src/block/Cake.php @@ -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); } diff --git a/src/block/Carpet.php b/src/block/Carpet.php index 1453d2a3a..9dfb39500 100644 --- a/src/block/Carpet.php +++ b/src/block/Carpet.php @@ -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; } diff --git a/src/block/Carrot.php b/src/block/Carrot.php index 0c6340811..1f25d64a2 100644 --- a/src/block/Carrot.php +++ b/src/block/Carrot.php @@ -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; diff --git a/src/block/Chest.php b/src/block/Chest.php index e09ef5041..7af2afd43 100644 --- a/src/block/Chest.php +++ b/src/block/Chest.php @@ -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), ); diff --git a/src/block/Clay.php b/src/block/Clay.php index dc6fb4409..2571c138c 100644 --- a/src/block/Clay.php +++ b/src/block/Clay.php @@ -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), ); } } \ No newline at end of file diff --git a/src/block/Coal.php b/src/block/Coal.php index 56cbff50e..de0a4da33 100644 --- a/src/block/Coal.php +++ b/src/block/Coal.php @@ -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), diff --git a/src/block/CoalOre.php b/src/block/CoalOre.php index f90144377..17f87bd02 100644 --- a/src/block/CoalOre.php +++ b/src/block/CoalOre.php @@ -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(); diff --git a/src/block/Cobblestone.php b/src/block/Cobblestone.php index dcaaa73e2..78e324fa9 100644 --- a/src/block/Cobblestone.php +++ b/src/block/Cobblestone.php @@ -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), diff --git a/src/block/CobblestoneStairs.php b/src/block/CobblestoneStairs.php index c4edcd70b..345d8c475 100644 --- a/src/block/CobblestoneStairs.php +++ b/src/block/CobblestoneStairs.php @@ -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"); } diff --git a/src/block/Cobweb.php b/src/block/Cobweb.php index 521128e4b..d8a240656 100644 --- a/src/block/Cobweb.php +++ b/src/block/Cobweb.php @@ -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(); } } \ No newline at end of file diff --git a/src/block/CyanFlower.php b/src/block/CyanFlower.php index 5add4d09f..01bf7d391 100644 --- a/src/block/CyanFlower.php +++ b/src/block/CyanFlower.php @@ -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; } diff --git a/src/block/Dandelion.php b/src/block/Dandelion.php index ea37d7e6c..0834062a5 100644 --- a/src/block/Dandelion.php +++ b/src/block/Dandelion.php @@ -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; } diff --git a/src/block/DeadBush.php b/src/block/DeadBush.php index d0286873b..62f617895 100644 --- a/src/block/DeadBush.php +++ b/src/block/DeadBush.php @@ -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; } diff --git a/src/block/Diamond.php b/src/block/Diamond.php index ed5a51f6c..358751056 100644 --- a/src/block/Diamond.php +++ b/src/block/Diamond.php @@ -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), diff --git a/src/block/DiamondOre.php b/src/block/DiamondOre.php index 9ee4e8b88..afcb3cecc 100644 --- a/src/block/DiamondOre.php +++ b/src/block/DiamondOre.php @@ -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(); diff --git a/src/block/Dirt.php b/src/block/Dirt.php index e53aa818c..530f2ea3d 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -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; } diff --git a/src/block/DoorBlock.php b/src/block/Door.php similarity index 59% rename from src/block/DoorBlock.php rename to src/block/Door.php index 9371f179c..75cb9b711 100644 --- a/src/block/DoorBlock.php +++ b/src/block/Door.php @@ -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; diff --git a/src/block/DoubleSlab.php b/src/block/DoubleSlab.php index 9c1a040f8..fda700905 100644 --- a/src/block/DoubleSlab.php +++ b/src/block/DoubleSlab.php @@ -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), diff --git a/src/block/DoubleWoodSlab.php b/src/block/DoubleWoodSlab.php index 0633f62f7..081037d88 100644 --- a/src/block/DoubleWoodSlab.php +++ b/src/block/DoubleWoodSlab.php @@ -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), ); diff --git a/src/block/FallableBlock.php b/src/block/Fallable.php similarity index 69% rename from src/block/FallableBlock.php rename to src/block/Fallable.php index 1e3f7fb7a..82b4d0dd9 100644 --- a/src/block/FallableBlock.php +++ b/src/block/Fallable.php @@ -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); diff --git a/src/block/Farmland.php b/src/block/Farmland.php index 361e67e46..bf0389e44 100644 --- a/src/block/Farmland.php +++ b/src/block/Farmland.php @@ -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), ); diff --git a/src/block/Fence.php b/src/block/Fence.php index fdabcd0ba..df3d2c9bb 100644 --- a/src/block/Fence.php +++ b/src/block/Fence.php @@ -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; diff --git a/src/block/FenceGate.php b/src/block/FenceGate.php index ea366c7a5..855c71480 100644 --- a/src/block/FenceGate.php +++ b/src/block/FenceGate.php @@ -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{ diff --git a/src/block/Fire.php b/src/block/Fire.php index c978468af..afffa8ef7 100644 --- a/src/block/Fire.php +++ b/src/block/Fire.php @@ -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; } diff --git a/src/block/FlowableBlock.php b/src/block/Flowable.php similarity index 87% rename from src/block/FlowableBlock.php rename to src/block/Flowable.php index 5e550b9d3..3260c902a 100644 --- a/src/block/FlowableBlock.php +++ b/src/block/Flowable.php @@ -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; diff --git a/src/block/Furnace.php b/src/block/Furnace.php index fd451de62..87df5c23d 100644 --- a/src/block/Furnace.php +++ b/src/block/Furnace.php @@ -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; diff --git a/src/block/GenericBlock.php b/src/block/Generic.php similarity index 55% rename from src/block/GenericBlock.php rename to src/block/Generic.php index 1fd362bb7..f5b0a06f5 100644 --- a/src/block/GenericBlock.php +++ b/src/block/Generic.php @@ -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; } } \ No newline at end of file diff --git a/src/block/Glass.php b/src/block/Glass.php index dad9c4900..362ab94e6 100644 --- a/src/block/Glass.php +++ b/src/block/Glass.php @@ -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(); } } \ No newline at end of file diff --git a/src/block/GlassPane.php b/src/block/GlassPane.php index d7c1e9af5..5345c87b7 100644 --- a/src/block/GlassPane.php +++ b/src/block/GlassPane.php @@ -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; diff --git a/src/block/GlowingObsidian.php b/src/block/GlowingObsidian.php index b6765bde0..000004865 100644 --- a/src/block/GlowingObsidian.php +++ b/src/block/GlowingObsidian.php @@ -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"); } diff --git a/src/block/GlowingRedstoneOre.php b/src/block/GlowingRedstoneOre.php index 708eeee30..df5047359 100644 --- a/src/block/GlowingRedstoneOre.php +++ b/src/block/GlowingRedstoneOre.php @@ -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(); diff --git a/src/block/Glowstone.php b/src/block/Glowstone.php index 8ae19711d..51f630e05 100644 --- a/src/block/Glowstone.php +++ b/src/block/Glowstone.php @@ -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)), ); } } \ No newline at end of file diff --git a/src/block/Gold.php b/src/block/Gold.php index 33d288605..ba3683d17 100644 --- a/src/block/Gold.php +++ b/src/block/Gold.php @@ -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), diff --git a/src/block/GoldOre.php b/src/block/GoldOre.php index e2398ec3c..3ab81e5e4 100644 --- a/src/block/GoldOre.php +++ b/src/block/GoldOre.php @@ -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), diff --git a/src/block/Grass.php b/src/block/Grass.php index 6e1e30e56..38b6c0b94 100644 --- a/src/block/Grass.php +++ b/src/block/Grass.php @@ -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; } diff --git a/src/block/Gravel.php b/src/block/Gravel.php index e5fdef6de..bb9501330 100644 --- a/src/block/Gravel.php +++ b/src/block/Gravel.php @@ -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), ); } diff --git a/src/block/HayBale.php b/src/block/HayBale.php index 2c3a6a84e..4ffb417fe 100644 --- a/src/block/HayBale.php +++ b/src/block/HayBale.php @@ -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), ); diff --git a/src/block/Ice.php b/src/block/Ice.php index 006f9f3b0..93571016e 100644 --- a/src/block/Ice.php +++ b/src/block/Ice.php @@ -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(); } } \ No newline at end of file diff --git a/src/block/Iron.php b/src/block/Iron.php index 508eb7256..dc4bf4d77 100644 --- a/src/block/Iron.php +++ b/src/block/Iron.php @@ -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), diff --git a/src/block/IronBars.php b/src/block/IronBars.php index 726c66c0e..baced9a3d 100644 --- a/src/block/IronBars.php +++ b/src/block/IronBars.php @@ -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; diff --git a/src/block/IronDoor.php b/src/block/IronDoor.php index 9bcaec602..93bf9fa4c 100644 --- a/src/block/IronDoor.php +++ b/src/block/IronDoor.php @@ -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(); diff --git a/src/block/IronOre.php b/src/block/IronOre.php index 3d08f9ac7..3f9cd236e 100644 --- a/src/block/IronOre.php +++ b/src/block/IronOre.php @@ -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), diff --git a/src/block/JungleWoodStairs.php b/src/block/JungleWoodStairs.php index 681d3bb24..f49ed6e71 100644 --- a/src/block/JungleWoodStairs.php +++ b/src/block/JungleWoodStairs.php @@ -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), ); diff --git a/src/block/Ladder.php b/src/block/Ladder.php index b59c7c712..4a23ffeef 100644 --- a/src/block/Ladder.php +++ b/src/block/Ladder.php @@ -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), ); diff --git a/src/block/Lapis.php b/src/block/Lapis.php index 20016cfdd..adb342c28 100644 --- a/src/block/Lapis.php +++ b/src/block/Lapis.php @@ -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), diff --git a/src/block/LapisOre.php b/src/block/LapisOre.php index 6282210ec..c5268ccd7 100644 --- a/src/block/LapisOre.php +++ b/src/block/LapisOre.php @@ -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(); diff --git a/src/block/Lava.php b/src/block/Lava.php index d61f3e84c..fb6995750 100644 --- a/src/block/Lava.php +++ b/src/block/Lava.php @@ -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; diff --git a/src/block/Leaves.php b/src/block/Leaves.php index 82214c632..6fe25808b 100644 --- a/src/block/Leaves.php +++ b/src/block/Leaves.php @@ -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); } } diff --git a/src/block/LiquidBlock.php b/src/block/Liquid.php similarity index 88% rename from src/block/LiquidBlock.php rename to src/block/Liquid.php index 9d370d1b9..eba8034e9 100644 --- a/src/block/LiquidBlock.php +++ b/src/block/Liquid.php @@ -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; diff --git a/src/block/LitPumpkin.php b/src/block/LitPumpkin.php index f0af6b7f5..281322ce7 100644 --- a/src/block/LitPumpkin.php +++ b/src/block/LitPumpkin.php @@ -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; diff --git a/src/block/Melon.php b/src/block/Melon.php index 173c87da4..1a741a930 100644 --- a/src/block/Melon.php +++ b/src/block/Melon.php @@ -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)), ); } } \ No newline at end of file diff --git a/src/block/MelonStem.php b/src/block/MelonStem.php index 11ba10f13..bc3a5872a 100644 --- a/src/block/MelonStem.php +++ b/src/block/MelonStem.php @@ -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)), ); } } \ No newline at end of file diff --git a/src/block/MossStone.php b/src/block/MossStone.php index baa1049f0..332f0ad05 100644 --- a/src/block/MossStone.php +++ b/src/block/MossStone.php @@ -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(); diff --git a/src/block/NetherBrick.php b/src/block/NetherBrick.php index a84051f17..3a40367a7 100644 --- a/src/block/NetherBrick.php +++ b/src/block/NetherBrick.php @@ -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), diff --git a/src/block/NetherBricksStairs.php b/src/block/NetherBricksStairs.php index f12bf36b2..d0a92609b 100644 --- a/src/block/NetherBricksStairs.php +++ b/src/block/NetherBricksStairs.php @@ -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"); } diff --git a/src/block/NetherReactor.php b/src/block/NetherReactor.php index fa1faed78..a97a5c503 100644 --- a/src/block/NetherReactor.php +++ b/src/block/NetherReactor.php @@ -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; diff --git a/src/block/Netherrack.php b/src/block/Netherrack.php index 204f2f00a..ab34335ac 100644 --- a/src/block/Netherrack.php +++ b/src/block/Netherrack.php @@ -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), diff --git a/src/block/Obsidian.php b/src/block/Obsidian.php index c261c5053..d5332b9c2 100644 --- a/src/block/Obsidian.php +++ b/src/block/Obsidian.php @@ -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), diff --git a/src/block/Planks.php b/src/block/Planks.php index 32a473372..05c9ef1f4 100644 --- a/src/block/Planks.php +++ b/src/block/Planks.php @@ -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( diff --git a/src/block/PotatoBlock.php b/src/block/Potato.php similarity index 72% rename from src/block/PotatoBlock.php rename to src/block/Potato.php index 3818d8619..ebfe8d21a 100644 --- a/src/block/PotatoBlock.php +++ b/src/block/Potato.php @@ -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; diff --git a/src/block/Pumpkin.php b/src/block/Pumpkin.php index 76b7c3864..0b66c5a33 100644 --- a/src/block/Pumpkin.php +++ b/src/block/Pumpkin.php @@ -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; diff --git a/src/block/PumpkinStem.php b/src/block/PumpkinStem.php index 61fbe085c..9e6ee4c95 100644 --- a/src/block/PumpkinStem.php +++ b/src/block/PumpkinStem.php @@ -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)), ); } } \ No newline at end of file diff --git a/src/block/Quartz.php b/src/block/Quartz.php index 9acb6db1b..3933fcaf6 100644 --- a/src/block/Quartz.php +++ b/src/block/Quartz.php @@ -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), diff --git a/src/block/QuartzStairs.php b/src/block/QuartzStairs.php index 4b32815eb..40d8d50b9 100644 --- a/src/block/QuartzStairs.php +++ b/src/block/QuartzStairs.php @@ -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"); } diff --git a/src/block/RedMushroom.php b/src/block/RedMushroom.php index deaa8b086..0192b20c3 100644 --- a/src/block/RedMushroom.php +++ b/src/block/RedMushroom.php @@ -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); diff --git a/src/block/RedstoneOre.php b/src/block/RedstoneOre.php index 7e55e738b..bd50bc12e 100644 --- a/src/block/RedstoneOre.php +++ b/src/block/RedstoneOre.php @@ -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(); diff --git a/src/block/Sand.php b/src/block/Sand.php index f389df8b3..b4fe25bbe 100644 --- a/src/block/Sand.php +++ b/src/block/Sand.php @@ -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; diff --git a/src/block/Sandstone.php b/src/block/Sandstone.php index 6f7547787..56f589323 100644 --- a/src/block/Sandstone.php +++ b/src/block/Sandstone.php @@ -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), diff --git a/src/block/SandstoneStairs.php b/src/block/SandstoneStairs.php index f01fcfa14..b92f86652 100644 --- a/src/block/SandstoneStairs.php +++ b/src/block/SandstoneStairs.php @@ -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"); } diff --git a/src/block/Sapling.php b/src/block/Sapling.php index 97484c98a..b81d29b74 100644 --- a/src/block/Sapling.php +++ b/src/block/Sapling.php @@ -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), ); diff --git a/src/block/SignPost.php b/src/block/SignPost.php index 60c247c82..b398fae79 100644 --- a/src/block/SignPost.php +++ b/src/block/SignPost.php @@ -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), ); } } \ No newline at end of file diff --git a/src/block/Slab.php b/src/block/Slab.php index db313e87e..82c278ca8 100644 --- a/src/block/Slab.php +++ b/src/block/Slab.php @@ -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), diff --git a/src/block/Snow.php b/src/block/Snow.php index 069fdad07..cd100d5fd 100644 --- a/src/block/Snow.php +++ b/src/block/Snow.php @@ -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; diff --git a/src/block/SnowLayer.php b/src/block/SnowLayer.php index 9f33744b3..489b8f135 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -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), ); } diff --git a/src/block/SolidBlock.php b/src/block/Solid.php similarity index 88% rename from src/block/SolidBlock.php rename to src/block/Solid.php index 7d85862c6..99f2f6975 100644 --- a/src/block/SolidBlock.php +++ b/src/block/Solid.php @@ -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; diff --git a/src/block/SoulSand.php b/src/block/SoulSand.php index fc005fc72..a545d7163 100644 --- a/src/block/SoulSand.php +++ b/src/block/SoulSand.php @@ -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; diff --git a/src/block/Sponge.php b/src/block/Sponge.php index e7db72723..1afcb19ca 100644 --- a/src/block/Sponge.php +++ b/src/block/Sponge.php @@ -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; diff --git a/src/block/SpruceWoodStairs.php b/src/block/SpruceWoodStairs.php index dfd7f5df1..253e7f825 100644 --- a/src/block/SpruceWoodStairs.php +++ b/src/block/SpruceWoodStairs.php @@ -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), ); diff --git a/src/block/StairBlock.php b/src/block/Stair.php similarity index 66% rename from src/block/StairBlock.php rename to src/block/Stair.php index 26d8b35ef..828e39ffc 100644 --- a/src/block/StairBlock.php +++ b/src/block/Stair.php @@ -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), diff --git a/src/block/StillLava.php b/src/block/StillLava.php index b53174d2e..76d7d84c0 100644 --- a/src/block/StillLava.php +++ b/src/block/StillLava.php @@ -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; diff --git a/src/block/StillWater.php b/src/block/StillWater.php index 7c7e9da4e..e7e4d372b 100644 --- a/src/block/StillWater.php +++ b/src/block/StillWater.php @@ -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; diff --git a/src/block/Stone.php b/src/block/Stone.php index 166201e90..de7b906cf 100644 --- a/src/block/Stone.php +++ b/src/block/Stone.php @@ -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), diff --git a/src/block/StoneBrickStairs.php b/src/block/StoneBrickStairs.php index 5e772b43b..1346de5ff 100644 --- a/src/block/StoneBrickStairs.php +++ b/src/block/StoneBrickStairs.php @@ -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"); } diff --git a/src/block/StoneBricks.php b/src/block/StoneBricks.php index 1953a400d..ac5b42a4c 100644 --- a/src/block/StoneBricks.php +++ b/src/block/StoneBricks.php @@ -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), diff --git a/src/block/StoneWall.php b/src/block/StoneWall.php index 0305949e6..a11cb693e 100644 --- a/src/block/StoneWall.php +++ b/src/block/StoneWall.php @@ -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"); diff --git a/src/block/Stonecutter.php b/src/block/Stonecutter.php index ef9c4afe4..07301ea3c 100644 --- a/src/block/Stonecutter.php +++ b/src/block/Stonecutter.php @@ -19,19 +19,22 @@ * */ -class StonecutterBlock extends SolidBlock{ +namespace PocketMine\Block; +use PocketMine; + +class Stonecutter extends Solid{ public function __construct($meta = 0){ parent::__construct(STONECUTTER, $meta, "Stonecutter"); $this->isActivable = true; } - public function onActivate(Item $item, Player $player){ + public function onActivate(Item\Item $item, Player $player){ $player->toCraft[-1] = 2; return true; } - public function getDrops(Item $item, Player $player){ + public function getDrops(Item\Item $item, Player $player){ return array( array($this->id, 0, 1), ); diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index a8344ccc3..23e4516d2 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -19,25 +19,28 @@ * */ -class SugarcaneBlock extends FlowableBlock{ +namespace PocketMine\Block; +use PocketMine; + +class Sugarcane extends Flowable{ public function __construct($meta = 0){ parent::__construct(SUGARCANE_BLOCK, $meta, "Sugarcane"); $this->hardness = 0; } - public function getDrops(Item $item, Player $player){ + public function getDrops(Item\Item $item, Player $player){ return array( - array(SUGARCANE, 0, 1), + array(Item\SUGARCANE, 0, 1), ); } - public function onActivate(Item $item, Player $player){ + public function onActivate(Item\Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){ 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 SugarcaneBlock(), true, false, true); + $this->level->setBlock($b, new Sugarcane(), true, false, true); break; } } @@ -59,8 +62,8 @@ class SugarcaneBlock extends FlowableBlock{ $down = $this->getSide(0); if($down->isTransparent === true and $down->getID() !== SUGARCANE_BLOCK){ //Replace with common break method //TODO - ServerAPI::request()->api->entity->drop($this, Item\Item::get(SUGARCANE)); - $this->level->setBlock($this, new AirBlock(), false, false, true); + //ServerAPI::request()->api->entity->drop($this, Item\Item::get(SUGARCANE)); + $this->level->setBlock($this, new Air(), false, false, true); return BLOCK_UPDATE_NORMAL; } @@ -70,7 +73,7 @@ class SugarcaneBlock extends FlowableBlock{ 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 SugarcaneBlock(), true, false, true); + $this->level->setBlock($b, new Sugarcane(), true, false, true); break; } } @@ -88,10 +91,10 @@ class SugarcaneBlock 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->getID() === SUGARCANE_BLOCK){ - $this->level->setBlock($block, new SugarcaneBlock(), true, false, true); + $this->level->setBlock($block, new Sugarcane(), true, false, true); return true; } elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){ @@ -99,9 +102,8 @@ class SugarcaneBlock extends FlowableBlock{ $block1 = $down->getSide(3); $block2 = $down->getSide(4); $block3 = $down->getSide(5); - if(($block0 instanceof WaterBlock) or ($block1 instanceof WaterBlock) or ($block2 instanceof WaterBlock) or ($block3 instanceof WaterBlock)){ - $this->level->setBlock($block, new SugarcaneBlock(), true, false, true); - $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); + if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){ + $this->level->setBlock($block, new Sugarcane(), true, false, true); return true; } diff --git a/src/block/TNT.php b/src/block/TNT.php index 3d39d5bf7..500406937 100644 --- a/src/block/TNT.php +++ b/src/block/TNT.php @@ -19,15 +19,18 @@ * */ -class TNTBlock extends SolidBlock{ +namespace PocketMine\Block; +use PocketMine; + +class TNT extends Solid{ public function __construct(){ parent::__construct(TNT, 0, "TNT"); $this->hardness = 0; $this->isActivable = true; } - public function onActivate(Item $item, Player $player){ - if($item->getID() === FLINT_STEEL){ + public function onActivate(Item\Item $item, Player $player){ + if($item->getID() === Item\FLINT_STEEL){ if(($player->gamemode & 0x01) === 0){ $item->useOn($this); } @@ -38,10 +41,10 @@ class TNTBlock extends SolidBlock{ "power" => 4, "fuse" => 20 * 4, //4 seconds ); - $this->level->setBlock($this, new AirBlock(), false, false, true); + $this->level->setBlock($this, new Air(), false, false, true); //TODO - $e = ServerAPI::request()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data); - $e->spawnToAll(); + //$e = ServerAPI::request()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data); + //$e->spawnToAll(); return true; } diff --git a/src/block/TallGrass.php b/src/block/TallGrass.php index c91c5eb63..ba17ea347 100644 --- a/src/block/TallGrass.php +++ b/src/block/TallGrass.php @@ -19,7 +19,7 @@ * */ -class TallGrassBlock extends FlowableBlock{ +class TallGrass extends Flowable{ public function __construct($meta = 1){ parent::__construct(TALL_GRASS, $meta, "Tall Grass"); $this->isReplaceable = true; @@ -35,7 +35,7 @@ class TallGrassBlock 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; } @@ -44,15 +44,15 @@ class TallGrassBlock extends FlowableBlock{ return false; } - public function getDrops(Item $item, Player $player){ + public function getDrops(Item\Item $item, Player $player){ $drops = array(); $possibleDrops = array( - array(WHEAT_SEEDS, 0, 1), - array(CARROT, 0, 1), - array(POTATO, 0, 1), - array(BEETROOT_SEEDS, 0, 1), - array(MELON_SEEDS, 0, 1), - array(PUMPKIN_SEEDS, 0, 1), + array(Item\WHEAT_SEEDS, 0, 1), + array(Item\CARROT, 0, 1), + array(Item\POTATO, 0, 1), + array(Item\BEETROOT_SEEDS, 0, 1), + array(Item\MELON_SEEDS, 0, 1), + array(Item\PUMPKIN_SEEDS, 0, 1), 0, 0, 0, diff --git a/src/block/Torch.php b/src/block/Torch.php index b4b1912ce..a935e5f0b 100644 --- a/src/block/Torch.php +++ b/src/block/Torch.php @@ -19,7 +19,10 @@ * */ -class TorchBlock extends FlowableBlock{ +namespace PocketMine\Block; +use PocketMine; + +class Torch extends Flowable{ public function __construct($meta = 0){ parent::__construct(TORCH, $meta, "Torch"); $this->hardness = 0; @@ -39,8 +42,9 @@ class TorchBlock extends FlowableBlock{ ); if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === FENCE)){ //Replace with common break method - ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id, 0, 1)); - $this->level->setBlock($this, new AirBlock(), true, false, true); + //TODO + //ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id, 0, 1)); + $this->level->setBlock($this, new Air(), true, false, true); return BLOCK_UPDATE_NORMAL; } @@ -49,7 +53,7 @@ class TorchBlock 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){ if($target->isTransparent === false and $face !== 0){ $faces = array( 1 => 5, @@ -72,7 +76,7 @@ class TorchBlock extends FlowableBlock{ return false; } - public function getDrops(Item $item, Player $player){ + public function getDrops(Item\Item $item, Player $player){ return array( array($this->id, 0, 1), ); diff --git a/src/block/TransparentBlock.php b/src/block/Transparent.php similarity index 89% rename from src/block/TransparentBlock.php rename to src/block/Transparent.php index 36ec99b42..4c03a9dc3 100644 --- a/src/block/TransparentBlock.php +++ b/src/block/Transparent.php @@ -19,12 +19,11 @@ * */ -class TransparentBlock extends GenericBlock{ - /** - * @param int $id - * @param int $meta - * @param string $name - */ +namespace PocketMine\Block; +use PocketMine; + +class Transparent extends Generic{ + public function __construct($id, $meta = 0, $name = "Unknown"){ parent::__construct($id, $meta, $name); $this->isActivable = false; diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index 76ab716f1..7cc626fc5 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -19,7 +19,10 @@ * */ -class TrapdoorBlock extends TransparentBlock{ +namespace PocketMine\Block; +use PocketMine; + +class Trapdoor extends Transparent{ public function __construct($meta = 0){ parent::__construct(TRAPDOOR, $meta, "Trapdoor"); $this->isActivable = true; @@ -31,7 +34,7 @@ class TrapdoorBlock 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){ if(($target->isTransparent === false or $target->getID() === SLAB) and $face !== 0 and $face !== 1){ $faces = array( 2 => 0, @@ -51,13 +54,13 @@ class TrapdoorBlock 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), ); } - public function onActivate(Item $item, Player $player){ + public function onActivate(Item\Item $item, Player $player){ $this->meta ^= 0x04; $this->level->setBlock($this, $this, true, false, true); diff --git a/src/block/WallSign.php b/src/block/WallSign.php index 2931da86f..dccad3b15 100644 --- a/src/block/WallSign.php +++ b/src/block/WallSign.php @@ -19,7 +19,10 @@ * */ -class WallSignBlock extends SignPostBlock{ +namespace PocketMine\Block; +use PocketMine; + +class WallSign extends SignPost{ public function __construct($meta = 0){ TransparentBlock::__construct(WALL_SIGN, $meta, "Wall Sign"); } diff --git a/src/block/Water.php b/src/block/Water.php index b59250880..0fabda529 100644 --- a/src/block/Water.php +++ b/src/block/Water.php @@ -19,13 +19,16 @@ * */ -class WaterBlock extends LiquidBlock{ +namespace PocketMine\Block; +use PocketMine; + +class Water extends Liquid{ public function __construct($meta = 0){ parent::__construct(WATER, $meta, "Water"); $this->hardness = 500; } - 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, 10, BLOCK_UPDATE_NORMAL); @@ -35,7 +38,7 @@ class WaterBlock extends LiquidBlock{ public function getSourceCount(){ $count = 0; for($side = 2; $side <= 5; ++$side){ - if($this->getSide($side) instanceof WaterBlock){ + if($this->getSide($side) instanceof Water){ $b = $this->getSide($side); $level = $b->meta & 0x07; if($level == 0x00){ @@ -53,12 +56,12 @@ class WaterBlock extends LiquidBlock{ continue; } $b = $this->getSide($side); - if($b instanceof LavaBlock){ + if($b instanceof Lava){ $level = $b->meta & 0x07; if($level == 0x00){ - $this->level->setBlock($b, new ObsidianBlock(), false, false, true); + $this->level->setBlock($b, new Obsidian(), false, false, true); } else{ - $this->level->setBlock($b, new CobblestoneBlock(), false, false, true); + $this->level->setBlock($b, new Cobblestone(), false, false, true); } return true; @@ -71,7 +74,7 @@ class WaterBlock extends LiquidBlock{ public function getFrom(){ for($side = 0; $side <= 5; ++$side){ $b = $this->getSide($side); - if($b instanceof WaterBlock){ + if($b instanceof Water){ $tlevel = $b->meta & 0x07; $level = $this->meta & 0x07; if(($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01)){ @@ -100,18 +103,18 @@ class WaterBlock extends LiquidBlock{ //Has Source or Its Source if($from !== null || $level == 0x00){ if($level !== 0x07){ - if($down instanceof AirBlock || $down instanceof WaterBlock){ - $this->level->setBlock($down, new WaterBlock(0x01), false, false, true); + if($down instanceof Air || $down instanceof Water){ + $this->level->setBlock($down, new Water(0x01), false, false, true); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); } else{ for($side = 2; $side <= 5; ++$side){ $b = $this->getSide($side); - if($b instanceof WaterBlock){ + if($b instanceof Water){ if($this->getSourceCount() >= 2 && $level != 0x00){ - $this->level->setBlock($this, new WaterBlock(0), false, false, true); + $this->level->setBlock($this, new Water(0), false, false, true); } } elseif($b->isFlowable === true){ - $this->level->setBlock($b, new WaterBlock($level + 1), false, false, true); + $this->level->setBlock($b, new Water($level + 1), false, false, true); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); } } @@ -121,30 +124,30 @@ class WaterBlock extends LiquidBlock{ //Extend Remove for Left Waters for($side = 2; $side <= 5; ++$side){ $sb = $this->getSide($side); - if($sb instanceof WaterBlock){ + if($sb instanceof Water){ $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), 10, 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 WaterBlock){ + if($b instanceof Water){ $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), 10, 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; diff --git a/src/block/Wheat.php b/src/block/Wheat.php index 086162121..8f8ea0d59 100644 --- a/src/block/Wheat.php +++ b/src/block/Wheat.php @@ -19,18 +19,20 @@ * */ -class WheatBlock extends FlowableBlock{ +namespace PocketMine\Block; +use PocketMine; + +class Wheat extends Flowable{ public function __construct($meta = 0){ parent::__construct(WHEAT_BLOCK, $meta, "Wheat 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 WheatBlock 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){ @@ -56,8 +58,8 @@ class WheatBlock 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(WHEAT_SEEDS, 0, 1)); - $this->level->setBlock($this, new AirBlock(), false, false, true); + //ServerAPI::request()->api->entity->drop($this, Item\Item::get(WHEAT_SEEDS, 0, 1)); + $this->level->setBlock($this, new Air(), false, false, true); return BLOCK_UPDATE_NORMAL; } @@ -73,13 +75,13 @@ class WheatBlock 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(WHEAT, 0, 1); - $drops[] = array(WHEAT_SEEDS, 0, mt_rand(0, 3)); + $drops[] = array(Item\WHEAT, 0, 1); + $drops[] = array(Item\WHEAT_SEEDS, 0, mt_rand(0, 3)); } else{ - $drops[] = array(WHEAT_SEEDS, 0, 1); + $drops[] = array(Item\WHEAT_SEEDS, 0, 1); } return $drops; diff --git a/src/block/Wood.php b/src/block/Wood.php index 9560b3ce0..26b2cd2db 100644 --- a/src/block/Wood.php +++ b/src/block/Wood.php @@ -19,7 +19,10 @@ * */ -class WoodBlock extends SolidBlock{ +namespace PocketMine\Block; +use PocketMine; + +class Wood extends Solid{ const OAK = 0; const SPRUCE = 1; const BIRCH = 2; @@ -37,7 +40,7 @@ class WoodBlock extends SolidBlock{ $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, @@ -53,7 +56,7 @@ class WoodBlock extends SolidBlock{ return true; } - public function getDrops(Item $item, Player $player){ + public function getDrops(Item\Item $item, Player $player){ return array( array($this->id, $this->meta & 0x03, 1), ); diff --git a/src/block/WoodDoor.php b/src/block/WoodDoor.php index 20bffb45e..a709745dd 100644 --- a/src/block/WoodDoor.php +++ b/src/block/WoodDoor.php @@ -19,16 +19,19 @@ * */ -class WoodDoorBlock extends DoorBlock{ +namespace PocketMine\Block; +use PocketMine; + +class WoodDoor extends Door{ public function __construct($meta = 0){ parent::__construct(WOOD_DOOR_BLOCK, $meta, "Wood Door Block"); $this->isActivable = true; $this->hardness = 15; } - public function getDrops(Item $item, Player $player){ + public function getDrops(Item\Item $item, Player $player){ return array( - array(WOODEN_DOOR, 0, 1), + array(Item\WOODEN_DOOR, 0, 1), ); } } \ No newline at end of file diff --git a/src/block/WoodSlab.php b/src/block/WoodSlab.php index 5e6184ae2..619ae4eda 100644 --- a/src/block/WoodSlab.php +++ b/src/block/WoodSlab.php @@ -19,7 +19,10 @@ * */ -class WoodSlabBlock extends TransparentBlock{ +namespace PocketMine\Block; +use PocketMine; + +class WoodSlab extends Transparent{ public function __construct($meta = 0){ parent::__construct(WOOD_SLAB, $meta, "Wooden Slab"); $names = array( @@ -37,15 +40,15 @@ class WoodSlabBlock 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){ $this->meta &= 0x07; if($face === 0){ if($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $this->level->setBlock($target, Block\Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); + $this->level->setBlock($target, Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } elseif($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $this->level->setBlock($block, Block\Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); + $this->level->setBlock($block, Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } else{ @@ -53,18 +56,18 @@ class WoodSlabBlock extends TransparentBlock{ } } elseif($face === 1){ if($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $this->level->setBlock($target, Block\Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); + $this->level->setBlock($target, Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } elseif($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $this->level->setBlock($block, Block\Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); + $this->level->setBlock($block, Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } - } elseif(!$player->entity->inBlock($block)){ + } elseif(!$player->inBlock($block)){ if($block->getID() === WOOD_SLAB){ if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $this->level->setBlock($block, Block\Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); + $this->level->setBlock($block, Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } @@ -86,7 +89,7 @@ class WoodSlabBlock 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; } @@ -106,7 +109,7 @@ class WoodSlabBlock extends TransparentBlock{ } } - public function getDrops(Item $item, Player $player){ + public function getDrops(Item\Item $item, Player $player){ return array( array($this->id, $this->meta & 0x07, 1), ); diff --git a/src/block/WoodStairs.php b/src/block/WoodStairs.php index fc6eceaca..7136af7e5 100644 --- a/src/block/WoodStairs.php +++ b/src/block/WoodStairs.php @@ -19,12 +19,15 @@ * */ -class WoodStairsBlock extends StairBlock{ +namespace PocketMine\Block; +use PocketMine; + +class WoodStairs extends Stair{ public function __construct($meta = 0){ parent::__construct(WOOD_STAIRS, $meta, "Wood Stairs"); } - public function getBreakTime(Item $item, Player $player){ + public function getBreakTime(Item\Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } @@ -44,7 +47,7 @@ class WoodStairsBlock extends StairBlock{ } } - public function getDrops(Item $item, Player $player){ + public function getDrops(Item\Item $item, Player $player){ return array( array($this->id, 0, 1), ); diff --git a/src/block/Wool.php b/src/block/Wool.php index 293947642..dd38df85c 100644 --- a/src/block/Wool.php +++ b/src/block/Wool.php @@ -19,7 +19,10 @@ * */ -class WoolBlock extends SolidBlock{ +namespace PocketMine\Block; +use PocketMine; + +class Wool extends Solid{ public function __construct($meta = 0){ parent::__construct(WOOL, $meta, "Wool"); $names = array( diff --git a/src/block/Workbench.php b/src/block/Workbench.php index 6bbee151d..e68212b06 100644 --- a/src/block/Workbench.php +++ b/src/block/Workbench.php @@ -19,20 +19,23 @@ * */ -class WorkbenchBlock extends SolidBlock{ +namespace PocketMine\Block; +use PocketMine; + +class Workbench extends Solid{ public function __construct($meta = 0){ parent::__construct(WORKBENCH, $meta, "Crafting Table"); $this->isActivable = true; $this->hardness = 15; } - public function onActivate(Item $item, Player $player){ + public function onActivate(Item\Item $item, Player $player){ $player->toCraft[-1] = 1; return true; } - public function getDrops(Item $item, Player $player){ + public function getDrops(Item\Item $item, Player $player){ return array( array($this->id, 0, 1), ); diff --git a/src/entity/Human.php b/src/entity/Human.php index bee38649e..4f19a7756 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -46,19 +46,19 @@ class Human extends Creature implements ProjectileSource, InventorySource{ } $this->hotbar = array(-1, -1, -1, -1, -1, -1, -1, -1, -1); $this->armor = array( - 0 => ItemItem::get(AIR, 0, 0), - 1 => ItemItem::get(AIR, 0, 0), - 2 => ItemItem::get(AIR, 0, 0), - 3 => ItemItem::get(AIR, 0, 0) + 0 => Item::get(AIR, 0, 0), + 1 => Item::get(AIR, 0, 0), + 2 => Item::get(AIR, 0, 0), + 3 => Item::get(AIR, 0, 0) ); foreach($nbt->Inventory as $item){ if($item->Slot >= 0 and $item->Slot < 9){ //Hotbar $this->hotbar[$item->Slot] = isset($item->TrueSlot) ? $item->TrueSlot : -1; } elseif($item->Slot >= 100 and $item->Slot < 104){ //Armor - $this->armor[$item->Slot - 100] = ItemItem::get($item->id, $item->Damage, $item->Count); + $this->armor[$item->Slot - 100] = Item::get($item->id, $item->Damage, $item->Count); } else{ - $this->inventory[$item->Slot - 9] = ItemItem::get($item->id, $item->Damage, $item->Count); + $this->inventory[$item->Slot - 9] = Item::get($item->id, $item->Damage, $item->Count); } } $this->slot = $this->hotbar[0]; @@ -204,7 +204,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{ public function getArmorSlot($slot){ $slot = (int) $slot; if(!isset($this->armor[$slot])){ - $this->armor[$slot] = ItemItem::get(AIR, 0, 0); + $this->armor[$slot] = Item::get(AIR, 0, 0); } return $this->armor[$slot]; @@ -216,7 +216,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{ if(isset($this->armor[$i]) and ($this->armor[$i] instanceof Item) and $this->armor[$i]->getID() > AIR){ $slots[$i] = $this->armor[$i]->getID() !== AIR ? $this->armor[$i]->getID() - 256 : 0; } else{ - $this->armor[$i] = ItemItem::get(AIR, 0, 0); + $this->armor[$i] = Item::get(AIR, 0, 0); $slots[$i] = 255; } } @@ -354,7 +354,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{ $i->setCount($i->getCount() - $item->getCount()); $this->setSlot($s, $i); } else{ - $this->setSlot($s, ItemItem::get(AIR, 0, 0)); + $this->setSlot($s, Item::get(AIR, 0, 0)); } break; } @@ -380,7 +380,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{ public function getSlot($slot){ $slot = (int) $slot; if(!isset($this->inventory[$slot])){ - $this->inventory[$slot] = ItemItem::get(AIR, 0, 0); + $this->inventory[$slot] = Item::get(AIR, 0, 0); } return $this->inventory[$slot]; diff --git a/src/level/Level.php b/src/level/Level.php index 0fc607ff1..317715bb6 100644 --- a/src/level/Level.php +++ b/src/level/Level.php @@ -48,7 +48,12 @@ class Level{ public $tiles = array(); public $chunkTiles = array(); - public $nextSave, $level; + public $nextSave; + + /** + * @var PMF\LevelFormat + */ + public $level; public $stopTime; private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $generator; diff --git a/src/level/Position.php b/src/level/Position.php index 54f77dca7..c7c8a9d2a 100644 --- a/src/level/Position.php +++ b/src/level/Position.php @@ -25,7 +25,11 @@ use PocketMine; use PocketMine\Math\Vector3 as Vector3; class Position extends Vector3{ - public $level; + + /** + * @var Level + */ + public $level = null; public function __construct($x = 0, $y = 0, $z = 0, Level $level){ if(($x instanceof Vector3) === true){ diff --git a/src/tile/Container.php b/src/tile/Container.php index 795e66069..2af878a21 100644 --- a/src/tile/Container.php +++ b/src/tile/Container.php @@ -80,7 +80,7 @@ trait Container{ if($slot->getID() > AIR and $slot->getCount() > 0){ $slots[] = $slot; } else{ - $slots[] = ItemItem::get(AIR, 0, 0); + $slots[] = Item::get(AIR, 0, 0); } } } @@ -97,7 +97,7 @@ trait Container{ if($slot->getID() > AIR and $slot->getCount() > 0){ $slots[] = $slot; } else{ - $slots[] = ItemItem::get(AIR, 0, 0); + $slots[] = Item::get(AIR, 0, 0); } } } @@ -128,7 +128,7 @@ trait Container{ if($slot->getID() > AIR and $slot->getCount() > 0){ $slots[] = $slot; } else{ - $slots[] = ItemItem::get(AIR, 0, 0); + $slots[] = Item::get(AIR, 0, 0); } } $pk = new ContainerSetContentPacket; @@ -153,9 +153,9 @@ trait Container{ public function getSlot($s){ $i = $this->getSlotIndex($s); if($i === false or $i < 0){ - return ItemItem::get(AIR, 0, 0); + return Item::get(AIR, 0, 0); } else{ - return ItemItem::get($this->namedtag->Items[$i]->id, $this->namedtag->Items[$i]->Damage, $this->namedtag->Items[$i]->Count); + return Item::get($this->namedtag->Items[$i]->id, $this->namedtag->Items[$i]->Damage, $this->namedtag->Items[$i]->Count); } }