diff --git a/src/constants/BlockEntityIDs.php b/src/constants/BlockEntityIDs.php new file mode 100644 index 00000000..2d039b85 --- /dev/null +++ b/src/constants/BlockEntityIDs.php @@ -0,0 +1,13 @@ +getID()] = $b->isSolid; + self::$isTransparent[$b->getID()] = $b->isTransparent; + self::$isFlowable[$b->getID()] = $b->isFlowable; + self::$isReplaceable[$b->getID()] = $b->isReplaceable; + self::$isPlaceable[$b->getID()] = $b->isPlaceable; + self::$hasPhysics[$b->getID()] = $b->hasPhysics; + self::$isLiquid[$b->getID()] = $b->isLiquid; + self::$isFullBlock[$b->getID()] = $b->isFullBlock; + self::$slipperiness[$b->getID()] = $b->slipperiness; + self::$boundingBoxes[$b->getID()] = $b->boundingBox; + self::$hardness[$b->getID()] = $b->getHardness(); + } + } + + public static function getBlock($id){ + return Block::$class[$id] ?? Block::$class[0]; + } + + public static function getHardness($id){ + return self::$hardness[$id] ?? StaticBlock::DEFAULT_HARDNESS; + } + + public static function getBoundingBoxForBlockCoords($id, $x, $y, $z){ + /**@var AxisAlignedBB $bb*/ + $bb = self::$boundingBoxes[$id] ?? false; + if($bb === false){ + return clone self::$NULL_BOUNDS; + } + $bb = clone $bb; + return $bb->setBounds($x + $bb->minX, $y + $bb->minY, $z + $bb->minZ, $x + $bb->maxX, $y + $bb->maxY, $z + $bb->maxZ); + } + + + public static function getSlipperiness($id){ + return self::$slipperiness[$id] ?? StaticBlock::DEFAULT_SLIPPERINESS; + } + + public static function getIsSolid($id){ + return self::$isSolid[$id] ?? false; + } + + public static function getIsTransparent($id){ + return self::$isTransparent[$id] ?? false; + } + + public static function getIsFlowable($id){ + return self::$isFlowable[$id] ?? false; + } + + public static function getIsReplaceable($id){ + return self::$isReplaceable[$id] ?? false; + } + + public static function getIsPlaceable($id){ + return self::$isPlaceable[$id] ?? false; + } + + public static function getHasPhysics($id){ + return self::$hasPhysics[$id] ?? false; + } + + public static function getIsLiquid($id){ + return self::$isLiquid[$id] ?? false; + } + + public static function getIsFullBlock($id){ + return self::$isFullBlock[$id] ?? false; + } +} diff --git a/src/material/block/misc/MobSpawnerBlock.php b/src/material/block/misc/MobSpawnerBlock.php new file mode 100644 index 00000000..1844eac6 --- /dev/null +++ b/src/material/block/misc/MobSpawnerBlock.php @@ -0,0 +1,30 @@ +isActivable = true; + } + + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $api = ServerAPI::request(); + $tile = $api->api->tile->add($this->level, TILE_MOB_SPAWNER, $this->x, $this->y, $this->z, [ + "id" => TILE_MOB_SPAWNER, + "x" => $this->x, + "y" => $this->y, + "z" => $this->z, + "EntityId" => MOB_SPIDER, //TODO vanilla values + "Delay" => 5, + "MinSpawnDelay" => 20, + "MaxSpawnDelay" => 80, + "SpawnCount" => 4, + "MaxNearbyEntities" => 0, + "RequiredPlayerRange" => 0, + "SpawnRange" => 4 + ]); + parent::place($item, $player, $block, $target, $face, $fx, $fy, $fz); + } +} + diff --git a/src/material/block/solid/PodzolBlock.php b/src/material/block/solid/PodzolBlock.php new file mode 100644 index 00000000..98b809c0 --- /dev/null +++ b/src/material/block/solid/PodzolBlock.php @@ -0,0 +1,62 @@ +hardness = 2.5; + } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_RANDOM){ + if(mt_rand(0, 3) == 0){ + $up = $this->getSide(1); + if(($up->isTransparent === false) or ($up->isLiquid) or ($up->getID() == 60)) return false; + if($this->getGrassInRadius()){ + $this->level->setBlock($this, BlockAPI::get(GRASS, 0), true, false, true); + } + } + } + return BLOCK_UPDATE_RANDOM; + } + + public function getBlockID($x, $y, $z){ + return $this->level->getBlock(new Vector3($x, $y, $z))->getID(); + } + + public function getGrassInRadius(){ + $x = $this->x; + $y = $this->y; + $z = $this->z; + + if($this->getBlockID($x+1, $y, $z+1) == 2) return true; + if($this->getBlockID($x+1, $y, $z) == 2) return true; + if($this->getBlockID($x+1, $y, $z-1) == 2) return true; + if($this->getBlockID($x, $y, $z+1) == 2) return true; + if($this->getBlockID($x, $y, $z-1) == 2) return true; + if($this->getBlockID($x-1, $y, $z+1) == 2) return true; + if($this->getBlockID($x-1, $y, $z) == 2) return true; + if($this->getBlockID($x-1, $y, $z-1) == 2) return true; + + if($this->getBlockID($x+1, $y-1, $z+1) == 2) return true; + if($this->getBlockID($x+1, $y-1, $z) == 2) return true; + if($this->getBlockID($x+1, $y-1, $z-1) == 2) return true; + if($this->getBlockID($x, $y-1, $z+1) == 2) return true; + if($this->getBlockID($x, $y-1, $z) == 2) return true; + if($this->getBlockID($x, $y-1, $z-1) == 2) return true; + if($this->getBlockID($x-1, $y-1, $z+1) == 2) return true; + if($this->getBlockID($x-1, $y-1, $z) == 2) return true; + if($this->getBlockID($x-1, $y-1, $z-1) == 2) return true; + + if($this->getBlockID($x+1, $y+1, $z+1) == 2) return true; + if($this->getBlockID($x+1, $y+1, $z) == 2) return true; + if($this->getBlockID($x+1, $y+1, $z-1) == 2) return true; + if($this->getBlockID($x, $y+1, $z+1) == 2) return true; + if($this->getBlockID($x, $y+1, $z-1) == 2) return true; + if($this->getBlockID($x-1, $y+1, $z+1) == 2) return true; + if($this->getBlockID($x-1, $y+1, $z) == 2) return true; + if($this->getBlockID($x-1, $y+1, $z-1) == 2) return true; + + return false; + } + +} \ No newline at end of file diff --git a/src/world/Level.php b/src/world/Level.php index 1dd4c778..3094113f 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -101,12 +101,7 @@ class Level{ if(!isset($this->level)){ return false; } - /*if(ADVANCED_CACHE == true){ - $identifier = "world:{$this->name}:$X:$Z"; - if(($cache = Cache::get($identifier)) !== false){ - return $cache; - } - }*/ + $gen = $this->generatorType === 1 || !($X > 15 || $X < 0 || $Z > 15 || $Z < 0); $orderedIds = ""; $orderedData = ""; @@ -149,7 +144,7 @@ class Level{ } $nbt = new NBT_new(NBT_new::LITTLE_ENDIAN); - foreach($chunkTiles as $tile){ + foreach($chunkTiles as $tile){ //TODO non-hardcoded nbt data switch($tile->class){ case "Sign": $text = $tile->getText(); @@ -183,9 +178,6 @@ class Level{ $orderedIds . $orderedData . $orderedSkyLight . $orderedLight . $orderedBiomeIds . $orderedBiomeColors . $tileEntities; $ordered = zlib_encode($orderedUncompressed, ZLIB_ENCODING_DEFLATE, 6); - /*if(ADVANCED_CACHE == true){ - Cache::add($identifier, $ordered, 60); - }*/ return $ordered; } diff --git a/src/world/generator/populator/GroundCover.php b/src/world/generator/populator/GroundCover.php index afbb48a1..29a05887 100644 --- a/src/world/generator/populator/GroundCover.php +++ b/src/world/generator/populator/GroundCover.php @@ -14,7 +14,7 @@ class GroundCover extends Populator if(count($cover) > 0){ $diffY = 0; - if(!BlockAPI::get($cover[0][0], $cover[0][1])->isSolid){ + if(!StaticBlock::getIsSolid($cover[0][0])){ $diffY = 1; } @@ -22,7 +22,7 @@ class GroundCover extends Populator for($y = 127; $y > 0; --$y){ $chunkY = $y >> 4; $b = $column[$chunkY][(($y & 0xf) + ($x << 6) + ($z << 10))]; - if($b !== "\x00" and !BlockAPI::get(ord($b))->isTransparent){ + if($b !== "\x00" and !StaticBlock::getIsTransparent(ord($b))){ break; } } @@ -31,20 +31,17 @@ class GroundCover extends Populator for($y = $startY; $y > $endY and $y >= 0; --$y){ $chunkY = $y >> 4; $pair = $cover[$startY - $y]; - $b = BlockAPI::get($pair[0], $pair[1]); - if($column[$chunkY][(($y & 0xf) + ($x << 6) + ($z << 10))] === "\x00" and $b->isSolid){ + //$b = BlockAPI::get($pair[0], $pair[1]); + $bid = $pair[0]; + $bmeta = $pair[1]; + if($column[$chunkY][(($y & 0xf) + ($x << 6) + ($z << 10))] === "\x00" and StaticBlock::getIsSolid($bid)){ break; } - if($y <= $waterHeight and $b->getID() == GRASS and $level->level->getBlockID($pcx, $y + 1, $pcz) == STILL_WATER){ - //$b = BlockAPI::get(DIRT); + if($y <= $waterHeight and $bid == GRASS and $level->level->getBlockID($pcx, $y + 1, $pcz) == STILL_WATER){ $level->level->setBlock($pcx, $y, $pcz, DIRT, 0); continue; } - //if($b->getMetadata() === 0){ - // $level->level->setBlockId($pcx, $y, $pcz, $b->getID()); - //}else{ - $level->level->setBlock($pcx, $y, $pcz, $b->getID(), $b->getMetadata()); - //} + $level->level->setBlock($pcx, $y, $pcz, $bid, $bmeta); } } } diff --git a/src/world/generator/populator/TallGrassPopulator.php b/src/world/generator/populator/TallGrassPopulator.php index d1c75f08..bf55c9ee 100644 --- a/src/world/generator/populator/TallGrassPopulator.php +++ b/src/world/generator/populator/TallGrassPopulator.php @@ -48,7 +48,6 @@ class TallGrassPopulator extends Populator{ }else{ $this->level->level->setBlock($xx, $yy, $zz, TALL_GRASS, 1); } - } } } @@ -59,7 +58,6 @@ class TallGrassPopulator extends Populator{ } private function getHighestWorkableBlock($x, $z){ - for($y = 128; $y > 0; --$y){ $b = $this->level->level->getBlockID($x, $y, $z); if($b == GRASS){