diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 05318d0c..5fff6f7b 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -24,14 +24,20 @@ 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), - array(STONE, 0), + array(DIRT, 0), array(GRASS, 0), array(CLAY_BLOCK, 0), @@ -43,10 +49,15 @@ class BlockAPI{ array(TRUNK, 0), array(TRUNK, 1), array(TRUNK, 2), + array(TRUNK, 3), + array(NETHER_BRICKS, 0), array(NETHERRACK, 0), array(COBBLESTONE_STAIRS, 0), - array(WOODEN_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), @@ -54,7 +65,11 @@ class BlockAPI{ array(QUARTZ_STAIRS, 0), array(SLAB, 0), array(SLAB, 1), - array(SLAB, 2), + //array(SLAB, 2), + 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), @@ -68,12 +83,19 @@ class BlockAPI{ array(DIAMOND_ORE, 0), array(LAPIS_ORE, 0), array(REDSTONE_ORE, 0), + array(OBSIDIAN, 0), + array(ICE, 0), + array(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(OBSIDIAN, 0), - array(SNOW_BLOCK, 0), + array(COAL_BLOCK, 0), + array(SNOW_LAYER, 0), array(GLASS, 0), array(GLOWSTONE_BLOCK, 0), array(NETHER_REACTOR, 0), @@ -94,15 +116,13 @@ class BlockAPI{ array(WOOL, 9), array(WOOL, 8), array(LADDER, 0), - array(TORCH, 0), + array(SPONGE, 0), array(GLASS_PANE, 0), - array(BUCKET, 0), - array(BUCKET, 8), - array(BUCKET, 10), 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), @@ -110,33 +130,76 @@ class BlockAPI{ array(STONECUTTER, 0), array(CHEST, 0), array(FURNACE, 0), - array(TNT, 0), array(DANDELION, 0), array(CYAN_FLOWER, 0), array(BROWN_MUSHROOM, 0), array(RED_MUSHROOM, 0), array(CACTUS, 0), array(MELON_BLOCK, 0), - array(SUGARCANE, 0), + array(PUMPKIN, 0), + array(LIT_PUMPKIN, 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(SEEDS, 0), - array(MELON_SEEDS, 0), - array(DYE, 15), //Bonemeal - array(IRON_HOE, 0), + array(LEAVES, 3), array(CAKE, 0), - array(FLINT_STEEL, 0), - array(DIAMOND_SWORD, 0), - array(BOW, 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), + + //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(FLINT_AND_STEEL, 0), + array(CLOCK, 0), + array(COMPASS, 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(POTATOE, 0), + //array(BEETROOT_SEEDS, 0), + array(DYE, 15), //Bonemeal + array(EGG, 0), + ); public static function fromString($str, $multiple = false){ diff --git a/src/Player.php b/src/Player.php index 5df60921..102c3353 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1402,6 +1402,7 @@ class Player{ if($this->spawned === false){ break; } + $data["eid"] = $this->eid; $data["player"] = $this; @@ -1416,9 +1417,26 @@ class Player{ $data["slot"] -= 9; } - $data["item"] = $this->getSlot($data["slot"]); - if(!($data["item"] instanceof Item)){ - break; + + if(($this->gamemode & 0x01) === SURVIVAL){ + $data["item"] = $this->getSlot($data["slot"]); + if(!($data["item"] instanceof Item)){ + break; + } + }elseif(($this->gamemode & 0x01) === CREATIVE){ + $data["slot"] = false; + foreach(BlockAPI::$creative as $i => $d){ + if($d[0] === $data["block"] and $d[1] === $data["meta"]){ + $data["slot"] = $i; + } + } + if($data["slot"] !== false){ + $data["item"] = $this->getSlot($data["slot"]); + }else{ + break; + } + }else{ + break;//????? } $data["block"] = $data["item"]->getID(); $data["meta"] = $data["item"]->getMetadata(); @@ -1769,6 +1787,9 @@ class Player{ MELON_SLICE => 2, GOLDEN_APPLE => 10, PUMPKIN_PIE => 8, + CARROT => 4, + POTATO => 1, + BAKED_POTATO => 6, //COOKIE => 2, //COOKED_FISH => 5, //RAW_FISH => 2, @@ -2077,6 +2098,9 @@ class Player{ } public function sendInventory(){ + if(($this->gamemode & 0x01) === CREATIVE){ + return; + } $this->dataPacket(MC_CONTAINER_SET_CONTENT, array( "windowid" => 0, "count" => count($this->inventory), diff --git a/src/constants/BlockIDs.php b/src/constants/BlockIDs.php index 46804c29..3eae94fb 100644 --- a/src/constants/BlockIDs.php +++ b/src/constants/BlockIDs.php @@ -83,6 +83,8 @@ define("FIRE", 51); define("WOOD_STAIRS", 53); define("WOODEN_STAIRS", 53); +define("OAK_WOOD_STAIRS", 53); +define("OAK_WOODEN_STAIRS", 53); define("CHEST", 54); define("DIAMOND_ORE", 56); @@ -166,6 +168,9 @@ define("COBBLE_WALL", 139); define("STONE_WALL", 139); define("COBBLESTONE_WALL", 139); +define("CARROT_BLOCK", 141); +define("POTATO_BLOCK", 141); + define("QUARTZ_BLOCK", 155); define("QUARTZ_STAIRS", 156); define("DOUBLE_WOOD_SLAB", 157); diff --git a/src/constants/ItemIDs.php b/src/constants/ItemIDs.php index e9f7f3ab..a8e13fe7 100644 --- a/src/constants/ItemIDs.php +++ b/src/constants/ItemIDs.php @@ -144,6 +144,13 @@ define("COOKED_CHICKEN", 366); define("SPAWN_EGG", 383); +define("CARROT", 391); +define("CARROTS", 391); +define("POTATO", 392); +define("POTATOES", 392); +define("BAKED_POTATO", 393); +define("BAKED_POTATOES", 393); + define("PUMPKIN_PIE", 400); define("NETHER_BRICK", 405); diff --git a/src/material/Block.php b/src/material/Block.php index e2c3960b..25564540 100644 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -127,6 +127,9 @@ abstract class Block extends Position{ BIRCH_WOOD_STAIRS => "BirchWoodStairsBlock", JUNGLE_WOOD_STAIRS => "JungleWoodStairsBlock", STONE_WALL => "StoneWallBlock", + + CARROT_BLOCK => "CarrotBlock", + POTATO_BLOCK => "PotatoBlock", QUARTZ_BLOCK => "QuartzBlock", QUARTZ_STAIRS => "QuartzStairsBlock", diff --git a/src/material/Item.php b/src/material/Item.php index f09480f5..4c4d5f79 100644 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -25,6 +25,8 @@ class Item{ WHEAT_SEEDS => "WheatSeedsItem", PUMPKIN_SEEDS => "PumpkinSeedsItem", MELON_SEEDS => "MelonSeedsItem", + CARROT => "CarrotItem", + POTATO => "PotatoItem", SIGN => "SignItem", WOODEN_DOOR => "WoodenDoorItem", BUCKET => "BucketItem", @@ -138,6 +140,10 @@ class Item{ $this->meta++; } return true; + }elseif($this->isHoe()){ + if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){ + $this->meta++; + } } return false; } diff --git a/src/material/block/nonfull/Carpet.php b/src/material/block/nonfull/Carpet.php index 867f963f..cf0ee62c 100644 --- a/src/material/block/nonfull/Carpet.php +++ b/src/material/block/nonfull/Carpet.php @@ -19,7 +19,7 @@ * */ -class CarpetBlock extends TransparentBlock{ +class CarpetBlock extends FlowableBlock{ public function __construct($meta = 0){ parent::__construct(CARPET, $meta, "Carpet"); $names = array( @@ -42,7 +42,8 @@ class CarpetBlock extends TransparentBlock{ ); $this->name = $names[$this->meta]; $this->hardness = 0; - $this->isFullBlock = false; + $this->isFullBlock = false; + $this->isSolid = true; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ @@ -57,6 +58,7 @@ class CarpetBlock 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($this->id, $this->meta, 1)); $this->level->setBlock($this, new AirBlock(), true, false, true); return BLOCK_UPDATE_NORMAL; } diff --git a/src/material/block/nonfull/GlassPane.php b/src/material/block/nonfull/GlassPane.php index 4228c15c..744e08be 100644 --- a/src/material/block/nonfull/GlassPane.php +++ b/src/material/block/nonfull/GlassPane.php @@ -22,6 +22,8 @@ class GlassPaneBlock extends TransparentBlock{ public function __construct(){ parent::__construct(GLASS_PANE, 0, "Glass Pane"); + $this->isFullBlock = false; + $this->isSolid = false; } } \ No newline at end of file diff --git a/src/material/block/nonfull/IronBars.php b/src/material/block/nonfull/IronBars.php index 11136b2d..9a26ff7b 100644 --- a/src/material/block/nonfull/IronBars.php +++ b/src/material/block/nonfull/IronBars.php @@ -22,6 +22,8 @@ class IronBarsBlock extends TransparentBlock{ public function __construct(){ parent::__construct(IRON_BARS, 0, "Iron Bars"); + $this->isFullBlock = false; + $this->isSolid = false; } } \ No newline at end of file diff --git a/src/material/block/nonfull/StoneWall.php b/src/material/block/nonfull/StoneWall.php index 6f711781..b56e8a76 100644 --- a/src/material/block/nonfull/StoneWall.php +++ b/src/material/block/nonfull/StoneWall.php @@ -27,6 +27,7 @@ class StoneWallBlock extends TransparentBlock{ $this->name = "Mossy Cobblestone Wall"; } $this->isFullBlock = false; + $this->isSolid = false; $this->hardness = 30; } diff --git a/src/material/block/plant/Carrot.php b/src/material/block/plant/Carrot.php new file mode 100644 index 00000000..dd162d14 --- /dev/null +++ b/src/material/block/plant/Carrot.php @@ -0,0 +1,81 @@ +isActivable = true; + $this->hardness = 0; + } + + public function place(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 + $this->meta = 0x07; + $this->level->setBlock($this, $this, true, false, true); + if(($player->gamemode & 0x01) === 0){ + $item->count--; + } + return true; + } + return false; + } + + 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)); + $this->level->setBlock($this, new AirBlock(), false, false, true); + return BLOCK_UPDATE_NORMAL; + } + }elseif($type === BLOCK_UPDATE_RANDOM){ + if(mt_rand(0, 2) == 1){ + if($this->meta < 0x07){ + ++$this->meta; + $this->level->setBlock($this, $this, true, false, true); + return BLOCK_UPDATE_RANDOM; + } + }else{ + return BLOCK_UPDATE_RANDOM; + } + } + return false; + } + + public function getDrops(Item $item, Player $player){ + $drops = array(); + if($this->meta >= 0x07){ + $drops[] = array(CARROT, 0, mt_rand(1, 4)); + }else{ + $drops[] = array(CARROT, 0, 1); + } + return $drops; + } +} \ No newline at end of file diff --git a/src/material/block/plant/PotatoBlock.php b/src/material/block/plant/PotatoBlock.php new file mode 100644 index 00000000..6962f5d7 --- /dev/null +++ b/src/material/block/plant/PotatoBlock.php @@ -0,0 +1,81 @@ +isActivable = true; + $this->hardness = 0; + } + + public function place(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 + $this->meta = 0x07; + $this->level->setBlock($this, $this, true, false, true); + if(($player->gamemode & 0x01) === 0){ + $item->count--; + } + return true; + } + return false; + } + + 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)); + $this->level->setBlock($this, new AirBlock(), false, false, true); + return BLOCK_UPDATE_NORMAL; + } + }elseif($type === BLOCK_UPDATE_RANDOM){ + if(mt_rand(0, 2) == 1){ + if($this->meta < 0x07){ + ++$this->meta; + $this->level->setBlock($this, $this, true, false, true); + return BLOCK_UPDATE_RANDOM; + } + }else{ + return BLOCK_UPDATE_RANDOM; + } + } + return false; + } + + public function getDrops(Item $item, Player $player){ + $drops = array(); + if($this->meta >= 0x07){ + $drops[] = array(POTATO, 0, mt_rand(1, 4)); + }else{ + $drops[] = array(POTATO, 0, 1); + } + return $drops; + } +} \ No newline at end of file diff --git a/src/material/item/generic/Carrot.php b/src/material/item/generic/Carrot.php new file mode 100644 index 00000000..4f431ada --- /dev/null +++ b/src/material/item/generic/Carrot.php @@ -0,0 +1,27 @@ +block = BlockAPI::get(CARROT_BLOCK); + parent::__construct(CARROT, 0, $count, "Carrot"); + } +} \ No newline at end of file diff --git a/src/material/item/generic/Potato.php b/src/material/item/generic/Potato.php new file mode 100644 index 00000000..01c15eec --- /dev/null +++ b/src/material/item/generic/Potato.php @@ -0,0 +1,27 @@ +block = BlockAPI::get(POTATO_BLOCK); + parent::__construct(POTATO, 0, $count, "Potato"); + } +} \ No newline at end of file diff --git a/src/recipes/SmeltingData.php b/src/recipes/SmeltingData.php index 046e4363..9648e758 100644 --- a/src/recipes/SmeltingData.php +++ b/src/recipes/SmeltingData.php @@ -36,6 +36,7 @@ class SmeltingData{ RAW_BEEF => array(STEAK, 0), RAW_CHICKEN => array(COOKED_CHICKEN, 0), RED_MUSHROOM => array(DYE, 1), + POTATO => array(BAKED_POTATO, 0), ); } \ No newline at end of file