diff --git a/src/BlockAPI.php b/src/BlockAPI.php index c43c91e09..1be59e6b0 100644 --- a/src/BlockAPI.php +++ b/src/BlockAPI.php @@ -249,44 +249,18 @@ class BlockAPI{ } if(defined(strtoupper($b[0]))){ - $item = BlockAPI::getItem(constant(strtoupper($b[0])), $meta); + $item = Item\Item::get(constant(strtoupper($b[0])), $meta); if($item->getID() === AIR and strtoupper($b[0]) !== "AIR"){ - $item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta); + $item = Item\Item::get(((int) $b[0]) & 0xFFFF, $meta); } } else{ - $item = BlockAPI::getItem(((int) $b[0]) & 0xFFFF, $meta); + $item = Item\Item::get(((int) $b[0]) & 0xFFFF, $meta); } return $item; } } - public static function get($id, $meta = 0, Position $v = null){ - if(isset(Block::$class[$id])){ - $classname = Block::$class[$id]; - $b = new $classname($meta); - } else{ - $b = new GenericBlock((int) $id, $meta); - } - if($v instanceof Position){ - $b->position($v); - } - - return $b; - } - - public static function getItem($id, $meta = 0, $count = 1){ - $id = (int) $id; - if(isset(Item::$class[$id])){ - $classname = Item::$class[$id]; - $i = new $classname($meta, $count); - } else{ - $i = new Item($id, $meta, $count); - } - - return $i; - } - function __construct(){ $this->server = ServerAPI::request(); } @@ -383,7 +357,7 @@ class BlockAPI{ if(($player->gamemode & 0x01) === 0x00 and count($drops) > 0){ foreach($drops as $drop){ echo "I dropped something\n"; - //$this->server->api->entity->drop(new Position($target->x + 0.5, $target->y, $target->z + 0.5, $target->level), BlockAPI::getItem($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\Item::get($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2])); } } @@ -400,7 +374,7 @@ class BlockAPI{ if(($player->getGamemode() & 0x01) === 0){ $item = $player->getSlot($player->slot); } else{ - $item = BlockAPI::getItem(BlockAPI::$creative[$player->slot][0], BlockAPI::$creative[$player->slot][1], 1); + $item = 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 @@ -436,7 +410,7 @@ class BlockAPI{ if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){ if($item->getCount() <= 0){ - $player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0)); + $player->setSlot($player->slot, Item\Item::get(AIR, 0, 0)); } return false; @@ -490,7 +464,7 @@ class BlockAPI{ if(($player->getGamemode() & 0x01) === 0){ $item->setCount($item->getCount() - 1); if($item->getCount() <= 0){ - $player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0)); + $player->setSlot($player->slot, Item\Item::get(AIR, 0, 0)); } } diff --git a/src/EntityOLD.php b/src/EntityOLD.php index 1e393592e..5110c9dfa 100644 --- a/src/EntityOLD.php +++ b/src/EntityOLD.php @@ -178,14 +178,14 @@ if($this->class === ENTITY_PLAYER and $this->player instanceof Player and ($this $inv = array(); for($i = 0; $i < PLAYER_SURVIVAL_SLOTS; ++$i){ $slot = $this->player->getSlot($i); -$this->player->setSlot($i, BlockAPI::getItem(AIR, 0, 0)); +$this->player->setSlot($i, Item\Item::get(AIR, 0, 0)); if($slot->getID() !== AIR and $slot->getCount() > 0){ $inv[] = array($slot->getID(), $slot->getMetadata(), $slot->getCount()); } } for($re = 0; $re < 4; $re++){ $slot = $this->player->getArmor($re); -$this->player->setArmor($re, BlockAPI::getItem(AIR, 0, 0)); +$this->player->setArmor($re, Item\Item::get(AIR, 0, 0)); if($slot->getID() !== AIR and $slot->getCount() > 0){ $inv[] = array($slot->getID(), $slot->getMetadata(), $slot->getCount()); } @@ -246,7 +246,7 @@ return array(); private function spawnDrops(){ foreach($this->getDrops() as $drop){ -$this->server->api->entity->drop($this, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF), true); +$this->server->api->entity->drop($this, Item\Item::get($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF), true); } } @@ -485,9 +485,9 @@ $this->y = $ny; $fall = $this->level->getBlock(new Math\Vector3(intval($this->x - 0.5), intval(ceil($this->y)), intval($this->z - 0.5))); $down = $this->level->getBlock(new Math\Vector3(intval($this->x - 0.5), intval(ceil($this->y) - 1), intval($this->z - 0.5))); if($fall->isFullBlock === false or $down->isFullBlock === false){ -$this->server->api->entity->drop($this, BlockAPI::getItem($this->data["Tile"] & 0xFFFF, 0, 1), true); +$this->server->api->entity->drop($this, Item\Item::get($this->data["Tile"] & 0xFFFF, 0, 1), true); }else{ -$this->level->setBlock($fall, BlockAPI::get($this->data["Tile"]), true, false, true); +$this->level->setBlock($fall, Block\Block::get($this->data["Tile"]), true, false, true); } $this->server->api->handle("entity.motion", $this); $this->close(); @@ -710,7 +710,7 @@ $pk->z = $this->z; $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->roll = 0; -$pk->item = BlockAPI::getItem($this->type, $this->meta, $this->stack); +$pk->item = Item\Item::get($this->type, $this->meta, $this->stack); $pk->metadata = $this->getMetadata(); $player->dataPacket($pk); diff --git a/src/Player.php b/src/Player.php index 6f8dc1d5c..bc972d92a 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 = BlockAPI::getItem(AIR, 0, 0); + $pk->item = 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, BlockAPI::getItem(AIR, 0, 0)); + $this->setSlot($slot, Item\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, BlockAPI::getItem($item->getID(), $item->getMetadata(), $item->getCount())); + $this->setSlot($slot, Item\Item::get($item->getID(), $item->getMetadata(), $item->getCount())); } else{ - $this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $s->getCount() + $item->getCount())); + $this->setSlot($slot, Item\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(BlockAPI::getItem(BUCKET, 0, 3)); + $this->addItem(Item\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 = BlockAPI::getItem($d[0], $d[1], 1); + $item = 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 = BlockAPI::getItem(AIR, 0, 0); + $s = Item\Item::get(AIR, 0, 0); } else{ - $s = BlockAPI::getItem($s + 256, 0, 1); + $s = Item\Item::get($s + 256, 0, 1); } $slot = $this->getArmorSlot($i); if($slot->getID() !== AIR and $s->getID() === AIR){ - if($this->setArmorSlot($i, BlockAPI::getItem(AIR, 0, 0)) === false){ + if($this->setArmorSlot($i, Item\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, BlockAPI::getItem(AIR, 0, 0)); + $this->setSlot($sl, Item\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, BlockAPI::getItem(AIR, 0, 0)); + $this->setSlot($this->slot, Item\Item::get(AIR, 0, 0)); } if($slot->getID() === MUSHROOM_STEW or $slot->getID() === BEETROOT_SOUP){ - $this->addItem(BlockAPI::getItem(BOWL, 0, 1)); + $this->addItem(Item\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, BlockAPI::getItem(AIR, 0, 0), false); + $this->setSlot($this->slot, Item\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 = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->getCount() - $packet->item->getCount()); + $use = Item\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 = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount() - $slot->getCount()); + $craftItem = Item\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 = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount()); + $craftItem = Item\Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount()); if(count($this->toCraft) === 0){ $this->toCraft[-1] = 0; } - $use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->getCount()); + $use = Item\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 = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount()); + $item = 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 = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount()); + $item = 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/ServerAPI.php b/src/ServerAPI.php index d7ebfb13a..31fa06926 100644 --- a/src/ServerAPI.php +++ b/src/ServerAPI.php @@ -390,7 +390,11 @@ class ServerAPI{ if($this->getProperty("enable-query") === true){ $this->query = new QueryHandler(); } + + Block\Block::init(); + Item\Item::init(); Crafting::init(); + $this->schedule(2, array($this, "checkTickUpdates"), array(), true); $this->server->init(); unregister_tick_function(array($this->server, "tick")); diff --git a/src/block/Bed.php b/src/block/Bed.php index 3a02e1955..478e461cc 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -83,8 +83,8 @@ class BedBlock extends TransparentBlock{ $downNext = $this->getSide(0); if($next->isReplaceable === true and $downNext->isTransparent === false){ $meta = (($d + 3) % 4) & 0x03; - $this->level->setBlock($block, BlockAPI::get($this->id, $meta), true, false, true); - $this->level->setBlock($next, BlockAPI::get($this->id, $meta | 0x08), true, false, true); + $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); return true; } diff --git a/src/block/Beetroot.php b/src/block/Beetroot.php index 310cff52e..a6a5deb32 100644 --- a/src/block/Beetroot.php +++ b/src/block/Beetroot.php @@ -55,7 +55,7 @@ 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, BlockAPI::getItem(BEETROOT_SEEDS, 0, 1)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get(BEETROOT_SEEDS, 0, 1)); $this->level->setBlock($this, new AirBlock(), false, false, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/Block.php b/src/block/Block.php index 7da98fd78..69a2c6713 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -19,133 +19,185 @@ * */ +namespace PocketMine\Block; +const AIR = 0; +const STONE = 1; +const GRASS = 2; +const DIRT = 3; +const COBBLESTONE = 4; +const COBBLE = 4; +const PLANK = 5; +const PLANKS = 5; +const WOODEN_PLANK = 5; +const WOODEN_PLANKS = 5; +const SAPLING = 6; +const SAPLINGS = 6; +const BEDROCK = 7; +const WATER = 8; +const STILL_WATER = 9; +const LAVA = 10; +const STILL_LAVA = 11; +const SAND = 12; +const GRAVEL = 13; +const GOLD_ORE = 14; +const IRON_ORE = 15; +const COAL_ORE = 16; +const WOOD = 17; +const TRUNK = 17; +const LOG = 17; +const LEAVES = 18; +const LEAVE = 18; +const SPONGE = 19; +const GLASS = 20; +const LAPIS_ORE = 21; +const LAPIS_BLOCK = 22; + +const SANDSTONE = 24; + +const BED_BLOCK = 26; + + +const COBWEB = 30; +const TALL_GRASS = 31; +const BUSH = 32; +const DEAD_BUSH = 32; +const WOOL = 35; +const DANDELION = 37; +const ROSE = 38; +const CYAN_FLOWER = 38; +const BROWN_MUSHROOM = 39; +const RED_MUSHROOM = 40; +const GOLD_BLOCK = 41; +const IRON_BLOCK = 42; +const DOUBLE_SLAB = 43; +const DOUBLE_SLABS = 43; +const SLAB = 44; +const SLABS = 44; +const BRICKS = 45; +const BRICKS_BLOCK = 45; +const TNT = 46; +const BOOKSHELF = 47; +const MOSS_STONE = 48; +const MOSSY_STONE = 48; +const OBSIDIAN = 49; +const TORCH = 50; +const FIRE = 51; + +const WOOD_STAIRS = 53; +const WOODEN_STAIRS = 53; +const OAK_WOOD_STAIRS = 53; +const OAK_WOODEN_STAIRS = 53; +const CHEST = 54; + +const DIAMOND_ORE = 56; +const DIAMOND_BLOCK = 57; +const CRAFTING_TABLE = 58; +const WORKBENCH = 58; +const WHEAT_BLOCK = 59; +const FARMLAND = 60; +const FURNACE = 61; +const BURNING_FURNACE = 62; +const LIT_FURNACE = 62; +const SIGN_POST = 63; +const DOOR_BLOCK = 64; +const WOODEN_DOOR_BLOCK = 64; +const WOOD_DOOR_BLOCK = 64; +const LADDER = 65; + +const COBBLE_STAIRS = 67; +const COBBLESTONE_STAIRS = 67; +const WALL_SIGN = 68; + +const IRON_DOOR_BLOCK = 71; + +const REDSTONE_ORE = 73; +const GLOWING_REDSTONE_ORE = 74; +const LIT_REDSTONE_ORE = 74; + +const SNOW = 78; +const SNOW_LAYER = 78; +const ICE = 79; +const SNOW_BLOCK = 80; +const CACTUS = 81; +const CLAY_BLOCK = 82; +const REEDS = 83; +const SUGARCANE_BLOCK = 83; + +const FENCE = 85; +const PUMPKIN = 86; +const NETHERRACK = 87; +const SOUL_SAND = 88; +const GLOWSTONE = 89; +const GLOWSTONE_BLOCK = 89; + + +const LIT_PUMPKIN = 91; +const JACK_O_LANTERN = 91; +const CAKE_BLOCK = 92; + +const TRAPDOOR = 96; + +const STONE_BRICKS = 98; +const STONE_BRICK = 98; + +const IRON_BAR = 101; +const IRON_BARS = 101; +const GLASS_PANE = 102; +const GLASS_PANEL = 102; +const MELON_BLOCK = 103; +const PUMPKIN_STEM = 104; +const MELON_STEM = 105; + +const FENCE_GATE = 107; +const BRICK_STAIRS = 108; +const STONE_BRICK_STAIRS = 109; + +const NETHER_BRICKS = 112; +const NETHER_BRICK_BLOCK = 112; + +const NETHER_BRICKS_STAIRS = 114; + +const SANDSTONE_STAIRS = 128; + +const SPRUCE_WOOD_STAIRS = 134; +const SPRUCE_WOODEN_STAIRS = 134; +const BIRCH_WOOD_STAIRS = 135; +const BIRCH_WOODEN_STAIRS = 135; +const JUNGLE_WOOD_STAIRS = 136; +const JUNGLE_WOODEN_STAIRS = 136; + +const COBBLE_WALL = 139; +const STONE_WALL = 139; +const COBBLESTONE_WALL = 139; + +const CARROT_BLOCK = 141; +const POTATO_BLOCK = 142; + +const QUARTZ_BLOCK = 155; +const QUARTZ_STAIRS = 156; +const DOUBLE_WOOD_SLAB = 157; +const DOUBLE_WOODEN_SLAB = 157; +const DOUBLE_WOOD_SLABS = 157; +const DOUBLE_WOODEN_SLABS = 157; +const WOOD_SLAB = 158; +const WOODEN_SLAB = 158; +const WOOD_SLABS = 158; +const WOODEN_SLABS = 158; + +const HAY_BALE = 170; +const CARPET = 171; + +const COAL_BLOCK = 173; + +const BEETROOT_BLOCK = 244; +const STONECUTTER = 245; +const GLOWING_OBSIDIAN = 246; +const NETHER_REACTOR = 247; + +use PocketMine; + abstract class Block extends Position{ - public static $class = array( - AIR => "AirBlock", - STONE => "StoneBlock", - GRASS => "GrassBlock", - DIRT => "DirtBlock", - COBBLESTONE => "CobblestoneBlock", - PLANKS => "PlanksBlock", - SAPLING => "SaplingBlock", - BEDROCK => "BedrockBlock", - WATER => "WaterBlock", - STILL_WATER => "StillWaterBlock", - LAVA => "LavaBlock", - STILL_LAVA => "StillLavaBlock", - SAND => "SandBlock", - GRAVEL => "GravelBlock", - GOLD_ORE => "GoldOreBlock", - IRON_ORE => "IronOreBlock", - COAL_ORE => "CoalOreBlock", - WOOD => "WoodBlock", - LEAVES => "LeavesBlock", - SPONGE => "SpongeBlock", - GLASS => "GlassBlock", - LAPIS_ORE => "LapisOreBlock", - LAPIS_BLOCK => "LapisBlock", - SANDSTONE => "SandstoneBlock", - BED_BLOCK => "BedBlock", - COBWEB => "CobwebBlock", - TALL_GRASS => "TallGrassBlock", - DEAD_BUSH => "DeadBushBlock", - WOOL => "WoolBlock", - DANDELION => "DandelionBlock", - CYAN_FLOWER => "CyanFlowerBlock", - BROWN_MUSHROOM => "BrownMushroomBlock", - RED_MUSHROOM => "RedMushRoomBlock", - GOLD_BLOCK => "GoldBlock", - IRON_BLOCK => "IronBlock", - DOUBLE_SLAB => "DoubleSlabBlock", - SLAB => "SlabBlock", - BRICKS_BLOCK => "BricksBlock", - TNT => "TNTBlock", - BOOKSHELF => "BookshelfBlock", - MOSS_STONE => "MossStoneBlock", - OBSIDIAN => "ObsidianBlock", - TORCH => "TorchBlock", - FIRE => "FireBlock", - - WOOD_STAIRS => "WoodStairsBlock", - CHEST => "ChestBlock", - - DIAMOND_ORE => "DiamondOreBlock", - DIAMOND_BLOCK => "DiamondBlock", - WORKBENCH => "WorkbenchBlock", - WHEAT_BLOCK => "WheatBlock", - FARMLAND => "FarmlandBlock", - FURNACE => "FurnaceBlock", - BURNING_FURNACE => "BurningFurnaceBlock", - SIGN_POST => "SignPostBlock", - WOOD_DOOR_BLOCK => "WoodDoorBlock", - LADDER => "LadderBlock", - - COBBLESTONE_STAIRS => "CobblestoneStairsBlock", - WALL_SIGN => "WallSignBlock", - - IRON_DOOR_BLOCK => "IronDoorBlock", - REDSTONE_ORE => "RedstoneOreBlock", - GLOWING_REDSTONE_ORE => "GlowingRedstoneOreBlock", - - SNOW_LAYER => "SnowLayerBlock", - ICE => "IceBlock", - SNOW_BLOCK => "SnowBlock", - CACTUS => "CactusBlock", - CLAY_BLOCK => "ClayBlock", - SUGARCANE_BLOCK => "SugarcaneBlock", - - FENCE => "FenceBlock", - PUMPKIN => "PumpkinBlock", - NETHERRACK => "NetherrackBlock", - SOUL_SAND => "SoulSandBlock", - GLOWSTONE_BLOCK => "GlowstoneBlock", - - LIT_PUMPKIN => "LitPumpkinBlock", - CAKE_BLOCK => "CakeBlock", - - TRAPDOOR => "TrapdoorBlock", - - STONE_BRICKS => "StoneBricksBlock", - - IRON_BARS => "IronBarsBlock", - GLASS_PANE => "GlassPaneBlock", - MELON_BLOCK => "MelonBlock", - PUMPKIN_STEM => "PumpkinStemBlock", - MELON_STEM => "MelonStemBlock", - - FENCE_GATE => "FenceGateBlock", - BRICK_STAIRS => "BrickStairsBlock", - STONE_BRICK_STAIRS => "StoneBrickStairsBlock", - - NETHER_BRICKS => "NetherBricksBlock", - - NETHER_BRICKS_STAIRS => "NetherBricksStairsBlock", - - SANDSTONE_STAIRS => "SandstoneStairsBlock", - - SPRUCE_WOOD_STAIRS => "SpruceWoodStairsBlock", - BIRCH_WOOD_STAIRS => "BirchWoodStairsBlock", - JUNGLE_WOOD_STAIRS => "JungleWoodStairsBlock", - STONE_WALL => "StoneWallBlock", - - CARROT_BLOCK => "CarrotBlock", - POTATO_BLOCK => "PotatoBlock", - - QUARTZ_BLOCK => "QuartzBlock", - QUARTZ_STAIRS => "QuartzStairsBlock", - DOUBLE_WOOD_SLAB => "DoubleWoodSlabBlock", - WOOD_SLAB => "WoodSlabBlock", - - HAY_BALE => "HayBaleBlock", - CARPET => "CarpetBlock", - - COAL_BLOCK => "CoalBlock", - - BEETROOT_BLOCK => "BeetrootBlock", - STONECUTTER => "StonecutterBlock", - GLOWING_OBSIDIAN => "GlowingObsidianBlock", - NETHER_REACTOR => "NetherReactorBlock", - ); + public static $list = array(); protected $id; protected $meta; protected $name; @@ -166,6 +218,149 @@ abstract class Block extends Position{ public $y = 0; public $z = 0; + public static function init(){ + if(count(self::$init) === 0){ + self::$init = array( + AIR => new Air(), + STONE => new Stone(), + GRASS => new Grass(), + DIRT => new Dirt(), + COBBLESTONE => new Cobblestone(), + PLANKS => new Planks(), + SAPLING => new Sapling(), + BEDROCK => new Bedrock(), + WATER => new Water(), + STILL_WATER => new StillWater(), + LAVA => new Lava(), + STILL_LAVA => new StillLava(), + SAND => new Sand(), + GRAVEL => new Gravel(), + GOLD_ORE => new GoldOre(), + IRON_ORE => new IronOre(), + COAL_ORE => new CoalOre(), + WOOD => new Wood(), + LEAVES => new Leaves(), + SPONGE => new Sponge(), + GLASS => new Glass(), + LAPIS_ORE => new LapisOre(), + LAPIS_BLOCK => new Lapis(), + SANDSTONE => new Sandstone(), + BED_BLOCK => new Bed(), + COBWEB => new Cobweb(), + TALL_GRASS => new TallGrass(), + DEAD_BUSH => new DeadBush(), + WOOL => new Wool(), + DANDELION => new Dandelion(), + CYAN_FLOWER => new CyanFlower(), + BROWN_MUSHROOM => new BrownMushroom(), + RED_MUSHROOM => new RedMushRoom(), + GOLD_BLOCK => new Gold(), + IRON_BLOCK => new Iron(), + DOUBLE_SLAB => new DoubleSlab(), + SLAB => new Slab(), + BRICKS_BLOCK => new Bricks(), + TNT => new TNT(), + BOOKSHELF => new Bookshelf(), + MOSS_STONE => new MossStone(), + OBSIDIAN => new Obsidian(), + TORCH => new Torch(), + FIRE => new Fire(), + + WOOD_STAIRS => new WoodStairs(), + CHEST => new Chest(), + + DIAMOND_ORE => new DiamondOre(), + DIAMOND_BLOCK => new Diamond(), + WORKBENCH => new Workbench(), + WHEAT_BLOCK => new Wheat(), + FARMLAND => new Farmland(), + FURNACE => new Furnace(), + BURNING_FURNACE => new BurningFurnace(), + SIGN_POST => new SignPost(), + WOOD_DOOR_BLOCK => new WoodDoor(), + LADDER => new Ladder(), + + COBBLESTONE_STAIRS => new CobblestoneStairs(), + WALL_SIGN => new WallSign(), + + IRON_DOOR_BLOCK => new IronDoor(), + REDSTONE_ORE => new RedstoneOre(), + GLOWING_REDSTONE_ORE => new GlowingRedstoneOre(), + + SNOW_LAYER => new SnowLayer(), + ICE => new Ice(), + SNOW_BLOCK => new Snow(), + CACTUS => new Cactus(), + CLAY_BLOCK => new Clay(), + SUGARCANE_BLOCK => new Sugarcane(), + + FENCE => new Fence(), + PUMPKIN => new Pumpkin(), + NETHERRACK => new Netherrack(), + SOUL_SAND => new SoulSand(), + GLOWSTONE_BLOCK => new Glowstone(), + + LIT_PUMPKIN => new LitPumpkin(), + CAKE_BLOCK => new Cake(), + + TRAPDOOR => new Trapdoor(), + + STONE_BRICKS => new StoneBricks(), + + IRON_BARS => new IronBars(), + GLASS_PANE => new GlassPane(), + MELON_BLOCK => new Melon(), + PUMPKIN_STEM => new PumpkinStem(), + MELON_STEM => new MelonStem(), + + FENCE_GATE => new FenceGate(), + BRICK_STAIRS => new BrickStairs(), + STONE_BRICK_STAIRS => new StoneBrickStairs(), + + NETHER_BRICKS => new NetherBricks(), + + NETHER_BRICKS_STAIRS => new NetherBricksStairs(), + + SANDSTONE_STAIRS => new SandstoneStairs(), + + SPRUCE_WOOD_STAIRS => new SpruceWoodStairs(), + BIRCH_WOOD_STAIRS => new BirchWoodStairs(), + JUNGLE_WOOD_STAIRS => new JungleWoodStairs(), + STONE_WALL => new StoneWall(), + + CARROT_BLOCK => new Carrot(), + POTATO_BLOCK => new Potato(), + + QUARTZ_BLOCK => new Quartz(), + QUARTZ_STAIRS => new QuartzStairs(), + DOUBLE_WOOD_SLAB => new DoubleWoodSlab(), + WOOD_SLAB => new WoodSlab(), + + HAY_BALE => new HayBale(), + CARPET => new Carpet(), + + COAL_BLOCK => new Coal(), + + BEETROOT_BLOCK => new Beetroot(), + STONECUTTER => new Stonecutter(), + GLOWING_OBSIDIAN => new GlowingObsidian(), + ); + } + } + + public static function get($id, $meta = 0, Level\Position $pos = null){ + if(isset(self::$list[$id])){ + $block = clone self::$list[$id]; + $block->setMetadata($meta); + }else{ + $block = new Generic($id, $meta); + } + if($pos instanceof Position){ + $block->position($pos); + } + return $block; + } + public function __construct($id, $meta = 0, $name = "Unknown"){ $this->id = (int) $id; $this->meta = (int) $meta; @@ -187,7 +382,11 @@ abstract class Block extends Position{ } final public function getMetadata(){ - return $this->meta & 0x0F; + return $this->meta; + } + + final public function setMetadata($meta){ + $this->meta = $meta & 0x0F; } final public function position(Position $v){ @@ -217,7 +416,7 @@ abstract class Block extends Position{ public function getSide($side){ $v = parent::getSide($side); - if($this->level instanceof Level){ + if($this->level instanceof Level\Level){ return $this->level->getBlock($v); } @@ -228,13 +427,13 @@ abstract class Block extends Position{ return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")"; } - abstract function isBreakable(Item $item, Player $player); + abstract function isBreakable(Item\Item $item, Player $player); - abstract function onBreak(Item $item, Player $player); + abstract function onBreak(Item\Item $item, Player $player); - abstract function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz); + abstract function place(Item\Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz); - abstract function onActivate(Item $item, Player $player); + abstract function onActivate(Item\Item $item, Player $player); abstract function onUpdate($type); } diff --git a/src/block/BrownMushroom.php b/src/block/BrownMushroom.php index d0f940383..430075cad 100644 --- a/src/block/BrownMushroom.php +++ b/src/block/BrownMushroom.php @@ -28,7 +28,7 @@ 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, BlockAPI::getItem($this->id)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id)); $this->level->setBlock($this, new AirBlock(), false, false, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/Cactus.php b/src/block/Cactus.php index ea5887a07..9efca6aaa 100644 --- a/src/block/Cactus.php +++ b/src/block/Cactus.php @@ -31,7 +31,7 @@ class CactusBlock extends TransparentBlock{ $down = $this->getSide(0); if($down->getID() !== SAND and $down->getID() !== CACTUS){ //Replace with common break method $this->level->setBlock($this, new AirBlock(), false); - ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id)); return BLOCK_UPDATE_NORMAL; } diff --git a/src/block/Carpet.php b/src/block/Carpet.php index 8aa7f7628..1453d2a3a 100644 --- a/src/block/Carpet.php +++ b/src/block/Carpet.php @@ -60,7 +60,7 @@ 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, BlockAPI::getItem($this->id, $this->meta, 1)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id, $this->meta, 1)); $this->level->setBlock($this, new AirBlock(), true, false, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/Carrot.php b/src/block/Carrot.php index a58a211ce..0c6340811 100644 --- a/src/block/Carrot.php +++ b/src/block/Carrot.php @@ -55,7 +55,7 @@ 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, BlockAPI::getItem(CARROT, 0, 1)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get(CARROT, 0, 1)); $this->level->setBlock($this, new AirBlock(), false, false, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/CyanFlower.php b/src/block/CyanFlower.php index ce85b4e8a..5add4d09f 100644 --- a/src/block/CyanFlower.php +++ b/src/block/CyanFlower.php @@ -39,7 +39,7 @@ 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, BlockAPI::getItem($this->id)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id)); $this->level->setBlock($this, new AirBlock(), false, false, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/Dandelion.php b/src/block/Dandelion.php index 6848170f5..ea37d7e6c 100644 --- a/src/block/Dandelion.php +++ b/src/block/Dandelion.php @@ -39,7 +39,7 @@ 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, BlockAPI::getItem($this->id)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id)); $this->level->setBlock($this, new AirBlock(), false, false, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/Dirt.php b/src/block/Dirt.php index 5a6f9d70b..e53aa818c 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -31,7 +31,7 @@ class DirtBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0){ $item->useOn($this); } - $this->level->setBlock($this, BlockAPI::get(FARMLAND, 0), true, false, true); + $this->level->setBlock($this, Block\Block::get(FARMLAND, 0), true, false, true); return true; } diff --git a/src/block/DoorBlock.php b/src/block/DoorBlock.php index 0bc1b7b7e..9371f179c 100644 --- a/src/block/DoorBlock.php +++ b/src/block/DoorBlock.php @@ -82,7 +82,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, BlockAPI::get($this->id, $metaUp), true, false, true); //Top + $this->level->setBlock($blockUp, Block\Block::get($this->id, $metaUp), true, false, true); //Top $this->meta = $direction & 0x03; $this->level->setBlock($block, $this, true, false, true); //Bottom @@ -126,7 +126,7 @@ class DoorBlock extends TransparentBlock{ $down = $this->getSide(0); if($down->getID() === $this->id){ $meta = $down->getMetadata() ^ 0x04; - $this->level->setBlock($down, BlockAPI::get($this->id, $meta), true, false, true); + $this->level->setBlock($down, Block\Block::get($this->id, $meta), true, false, true); $players = ServerAPI::request()->api->player->getAll($this->level); unset($players[$player->CID]); $pk = new LevelEventPacket; diff --git a/src/block/GlowingRedstoneOre.php b/src/block/GlowingRedstoneOre.php index 2ccc1daaa..708eeee30 100644 --- a/src/block/GlowingRedstoneOre.php +++ b/src/block/GlowingRedstoneOre.php @@ -27,7 +27,7 @@ class GlowingRedstoneOreBlock extends SolidBlock{ public function onUpdate($type){ if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){ - $this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false, false, true); + $this->level->setBlock($this, Block\Block::get(REDSTONE_ORE, $this->meta), false, false, true); return BLOCK_UPDATE_WEAK; } else{ diff --git a/src/block/Ladder.php b/src/block/Ladder.php index 70bdc8d8e..b59c7c712 100644 --- a/src/block/Ladder.php +++ b/src/block/Ladder.php @@ -49,7 +49,7 @@ class LadderBlock 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, BlockAPI::getItem(LADDER, 0, 1)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get(LADDER, 0, 1)); $this->level->setBlock($this, new AirBlock(), true, true, true); return BLOCK_UPDATE_NORMAL; }*/ diff --git a/src/block/Leaves.php b/src/block/Leaves.php index 2e7bcb33c..82214c632 100644 --- a/src/block/Leaves.php +++ b/src/block/Leaves.php @@ -118,11 +118,11 @@ class LeavesBlock extends TransparentBlock{ $this->level->setBlock($this, new AirBlock(), false, false, true); if(mt_rand(1, 20) === 1){ //Saplings //TODO - ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1)); + 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 //TODO - ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get(APPLE, 0, 1)); } return BLOCK_UPDATE_NORMAL; diff --git a/src/block/MelonStem.php b/src/block/MelonStem.php index aa2275d4d..11ba10f13 100644 --- a/src/block/MelonStem.php +++ b/src/block/MelonStem.php @@ -41,7 +41,7 @@ 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, BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2))); + 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); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/PotatoBlock.php b/src/block/PotatoBlock.php index 3402d56f0..3818d8619 100644 --- a/src/block/PotatoBlock.php +++ b/src/block/PotatoBlock.php @@ -55,7 +55,7 @@ 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, BlockAPI::getItem(POTATO, 0, 1)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get(POTATO, 0, 1)); $this->level->setBlock($this, new AirBlock(), false, false, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/PumpkinStem.php b/src/block/PumpkinStem.php index 0a9286225..61fbe085c 100644 --- a/src/block/PumpkinStem.php +++ b/src/block/PumpkinStem.php @@ -41,7 +41,7 @@ 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, BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2))); + 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); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/RedMushroom.php b/src/block/RedMushroom.php index ffd707f98..deaa8b086 100644 --- a/src/block/RedMushroom.php +++ b/src/block/RedMushroom.php @@ -29,7 +29,7 @@ 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, BlockAPI::getItem($this->id)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id)); $this->level->setBlock($this, new AirBlock(), false); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/RedstoneOre.php b/src/block/RedstoneOre.php index d5d3ab8ea..7e55e738b 100644 --- a/src/block/RedstoneOre.php +++ b/src/block/RedstoneOre.php @@ -27,7 +27,7 @@ class RedstoneOreBlock extends SolidBlock{ public function onUpdate($type){ if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){ - $this->level->setBlock($this, BlockAPI::get(GLOWING_REDSTONE_ORE, $this->meta), false, false, true); + $this->level->setBlock($this, Block\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; diff --git a/src/block/Sapling.php b/src/block/Sapling.php index 5bb38aece..97484c98a 100644 --- a/src/block/Sapling.php +++ b/src/block/Sapling.php @@ -68,7 +68,7 @@ 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, BlockAPI::getItem($this->id)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id)); $this->level->setBlock($this, new AirBlock(), false, false, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/SignPost.php b/src/block/SignPost.php index 1d3876bac..60c247c82 100644 --- a/src/block/SignPost.php +++ b/src/block/SignPost.php @@ -37,12 +37,12 @@ class SignPostBlock extends TransparentBlock{ ); if(!isset($faces[$face])){ $this->meta = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F; - $this->level->setBlock($block, BlockAPI::get(SIGN_POST, $this->meta), true, false, true); + $this->level->setBlock($block, Block\Block::get(SIGN_POST, $this->meta), true, false, true); return true; } else{ $this->meta = $faces[$face]; - $this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta), true, false, true); + $this->level->setBlock($block, Block\Block::get(WALL_SIGN, $this->meta), true, false, true); return true; } @@ -54,7 +54,7 @@ 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, BlockAPI::getItem(SIGN, 0, 1)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get(SIGN, 0, 1)); $this->level->setBlock($this, new AirBlock(), true, true, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/Slab.php b/src/block/Slab.php index 90329eb8a..db313e87e 100644 --- a/src/block/Slab.php +++ b/src/block/Slab.php @@ -45,11 +45,11 @@ class SlabBlock extends TransparentBlock{ $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, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); + $this->level->setBlock($target, Block\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, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); + $this->level->setBlock($block, Block\Block::get(DOUBLE_SLAB, $this->meta), true, false, true); return true; } else{ @@ -57,18 +57,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, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); + $this->level->setBlock($target, Block\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, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); + $this->level->setBlock($block, Block\Block::get(DOUBLE_SLAB, $this->meta), true, false, true); return true; } } elseif(!$player->entity->inBlock($block)){ if($block->getID() === SLAB){ if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); + $this->level->setBlock($block, Block\Block::get(DOUBLE_SLAB, $this->meta), true, false, true); return true; } diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index 278261a0c..a8344ccc3 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -59,7 +59,7 @@ 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, BlockAPI::getItem(SUGARCANE)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get(SUGARCANE)); $this->level->setBlock($this, new AirBlock(), false, false, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/Torch.php b/src/block/Torch.php index d8277ccca..b4b1912ce 100644 --- a/src/block/Torch.php +++ b/src/block/Torch.php @@ -39,7 +39,7 @@ 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, BlockAPI::getItem($this->id, 0, 1)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get($this->id, 0, 1)); $this->level->setBlock($this, new AirBlock(), true, false, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/Wheat.php b/src/block/Wheat.php index b1238b38d..086162121 100644 --- a/src/block/Wheat.php +++ b/src/block/Wheat.php @@ -56,7 +56,7 @@ 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, BlockAPI::getItem(WHEAT_SEEDS, 0, 1)); + ServerAPI::request()->api->entity->drop($this, Item\Item::get(WHEAT_SEEDS, 0, 1)); $this->level->setBlock($this, new AirBlock(), false, false, true); return BLOCK_UPDATE_NORMAL; diff --git a/src/block/WoodSlab.php b/src/block/WoodSlab.php index ce1434c8f..5e6184ae2 100644 --- a/src/block/WoodSlab.php +++ b/src/block/WoodSlab.php @@ -41,11 +41,11 @@ class WoodSlabBlock extends TransparentBlock{ $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, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); + $this->level->setBlock($target, Block\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, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); + $this->level->setBlock($block, Block\Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } else{ @@ -53,18 +53,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, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); + $this->level->setBlock($target, Block\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, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); + $this->level->setBlock($block, Block\Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } } elseif(!$player->entity->inBlock($block)){ if($block->getID() === WOOD_SLAB){ if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); + $this->level->setBlock($block, Block\Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } diff --git a/src/constants/BlockIDs.php b/src/constants/BlockIDs.php deleted file mode 100644 index 1c5226731..000000000 --- a/src/constants/BlockIDs.php +++ /dev/null @@ -1,195 +0,0 @@ -hotbar = array(-1, -1, -1, -1, -1, -1, -1, -1, -1); $this->armor = array( - 0 => BlockAPI::getItem(AIR, 0, 0), - 1 => BlockAPI::getItem(AIR, 0, 0), - 2 => BlockAPI::getItem(AIR, 0, 0), - 3 => BlockAPI::getItem(AIR, 0, 0) + 0 => Item\Item::get(AIR, 0, 0), + 1 => Item\Item::get(AIR, 0, 0), + 2 => Item\Item::get(AIR, 0, 0), + 3 => Item\Item::get(AIR, 0, 0) ); 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] = BlockAPI::getItem($item->id, $item->Damage, $item->Count); + $this->armor[$item->Slot - 100] = Item\Item::get($item->id, $item->Damage, $item->Count); } else{ - $this->inventory[$item->Slot - 9] = BlockAPI::getItem($item->id, $item->Damage, $item->Count); + $this->inventory[$item->Slot - 9] = Item\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] = BlockAPI::getItem(AIR, 0, 0); + $this->armor[$slot] = Item\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] = BlockAPI::getItem(AIR, 0, 0); + $this->armor[$i] = Item\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, BlockAPI::getItem(AIR, 0, 0)); + $this->setSlot($s, Item\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] = BlockAPI::getItem(AIR, 0, 0); + $this->inventory[$slot] = Item\Item::get(AIR, 0, 0); } return $this->inventory[$slot]; diff --git a/src/item/Apple.php b/src/item/Apple.php index 6d4b917d4..df939d2fa 100644 --- a/src/item/Apple.php +++ b/src/item/Apple.php @@ -19,7 +19,10 @@ * */ -class AppleItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Apple extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(APPLE, 0, $count, "Apple"); } diff --git a/src/item/Bed.php b/src/item/Bed.php index 2aac1a814..f7f198b46 100644 --- a/src/item/Bed.php +++ b/src/item/Bed.php @@ -19,9 +19,12 @@ * */ -class BedItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Bed extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(BED_BLOCK); + $this->block = Block\Block::get(BED_BLOCK); parent::__construct(BED, 0, $count, "Bed"); $this->maxStackSize = 1; } diff --git a/src/item/BeetrootSeeds.php b/src/item/BeetrootSeeds.php index 0a7ba32c8..f730c49c3 100644 --- a/src/item/BeetrootSeeds.php +++ b/src/item/BeetrootSeeds.php @@ -19,9 +19,12 @@ * */ -class BeetrootSeedsItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class BeetrootSeeds extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(BEETROOT_BLOCK); + $this->block = Block\Block::get(BEETROOT_BLOCK); parent::__construct(BEETROOT_SEEDS, 0, $count, "Beetroot Seeds"); } } \ No newline at end of file diff --git a/src/item/BeetrootSoup.php b/src/item/BeetrootSoup.php index dae2a40ad..d4023e383 100644 --- a/src/item/BeetrootSoup.php +++ b/src/item/BeetrootSoup.php @@ -19,7 +19,10 @@ * */ -class BeetrootSoupItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class BeetrootSoup extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(BEETROOT_SOUP, 0, $count, "Beetroot Soup"); $this->maxStackSize = 1; diff --git a/src/item/Block.php b/src/item/Block.php new file mode 100644 index 000000000..1fdcad92e --- /dev/null +++ b/src/item/Block.php @@ -0,0 +1,40 @@ +block = clone $block; + parent::__construct($block->getID(), $block->getMetadata(), $count, $block->getName()); + } + + public function setMetadata($meta){ + $this->meta = $meta & 0x0F; + $this->block->setMetadata($this->meta); + } + + public function getBlock(){ + return $this->block; + } + +} \ No newline at end of file diff --git a/src/item/Bowl.php b/src/item/Bowl.php index 557bc1964..878e0d3ea 100644 --- a/src/item/Bowl.php +++ b/src/item/Bowl.php @@ -19,7 +19,10 @@ * */ -class BowlItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Bowl extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(BOWL, 0, $count, "Bowl"); } diff --git a/src/item/Brick.php b/src/item/Brick.php index f83eba9b4..c07a35f5b 100644 --- a/src/item/Brick.php +++ b/src/item/Brick.php @@ -19,7 +19,10 @@ * */ -class BrickItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Brick extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(BRICK, 0, $count, "Brick"); } diff --git a/src/item/Bucket.php b/src/item/Bucket.php index 2d221d4f0..1985d2fad 100644 --- a/src/item/Bucket.php +++ b/src/item/Bucket.php @@ -19,27 +19,30 @@ * */ -class BucketItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Bucket extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(BUCKET, $meta, $count, "Bucket"); $this->isActivable = true; $this->maxStackSize = 1; } - public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level\Level $level, Player $player, Block\Block $block, Block\Block $target, $face, $fx, $fy, $fz){ if($this->meta === AIR){ - if($target instanceof LiquidBlock){ - $level->setBlock($target, new AirBlock(), true, false, true); + if($target instanceof Block\Liquid){ + $level->setBlock($target, new Block\Air(), true, false, true); if(($player->gamemode & 0x01) === 0){ - $this->meta = ($target instanceof WaterBlock) ? WATER : LAVA; + $this->meta = ($target instanceof Block\Water) ? WATER : LAVA; } return true; } } elseif($this->meta === WATER){ //Support Make Non-Support Water to Support Water - if($block->getID() === AIR || ($block instanceof WaterBlock && ($block->getMetadata() & 0x07) != 0x00)){ - $water = new WaterBlock(); + if($block->getID() === AIR || ($block instanceof Block\Water && ($block->getMetadata() & 0x07) != 0x00)){ + $water = new Block\Water(); $level->setBlock($block, $water, true, false, true); $water->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz); if(($player->gamemode & 0x01) === 0){ @@ -50,7 +53,7 @@ class BucketItem extends Item{ } } elseif($this->meta === LAVA){ if($block->getID() === AIR){ - $level->setBlock($block, new LavaBlock(), true, false, true); + $level->setBlock($block, new Block\Lava(), true, false, true); if(($player->gamemode & 0x01) === 0){ $this->meta = 0; } diff --git a/src/item/Cake.php b/src/item/Cake.php index 3e190569e..b2834a94c 100644 --- a/src/item/Cake.php +++ b/src/item/Cake.php @@ -19,9 +19,12 @@ * */ -class CakeItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Cake extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(CAKE_BLOCK); + $this->block = Block\Block::get(CAKE_BLOCK); $this->maxStackSize = 1; parent::__construct(CAKE, 0, $count, "Cake"); } diff --git a/src/item/Carrot.php b/src/item/Carrot.php index 6c41d38f6..e5b085744 100644 --- a/src/item/Carrot.php +++ b/src/item/Carrot.php @@ -19,9 +19,12 @@ * */ -class CarrotItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Carrot extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(CARROT_BLOCK); + $this->block = Block\Block::get(CARROT_BLOCK); parent::__construct(CARROT, 0, $count, "Carrot"); } } \ No newline at end of file diff --git a/src/item/Coal.php b/src/item/Coal.php index 47072d5d3..61634c87c 100644 --- a/src/item/Coal.php +++ b/src/item/Coal.php @@ -19,7 +19,10 @@ * */ -class CoalItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Coal extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(COAL, $meta & 0x01, $count, "Coal"); if($this->meta === 1){ diff --git a/src/item/Diamond.php b/src/item/Diamond.php index 09d5c7f4f..1559e6610 100644 --- a/src/item/Diamond.php +++ b/src/item/Diamond.php @@ -19,7 +19,10 @@ * */ -class DiamondItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Diamond extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(DIAMOND, 0, $count, "Diamond"); } diff --git a/src/item/Feather.php b/src/item/Feather.php index 462e423d7..59bc85a94 100644 --- a/src/item/Feather.php +++ b/src/item/Feather.php @@ -19,7 +19,10 @@ * */ -class FeatherItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Feather extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(FEATHER, 0, $count, "Feather"); } diff --git a/src/item/FlintSteel.php b/src/item/FlintSteel.php index 9089dc4f9..d121201de 100644 --- a/src/item/FlintSteel.php +++ b/src/item/FlintSteel.php @@ -19,22 +19,23 @@ * */ -class FlintSteelItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class FlintSteel extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(FLINT_STEEL, $meta, $count, "Flint and Steel"); $this->isActivable = true; $this->maxStackSize = 1; } - public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level\Level $level, Player $player, Block\Block $block, Block\Block $target, $face, $fx, $fy, $fz){ if(($player->gamemode & 0x01) === 0 and $this->useOn($block) and $this->getMetadata() >= $this->getMaxDurability()){ $player->setSlot($player->slot, new Item(AIR, 0, 0)); } - if($block->getID() === AIR and ($target instanceof SolidBlock)){ - $level->setBlock($block, new FireBlock(), true, false, true); - $block->level->scheduleBlockUpdate(new Position($block, 0, 0, $block->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); - + if($block->getID() === AIR and ($target instanceof Block\Solid)){ + $level->setBlock($block, new Block\Fire(), true, false, true); return true; } diff --git a/src/item/GoldIngot.php b/src/item/GoldIngot.php index f15b00e6a..ca0462926 100644 --- a/src/item/GoldIngot.php +++ b/src/item/GoldIngot.php @@ -19,7 +19,10 @@ * */ -class GoldIngotItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class GoldIngot extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(GOLD_INGOT, 0, $count, "Gold Ingot"); } diff --git a/src/item/IronAxe.php b/src/item/IronAxe.php index 63d66ec00..0e62f1afe 100644 --- a/src/item/IronAxe.php +++ b/src/item/IronAxe.php @@ -19,7 +19,10 @@ * */ -class IronAxeItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class IronAxe extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_AXE, 0, $count, "Iron Axe"); } diff --git a/src/item/IronDoor.php b/src/item/IronDoor.php index 1664ab224..660570757 100644 --- a/src/item/IronDoor.php +++ b/src/item/IronDoor.php @@ -19,9 +19,12 @@ * */ -class IronDoorItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class IronDoor extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(IRON_DOOR_BLOCK); + $this->block = Block\Block::get(IRON_DOOR_BLOCK); parent::__construct(IRON_DOOR, 0, $count, "Iron Door"); $this->maxStackSize = 1; } diff --git a/src/item/IronHoe.php b/src/item/IronHoe.php index f27a4c72a..23fd6b5a3 100644 --- a/src/item/IronHoe.php +++ b/src/item/IronHoe.php @@ -19,7 +19,10 @@ * */ -class IronHoeItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class IronHoe extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_HOE, 0, $count, "Iron Hoe"); } diff --git a/src/item/IronIngot.php b/src/item/IronIngot.php index c780c92d4..e6d4313fe 100644 --- a/src/item/IronIngot.php +++ b/src/item/IronIngot.php @@ -19,7 +19,10 @@ * */ -class IronIngotItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class IronIngot extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_INGOT, 0, $count, "Iron Ingot"); } diff --git a/src/item/IronPickaxe.php b/src/item/IronPickaxe.php index 9c90e519c..c1fb215b6 100644 --- a/src/item/IronPickaxe.php +++ b/src/item/IronPickaxe.php @@ -19,7 +19,10 @@ * */ -class IronPickaxeItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class IronPickaxe extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_PICKAXE, 0, $count, "Iron Pickaxe"); } diff --git a/src/item/IronShovel.php b/src/item/IronShovel.php index 436c51b68..cd6410e57 100644 --- a/src/item/IronShovel.php +++ b/src/item/IronShovel.php @@ -19,7 +19,10 @@ * */ -class IronShovelItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class IronShovel extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_SHOVEL, 0, $count, "Iron Shovel"); } diff --git a/src/item/Item.php b/src/item/Item.php index 895144209..e1652429f 100644 --- a/src/item/Item.php +++ b/src/item/Item.php @@ -15,48 +15,340 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ +namespace PocketMine\Item; + +//All Block IDs are here too +const AIR = 0; +const STONE = 1; +const GRASS = 2; +const DIRT = 3; +const COBBLESTONE = 4; +const COBBLE = 4; +const PLANK = 5; +const PLANKS = 5; +const WOODEN_PLANK = 5; +const WOODEN_PLANKS = 5; +const SAPLING = 6; +const SAPLINGS = 6; +const BEDROCK = 7; +const WATER = 8; +const STILL_WATER = 9; +const LAVA = 10; +const STILL_LAVA = 11; +const SAND = 12; +const GRAVEL = 13; +const GOLD_ORE = 14; +const IRON_ORE = 15; +const COAL_ORE = 16; +const WOOD = 17; +const TRUNK = 17; +const LEAVES = 18; +const LEAVE = 18; +const SPONGE = 19; +const GLASS = 20; +const LAPIS_ORE = 21; +const LAPIS_BLOCK = 22; + +const SANDSTONE = 24; + +const BED_BLOCK = 26; + + +const COBWEB = 30; +const TALL_GRASS = 31; +const BUSH = 32; +const DEAD_BUSH = 32; +const WOOL = 35; +const DANDELION = 37; +const ROSE = 38; +const CYAN_FLOWER = 38; +const BROWN_MUSHROOM = 39; +const RED_MUSHROOM = 40; +const GOLD_BLOCK = 41; +const IRON_BLOCK = 42; +const DOUBLE_SLAB = 43; +const DOUBLE_SLABS = 43; +const SLAB = 44; +const SLABS = 44; +const BRICKS = 45; +const BRICKS_BLOCK = 45; +const TNT = 46; +const BOOKSHELF = 47; +const MOSS_STONE = 48; +const MOSSY_STONE = 48; +const OBSIDIAN = 49; +const TORCH = 50; +const FIRE = 51; + +const WOOD_STAIRS = 53; +const WOODEN_STAIRS = 53; +const OAK_WOOD_STAIRS = 53; +const OAK_WOODEN_STAIRS = 53; +const CHEST = 54; + +const DIAMOND_ORE = 56; +const DIAMOND_BLOCK = 57; +const CRAFTING_TABLE = 58; +const WORKBENCH = 58; +const WHEAT_BLOCK = 59; +const FARMLAND = 60; +const FURNACE = 61; +const BURNING_FURNACE = 62; +const LIT_FURNACE = 62; +const SIGN_POST = 63; +const DOOR_BLOCK = 64; +const WOODEN_DOOR_BLOCK = 64; +const WOOD_DOOR_BLOCK = 64; +const LADDER = 65; + +const COBBLE_STAIRS = 67; +const COBBLESTONE_STAIRS = 67; +const WALL_SIGN = 68; + +const IRON_DOOR_BLOCK = 71; + +const REDSTONE_ORE = 73; +const GLOWING_REDSTONE_ORE = 74; +const LIT_REDSTONE_ORE = 74; + +const SNOW = 78; +const SNOW_LAYER = 78; +const ICE = 79; +const SNOW_BLOCK = 80; +const CACTUS = 81; +const CLAY_BLOCK = 82; +const REEDS = 83; +const SUGARCANE_BLOCK = 83; + +const FENCE = 85; +const PUMPKIN = 86; +const NETHERRACK = 87; +const SOUL_SAND = 88; +const GLOWSTONE = 89; +const GLOWSTONE_BLOCK = 89; + + +const LIT_PUMPKIN = 91; +const JACK_O_LANTERN = 91; +const CAKE_BLOCK = 92; + +const TRAPDOOR = 96; + +const STONE_BRICKS = 98; +const STONE_BRICK = 98; + +const IRON_BAR = 101; +const IRON_BARS = 101; +const GLASS_PANE = 102; +const GLASS_PANEL = 102; +const MELON_BLOCK = 103; +const PUMPKIN_STEM = 104; +const MELON_STEM = 105; + +const FENCE_GATE = 107; +const BRICK_STAIRS = 108; +const STONE_BRICK_STAIRS = 109; + +const NETHER_BRICKS = 112; +const NETHER_BRICK_BLOCK = 112; + +const NETHER_BRICKS_STAIRS = 114; + +const SANDSTONE_STAIRS = 128; + +const SPRUCE_WOOD_STAIRS = 134; +const SPRUCE_WOODEN_STAIRS = 134; +const BIRCH_WOOD_STAIRS = 135; +const BIRCH_WOODEN_STAIRS = 135; +const JUNGLE_WOOD_STAIRS = 136; +const JUNGLE_WOODEN_STAIRS = 136; + +const COBBLE_WALL = 139; +const STONE_WALL = 139; +const COBBLESTONE_WALL = 139; + +const CARROT_BLOCK = 141; +const POTATO_BLOCK = 142; + +const QUARTZ_BLOCK = 155; +const QUARTZ_STAIRS = 156; +const DOUBLE_WOOD_SLAB = 157; +const DOUBLE_WOODEN_SLAB = 157; +const DOUBLE_WOOD_SLABS = 157; +const DOUBLE_WOODEN_SLABS = 157; +const WOOD_SLAB = 158; +const WOODEN_SLAB = 158; +const WOOD_SLABS = 158; +const WOODEN_SLABS = 158; + +const HAY_BALE = 170; +const CARPET = 171; + +const COAL_BLOCK = 173; + +const BEETROOT_BLOCK = 244; +const STONECUTTER = 245; +const GLOWING_OBSIDIAN = 246; +const NETHER_REACTOR = 247; + + +//Normal Item IDs + +const IRON_SHOVEL = 256; //Implemented +const IRON_PICKAXE = 257; //Implemented +const IRON_AXE = 258; //Implemented +const FLINT_STEEL = 259; +const FLINT_AND_STEEL = 259; +const APPLE = 260; //Implemented +const BOW = 261; +const ARROW = 262; +const COAL = 263; //Implemented +const DIAMOND = 264; //Implemented +const IRON_INGOT = 265; //Implemented +const GOLD_INGOT = 266; //Implemented +const IRON_SWORD = 267; +const WOODEN_SWORD = 268; //Implemented +const WOODEN_SHOVEL = 269; //Implemented +const WOODEN_PICKAXE = 270; //Implemented +const WOODEN_AXE = 271; //Implemented +const STONE_SWORD = 272; +const STONE_SHOVEL = 273; +const STONE_PICKAXE = 274; +const STONE_AXE = 275; +const DIAMOND_SWORD = 276; +const DIAMOND_SHOVEL = 277; +const DIAMOND_PICKAXE = 278; +const DIAMOND_AXE = 279; +const STICK = 280; //Implemented +const STICKS = 280; +const BOWL = 281; //Implemented +const MUSHROOM_STEW = 282; +const GOLD_SWORD = 283; +const GOLD_SHOVEL = 284; +const GOLD_PICKAXE = 285; +const GOLD_AXE = 286; +const GOLDEN_SWORD = 283; +const GOLDEN_SHOVEL = 284; +const GOLDEN_PICKAXE = 285; +const GOLDEN_AXE = 286; +const STRING = 287; +const FEATHER = 288; //Implemented +const GUNPOWDER = 289; +const WOODEN_HOE = 290; +const STONE_HOE = 291; +const IRON_HOE = 292; //Implemented +const DIAMOND_HOE = 293; +const GOLD_HOE = 294; +const GOLDEN_HOE = 294; +const SEEDS = 295; +const WHEAT_SEEDS = 295; +const WHEAT = 296; +const BREAD = 297; +const LEATHER_CAP = 298; +const LEATHER_TUNIC = 299; +const LEATHER_PANTS = 300; +const LEATHER_BOOTS = 301; +const CHAIN_HELMET = 302; +const CHAIN_CHESTPLATE = 303; +const CHAIN_LEGGINGS = 304; +const CHAIN_BOOTS = 305; +const IRON_HELMET = 306; +const IRON_CHESTPLATE = 307; +const IRON_LEGGINGS = 308; +const IRON_BOOTS = 309; +const DIAMOND_HELMET = 310; +const DIAMOND_CHESTPLATE = 311; +const DIAMOND_LEGGINGS = 312; +const DIAMOND_BOOTS = 313; +const GOLD_HELMET = 314; +const GOLD_CHESTPLATE = 315; +const GOLD_LEGGINGS = 316; +const GOLD_BOOTS = 317; +const FLINT = 318; +const RAW_PORKCHOP = 319; +const COOKED_PORKCHOP = 320; +const PAINTING = 321; +const GOLDEN_APPLE = 322; +const SIGN = 323; +const WOODEN_DOOR = 324; +const BUCKET = 325; + +const MINECART = 329; + +const IRON_DOOR = 330; +const REDSTONE = 331; +const REDSTONE_DUST = 331; +const SNOWBALL = 332; + +const LEATHER = 334; + +const BRICK = 336; +const CLAY = 337; +const SUGARCANE = 338; +const SUGAR_CANE = 338; +const SUGAR_CANES = 338; +const PAPER = 339; +const BOOK = 340; +const SLIMEBALL = 341; + +const EGG = 344; +const COMPASS = 345; + +const CLOCK = 347; +const GLOWSTONE_DUST = 348; +//const RAW_FISH = 349; +//const COOKED_FISH = 350; +const DYE = 351; +const BONE = 352; +const SUGAR = 353; +const CAKE = 354; +const BED = 355; + + +//const COOKIE = 357; + + +const SHEARS = 359; +const MELON = 360; +const MELON_SLICE = 360; +const PUMPKIN_SEEDS = 361; +const MELON_SEEDS = 362; +const RAW_BEEF = 363; +const STEAK = 364; +const COOKED_BEEF = 364; + +const RAW_CHICKEN = 365; +const COOKED_CHICKEN = 366; + +const SPAWN_EGG = 383; + +const CARROT = 391; +const CARROTS = 391; +const POTATO = 392; +const POTATOES = 392; //@shoghicp Why the heck do we need plural redundant Item ID here???? +const BAKED_POTATO = 393; +const BAKED_POTATOES = 393; + +const PUMPKIN_PIE = 400; + +const NETHER_BRICK = 405; +const QUARTZ = 406; +const NETHER_QUARTZ = 406; + +const CAMERA = 456; +const BEETROOT = 457; +const BEETROOT_SEEDS = 458; +const BEETROOT_SEED = 458; +const BEETROOT_SOUP = 459; +use PocketMine; + class Item{ - public static $class = array( - SUGARCANE => "SugarcaneItem", - WHEAT_SEEDS => "WheatSeedsItem", - PUMPKIN_SEEDS => "PumpkinSeedsItem", - MELON_SEEDS => "MelonSeedsItem", - MUSHROOM_STEW => "MushroomStewItem", - BEETROOT_SOUP => "BeetrootSoupItem", - CARROT => "CarrotItem", - POTATO => "PotatoItem", - BEETROOT_SEEDS => "BeetrootSeedsItem", - SIGN => "SignItem", - WOODEN_DOOR => "WoodenDoorItem", - BUCKET => "BucketItem", - IRON_DOOR => "IronDoorItem", - CAKE => "CakeItem", - BED => "BedItem", - PAINTING => "PaintingItem", - COAL => "CoalItem", - APPLE => "AppleItem", - SPAWN_EGG => "SpawnEggItem", - DIAMOND => "DiamondItem", - STICK => "StickItem", - BOWL => "BowlItem", - FEATHER => "FeatherItem", - BRICK => "BrickItem", - IRON_INGOT => "IronIngotItem", - GOLD_INGOT => "GoldIngotItem", - IRON_SHOVEL => "IronShovelItem", - IRON_PICKAXE => "IronPickaxeItem", - IRON_AXE => "IronAxeItem", - IRON_HOE => "IronHoeItem", - WOODEN_SWORD => "WoodenSwordItem", - WOODEN_SHOVEL => "WoodenShovelItem", - WOODEN_PICKAXE => "WoodenPickaxeItem", - WOODEN_AXE => "WoodenAxeItem", - FLINT_STEEL => "FlintSteelItem", - ); + + public static $list = array(); protected $block; protected $id; protected $meta; @@ -66,13 +358,70 @@ class Item{ protected $name; public $isActivable = false; + public static function init(){ + if(count(self::$init) === 0){ + self::$init = array( + SUGARCANE => new Sugarcane(), + WHEAT_SEEDS => new WheatSeeds(), + PUMPKIN_SEEDS => new PumpkinSeeds(), + MELON_SEEDS => new MelonSeeds(), + MUSHROOM_STEW => new MushroomStew(), + BEETROOT_SOUP => new BeetrootSoup(), + CARROT => new Carrot(), + POTATO => new Potato(), + BEETROOT_SEEDS => new BeetrootSeeds(), + SIGN => new Sign(), + WOODEN_DOOR => new WoodenDoor(), + BUCKET => new Bucket(), + IRON_DOOR => new IronDoor(), + CAKE => new Cake(), + BED => new Bed(), + PAINTING => new Painting(), + COAL => new Coal(), + APPLE => new Apple(), + SPAWN_EGG => new SpawnEgg(), + DIAMOND => new Diamond(), + STICK => new Stick(), + BOWL => new Bowl(), + FEATHER => new Feather(), + BRICK => new Brick(), + IRON_INGOT => new IronIngot(), + GOLD_INGOT => new GoldIngot(), + IRON_SHOVEL => new IronShovel(), + IRON_PICKAXE => new IronPickaxe(), + IRON_AXE => new IronAxe(), + IRON_HOE => new IronHoe(), + WOODEN_SWORD => new WoodenSword(), + WOODEN_SHOVEL => new WoodenShovel(), + WOODEN_PICKAXE => new WoodenPickaxe(), + WOODEN_AXE => new WoodenAxe(), + FLINT_STEEL => new FlintSteel(), + ); + foreach(Block\Block::$list as $id => $class){ + self::$list[$id] = new Item\Block($class); + } + + } + } + + public static function get($id, $meta = 0, $count = 1){ + if(isset(self::$list[$id])){ + $item = clone self::$list[$id]; + $item->setMetadata($meta); + $item->setCount($count); + }else{ + $item = new Item($id, $meta, $count); + } + return $item; + } + public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){ $this->id = (int) $id; $this->meta = (int) $meta; $this->count = (int) $count; $this->name = $name; if(!isset($this->block) and $this->id <= 0xff and isset(Block::$class[$this->id])){ - $this->block = BlockAPI::get($this->id, $this->meta); + $this->block = Block\Block::get($this->id, $this->meta); $this->name = $this->block->getName(); } if($this->isTool() !== false){ @@ -80,6 +429,7 @@ class Item{ } } + public function getCount(){ return $this->count; } @@ -93,14 +443,14 @@ class Item{ } final public function isPlaceable(){ - return (($this->block instanceof Block) and $this->block->isPlaceable === true); + return (($this->block instanceof Block\Block) and $this->block->isPlaceable === true); } - final public function getBlock(){ - if($this->block instanceof Block){ + public function getBlock(){ + if($this->block instanceof Block\Block){ return $this->block; } else{ - return BlockAPI::get(AIR); + return Block\Block::get(AIR); } } @@ -112,6 +462,10 @@ class Item{ return $this->meta; } + public function setMetadata($meta){ + $this->meta = $meta & 0xFFFF; + } + final public function getMaxStackSize(){ return $this->maxStackSize; } @@ -133,20 +487,20 @@ class Item{ } if(isset(Recipes\Smelt::$product[$this->id][0]) and !is_array(Recipes\Smelt::$product[$this->id][0])){ - return BlockAPI::getItem(Recipes\Smelt::$product[$this->id][0], Recipes\Smelt::$product[$this->id][1]); + return Item\Item::get(Recipes\Smelt::$product[$this->id][0], Recipes\Smelt::$product[$this->id][1]); } if(!isset(Recipes\Smelt::$product[$this->id][$this->meta])){ return false; } - return BlockAPI::getItem(Recipes\Smelt::$product[$this->id][$this->meta][0], Recipes\Smelt::$product[$this->id][$this->meta][1]); + return Item\Item::get(Recipes\Smelt::$product[$this->id][$this->meta][0], Recipes\Smelt::$product[$this->id][$this->meta][1]); } public function useOn($object, $force = false){ if($this->isTool() or $force === true){ - if(($object instanceof Entity) and !$this->isSword()){ + if(($object instanceof Entity\Entity) and !$this->isSword()){ $this->meta += 2; } else{ $this->meta++; @@ -154,7 +508,7 @@ class Item{ return true; } elseif($this->isHoe()){ - if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){ + if(($object instanceof Block\Block) and ($object->getID() === Block\GRASS or $object->getID() === Block\DIRT)){ $this->meta++; } } @@ -290,7 +644,7 @@ class Item{ return 1; } - public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level\Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ return false; } diff --git a/src/item/MelonSeeds.php b/src/item/MelonSeeds.php index b2b128cab..683cdf954 100644 --- a/src/item/MelonSeeds.php +++ b/src/item/MelonSeeds.php @@ -19,9 +19,12 @@ * */ -class MelonSeedsItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class MelonSeeds extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(MELON_STEM); + $this->block = Block\Block::get(MELON_STEM); parent::__construct(MELON_SEEDS, 0, $count, "Melon Seeds"); } } \ No newline at end of file diff --git a/src/item/MushroomStew.php b/src/item/MushroomStew.php index 68cfe2bc4..ee70030e3 100644 --- a/src/item/MushroomStew.php +++ b/src/item/MushroomStew.php @@ -19,7 +19,10 @@ * */ -class MushroomStewItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class MushroomStew extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(MUSHROOM_STEW, 0, $count, "Mushroom Stew"); $this->maxStackSize = 1; diff --git a/src/item/Painting.php b/src/item/Painting.php index 132cb4140..971dab2f6 100644 --- a/src/item/Painting.php +++ b/src/item/Painting.php @@ -19,13 +19,16 @@ * */ -class PaintingItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Painting extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(PAINTING, 0, $count, "Painting"); $this->isActivable = true; } - public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level\Level $level, Player $player, Block\Block $block, Block\Block $target, $face, $fx, $fy, $fz){ if($target->isTransparent === false and $face > 1 and $block->isSolid === false){ $server = ServerAPI::request(); $faces = array( @@ -73,10 +76,10 @@ class PaintingItem extends Item{ "Motive" => $motive[0], ); //TODO - $e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data); - $e->spawnToAll(); + //$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data); + //$e->spawnToAll(); if(($player->gamemode & 0x01) === 0x00){ - $player->removeItem(BlockAPI::getItem($this->getID(), $this->getMetadata(), 1)); + $player->removeItem(Item::get($this->getID(), $this->getMetadata(), 1)); } return true; diff --git a/src/item/Potato.php b/src/item/Potato.php index 01289326d..418a21493 100644 --- a/src/item/Potato.php +++ b/src/item/Potato.php @@ -19,9 +19,12 @@ * */ -class PotatoItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Potato extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(POTATO_BLOCK); + $this->block = Block\Block::get(POTATO_BLOCK); parent::__construct(POTATO, 0, $count, "Potato"); } } \ No newline at end of file diff --git a/src/item/PumpkinSeeds.php b/src/item/PumpkinSeeds.php index 25f28ba3c..22a9ca9fe 100644 --- a/src/item/PumpkinSeeds.php +++ b/src/item/PumpkinSeeds.php @@ -19,9 +19,12 @@ * */ -class PumpkinSeedsItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class PumpkinSeeds extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(PUMPKIN_STEM); + $this->block = Block\Block::get(PUMPKIN_STEM); parent::__construct(PUMPKIN_SEEDS, 0, $count, "Pumpkin Seeds"); } } \ No newline at end of file diff --git a/src/item/SignItem.php b/src/item/SignItem.php index 66d7597d2..d7be35338 100644 --- a/src/item/SignItem.php +++ b/src/item/SignItem.php @@ -19,9 +19,12 @@ * */ -class SignItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Sign extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(SIGN_POST); + $this->block = Block\Block::get(SIGN_POST); $this->maxStackSize = 16; parent::__construct(SIGN, 0, $count, "Sign"); } diff --git a/src/item/SpawnEgg.php b/src/item/SpawnEgg.php index 2933ecc63..6a50169e7 100644 --- a/src/item/SpawnEgg.php +++ b/src/item/SpawnEgg.php @@ -19,26 +19,29 @@ * */ -class SpawnEggItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class SpawnEgg extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(SPAWN_EGG, 0, $count, "Spawn Egg"); $this->meta = $meta; $this->isActivable = true; } - public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level\Level $level, Player $player, Block\Block $block, Block\Block $target, $face, $fx, $fy, $fz){ switch($this->meta){ - case MOB_CHICKEN: - case MOB_SHEEP: - case MOB_COW: - case MOB_PIG: + case Entity\CHICKEN: + case Entity\SHEEP: + case Entity\COW: + case Entity\PIG: $data = array( "x" => $block->x + 0.5, "y" => $block->y, "z" => $block->z + 0.5, ); - $e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data); - ServerAPI::request()->api->entity->spawnToAll($e); + //$e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data); + //ServerAPI::request()->api->entity->spawnToAll($e); if(($player->gamemode & 0x01) === 0){ --$this->count; } diff --git a/src/item/Stick.php b/src/item/Stick.php index babe72e61..8b387c5b1 100644 --- a/src/item/Stick.php +++ b/src/item/Stick.php @@ -19,7 +19,10 @@ * */ -class StickItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Stick extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(STICK, 0, $count, "Stick"); } diff --git a/src/item/Sugarcane.php b/src/item/Sugarcane.php index 14fbfcaec..98e4bdbe8 100644 --- a/src/item/Sugarcane.php +++ b/src/item/Sugarcane.php @@ -19,9 +19,12 @@ * */ -class SugarcaneItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class Sugarcane extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(SUGARCANE_BLOCK); + $this->block = Block\Block::get(SUGARCANE_BLOCK); parent::__construct(SUGARCANE, 0, $count, "Sugar Cane"); } } \ No newline at end of file diff --git a/src/item/WheatSeeds.php b/src/item/WheatSeeds.php index 89eaaecbc..cd4f26e95 100644 --- a/src/item/WheatSeeds.php +++ b/src/item/WheatSeeds.php @@ -19,9 +19,12 @@ * */ -class WheatSeedsItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class WheatSeeds extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(WHEAT_BLOCK); + $this->block = Block\Block::get(WHEAT_BLOCK); parent::__construct(WHEAT_SEEDS, 0, $count, "Wheat Seeds"); } } \ No newline at end of file diff --git a/src/item/WoodenAxe.php b/src/item/WoodenAxe.php index 3fdf984bf..9428d7ba9 100644 --- a/src/item/WoodenAxe.php +++ b/src/item/WoodenAxe.php @@ -19,7 +19,10 @@ * */ -class WoodenAxeItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class WoodenAxe extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(WOODEN_AXE, 0, $count, "Wooden Axe"); } diff --git a/src/item/WoodenDoor.php b/src/item/WoodenDoor.php index 2ab02abcf..73e47f454 100644 --- a/src/item/WoodenDoor.php +++ b/src/item/WoodenDoor.php @@ -19,9 +19,12 @@ * */ -class WoodenDoorItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class WoodenDoor extends Item{ public function __construct($meta = 0, $count = 1){ - $this->block = BlockAPI::get(WOODEN_DOOR_BLOCK); + $this->block = Block\Block::get(WOODEN_DOOR_BLOCK); parent::__construct(WOODEN_DOOR, 0, $count, "Wooden Door"); $this->maxStackSize = 1; } diff --git a/src/item/WoodenPickaxe.php b/src/item/WoodenPickaxe.php index 1b182df81..a6a511c70 100644 --- a/src/item/WoodenPickaxe.php +++ b/src/item/WoodenPickaxe.php @@ -19,7 +19,10 @@ * */ -class WoodenPickaxeItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class WoodenPickaxe extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(WOODEN_PICKAXE, 0, $count, "Wooden Pickaxe"); } diff --git a/src/item/WoodenShovel.php b/src/item/WoodenShovel.php index a8937fc4f..b80d91234 100644 --- a/src/item/WoodenShovel.php +++ b/src/item/WoodenShovel.php @@ -19,7 +19,10 @@ * */ -class WoodenShovelItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class WoodenShovel extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(WOODEN_SHOVEL, 0, $count, "Wooden Shovel"); } diff --git a/src/item/WoodenSword.php b/src/item/WoodenSword.php index d595f3f21..a86a33ca8 100644 --- a/src/item/WoodenSword.php +++ b/src/item/WoodenSword.php @@ -19,7 +19,10 @@ * */ -class WoodenSwordItem extends Item{ +namespace PocketMine\Item; +use PocketMine; + +class WoodenSword extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(WOODEN_SWORD, 0, $count, "Wooden Sword"); } diff --git a/src/level/Explosion.php b/src/level/Explosion.php index 25df03ae9..4be0c07fb 100644 --- a/src/level/Explosion.php +++ b/src/level/Explosion.php @@ -75,7 +75,7 @@ class Explosion{ $blockID = $this->level->level->getBlockID($vBlock->x, $vBlock->y, $vBlock->z); if($blockID > 0){ - $block = BlockAPI::get($blockID, 0); + $block = Block\Block::get($blockID, 0); $block->x = $vBlock->x; $block->y = $vBlock->y; $block->z = $vBlock->z; @@ -120,10 +120,10 @@ class Explosion{ } elseif(mt_rand(0, 10000) < ((1 / $this->size) * 10000)){ if(isset(self::$specialDrops[$block->getID()])){ //TODO - //$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem(self::$specialDrops[$block->getID()], 0)); + //$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), Item\Item::get(self::$specialDrops[$block->getID()], 0)); } else{ //TODO - //$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z))); + //$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), Item\Item::get($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z))); } } $this->level->level->setBlockID($block->x, $block->y, $block->z, 0); diff --git a/src/level/Level.php b/src/level/Level.php index 776c21670..8b74b4019 100644 --- a/src/level/Level.php +++ b/src/level/Level.php @@ -276,7 +276,7 @@ class Level{ public function getBlockRaw(Vector3 $pos){ $b = $this->level->getBlock($pos->x, $pos->y, $pos->z); - return BlockAPI::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this)); + return Block\Block::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this)); } public function getBlock(Vector3 $pos){ @@ -285,7 +285,7 @@ class Level{ } $b = $this->level->getBlock($pos->x, $pos->y, $pos->z); - return BlockAPI::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this)); + return Block\Block::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this)); } public function setBlockRaw(Vector3 $pos, Block $block, $direct = true, $send = true){ diff --git a/src/level/PocketChunkParser.php b/src/level/PocketChunkParser.php index 8ca9dda18..25a2f4242 100644 --- a/src/level/PocketChunkParser.php +++ b/src/level/PocketChunkParser.php @@ -30,7 +30,9 @@ use PocketMine\Utils\Utils as Utils; * */ class PocketChunkParser{ - private $location, $raw = b"", $file; + private $location + private $raw = b"" + private $file; public $sectorLength = 4096; //16 * 16 * 16 public $chunkLength = 86016; //21 * $sectorLength public $map = array(); @@ -144,6 +146,7 @@ class PocketChunkParser{ } $this->raw = b""; console("[DEBUG] Chunks loaded!", true, true, 2); + return true; } public function saveMap($final = false){ diff --git a/src/level/generator/object/TallGrass.php b/src/level/generator/object/TallGrass.php index 37ee6ea49..5335744d1 100644 --- a/src/level/generator/object/TallGrass.php +++ b/src/level/generator/object/TallGrass.php @@ -29,12 +29,12 @@ use PocketMine\BlockAPI as BlockAPI; class TallGrass{ public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10){ $arr = array( - BlockAPI::get(DANDELION, 0), - BlockAPI::get(CYAN_FLOWER, 0), - BlockAPI::get(TALL_GRASS, 1), - BlockAPI::get(TALL_GRASS, 1), - BlockAPI::get(TALL_GRASS, 1), - BlockAPI::get(TALL_GRASS, 1) + Block\Block::get(DANDELION, 0), + Block\Block::get(CYAN_FLOWER, 0), + Block\Block::get(TALL_GRASS, 1), + Block\Block::get(TALL_GRASS, 1), + Block\Block::get(TALL_GRASS, 1), + Block\Block::get(TALL_GRASS, 1) ); $arrC = count($arr) - 1; for($c = 0; $c < $count; ++$c){ diff --git a/src/network/protocol/DataPacket.php b/src/network/protocol/DataPacket.php index 1b57638a5..99a3a770c 100644 --- a/src/network/protocol/DataPacket.php +++ b/src/network/protocol/DataPacket.php @@ -155,7 +155,7 @@ abstract class DataPacket{ $id = $this->getShort(); $cnt = $this->getByte(); - return BlockAPI::getItem( + return Item\Item::get( $id, $this->getShort(), $cnt diff --git a/src/tile/Container.php b/src/tile/Container.php index 94733a8fb..9e22e2416 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[] = BlockAPI::getItem(AIR, 0, 0); + $slots[] = Item\Item::get(AIR, 0, 0); } } } @@ -97,7 +97,7 @@ trait Container{ if($slot->getID() > AIR and $slot->getCount() > 0){ $slots[] = $slot; } else{ - $slots[] = BlockAPI::getItem(AIR, 0, 0); + $slots[] = Item\Item::get(AIR, 0, 0); } } } @@ -128,7 +128,7 @@ trait Container{ if($slot->getID() > AIR and $slot->getCount() > 0){ $slots[] = $slot; } else{ - $slots[] = BlockAPI::getItem(AIR, 0, 0); + $slots[] = Item\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 BlockAPI::getItem(AIR, 0, 0); + return Item\Item::get(AIR, 0, 0); } else{ - return BlockAPI::getItem($this->namedtag->Items[$i]->id, $this->namedtag->Items[$i]->Damage, $this->namedtag->Items[$i]->Count); + return Item\Item::get($this->namedtag->Items[$i]->id, $this->namedtag->Items[$i]->Damage, $this->namedtag->Items[$i]->Count); } } diff --git a/src/tile/Furnace.php b/src/tile/Furnace.php index ef55f60b0..098f451ea 100644 --- a/src/tile/Furnace.php +++ b/src/tile/Furnace.php @@ -68,12 +68,12 @@ class Furnace extends Tile{ $this->namedtag->BurnTicks = 0; $fuel->setCount($fuel->getCount() - 1); if($fuel->getCount() === 0){ - $fuel = BlockAPI::getItem(AIR, 0, 0); + $fuel = Item\Item::get(AIR, 0, 0); } $this->setSlot(1, $fuel, false); $current = $this->level->getBlock($this); if($current->getID() === FURNACE){ - $this->level->setBlock($this, BlockAPI::get(BURNING_FURNACE, $current->getMetadata()), true, false, true); + $this->level->setBlock($this, Block\Block::get(BURNING_FURNACE, $current->getMetadata()), true, false, true); } } if($this->namedtag->BurnTime > 0){ @@ -83,11 +83,11 @@ class Furnace extends Tile{ if($smelt !== false and $canSmelt){ $this->namedtag->CookTime += $ticks; if($this->namedtag->CookTime >= 200){ //10 seconds - $product = BlockAPI::getItem($smelt->getID(), $smelt->getMetadata(), $product->getCount() + 1); + $product = Item\Item::get($smelt->getID(), $smelt->getMetadata(), $product->getCount() + 1); $this->setSlot(2, $product, false); $raw->setCount($raw->getCount() - 1); if($raw->getCount() === 0){ - $raw = BlockAPI::getItem(AIR, 0, 0); + $raw = Item\Item::get(AIR, 0, 0); } $this->setSlot(0, $raw, false); $this->namedtag->CookTime -= 200; @@ -103,7 +103,7 @@ class Furnace extends Tile{ } else{ $current = $this->level->getBlock($this); if($current->getID() === BURNING_FURNACE){ - $this->level->setBlock($this, BlockAPI::get(FURNACE, $current->getMetadata()), true, false, true); + $this->level->setBlock($this, Block\Block::get(FURNACE, $current->getMetadata()), true, false, true); } $this->namedtag->CookTime = 0; $this->namedtag->BurnTime = 0; diff --git a/src/utils/Utils.php b/src/utils/Utils.php index dc5632aa5..c54688b00 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -203,7 +203,7 @@ class Utils{ $id = Utils::readShort($ob->get(2)); $cnt = ord($ob->get(1)); - return BlockAPI::getItem( + return Item\Item::get( $id, Utils::readShort($ob->get(2)), $cnt