diff --git a/src/Player.php b/src/Player.php index a30c24b6..aed5ab4e 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1226,8 +1226,8 @@ class Player{ $motionSent = false; $moveSent = false; $headSent = false; - if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){ - if(!($e->speedY < 0 && $e->onGround) || $e->speedX != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){ + //if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){ + // if(!($e->speedY < 0 && $e->onGround) || $e->speedX != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){ $motion = new SetEntityMotionPacket(); $motion->eid = $e->eid; $motion->speedX = $e->speedX; @@ -1237,9 +1237,9 @@ class Player{ $len += 1 + strlen($motion->buffer); ++$packets; $motionSent = true; - } - } - if($e->x != $e->lastX || $e->y != $e->lastY || $e->z != $e->lastZ || $e->yaw != $e->lastYaw || $e->pitch != $e->lastPitch){ + // } + //} + //if($e->x != $e->lastX || $e->y != $e->lastY || $e->z != $e->lastZ || $e->yaw != $e->lastYaw || $e->pitch != $e->lastPitch){ $move = new MoveEntityPacket_PosRot(); $move->eid = $e->eid; $move->x = $e->x; @@ -1251,8 +1251,8 @@ class Player{ $len += strlen($move->buffer) + 1; ++$packets; $moveSent = true; - } - if($e->headYaw != $e->lastHeadYaw){ + //} + //if($e->headYaw != $e->lastHeadYaw){ $headyaw = new RotateHeadPacket(); $headyaw->eid = $e->eid; $headyaw->yaw = $e->headYaw; @@ -1260,7 +1260,7 @@ class Player{ $len += strlen($headyaw->buffer) + 1; ++$packets; $headSent = true; - } + //} if($packets <= 0) return; //console("Update {$e}: $packets, mot: $motionSent, mov: $moveSent, hed: $headSent"); $MTU = $this->MTU - 24; @@ -1879,9 +1879,12 @@ class Player{ //CANCEL but i am too lazy $power = 0.1; } - $e->critical = ($power === 1); - $e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power+$power) * 1.5, 1.0); - $this->server->api->entity->spawnToAll($e); + if(DEBUG){ + $e->critical = ($power === 1); + $e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power+$power) * 1.5, 1.0); + $this->server->api->entity->spawnToAll($e); + } + } } } diff --git a/src/entity/object/Arrow.php b/src/entity/object/Arrow.php index 20f948ab..2d053e45 100644 --- a/src/entity/object/Arrow.php +++ b/src/entity/object/Arrow.php @@ -3,12 +3,20 @@ class Arrow extends Projectile{ const TYPE = OBJECT_ARROW; - public $criticial = false; + public $shooterEID = 0; public $shotByEntity; - public $airTicks = 0; + public $inWall = false; public $groundTicks = 0; + + public $xTile, $yTile, $zTile; + public $inTile, $inData; + public $shake; + public $inGround; + public $airTicks = 0; + public $criticial = false; + function __construct(Level $level, $eid, $class, $type = 0, $data = [], $shooter = false){ parent::__construct($level, $eid, $class, $type, $data); $this->gravity = 0.05; @@ -66,68 +74,128 @@ class Arrow extends Projectile{ } } public function update($now){ - $this->needsUpdate = false; //TODO reenable - return; - //parent::update(); - if($this->closed || ($this->x > 255 || $this->x < 0 || $this->y < 0 || $this->z < 0 || $this->z > 255) || $this->groundTicks > 200) { //remove after 10 seconds in wall, idc about vanilla - $this->server->api->entity->remove($this->eid); - return; - } - + $this->lastX = $this->x; + $this->lastY = $this->y; + $this->lastZ = $this->z; + $this->lastPitch = $this->pitch; + $this->lastYaw = $this->yaw; $this->needsUpdate = true; - if($this->inWall) { - ++$this->groundTicks; - return; //yeah whatever - } - if($this->speedX != 0 or $this->speedY != 0 or $this->speedZ != 0){ - $f = sqrt(($this->speedX * $this->speedX) + ($this->speedZ * $this->speedZ)); - $this->yaw = (atan2($this->speedX, $this->speedZ) * 180 / M_PI); - $this->pitch = (atan2($this->speedY, $f) * 180 / M_PI); - } - $rt = $this->boundingBox->shrink(0.4, 0.4, 0.4)->addCoord($this->speedX, $this->speedY, $this->speedZ); - for($x = floor($rt->minX); $x < ceil($rt->maxX); ++$x){ - for($z = floor($rt->minZ); $z < ceil($rt->maxZ); ++$z){ - for($y = ceil($rt->minY); $y < ceil($rt->maxY); ++$y){ - $b = $this->level->level->getBlockID($x, $y, $z); - if(StaticBlock::getIsSolid($b)){ - $bb = StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z); - $this->speedY = $bb->calculateYOffset($this->boundingBox, $this->speedY); - $this->speedX = $bb->calculateXOffset($this->boundingBox, $this->speedX); - $this->speedZ = $bb->calculateZOffset($this->boundingBox, $this->speedZ); - $this->inWall = true; - break; - } + $this->handleWaterMovement(); //TODO: maybe just call parent::update(); ? + if($this->fire > 0){ + if(!$this->isImmuneToFire){ + if(($this->fire % 20) == 0){ + $this->harm(1, "burning"); } + --$this->fire; + }else{ + $this->fire -= 4; + if($this->fire <= 0) $this->fire = 0; } - } - if(!$this->inWall){ - $bbexp = $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ)->expand(0, 0.2, 0); - foreach($this->level->entityList as $e){ - if($e instanceof Entity && $e->eid !== $this->eid && !$e->closed && $e->canBeShot() && $e->boundingBox->intersectsWith($bbexp)){ - if($this->shotByEntity && $this->shooterEID === $e->eid && $this->airTicks < 5) continue; - $dmg = ceil(sqrt($this->speedX * $this->speedX + $this->speedY * $this->speedY + $this->speedZ * $this->speedZ) * 2); - if($this->criticial){ - $dmg += mt_rand(0, (int)($dmg/2+1)); - } - $e->harm($dmg, $this->eid); - $this->closed = true; - break; - } + + if($this->fire <= 0){ + $this->updateMetadata(); } } - $this->x += $this->speedX; - $this->y += $this->speedY; - $this->z += $this->speedZ; - ++$this->airTicks; //TODO onGround state + if($this->handleLavaMovement()){ + if(!$this->isImmuneToFire){ + $this->harm(4, "fire"); + $oldOnFire = $this->fire; + if($oldOnFire < 20*30) $this->fire = 20*30; //30 seconds + } + } - $this->speedX *= 0.99; - $this->speedY *= 0.99; - $this->speedZ *= 0.99; - $this->speedY -= $this->gravity; + if($this->isInVoid()){ + $this->outOfWorld(); + } + //Entity::update end + + + if($this->lastPitch == $this->lastYaw && $this->lastYaw == 0){ + $v1 = sqrt($this->speedX*$this->speedX + $this->speedZ*$this->speedZ); + $this->lastYaw = $this->yaw = atan2($this->speedX, $this->speedZ) * 180 / M_PI; + $this->lastPitch = $this->pitch = atan2($this->speedY, $v1) * 180 / M_PI; + } + + $v16 = $this->level->level->getBlockID($this->xTile, $this->yTile, $this->zTile); + if($v16 > 0){ + //TODO this->inGround = true + checks + } + + if($this->shake > 0){ + --$this->shake; + } + + if($this->inGround){ + //TODO despawn after 1200 if if & meta == this->inTIle, this->inData + }else{ + ++$this->airTicks; + $start = new Vector3($this->x, $this->y, $this->z); + $end = new Vector3($this->x + $this->speedX, $this->y + $this->speedY, $this->z + $this->speedZ); + /** + * @var MovingObjectPosition $v4 + */ + $v4 = $this->level->rayTraceBlocks($start, $end); + $start = new Vector3($this->x, $this->y, $this->z); //TODO remove? + if($v4 != null){ + $end = new Vector3($v4->hitVector->x, $v4->hitVector->y, $v4->hitVector->z); + }else{ + $end = new Vector3($this->x + $this->speedX, $this->y + $this->speedY, $this->z + $this->speedZ); + } + + //TODO entity collisions + console($v4); + if($v4 != null){ + if($v4->entityHit != null){ + //TODO entity hit + }else{ + $this->xTile = $v4->blockX; + $this->yTile = $v4->blockY; + $this->zTile = $v4->blockZ; + + [$this->inTile, $this->inData] = $this->level->level->getBlock($this->xTile, $this->yTile, $this->zTile); + + $this->speedX = $v4->hitVector->x - $this->x; + $this->speedY = $v4->hitVector->y - $this->y; + $this->speedZ = $v4->hitVector->z - $this->z; + + $v21 = sqrt($this->speedX*$this->speedX + $this->speedY*$this->speedY + $this->speedZ*$this->speedZ); + $this->x -= $this->speedX / $v21 * 0.05; + $this->y -= $this->speedY / $v21 * 0.05; + $this->z -= $this->speedZ / $v21 * 0.05; + + $this->inGround = true; + $this->shake = 7; + $this->criticial = false; + } + } + + $this->x += $this->speedX; + $this->y += $this->speedY; + $this->z += $this->speedZ; + $v21 = sqrt($this->speedX*$this->speedX + $this->speedZ*$this->speedZ); + $this->yaw = atan2($this->speedX, $this->speedZ) * 180 / M_PI; + $this->pitch = atan2($this->speedY, $v21) * 180 / M_PI; + + $this->pitch = $this->lastPitch + ($this->pitch - $this->lastPitch) * 0.2; + $this->yaw = $this->lastYaw + ($this->yaw - $this->lastYaw) * 0.2; + + $v24 = $this->inWater ? 0.8 : 0.99; + $this->speedX *= $v24; + $this->speedY *= $v24; + $this->speedZ *= $v24; + $this->speedY -= 0.05; + //$this->setP + $v7 = $this->width / 2; + $v8 = $this->height; + $this->boundingBox->setBounds($this->x - $v7, $this->y - $this->yOffset /*+ $this->ySize*/, $this->z - $v7, $this->x + $v7, $this->y - $this->yOffset + $v8 /*+ $this->ySize*/, $this->z + $v7); + + $this->doBlocksCollision(); + console($this); + + } - $this->updatePosition(); } diff --git a/src/material/Block.php b/src/material/Block.php index 4884c85e..345d624b 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -155,19 +155,63 @@ abstract class Block extends Position{ public $z = 0; public $slipperiness; - public static $minX = 0, $minY = 0, $minZ = 0, $maxX = 1, $maxY = 1, $maxZ = 1; - public static function setBlockBounds($minX, $minY, $minZ, $maxX, $maxY, $maxZ){ //TODO call for some specific blocks - static::$minX = $minX; - static::$minY = $minY; - static::$minZ = $minZ; - static::$maxX = $maxX; - static::$maxY = $maxY; - static::$maxZ = $maxZ; - } public static function getAABB(Level $level, $x, $y, $z){ - return new AxisAlignedBB(static::$minX + $x, static::$minY + $y, static::$minZ + $z, static::$maxX + $x, static::$maxY + $y, static::$maxZ + $z); + return StaticBlock::getAABB($level, $x, $y, $z); } + public static function containsX($id, $v){ + return $v == null ? false : $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id]; + } + + public static function containsY($id, $v){ + return $v == null ? false : $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id]; + } + + public static function containsZ($id, $v){ + return $v == null ? false : $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id]; + } + + public static function clip(Level $level, $x, $y, $z, Vector3 $start, Vector3 $end){ + //self::updateShape($level, $x, $y, $z); TODO update shape + $id = $level->level->getBlockID($x, $y, $z); + + $start = $start->subtract($x, $y, $z); + $end = $end->subtract($x, $y, $z); + + $v7 = $start->clipX($end, StaticBlock::$minXs[$id]); + $v8 = $start->clipX($end, StaticBlock::$maxXs[$id]); + $v9 = $start->clipY($end, StaticBlock::$minYs[$id]); + $v10 = $start->clipY($end, StaticBlock::$maxYs[$id]); + $v11 = $start->clipZ($end, StaticBlock::$minZs[$id]); + $v12 = $start->clipZ($end, StaticBlock::$maxZs[$id]); + + if(!self::containsX($id, $v7)) $v7 = null; + if(!self::containsX($id, $v8)) $v8 = null; + if(!self::containsY($id, $v9)) $v9 = null; + if(!self::containsY($id, $v10)) $v10 = null; + if(!self::containsZ($id, $v11)) $v11 = null; + if(!self::containsZ($id, $v12)) $v12 = null; + + $v13 = null; + if($v7 != null && ($v13 == null || $start->distanceSquared($v7) < $start->distanceSquared($v13))) $v13 = $v7; + if($v8 != null && ($v13 == null || $start->distanceSquared($v8) < $start->distanceSquared($v13))) $v13 = $v8; + if($v9 != null && ($v13 == null || $start->distanceSquared($v9) < $start->distanceSquared($v13))) $v13 = $v9; + if($v10 != null && ($v13 == null || $start->distanceSquared($v10) < $start->distanceSquared($v13))) $v13 = $v10; + if($v11 != null && ($v13 == null || $start->distanceSquared($v11) < $start->distanceSquared($v13))) $v13 = $v11; + if($v12 != null && ($v13 == null || $start->distanceSquared($v12) < $start->distanceSquared($v13))) $v13 = $v12; + + if($v13 == null) return null; + + $v14 = -1; + if($v13 == $v7) $v14 = 4; + if($v13 == $v8) $v14 = 5; + if($v13 == $v9) $v14 = 0; + if($v13 == $v10) $v14 = 1; + if($v13 == $v11) $v14 = 2; + if($v13 == $v12) $v14 = 3; + + return MovingObjectPosition::fromBlock($x, $y, $z, $v14, $v13->add($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/StaticBlock.php b/src/material/StaticBlock.php index 7613b25c..669050ec 100644 --- a/src/material/StaticBlock.php +++ b/src/material/StaticBlock.php @@ -6,6 +6,7 @@ class StaticBlock { const DEFAULT_SLIPPERINESS = 0.6; const DEFAULT_HARDNESS = 0; + private static $NULL_BOUNDS; public static $isSolid = []; public static $isTransparent = []; @@ -19,6 +20,8 @@ class StaticBlock public static $hardness = []; public static $slipperiness = []; public static $boundingBoxes = []; + public static $minXs = [], $minYs = [], $minZs = [], $maxXs = [], $maxYs = [], $maxZs = []; + public static function init(){ self::$NULL_BOUNDS = new AxisAlignedBB(0, 0, 0, 0, 0, 0); foreach(Block::$class as $nonstaticname){ @@ -39,32 +42,35 @@ class StaticBlock FireBlock::setFlammabilityAndCatchingChance($b->getID(), 0, 0); + self::setBlockBounds($b->getID(), 0, 0, 0, 1, 1, 1); } - Block::$class[BED_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.5625, 1); + self::setBlockBounds(BED_BLOCK, 0, 0, 0, 1, 0.5625, 1); //Cake: has bounds based on world state //Chest: has bounds based on world state - Block::$class[WHEAT_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.25, 1); - Block::$class[CARROT_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.25, 1); - Block::$class[POTATO_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.25, 1); - Block::$class[BEETROOT_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.25, 1); //i assume it extends class Crops - Block::$class[WHEAT_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.25, 1); - Block::$class[DEAD_BUSH]::setBlockBounds(0.1, 0, 0.1, 0.9, 0.8, 0.9); - Block::$class[DOOR_BLOCK]::setBlockBounds(0, 0, 0, 1, 1, 1); //has bounds based on rotation - Block::$class[FARMLAND]::setBlockBounds(0, 0, 0, 1, 0.9375, 1); + self::setBlockBounds(WHEAT_BLOCK, 0, 0, 0, 1, 0.25, 1); + self::setBlockBounds(CARROT_BLOCK, 0, 0, 0, 1, 0.25, 1); + self::setBlockBounds(POTATO_BLOCK,0, 0, 0, 1, 0.25, 1); + self::setBlockBounds(BEETROOT_BLOCK, 0, 0, 0, 1, 0.25, 1); //i assume it extends class Crops + self::setBlockBounds(WHEAT_BLOCK, 0, 0, 0, 1, 0.25, 1); + self::setBlockBounds(DEAD_BUSH, 0.1, 0, 0.1, 0.9, 0.8, 0.9); + self::setBlockBounds(DOOR_BLOCK, 0, 0, 0, 1, 1, 1); //has bounds based on rotation + self::setBlockBounds(FARMLAND, 0, 0, 0, 1, 0.9375, 1); //Fence: bounds on state //Fence Gate: bounds on state - Block::$class[TALL_GRASS]::setBlockBounds(0.1, 0, 0.1, 0.9, 0.8, 0.9); - Block::$class[MELON_STEM]::setBlockBounds(0.5 - 0.125, 0, 0.5 - 0.125, 0.5 + 0.125, 0.25, 0.5 + 0.125); - Block::$class[PUMPKIN_STEM]::setBlockBounds(0.5 - 0.125, 0, 0.5 - 0.125, 0.5 + 0.125, 0.25, 0.5 + 0.125); - Block::$class[SAPLING]::setBlockBounds(0.1, 0, 0.1, 0.9, 0.8, 0.9); - Block::$class[BROWN_MUSHROOM]::setBlockBounds(0.3, 0, 0.3, 0.8, 0.4, 0.8); - Block::$class[SLAB]::setBlockBounds(0, 0, 0, 1, 0.5, 1); + self::setBlockBounds(TALL_GRASS, 0.1, 0, 0.1, 0.9, 0.8, 0.9); + self::setBlockBounds(MELON_STEM, 0.5 - 0.125, 0, 0.5 - 0.125, 0.5 + 0.125, 0.25, 0.5 + 0.125); + self::setBlockBounds(PUMPKIN_STEM, 0.5 - 0.125, 0, 0.5 - 0.125, 0.5 + 0.125, 0.25, 0.5 + 0.125); + self::setBlockBounds(SAPLING, 0.1, 0, 0.1, 0.9, 0.8, 0.9); + self::setBlockBounds(BROWN_MUSHROOM, 0.3, 0, 0.3, 0.8, 0.4, 0.8); + self::setBlockBounds(SLAB, 0, 0, 0, 1, 0.5, 1); //Ladder: based on rotation //Glass Pane: based on state - RailBaseBlock::setBlockBounds(0, 0, 0, 1, 0.125, 1); - Block::$class[SUGARCANE_BLOCK]::setBlockBounds(0.5 - 0.375, 0, 0.5 - 0.375, 0.5 + 0.375, 1, 0.5 + 0.375); - Block::$class[SNOW_LAYER]::setBlockBounds(0, 0, 0, 1, 0.125, 1); + self::setBlockBounds(RAIL, 0, 0, 0, 1, 0.125, 1); + self::setBlockBounds(POWERED_RAIL, 0, 0, 0, 1, 0.125, 1); + + self::setBlockBounds(SUGARCANE_BLOCK, 0.5 - 0.375, 0, 0.5 - 0.375, 0.5 + 0.375, 1, 0.5 + 0.375); + self::setBlockBounds(SNOW_LAYER, 0, 0, 0, 1, 0.125, 1); //Stairs: based on different factors //Stone wall: based on state @@ -92,6 +98,21 @@ class StaticBlock FireBlock::setFlammabilityAndCatchingChance(SPONGE, 30, 60); } + public static function setBlockBounds($blockID, $minX, $minY, $minZ, $maxX, $maxY, $maxZ){ + self::$maxXs[$blockID] = $maxX; + self::$maxYs[$blockID] = $maxY; + self::$maxZs[$blockID] = $maxZ; + + self::$minXs[$blockID] = $minX; + self::$minYs[$blockID] = $minY; + self::$minZs[$blockID] = $minZ; + } + + public static function getAABB(Level $level, $x, $y, $z){ + $id = $level->level->getBlockID($x, $y, $z); + return new AxisAlignedBB(self::$minXs[$id] + $x, self::$minYs[$id] + $y, self::$minZs[$id] + $z, self::$maxXs[$id] + $x, self::$maxYs[$id] + $y, self::$maxZs[$id] + $z); //TODO get bb from self::$boundingBoxes ? + } + public static function getBlock($id){ return Block::$class[$id] ?? Block::$class[0]; } diff --git a/src/math/Vector3.php b/src/math/Vector3.php index 9e8c9955..852ccf2e 100644 --- a/src/math/Vector3.php +++ b/src/math/Vector3.php @@ -197,7 +197,7 @@ class Vector3{ * * @return Vector3 */ - public function getIntermediateWithXValue(Vector3 $v, $x){ + public function clipX(Vector3 $v, $x){ $xDiff = $v->x - $this->x; $yDiff = $v->y - $this->y; $zDiff = $v->z - $this->z; @@ -214,6 +214,9 @@ class Vector3{ return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); } } + public function getIntermediateWithXValue(Vector3 $v, $y){ + return $this->clipZ($v, $y); + } /** * Returns a new vector with y value equal to the second parameter, along the line between this vector and the @@ -224,7 +227,7 @@ class Vector3{ * * @return Vector3 */ - public function getIntermediateWithYValue(Vector3 $v, $y){ + public function clipY(Vector3 $v, $y){ $xDiff = $v->x - $this->x; $yDiff = $v->y - $this->y; $zDiff = $v->z - $this->z; @@ -242,6 +245,9 @@ class Vector3{ } } + public function getIntermediateWithYValue(Vector3 $v, $y){ + return $this->clipY($v, $y); + } /** * Returns a new vector with z value equal to the second parameter, along the line between this vector and the * passed in vector, or null if not possible. @@ -251,7 +257,7 @@ class Vector3{ * * @return Vector3 */ - public function getIntermediateWithZValue(Vector3 $v, $z){ + public function clipZ(Vector3 $v, $z){ $xDiff = $v->x - $this->x; $yDiff = $v->y - $this->y; $zDiff = $v->z - $this->z; @@ -268,4 +274,8 @@ class Vector3{ return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); } } + + public function getIntermediateWithZValue(Vector3 $v, $y){ + return $this->clipZ($v, $y); + } } \ No newline at end of file diff --git a/src/world/Level.php b/src/world/Level.php index 168dff6c..33686a83 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -82,7 +82,7 @@ class Level{ return true; } - /* TODO neccessary for projectiles + // TODO neccessary for projectiles public function rayTraceBlocks(Vector3 $start, Vector3 $end){ $par3 = false; //TODO move to params? @@ -97,6 +97,8 @@ class Level{ [$startID, $startMeta] = $this->level->getBlock($xStart, $yStart, $zStart); $block = StaticBlock::getBlock($startID); + console("($xStart, $yStart, $zStart): $startID"); + console("start end: $start $end BEFORE"); //$block::updateShape($this, $xStart, $yStart, $zStart); //TODO better way to do it $aabb = $block::getAABB($this, $xStart, $yStart, $zStart); if($startID > 0 && $aabb != null){ //TODO also block::canColideCheck @@ -107,7 +109,6 @@ class Level{ for($i = 0; $i <= 200; ++$i){ if($xStart == $xEnd && $yStart == $yEnd && $zStart == $zEnd){ //also add checks for nan? - console("$start $end"); return null; } @@ -135,7 +136,6 @@ class Level{ if($v40) $v23 = ($v17 - $start->y) / $v29; if($v41) $v25 = ($v19 - $start->z) / $v31; - $v33 = false; if($v21 < $v23 && $v21 < $v25){ $v42 = $xEnd > $xStart ? 4 : 5; @@ -151,8 +151,8 @@ class Level{ }else{ $v42 = $zEnd > $zStart ? 2 : 3; - $start->x += $v27 * $v23; - $start->y += $v29 * $v21; + $start->x += $v27 * $v25; + $start->y += $v29 * $v25; $start->z = $v19; } @@ -167,18 +167,20 @@ class Level{ [$blockID, $blockMeta] = $this->level->getBlock($xStart, $yStart, $zStart); $block = StaticBlock::getBlock($blockID); - + console("$i($xStart, $yStart, $zStart): $blockID"); + console("start end: $start $end BEFORE"); + $aabb = $block::getAABB($this, $xStart, $yStart, $zStart); if($startID > 0 && $aabb != null){ //TODO also block::canColideCheck $v38 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end); if($v38 != null) return $v38; } + console("start end: $start $end AFTER"); } return null; } - */ - //TODO mayPlace + public function isLavaInBB($aabb){ $minX = floor($aabb->minX); $maxX = floor($aabb->maxX + 1); diff --git a/src/world/MovingObjectPosition.php b/src/world/MovingObjectPosition.php index 7b495b19..486d6d68 100644 --- a/src/world/MovingObjectPosition.php +++ b/src/world/MovingObjectPosition.php @@ -23,7 +23,11 @@ class MovingObjectPosition{ protected function __construct(){ } - + + public function __toString(){ + return "MovingObjectPosition: {blockXYZ: {$this->blockX} {$this->blockY} {$this->blockZ}, side: {$this->sideHit} hitVec: {$this->hitVector} entityHit: {$this->entityHit}}"; + } + /** * @param int $x * @param int $y @@ -39,6 +43,7 @@ class MovingObjectPosition{ $ob->blockX = $x; $ob->blockY = $y; $ob->blockZ = $z; + $ob->sideHit = $side; $ob->hitVector = new Vector3($hitVector->x, $hitVector->y, $hitVector->z); return $ob; }