diff --git a/src/material/block/plant/BrownMushroom.php b/src/material/block/plant/BrownMushroom.php index d4b6d60abc..85dd73431f 100644 --- a/src/material/block/plant/BrownMushroom.php +++ b/src/material/block/plant/BrownMushroom.php @@ -30,6 +30,17 @@ class BrownMushroomBlock extends FlowableBlock{ parent::__construct(BROWN_MUSHROOM, 0, "Brown Mushroom"); $this->isFlowable = true; } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->isFlowable === true){ //Replace wit common break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + } + return false; + } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); diff --git a/src/material/block/plant/Cactus.php b/src/material/block/plant/Cactus.php index c161051c1c..2d11f36611 100644 --- a/src/material/block/plant/Cactus.php +++ b/src/material/block/plant/Cactus.php @@ -29,19 +29,31 @@ class CactusBlock extends TransparentBlock{ public function __construct(){ parent::__construct(CACTUS, 0, "Cactus"); } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + $down = $this->getSide(0)->getID(); + if($down !== SAND and $down !== CACTUS){ //Replace wit common break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + } + return false; + } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $down = $this->getSide(0); - if($down->getID() === SAND or $down->getID() === CACTUS){ - $block0 = $this->getSide(2); - $block1 = $this->getSide(3); - $block2 = $this->getSide(4); - $block3 = $this->getSide(5); - if($block0->isFlowable === true and $block1->isFlowable === true and $block2->isFlowable === true and $block3->isFlowable === true){ - $this->level->setBlock($block, $this); - return true; - } + $down = $this->getSide(0); + if($down->getID() === SAND or $down->getID() === CACTUS){ + $block0 = $this->getSide(2); + $block1 = $this->getSide(3); + $block2 = $this->getSide(4); + $block3 = $this->getSide(5); + if($block0->isFlowable === true and $block1->isFlowable === true and $block2->isFlowable === true and $block3->isFlowable === true){ + $this->level->setBlock($block, $this); + return true; } + } return false; } diff --git a/src/material/block/plant/CyanFlower.php b/src/material/block/plant/CyanFlower.php index 2614dce7eb..146769543c 100644 --- a/src/material/block/plant/CyanFlower.php +++ b/src/material/block/plant/CyanFlower.php @@ -30,6 +30,7 @@ class CyanFlowerBlock extends FlowableBlock{ parent::__construct(CYAN_FLOWER, 0, "Cyan Flower"); $this->isFlowable = true; } + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){ @@ -37,5 +38,16 @@ class CyanFlowerBlock extends FlowableBlock{ return true; } return false; - } + } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->isFlowable === true){ //Replace wit common break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + } + return false; + } } \ No newline at end of file diff --git a/src/material/block/plant/Dandelion.php b/src/material/block/plant/Dandelion.php index 10c255d532..6503b3157e 100644 --- a/src/material/block/plant/Dandelion.php +++ b/src/material/block/plant/Dandelion.php @@ -30,6 +30,7 @@ class DandelionBlock extends FlowableBlock{ parent::__construct(DANDELION, 0, "Dandelion"); $this->isFlowable = true; } + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){ @@ -37,5 +38,16 @@ class DandelionBlock extends FlowableBlock{ return true; } return false; - } + } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->isFlowable === true){ //Replace wit common break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + } + return false; + } } \ No newline at end of file diff --git a/src/material/block/plant/DeadBush.php b/src/material/block/plant/DeadBush.php index d75599119b..bd15e9ef93 100644 --- a/src/material/block/plant/DeadBush.php +++ b/src/material/block/plant/DeadBush.php @@ -31,5 +31,15 @@ class DeadBushBlock extends FlowableBlock{ $this->isFlowable = true; $this->isReplaceable = true; } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->isFlowable === true){ //Replace wit common break method + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + } + return false; + } } \ No newline at end of file diff --git a/src/material/block/plant/MelonStem.php b/src/material/block/plant/MelonStem.php index 0cdfa1bccd..05b5c25394 100644 --- a/src/material/block/plant/MelonStem.php +++ b/src/material/block/plant/MelonStem.php @@ -38,6 +38,17 @@ class MelonStemBlock extends TransparentBlock{ } return false; } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->isFlowable === true){ //Replace wit common break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2))); + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + } + return false; + } public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal diff --git a/src/material/block/plant/RedMushroom.php b/src/material/block/plant/RedMushroom.php index 37960799e2..353cbb4435 100644 --- a/src/material/block/plant/RedMushroom.php +++ b/src/material/block/plant/RedMushroom.php @@ -31,6 +31,17 @@ class RedMushroomBlock extends FlowableBlock{ $this->isFlowable = true; } + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->isFlowable === true){ //Replace wit common break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + } + return false; + } + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->isTransparent === false){ diff --git a/src/material/block/plant/Sapling.php b/src/material/block/plant/Sapling.php index e5dcf4b645..4c093c6bf9 100644 --- a/src/material/block/plant/Sapling.php +++ b/src/material/block/plant/Sapling.php @@ -59,9 +59,14 @@ class SaplingBlock extends TransparentBlock{ } return false; } - public function onUpdate($type){ - if($type === BLOCK_UPDATE_RANDOM and mt_rand(0,2) === 0){ //Growth + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->isFlowable === true){ //Replace wit common break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id)); + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + }elseif($type === BLOCK_UPDATE_RANDOM and mt_rand(0,2) === 0){ //Growth if(($this->meta & 0x08) === 0x08){ TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03); }else{ diff --git a/src/material/block/plant/Sugarcane.php b/src/material/block/plant/Sugarcane.php index f1e0cb86fc..b26bc401de 100644 --- a/src/material/block/plant/Sugarcane.php +++ b/src/material/block/plant/Sugarcane.php @@ -35,6 +35,17 @@ class SugarcaneBlock extends TransparentBlock{ array(SUGARCANE, 0, 1), ); } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->isFlowable === true){ //Replace wit common break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE)); + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + } + return false; + } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); diff --git a/src/material/block/plant/TallGrass.php b/src/material/block/plant/TallGrass.php index dd3cc1f375..c20a96b6e1 100644 --- a/src/material/block/plant/TallGrass.php +++ b/src/material/block/plant/TallGrass.php @@ -37,11 +37,21 @@ class TallGrassBlock extends FlowableBlock{ ); $this->name = $names[$this->meta & 0x03]; } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->isFlowable === true){ //Replace wit common break method + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + } + return false; + } public function getDrops(Item $item, Player $player){ $drops = array(); if(mt_rand(1,10) === 1){//Seeds - $drops[] = array(295, 0, 1); + $drops[] = array(WEATH_SEEDS, 0, 1); } return $drops; } diff --git a/src/material/block/plant/Wheat.php b/src/material/block/plant/Wheat.php index 6a3ecaec63..a31d15388e 100644 --- a/src/material/block/plant/Wheat.php +++ b/src/material/block/plant/Wheat.php @@ -48,6 +48,17 @@ class WheatBlock extends FlowableBlock{ } return false; } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + if($this->getSide(0)->isFlowable === true){ //Replace wit common break method + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(WHEAT_SEEDS, 0, 1)); + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + } + return false; + } public function getDrops(Item $item, Player $player){ $drops = array(); diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php new file mode 100644 index 0000000000..ed89bab0da --- /dev/null +++ b/src/world/generator/NormalGenerator.php @@ -0,0 +1,83 @@ +options = $options; + if(isset($this->options["elevation"])){ + $this->options["elevation"] = intval($this->options["elevation"]); + }else{ + $this->options["elevation"] = 62; + } + $this->chunks = array(); + } + + public function init(Level $level, Random $random){ + $this->level = $level; + $this->random = $random; + $this->noise1 = new NoiseGeneratorOctaves($this->random, 16); + $this->chunkNoise = array(); + } + + public function generateChunk($chunkX, $chunkY, $chunkZ){ + $ix = $chunkX.".".$chunkZ; + if(!isset($this->chunkNoise[$ix])){ + $this->chunkNoise[$ix] = $this->noise1->generateNoiseOctaves(); + } + $this->random->setSeed((int) ($chunkX * 0xdead + $chunkZ * 0xbeef)); + $startY = $chunkY << 4; + $endY = $startY + 16; + for($z = 0; $z < 16; ++$z){ + for($x = 0; $x < 16; ++$x){ + $blocks = ""; + $metas = ""; + for($y = $startY; $y < $endY; ++$y){ + + } + } + } + $this->level->setMiniChunk($chunkX, $chunkZ, $chunkY, $this->chunks[$chunkY]); + } + + public function populateChunk($chunkX, $chunkY, $chunkZ){ + + } + + public function populateLevel(){ + + } + + public function getSpawn(){ + return new Vector3(128, 128, 128); + } +} \ No newline at end of file