diff --git a/src/Player.php b/src/Player.php index 5d64b494..1c5f57c5 100755 --- a/src/Player.php +++ b/src/Player.php @@ -202,8 +202,13 @@ class Player{ $this->dataPacket($pk); }else{ - $pk = new RemoveEntityPacket; + $pk = new MoveEntityPacket_PosRot(); $pk->eid = $e->eid; + $pk->x = -256; + $pk->y = 128; + $pk->z = -256; + $pk->yaw = 0; + $pk->pitch = 0; $this->dataPacket($pk); } } @@ -219,8 +224,22 @@ class Player{ $this->level->players[$this->CID] = $this; $this->chunksLoaded = []; $this->server->api->entity->spawnToAll($this->entity); - $this->server->api->entity->spawnAll($this); - + //$this->server->api->entity->spawnAll($this); + foreach($this->level->entityList as $e){ + if($e->eid !== $this->entity->eid){ + if(!$e->isPlayer()){ + $pk = new MoveEntityPacket_PosRot(); + $pk->eid = $e->eid; + $pk->x = $e->x; + $pk->y = $e->y; + $pk->z = $e->z; + $pk->yaw = $e->yaw; + $pk->pitch = $e->pitch; + $this->dataPacket($pk); + } + } + } + $pk = new SetTimePacket; $pk->time = $this->level->getTime(); $this->dataPacket($pk); diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index a006735e..00f41ac8 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -170,6 +170,11 @@ class ItemEntity extends Entity{ return 0; } } + + public function handleWaterMovement(){ + return $this->level->handleMaterialAcceleration($this->boundingBox, 0, $this); + } + public function updateEntityMovement(){ //TODO custom update( method $this->speedY -= 0.04; diff --git a/src/material/Block.php b/src/material/Block.php index 8b49559c..894c7e54 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -219,6 +219,7 @@ abstract class Block extends Position{ return MovingObjectPosition::fromBlock($x, $y, $z, $v14, $v13->add($x, $y, $z)); } + public static function onPlace(Level $level, $x, $y, $z){} public static function addVelocityToEntity(Level $level, $x, $y, $z, Entity $entity, Vector3 $velocityVector){} public static function onRandomTick(Level $level, $x, $y, $z){} diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index 001a23ed..feafe045 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -41,6 +41,117 @@ class LiquidBlock extends TransparentBlock{ return $f; } + public static function getRenderedDepth(Level $level, $x, $y, $z){ + [$id, $meta] = $level->level->getBlock($x, $y, $z); + + $cond = match($id){ + WATER, STILL_WATER => static::$blockID == WATER || static::$blockID == STILL_WATER, + LAVA, STILL_LAVA => static::$blockID == LAVA || static::$blockID == STILL_LAVA, + default => static::$blockID == $id + }; + if(!$cond) return -1; + return $meta >= 8 ? 0 : $meta; + } + + public static function shouldRenderFace(Level $level, $x, $y, $z, $face){ + $id = $level->level->getBlockID($x, $y, $z); + + if($id == ICE) return false; + if((($id == WATER || $id == STILL_WATER) && (static::$blockID == WATER || static::$blockID == STILL_WATER))) return false; + if((($id == LAVA || $id == STILL_LAVA) && (static::$blockID == LAVA || static::$blockID == STILL_LAVA))) return false; + + if($face == 1) return true; + return StaticBlock::getIsSolid($id); + //return parent::shouldRenderFace($level, $x, $y, $z, $face); + } + + public static function getFlow(Level $level, $x, $y, $z){ + $flowVector = new Vector3(0, 0, 0); + $v6 = static::getRenderedDepth($level, $x, $y, $z); + + for($v7 = 0; $v7 < 4; ++$v7){ + $v8 = $x; + $v10 = $z; + switch($v7){ + case 0: + --$v8; + break; + case 1: + --$v10; + break; + case 2: + ++$v8; + break; + case 3: + ++$v10; + break; + } + + $v11 = static::getRenderedDepth($level, $v8, $y, $v10); + if($v11 < 0){ + if(!StaticBlock::getIsSolid($level->level->getBlockID($v8, $y, $v10))){ //TODO material.blocksMovement + $v11 = static::getRenderedDepth($level, $v8, $y - 1, $v10); + + if($v11 >= 0){ + $v12 = $v11 - ($v6 - 8); + $flowVector->x += ($v8 - $x) * $v12; + $flowVector->y += ($y - $y) * $v12; + $flowVector->z += ($v10 - $z) * $v12; + } + } + }else if($v11 >= 0){ + $v12 = $v11 - $v6; + $flowVector->x += ($v8 - $x) * $v12; + $flowVector->y += ($y - $y) * $v12; + $flowVector->z += ($v10 - $z) * $v12; + } + } + + $meta = $level->level->getBlockDamage($x, $y, $z); + + if($meta >= 8){ + $v13 = //TODO more vanilla way to do it + static::shouldRenderFace($level, $x, $y, $z - 1, 2) || + static::shouldRenderFace($level, $x, $y, $z + 1, 3) || + static::shouldRenderFace($level, $x - 1, $y, $z, 4) || + static::shouldRenderFace($level, $x + 1, $y, $z, 5) || + + static::shouldRenderFace($level, $x, $y + 1, $z - 1, 2) || + static::shouldRenderFace($level, $x, $y + 1, $z + 1, 3) || + static::shouldRenderFace($level, $x - 1, $y + 1, $z, 4) || + static::shouldRenderFace($level, $x + 1, $y + 1, $z, 5) + ; + + if($v13){ + $ln = $flowVector->length(); + if($ln){ + $flowVector->x /= $ln; + $flowVector->y = ($flowVector->y / $ln) - 6; + $flowVector->z /= $ln; + }else{ + $flowVector->x = $flowVector->y = $flowVector->z = 0; + } + } + } + $ln = $flowVector->length(); + if($ln){ + $flowVector->x /= $ln; + $flowVector->y /= $ln; + $flowVector->z /= $ln; + }else{ + $flowVector->x = $flowVector->y = $flowVector->z = 0; + } + + return $flowVector; + } + + public static function addVelocityToEntity(Level $level, $x, $y, $z, Entity $entity, Vector3 $velocityVector){ + $flow = static::getFlow($level, $x, $y, $z); + $velocityVector->x += $flow->x * 0.5; + $velocityVector->y += $flow->y * 0.5; + $velocityVector->z += $flow->z * 0.5; + } + public static function getTickDelay(){ throw new RuntimeException("If you see this, something bad happened"); } diff --git a/src/world/Level.php b/src/world/Level.php index 8b02b4d4..261b5fe0 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -210,7 +210,6 @@ class Level{ $appliedVelocity = false; $velocityVec = new Vector3(0, 0, 0); - for($x = $minX; $x < $maxX; ++$x){ for($y = $minY; $y < $maxY; ++$y){ for($z = $minZ; $z < $maxZ; ++$z){ @@ -221,6 +220,7 @@ class Level{ $appliedVelocity = true; Block::$class[$block]::addVelocityToEntity($this, $x, $y, $z, $entity, $velocityVec); } + } } }