diff --git a/src/Player.php b/src/Player.php index 5481cfbb..fa4eb5f4 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1221,7 +1221,7 @@ class Player{ $move = new MoveEntityPacket_PosRot(); $move->eid = $e->eid; $move->x = $e->x; - $move->y = $e->y; //TODO fix items getting into farmland in client side somehow else + $move->y = $e->y; $move->z = $e->z; $move->yaw = $e->yaw; $move->pitch = $e->pitch; diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 0342eef1..088283be 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -90,6 +90,8 @@ class Entity extends Position public $chunkX = 0; public $chunkZ = 0; + public $isCollidedHorizontally, $isCollidedVertically, $isCollided; + function __construct(Level $level, $eid, $class, $type = 0, $data = array()) { $this->random = new Random(); @@ -552,9 +554,9 @@ class Entity extends Position $z0 = floor($aABB->minZ); $z1 = floor($aABB->maxZ) + 1; - for($x = $x0; $x <= $x1; ++$x){ - for($y = $y0; $y <= $y1; ++$y){ - for($z = $z0; $z <= $z1; ++$z){ + for($x = $x0; $x < $x1; ++$x){ + for($y = $y0; $y < $y1; ++$y){ + for($z = $z0; $z < $z1; ++$z){ $b = $this->level->level->getBlockID($x, $y, $z); if($b != 0){ $blockBounds = Block::$class[$b]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this); @@ -619,10 +621,10 @@ class Entity extends Position $this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2; $this->y = $this->boundingBox->minY + $this->yOffset; $this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2; - //$this.isCollidedHorizontally = savedDX != dx || savedDZ != dz; - //$this.isCollidedVertically = savedDY != dy; + $this->isCollidedHorizontally = $savedDX != $dx || $savedDZ != $dz; + $this->isCollidedVertically = $savedDY != $dy; $this->onGround = $savedDY != $dy && $savedDY < 0.0; - //$this.isCollided = this.isCollidedHorizontally || this.isCollidedVertically; + $this->isCollided = $this->isCollidedHorizontally || $this->isCollidedVertically; $this->updateFallState($this->speedY); @@ -643,6 +645,35 @@ class Entity extends Position } } + //in MCP it is called isOffsetPositionInLiquid, in 0.8 - isFree + public function isFree($offsetX, $offsetY, $offsetZ){ + $offsetBB = $this->boundingBox->getOffsetBoundingBox($offsetX, $offsetY, $offsetZ); + + $minX = floor($offsetBB->minX); + $minY = floor($offsetBB->minY); + $minZ = floor($offsetBB->minZ); + $maxX = floor($offsetBB->maxX + 1); + $maxY = floor($offsetBB->maxY + 1); + $maxZ = floor($offsetBB->maxZ + 1); + + $hasLiquid = false; + $result = false; + for($x = $minX; $x < $maxX; ++$x){ + for($z = $minZ; $z < $maxZ; ++$z){ + for($y = $minY - 1; $y < $maxY; ++$y){ + $v12 = $this->level->level->getBlockID($x, $y, $z); + if($y != ($minY - 1)) $hasLiquid |= StaticBlock::getIsLiquid($v12); + if($v12 != 0){ + $result = true; + break 3; + } + } + } + } + if($result) return !$hasLiquid; + return false; + } + public function isInVoid(){ return $this->y < -1.6; } diff --git a/src/entity/Living.php b/src/entity/Living.php index 382c3357..0f836bc7 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -170,8 +170,10 @@ abstract class Living extends Entity implements Pathfindable{ if($this->jumpTicks > 0) --$this->jumpTicks; } + public function moveEntityWithHeading($strafe, $forward){ if($this->inWater){ //also check is player, and can it fly or not + $prevPosY = $this->y; $this->moveFlying($strafe, $forward, 0.04); //TODO speed: this.isAIEnabled() ? 0.04F : 0.02F $this->move($this->speedX, $this->speedY, $this->speedZ); $this->speedX *= 0.8; @@ -179,11 +181,10 @@ abstract class Living extends Entity implements Pathfindable{ $this->speedZ *= 0.8; $this->speedY -= 0.02; - //TODO: static speedY - //if (this.isCollidedHorizontally && this.isOffsetPositionInLiquid(this.motionX, this.motionY + 0.6 - this.posY + var9, this.motionZ)) - //{ - // this.motionY = 0.3; - //} + + if($this->isCollidedHorizontally && $this->isFree($this->speedX, $this->speedY + 0.6 - $this->y + $prevPosY, $this->speedZ)){ + $this->speedY = 0.3; + } } //TODO lava else{ diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index 194bd731..4d036849 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -95,7 +95,6 @@ class ItemEntity extends Entity{ if($this->closed) return; $friction = 0.98; - if($this->onGround){ $friction = 0.588; $v3 = $this->level->level->getBlockID($this->x, floor($this->boundingBox->minY) - 1, $this->z); diff --git a/src/world/Level.php b/src/world/Level.php index e794a354..12e80a1b 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -477,7 +477,6 @@ class Level{ $maxChunkX = ((int)($bb->maxX)) >> 4; $maxChunkZ = ((int)($bb->maxZ)) >> 4; $ents = []; - console("nya $minChunkX $minChunkZ $maxChunkX $maxChunkZ"); for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){ for($chunkZ = $minChunkZ; $chunkZ <= $maxChunkZ; ++$chunkZ){ $ind = "$chunkX $chunkZ";