diff --git a/src/entity/Entity.php b/src/entity/Entity.php index c02d40c2..2d2a1572 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -468,20 +468,6 @@ class Entity extends Position $hasUpdate = true; } break; - /*default: - - if($this->isPlayer()){ - ConsoleAPI::debug("new {}"); - ConsoleAPI::debug($this->boundingBox); - ConsoleAPI::debug(($this->boundingBox->maxY - $this->boundingBox->minY).", {$this->onGround}"); - } - if (!$b->isTransparent && $b->boundingBox->intersectsWith($bup) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)) { - $this->harm(1, "suffocation"); // Suffocation - $hasUpdate = true; - } elseif ($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)) { - $this->air = 200; // Breathing - } - break;*/ } } } @@ -731,6 +717,17 @@ class Entity extends Position public function fall(){ if($this->isPlayer()){ + + $x = floor($this->x); + $y = floor($this->y - 0.2); + $z = floor($this->z); + $bid = $this->level->level->getBlockID($x, $y, $z); + + if($bid > 0){ + $clz = StaticBlock::getBlock($bid); + $clz::fallOn($this->level, $x, $y, $z, $this, floor($this->fallStart - $this->y)); + } + $dmg = floor($this->fallStart - $this->y) - 3; if($dmg > 0){ $this->harm($dmg, "fall"); diff --git a/src/material/Block.php b/src/material/Block.php index f0546eff..e2718a1c 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -156,7 +156,7 @@ abstract class Block extends Position{ public $slipperiness; public static function onRandomTick(Level $level, $x, $y, $z){} - + public static function fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){} public function __construct($id, $meta = 0, $name = "Unknown"){ $this->id = (int) $id; $this->meta = (int) $meta; diff --git a/src/material/StaticBlock.php b/src/material/StaticBlock.php index 0887b3ef..51b0e7b2 100644 --- a/src/material/StaticBlock.php +++ b/src/material/StaticBlock.php @@ -37,6 +37,10 @@ class StaticBlock } } + public static function getBlock($id){ + return nullsafe(Block::$class[$id], Block::$class[0]); + } + public static function getBoundingBoxForBlockCoords($id, $x, $y, $z){ /**@var AxisAlignedBB $bb*/ $bb = nullsafe(self::$boundingBoxes[$id], false); diff --git a/src/material/block/nonfull/FarmlandBlock.php b/src/material/block/nonfull/FarmlandBlock.php index f3e21432..d6f52fd9 100644 --- a/src/material/block/nonfull/FarmlandBlock.php +++ b/src/material/block/nonfull/FarmlandBlock.php @@ -16,6 +16,14 @@ class FarmlandBlock extends TransparentBlock{ return $b->isTransparent && $b->id != 0; } + public static function fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){ + $rv = lcg_value(); + console("rv: $rv, fd: ".($fallDistance - 0.5)); + if($rv < ($fallDistance - 0.5)){ + $level->fastSetBlockUpdate($x, $y, $z, DIRT, 0); + } + } + public static function onRandomTick(Level $level, $x, $y, $z){ $meta = $level->level->getBlockDamage($x, $y, $z); $b = $level->level->getBlockID($x, $y + 1, $z); diff --git a/src/material/block/solid/DirtBlock.php b/src/material/block/solid/DirtBlock.php index a3ca0e4d..9f006051 100644 --- a/src/material/block/solid/DirtBlock.php +++ b/src/material/block/solid/DirtBlock.php @@ -15,7 +15,7 @@ class DirtBlock extends SolidBlock{ if($item->getMetadata() >= $item->getMaxDurability()) $player->setSlot($player->slot, new Item(AIR, 0, 0), false); else $player->setSlot($player->slot, $item, true); } - $this->level->setBlock($this, BlockAPI::get(FARMLAND, 0), true, false, true); + $this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, FARMLAND, 0, true); return true; } return false; diff --git a/src/material/block/solid/GrassBlock.php b/src/material/block/solid/GrassBlock.php index 99eec531..4d4a8f22 100644 --- a/src/material/block/solid/GrassBlock.php +++ b/src/material/block/solid/GrassBlock.php @@ -27,7 +27,7 @@ class GrassBlock extends SolidBlock{ if($item->getMetadata() >= $item->getMaxDurability()) $player->setSlot($player->slot, new Item(AIR, 0, 0), false); else $player->setSlot($player->slot, $item, true); } - $this->level->setBlock($this, new FarmlandBlock()); + $this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, FARMLAND, 0, true); $this->seedsDrop(); return true; } diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 3f040820..d9851a2d 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -586,11 +586,14 @@ class Utils{ } public static function chance($i){//GameHerobrine's code - return self::randomFloat() <= $i / 100; + return lcg_value() <= $i / 100; } - - public static function randomFloat(){//GameHerobrine's code - return rand() / getrandmax(); + + /** + * @deprecated use lcg_value instead + */ + public static function randomFloat(){ + return lcg_value(); } public static function round($number){ diff --git a/src/world/Level.php b/src/world/Level.php index b4cb5b36..b42b564a 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -311,7 +311,7 @@ class Level{ $pk->meta = $meta; $this->server->api->player->broadcastPacket($this->players, $pk); if($updateBlock){ - $this->server->api->block->blockUpdateAround(new Vector3($x, $y, $z), BLOCK_UPDATE_NORMAL, 1); + $this->server->api->block->blockUpdateAround(new Position($x, $y, $z, $this), BLOCK_UPDATE_NORMAL, 1); } }