From b84093e4ceffb6b4c43a8b82f5de5e138119893b Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 19 Dec 2023 22:34:04 +0300 Subject: [PATCH] cleanup --- src/API/ServerAPI.php | 4 +- src/Player.php | 4 +- src/PocketMinecraftServer.php | 2 - src/config.php | 1 - src/entity/Animal.php | 9 +-- src/entity/Creature.php | 5 +- src/entity/Entity.php | 76 ++----------------- src/entity/Living.php | 2 +- src/entity/ProjectileSource.php | 0 .../ai/tasks/TaskDestroyServerPerformance.php | 2 +- src/entity/ai/tasks/TaskTempt.php | 2 +- src/entity/monster/Creeper.php | 2 +- src/material/block/LiquidBlock.php | 2 +- .../block/misc/NetherReactorBlock.php | 7 +- src/material/block/nonfull/SlabBlock.php | 24 +++--- src/material/item/generic/PaintingItem.php | 2 +- src/material/item/tool/FlintSteelItem.php | 2 +- src/math/Vector3Pos.php | 20 ----- src/pmf/PMFLevel.php | 2 +- src/utils/RailLogic.php | 3 +- src/utils/Utils.php | 2 +- src/utils/VersionString.php | 18 ----- src/world/MobSpawner.php | 2 +- .../generator/noise/NoiseGeneratorPerlin.php | 9 +-- .../generator/vanilla/VanillaGenerator.php | 9 +-- 25 files changed, 48 insertions(+), 163 deletions(-) delete mode 100644 src/entity/ProjectileSource.php delete mode 100644 src/math/Vector3Pos.php delete mode 100644 src/utils/VersionString.php diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 8f660d0a..7003300d 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -35,7 +35,6 @@ class ServerAPI{ */ public $entity; - //TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs. /** * @var TimeAPI */ @@ -104,7 +103,6 @@ class ServerAPI{ } } - $version = new VersionString(); console("[INFO] Starting Minecraft PE server version " . FORMAT_AQUA . CURRENT_MINECRAFT_VERSION); console("[INFO] Loading properties..."); @@ -161,7 +159,7 @@ class ServerAPI{ $this->server->api = $this; self::$serverRequest = $this->server; $this->server->send2Discord("[INFO] Starting Minecraft PE server version " . CURRENT_MINECRAFT_VERSION); - console("[INFO] This server is running NostalgiaCore version " . ($version->isDev() ? FORMAT_YELLOW : "") . MAJOR_VERSION . FORMAT_RESET . " \"" . CODENAME . "\" (MCPE: " . CURRENT_MINECRAFT_VERSION . ") (API " . CURRENT_API_VERSION . ") (PHP " . PHP_VERSION . ")", true, true, 0); + console("[INFO] This server is running NostalgiaCore version " . MAJOR_VERSION . FORMAT_RESET . " \"" . CODENAME . "\" (MCPE: " . CURRENT_MINECRAFT_VERSION . ") (API " . CURRENT_API_VERSION . ") (PHP " . PHP_VERSION . ")", true, true, 0); console("[INFO] NostalgiaCore is distributed under the LGPL License", true, true, 0); $this->loadProperties(); diff --git a/src/Player.php b/src/Player.php index d0d31740..6dd658c1 100755 --- a/src/Player.php +++ b/src/Player.php @@ -2234,7 +2234,7 @@ class Player{ $tile->setSlot($packet->slot, $item); } break; - case ProtocolInfo::SEND_INVENTORY_PACKET: //TODO, Mojang, enable this ´^_^` + case ProtocolInfo::SEND_INVENTORY_PACKET: if($this->spawned === false){ break; } @@ -2283,7 +2283,7 @@ class Player{ $this->entity->linkedEntity->sendMoveUpdate(); } - break; //TODO player input- + break; default: console("[DEBUG] Unhandled 0x" . dechex($packet->pid()) . " data packet for " . $this->username . " (" . $this->clientID . "): " . print_r($packet, true), true, true, 2); break; diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 34c3fb9e..68903385 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -29,8 +29,6 @@ class PocketMinecraftServer{ private function load(){ global $dolog; - - $this->version = new VersionString(); /*if(defined("DEBUG") and DEBUG >= 0){ @cli_set_process_title("NostalgiaCore ".MAJOR_VERSION); }*/ diff --git a/src/config.php b/src/config.php index 15f30f79..5b9eceb8 100644 --- a/src/config.php +++ b/src/config.php @@ -7,7 +7,6 @@ if(ini_get("date.timezone") == ""){ //No Timezone set if(strpos(" " . strtoupper(php_uname("s")), " WIN") !== false){ $time = time(); $time -= $time % 60; - //TODO: Parse different time & date formats by region. ¬¬ world //Example: USA exec("time.exe /T", $hour); $i = array_map("intval", explode(":", trim($hour[0]))); diff --git a/src/entity/Animal.php b/src/entity/Animal.php index f5655517..63e2eb6c 100644 --- a/src/entity/Animal.php +++ b/src/entity/Animal.php @@ -1,8 +1,5 @@ isPlayer() && $action === InteractPacket::ACTION_HOLD){ $slot = $e->player->getHeldItem(); - if($this->isFood($slot->getID()) && $this->inLove <= 0 && !$this->isBaby()){ //TODO check vanilla + if($this->isFood($slot->getID()) && $this->inLove <= 0 && !$this->isBaby()){ if(($e->player->gamemode & 0x01) === SURVIVAL){ $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1); } - $this->inLove = 600; //600 ticks, original mehod from mcpe + $this->inLove = 600; return true; } } diff --git a/src/entity/Creature.php b/src/entity/Creature.php index 3d9e2378..be6b2366 100644 --- a/src/entity/Creature.php +++ b/src/entity/Creature.php @@ -1,8 +1,5 @@ z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z; $this->setHealth(1, "generic"); $this->stepHeight = false; - // $this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type)); + $this->width = 1; $this->height = 1; if($this->type === OBJECT_SNOWBALL){ $this->server->schedule(1210, array( $this, "update" - )); // Despawn - // $this->update(); + )); } break; } $this->radius = $this->width / 2; $this->boundingBox = new AxisAlignedBB($this->x - $this->radius, $this->y, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height, $this->z + $this->radius); - //$this->update(); $this->updateLast(); $this->updatePosition(); if($this->isInVoid()){ @@ -281,24 +279,6 @@ class Entity extends Position return $this->width; } - public function lookOn(Vector3 $target) - { - $horizontal = sqrt(pow(($target->x - $this->x), 2) + pow(($target->z - $this->z), 2)); - $vertical = $target->y - ($this->y + - 0.5); /* 0.5 = $entity->getEyeHeight() */ - $pitch = - asin($horizontal) / M_PI * 180; // negative is up, positive is down - - $xDist = $target->x - $this->x; - $zDist = $target->z - $this->z; - - $yaw = atan2($zDist, $xDist) / M_PI * 180 - 90; - if($yaw < 0){ - $yaw += 360.0; - } - $this->yaw = $yaw; - $this->pitch = $pitch; - $this->server->query("UPDATE entities SET pitch = " . $this->pitch . ", yaw = " . $this->yaw . " WHERE EID = " . $this->eid . ";"); - } - public function getDrops() { if($this->class === ENTITY_PLAYER and $this->player instanceof Player and ($this->player->gamemode & 0x01) === 0){ @@ -407,8 +387,7 @@ class Entity extends Position $endX = ceil($this->boundingBox->maxX); $endY = ceil($this->boundingBox->maxY); $endZ = ceil($this->boundingBox->maxZ); - $waterDone = false; - //$bup = new AxisAlignedBB($startX, $startY + 1, $startZ, $endX, $endY, $endZ); + if(!($this instanceof Painting) && !($this->isPlayer() && $this->player->isSleeping !== false)){ //TODO better way to fix for($i = 0; $i < 8; ++$i){ $x = ((($i >> 0) % 2) - 0.5) * $this->width * 0.8; @@ -597,7 +576,7 @@ class Entity extends Position $this->fallDistance = 0; } if($b != 0){ - $blockBounds = Block::$class[$b]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z); + $blockBounds = Block::$class[$b]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this); foreach($blockBounds as $blockBound){ $this->speedY = $blockBound->calculateYOffset($this->boundingBox, $this->speedY); $this->speedX = $blockBound->calculateXOffset($this->boundingBox, $this->speedX); @@ -640,12 +619,6 @@ class Entity extends Position } $this->boundingBox->offset(0, 0, $this->speedZ); - //$this->speedY = -$this->stepHeight; - //foreach($aaBBs as $bb){ //TODO optimize - // $this->speedY = $bb->calculateYOffset($this->boundingBox, $this->speedY); - //} - //$this->boundingBox->offset(0, $this->speedY, 0); - if ($cx*$cx + $cz*$cz >= $this->speedX*$this->speedX + $this->speedZ*$this->speedZ) { $this->speedX = $cx; @@ -702,9 +675,6 @@ class Entity extends Position if($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){ - // $this->speedX = 0; - // $this->speedY = 0; - // $this->speedZ = 0; $this->server->api->handle("entity.move", $this); $update = true; }elseif ($this->lastYaw != $this->yaw || $this->lastPitch != $this->pitch || $this->lastHeadYaw != $this->headYaw) { @@ -748,13 +718,11 @@ class Entity extends Position $this->fallStart = $this->y; } - if(!$this->onGround && ($prevGroundState /*|| $this->y > $this->fallStart*/)){ + if(!$this->onGround && $prevGroundState){ $this->fallStart = $this->y; } - //if($prevGroundState != $this->onGround){ - // $this->player->sendChat("I am now" . ($this->onGround ? 'on Ground' : 'not on Ground')." and fd: ".$this->fallDistance); - //} - $this->updateFallState(Utils::getSign($this->speedY)*0.1); + + $this->updateFallState(($this->speedY <=> 0)*0.1); if($this->onGround) $this->fallDistance = 0; $hasUpdate = true; } @@ -763,9 +731,6 @@ class Entity extends Position $this->counterUpdate(); - if($this->lastHeadYaw != $this->headYaw){ - $this->sendHeadYaw(); - } if($this->isPlayer() || $update){ $this->updateMovement(); } @@ -829,8 +794,6 @@ class Entity extends Position if($this->server->api->handle("entity.move", $this) === false){ if($this->class === ENTITY_PLAYER){ $this->player->teleport(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]); - } else{ - //TODO fix $this->setPosition($this->last[0], $this->last[1], $this->last[2], $this->last[3], $this->last[4]); } } else{ $players = $this->server->api->player->getAll($this->level); @@ -1157,17 +1120,9 @@ class Entity extends Position { $this->server->query("UPDATE entities SET level = '" . $this->level->getName() . "', x = " . $this->x . ", y = " . $this->y . ", z = " . $this->z . ", pitch = " . $this->pitch . ", yaw = " . $this->yaw . " WHERE EID = " . $this->eid . ";"); $this->sendMoveUpdate(); - // $this->sendMotion(); $this->updateAABB(); } - public function sendHeadYaw(){ - /*$pk = new RotateHeadPacket; - $pk->eid = $this->eid; - $pk->yaw = $this->headYaw; - $this->server->api->player->broadcastPacket($this->level->players, $pk);*/ - } - public function setPosition(Vector3 $pos, $yaw = false, $pitch = false) { if($pos instanceof Position and $pos->level instanceof Level and $this->level !== $pos->level){ @@ -1306,7 +1261,6 @@ class Entity extends Position $this->last[3] = $this->yaw; $this->last[4] = $this->pitch; $this->last[5] = microtime(true); - //$this->lastHeadYaw = $this->headYaw; } public function getPosition($round = false) @@ -1328,10 +1282,9 @@ class Entity extends Position for ($d1 = $entity->z - $this->z; $d * $d + $d1 * $d1 < 0.0001; $d1 = (lcg_value() - lcg_value()) * 0.01) { $d = (lcg_value() - lcg_value()) * 0.01; } - // attackedAtYaw = (float)((Math.atan2($d1, $d) * 180D) / 3.1415927410125732D) > + $this->knockBack($d, $d1); $this->knockbackTime = 10; - $this->sendMotion(); } @@ -1355,23 +1308,11 @@ class Entity extends Position return $this->setHealth(min(20, $this->getHealth() + ((int) $health)), $cause); } - public function sendMotion() - { - /*$pk = new SetEntityMotionPacket(); - $pk->eid = $this->eid; - $pk->speedX = $this->speedX; - $pk->speedY = $this->speedY; - $pk->speedZ = $this->speedZ; - $this->server->api->player->broadcastPacket($this->level->players, $pk);*/ - } - public function linkEntity(Entity $e, $type) { - //if($e->isPlayer()){ $this->linkedEntity = $e; $e->linkedEntity = $this; $this->server->api->dhandle("entity.link", ["rider" => $e->eid, "riding" => $this->eid, "type" => 0]); - //} } public function isPlayer() @@ -1543,7 +1484,6 @@ class Entity extends Position if($this->speedY > 0.4){ $this->speedY = 0.4; } - //$this->speedY /= 2; } public function getHealth() diff --git a/src/entity/Living.php b/src/entity/Living.php index a856139d..15438f94 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -42,7 +42,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{ return true; } public function collideHandler(){ - $this->level->applyCallbackToNearbyEntities($this, [$this, "applyCollision"], 2); //TODO radiuses + } public function applyCollision(Entity $collided){ diff --git a/src/entity/ProjectileSource.php b/src/entity/ProjectileSource.php deleted file mode 100644 index e69de29b..00000000 diff --git a/src/entity/ai/tasks/TaskDestroyServerPerformance.php b/src/entity/ai/tasks/TaskDestroyServerPerformance.php index 8d5d1444..a73804d3 100644 --- a/src/entity/ai/tasks/TaskDestroyServerPerformance.php +++ b/src/entity/ai/tasks/TaskDestroyServerPerformance.php @@ -23,7 +23,7 @@ class TaskDestroyServerPerformance extends TaskTempt if(Utils::distance_noroot($this->target, $ai->entity) > 100){ $ai->mobController->moveTo($this->target->x, floor($ai->entity->y), $this->target->z, false); }else{ - //TODO move away + } $ai->mobController->lookOn($this->target); diff --git a/src/entity/ai/tasks/TaskTempt.php b/src/entity/ai/tasks/TaskTempt.php index 9519543a..3afae162 100644 --- a/src/entity/ai/tasks/TaskTempt.php +++ b/src/entity/ai/tasks/TaskTempt.php @@ -29,7 +29,7 @@ class TaskTempt extends TaskBase public function canBeExecuted(EntityAI $ai) { - if(!($ai->entity instanceof Breedable) || $ai->entity->inPanic || $ai->isStarted("TaskMate")){ //TODO Work with path + if(!($ai->entity instanceof Breedable) || $ai->entity->inPanic || $ai->isStarted("TaskMate")){ return false; } $target = $this->findTarget($ai->entity, 10); diff --git a/src/entity/monster/Creeper.php b/src/entity/monster/Creeper.php index d1045770..9e40e7ba 100644 --- a/src/entity/monster/Creeper.php +++ b/src/entity/monster/Creeper.php @@ -15,7 +15,7 @@ class Creeper extends Monster{ } public function getAttackDamage(){ - return 0; //TODO special attack + return 0; } public function setIgnited($v = null){ diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index ae70fb9e..215e225d 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -26,7 +26,7 @@ class LiquidBlock extends TransparentBlock{ return array(); } - public function getLiquidHeight(){ //TODO lava,water meta + public function getLiquidHeight(){ return (($this->meta >= 8 ? 0 : $this->meta)+1) / 9; } } \ No newline at end of file diff --git a/src/material/block/misc/NetherReactorBlock.php b/src/material/block/misc/NetherReactorBlock.php index 1abe5482..c0bf435c 100644 --- a/src/material/block/misc/NetherReactorBlock.php +++ b/src/material/block/misc/NetherReactorBlock.php @@ -58,12 +58,11 @@ class NetherReactorBlock extends SolidBlock{ } private function decay($x, $y, $z, $aOne, $aTwo, $aThree, $bOne, $bTwo, $bThree, $cOne, $cTwo, $cThree) { - for($a = $aOne; $a < $aTwo; $a += $aThree) { //wth those cycles are? TODO simplify if possible(makes server lag) + for($a = $aOne; $a < $aTwo; $a += $aThree) { for($b = $bOne; $b < $bTwo; $b += $bThree) { for($c = $cOne; $c < $cTwo; $c += $cThree) { if ($this->level->level->getBlockID($x+$a, $y+$b, $z+$c) === NETHERRACK && lcg_value() > 0.75){ - //$this->level->setBlock(new Vector3($x+$a, $y+$b, $z+$c), new AirBlock()); - $this->level->fastSetBlockUpdate($x+$a, $y+$b, $z+$c, 0, 0); //TODO might be better to set not directly? + $this->level->fastSetBlockUpdate($x+$a, $y+$b, $z+$c, 0, 0); } } } @@ -192,7 +191,7 @@ class NetherReactorBlock extends SolidBlock{ $b = $this->level->level->getBlockID($x + $offsetX, $y + $yOffset, $z + $offsetZ); switch($char){ case "G": - if($b === GOLD_BLOCK){ //TODO make it use structure class + if($b === GOLD_BLOCK){ break; } return false; diff --git a/src/material/block/nonfull/SlabBlock.php b/src/material/block/nonfull/SlabBlock.php index 538955a2..82ec32d8 100644 --- a/src/material/block/nonfull/SlabBlock.php +++ b/src/material/block/nonfull/SlabBlock.php @@ -1,19 +1,21 @@ "Stone", + 1 => "Sandstone", + 2 => "Wooden", + 3 => "Cobblestone", + 4 => "Brick", + 5 => "Stone Brick", + 6 => "Quartz", + 7 => "", + ]; + public function __construct($meta = 0){ parent::__construct(SLAB, $meta, "Slab"); - $names = array( //TODO make it static - 0 => "Stone", - 1 => "Sandstone", - 2 => "Wooden", - 3 => "Cobblestone", - 4 => "Brick", - 5 => "Stone Brick", - 6 => "Quartz", - 7 => "", - ); - $this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab"; + $this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . self::$NAMES[$this->meta & 0x07] . " Slab"; if(($this->meta & 0x08) === 0x08){ $this->isFullBlock = true; }else{ diff --git a/src/material/item/generic/PaintingItem.php b/src/material/item/generic/PaintingItem.php index 959379d1..9be8dc4d 100644 --- a/src/material/item/generic/PaintingItem.php +++ b/src/material/item/generic/PaintingItem.php @@ -68,7 +68,7 @@ class PaintingItem extends Item{ $validMotives[] = $motive; } } - $motive = $validMotives[array_rand($validMotives)]; //TODO simplify if possible + $motive = $validMotives[array_rand($validMotives)]; $data = array( "x" => $target->x, "y" => $target->y, diff --git a/src/material/item/tool/FlintSteelItem.php b/src/material/item/tool/FlintSteelItem.php index e7ca11f5..b95ba3ed 100644 --- a/src/material/item/tool/FlintSteelItem.php +++ b/src/material/item/tool/FlintSteelItem.php @@ -9,7 +9,7 @@ class FlintSteelItem extends ItemTool{ public function onActivate(Level $level, Player $player, 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), false); //TODO check + $player->setSlot($player->slot, new Item(AIR, 0, 0), false); } if($block->getID() === AIR and ($target instanceof SolidBlock)){ $level->setBlock($block, new FireBlock(), true, false, true); diff --git a/src/math/Vector3Pos.php b/src/math/Vector3Pos.php deleted file mode 100644 index 7edf577f..00000000 --- a/src/math/Vector3Pos.php +++ /dev/null @@ -1,20 +0,0 @@ -x = &$x; - $this->y = &$y; - $this->z = &$z; - } - - public function addToValues($v){ - $this->x += $v->x; - $this->y += $v->y; - $this->z += $v->z; - return $this; - } - -} - diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index a642aea4..46e99b4a 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -518,7 +518,7 @@ class PMFLevel extends PMF{ } public function doSaveRound(){ - foreach($this->chunks as $index => $chunk){ //TODO fix variables($X, $Z are undefined) + foreach($this->chunks as $index => $chunk){ $this->getXZ($index, $X, $Z); $this->saveChunk($X, $Z); } diff --git a/src/utils/RailLogic.php b/src/utils/RailLogic.php index 63635ebd..23b75c0f 100644 --- a/src/utils/RailLogic.php +++ b/src/utils/RailLogic.php @@ -47,7 +47,7 @@ class RailLogic if($logic != null && $this->connectsTo($logic)){ $this->railPositions[$ind] = new Vector3($logic->x, $logic->y, $logic->z); }else{ - unset($this->railPositions[$ind--]); //TODO check? + unset($this->railPositions[$ind--]); $this->railPositions = array_values($this->railPositions); //reindexing } } @@ -63,7 +63,6 @@ class RailLogic } public function canConnectTo(RailLogic $rail){ - //return this.isRailChunkPositionCorrect(par1BlockBaseRailLogic) ? true : (this.railChunkPosition.size() == 2 ? false : (this.railChunkPosition.isEmpty() ? true : true)); return $this->connectsTo($rail) ? true : (count($this->railPositions) == 2 ? false : (empty($this->railPositions) ? true : true)); } diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 9f90118a..0639cdcf 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -73,7 +73,7 @@ class Utils{ return $angle < 0 ? $angle + 360 : $angle - 180; } public static function getSign($v){ - return $v > 0 ? 1 : ($v < 0 ? -1 : 0); + return $v <=> 0; } public static function clampDegrees($v){ diff --git a/src/utils/VersionString.php b/src/utils/VersionString.php deleted file mode 100644 index 83cf76f8..00000000 --- a/src/utils/VersionString.php +++ /dev/null @@ -1,18 +0,0 @@ -development = Utils::endsWith($version, "dev"); - } - - public function isDev(){ - return $this->development === true; - } - - public function __toString(){ - return MAJOR_VERSION; - } -} \ No newline at end of file diff --git a/src/world/MobSpawner.php b/src/world/MobSpawner.php index f2ba92e3..9f502c92 100644 --- a/src/world/MobSpawner.php +++ b/src/world/MobSpawner.php @@ -25,7 +25,7 @@ class MobSpawner{ $phase = $this->server->api->time->getPhase($this->level); if(self::$spawnAnimals && ($phase == "day" || $phase == "sunrise")){ //Animal $type = mt_rand(10, 13); - $baby = false; //TODO baby + $baby = false; $grassOnly = true; }elseif(self::$spawnMobs && ($phase == "night" || $phase == "sunset")){ //Monster, true night $type = mt_rand(32, 35); diff --git a/src/world/generator/noise/NoiseGeneratorPerlin.php b/src/world/generator/noise/NoiseGeneratorPerlin.php index c7e469ee..edad5c3f 100644 --- a/src/world/generator/noise/NoiseGeneratorPerlin.php +++ b/src/world/generator/noise/NoiseGeneratorPerlin.php @@ -32,12 +32,9 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ $d3 = $d + $this->xCoord; $d4 = $d1 + $this->yCoord; $d5 = $d2 + $this->zCoord; - $i = (int) $d3; - $j = (int) $d4; - $k = (int) $d5; - if($d3 < $i) --$i; - if($d4 < $j) --$j; - if($d5 < $k) --$k; + $i = floor($d3); + $j = floor($d4); + $k = floor($d5); $l = $i & 0xff; $i1 = $j & 0xff; $j1 = $k & 0xff; diff --git a/src/world/generator/vanilla/VanillaGenerator.php b/src/world/generator/vanilla/VanillaGenerator.php index 663ba8d4..9ec18d45 100644 --- a/src/world/generator/vanilla/VanillaGenerator.php +++ b/src/world/generator/vanilla/VanillaGenerator.php @@ -98,13 +98,11 @@ class VanillaGenerator implements LevelGenerator for($i8 = 0; $i8 < 8; ++$i8){ OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), REDSTONE_ORE, 7); } - //for($i9 = 0; $i9 < 1; ++$i9){ //TODO loop is not neccessary + OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), DIAMOND_ORE, 7); - //} - //for($i10 = 0; $i10 < 1; ++$i10){ OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16) + $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), LAPIS_ORE, 6); - //} - //sample= (int) ((((this.treeNoise.getValue(chunkXWorld * 0.5f, chunkZWorld * 0.5f) / 8.0f) + (this.rand.nextFloat() * 4.0f)) + 4.0f) / 3.0f); + + $sample = (int) (((($this->treeNoise->getValue($chunkXWorld * 0.5, $chunkZWorld * 0.5) / 8) + ($this->rand->nextFloat() * 4)) + 4) / 3); $treesAmount = $this->rand->nextInt(10) == 0; if($biome == Biome::$forest) $treesAmount += $sample + 2; @@ -166,7 +164,6 @@ class VanillaGenerator implements LevelGenerator } $this->level->level->chunkChange[$index][-1] = true; - //console($this->level->level->getBlockID($chunkX*16, 20, $chunkZ*16)); } public function populateLevel()