Forgot to check chunks after moving

This commit is contained in:
Shoghi Cervantes 2015-05-28 22:55:09 +02:00
parent 75cab3dfc3
commit 0f5f71e612
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
3 changed files with 34 additions and 38 deletions

View File

@ -877,7 +877,7 @@ abstract class Entity extends Location implements Metadatable{
$x = -$xz * sin(deg2rad($this->yaw)); $x = -$xz * sin(deg2rad($this->yaw));
$z = $xz * cos(deg2rad($this->yaw)); $z = $xz * cos(deg2rad($this->yaw));
return (new Vector3($x, $y, $z))->normalize(); return $this->temporalVector->setComponents($x, $y, $z)->normalize();
} }
public function getDirectionPlane(){ public function getDirectionPlane(){
@ -1048,7 +1048,7 @@ abstract class Entity extends Location implements Metadatable{
} }
public function isInsideOfWater(){ public function isInsideOfWater(){
$block = $this->level->getBlock(new Vector3(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z))); $block = $this->level->getBlock($this->temporalVector->setComponents(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
if($block instanceof Water){ if($block instanceof Water){
$f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); $f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
@ -1059,7 +1059,7 @@ abstract class Entity extends Location implements Metadatable{
} }
public function isInsideOfSolid(){ public function isInsideOfSolid(){
$block = $this->level->getBlock(new Vector3(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z))); $block = $this->level->getBlock($this->temporalVector->setComponents(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
$bb = $block->getBoundingBox(); $bb = $block->getBoundingBox();
@ -1086,34 +1086,28 @@ abstract class Entity extends Location implements Metadatable{
$this->boundingBox = $newBB; $this->boundingBox = $newBB;
} }
$pos = new Vector3( $this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2;
($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->y = $this->boundingBox->minY - $this->ySize;
$this->boundingBox->minY, $this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2;
($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2
);
$result = true; $this->checkChunks();
if(!$this->setPosition($pos)){ if(!$this->onGround or $dy != 0){
$this->boundingBox->setBB($axisalignedbb); $bb = clone $this->boundingBox;
$result = false; $bb->minY -= 0.75;
}else{ $this->onGround = false;
if(!$this->onGround or $dy != 0){
$bb = clone $this->boundingBox;
$bb->minY -= 0.75;
$this->onGround = false;
if(count($this->level->getCollisionBlocks($bb)) > 0){ if(count($this->level->getCollisionBlocks($bb)) > 0){
$this->onGround = true; $this->onGround = true;
}
} }
$this->isCollided = $this->onGround;
$this->updateFallState($dy, $this->onGround);
} }
$this->isCollided = $this->onGround;
$this->updateFallState($dy, $this->onGround);
Timings::$entityMoveTimer->stopTiming(); Timings::$entityMoveTimer->stopTiming();
return $result; return true;
} }
public function move($dx, $dy, $dz){ public function move($dx, $dy, $dz){
@ -1124,7 +1118,7 @@ abstract class Entity extends Location implements Metadatable{
if($this->keepMovement){ if($this->keepMovement){
$this->boundingBox->offset($dx, $dy, $dz); $this->boundingBox->offset($dx, $dy, $dz);
$this->setPosition(new Vector3(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2)); $this->setPosition($this->temporalVector->setComponents(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2));
$this->onGround = $this instanceof Player ? true : false; $this->onGround = $this instanceof Player ? true : false;
return true; return true;
}else{ }else{
@ -1247,6 +1241,8 @@ abstract class Entity extends Location implements Metadatable{
$this->y = $this->boundingBox->minY - $this->ySize; $this->y = $this->boundingBox->minY - $this->ySize;
$this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2; $this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2;
$this->checkChunks();
if($this instanceof Player){ if($this instanceof Player){
if(!$this->onGround or $movY != 0){ if(!$this->onGround or $movY != 0){
$bb = clone $this->boundingBox; $bb = clone $this->boundingBox;
@ -1295,7 +1291,7 @@ abstract class Entity extends Location implements Metadatable{
$maxY = Math::ceilFloat($this->boundingBox->maxY - 0.001); $maxY = Math::ceilFloat($this->boundingBox->maxY - 0.001);
$maxZ = Math::ceilFloat($this->boundingBox->maxZ - 0.001); $maxZ = Math::ceilFloat($this->boundingBox->maxZ - 0.001);
$vector = new Vector3(0, 0, 0); $vector = $this->temporalVector;
$v = new Vector3(0, 0, 0); $v = new Vector3(0, 0, 0);
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){ for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){
@ -1443,8 +1439,8 @@ abstract class Entity extends Location implements Metadatable{
$this->ySize = 0; $this->ySize = 0;
$pos = $ev->getTo(); $pos = $ev->getTo();
$this->setMotion(new Vector3(0, 0, 0)); $this->setMotion($this->temporalVector->setComponents(0, 0, 0));
if($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch, true) !== false){ if($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch) !== false){
$this->resetFallDistance(); $this->resetFallDistance();
$this->onGround = true; $this->onGround = true;

View File

@ -1405,7 +1405,7 @@ class Level implements ChunkManager, Metadatable{
$item = Item::get(Item::AIR, 0, 0); $item = Item::get(Item::AIR, 0, 0);
} }
if($player instanceof Player){ if($player !== null){
$ev = new BlockBreakEvent($player, $target, $item, ($player->getGamemode() & 0x01) === 1 ? true : false); $ev = new BlockBreakEvent($player, $target, $item, ($player->getGamemode() & 0x01) === 1 ? true : false);
if($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)){ if($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)){
@ -1434,15 +1434,15 @@ class Level implements ChunkManager, Metadatable{
} }
$player->lastBreak = PHP_INT_MAX; $player->lastBreak = PHP_INT_MAX;
}elseif($item instanceof Item and !$target->isBreakable($item)){ }elseif($item !== null and !$target->isBreakable($item)){
return false; return false;
} }
$level = $target->getLevel(); $level = $target->getLevel();
if($level instanceof Level){ if($level !== null){
$above = $level->getBlock(new Vector3($target->x, $target->y + 1, $target->z)); $above = $level->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
if($above instanceof Block){ if($above !== null){
if($above->getId() === Item::FIRE){ if($above->getId() === Item::FIRE){
$level->setBlock($above, new Air(), true); $level->setBlock($above, new Air(), true);
} }
@ -1466,7 +1466,7 @@ class Level implements ChunkManager, Metadatable{
$target->onBreak($item); $target->onBreak($item);
$tile = $this->getTile($target); $tile = $this->getTile($target);
if($tile instanceof Tile){ if($tile !== null){
if($tile instanceof InventoryHolder){ if($tile instanceof InventoryHolder){
if($tile instanceof Chest){ if($tile instanceof Chest){
$tile->unpair(); $tile->unpair();
@ -1480,14 +1480,14 @@ class Level implements ChunkManager, Metadatable{
$tile->close(); $tile->close();
} }
if($item instanceof Item){ if($item !== null){
$item->useOn($target); $item->useOn($target);
if($item->isTool() and $item->getDamage() >= $item->getMaxDurability()){ if($item->isTool() and $item->getDamage() >= $item->getMaxDurability()){
$item = Item::get(Item::AIR, 0, 0); $item = Item::get(Item::AIR, 0, 0);
} }
} }
if(!($player instanceof Player) or $player->isSurvival()){ if($player === null or $player->isSurvival()){
foreach($drops as $drop){ foreach($drops as $drop){
if($drop[2] > 0){ if($drop[2] > 0){
$this->dropItem($vector->add(0.5, 0.5, 0.5), Item::get(...$drop)); $this->dropItem($vector->add(0.5, 0.5, 0.5), Item::get(...$drop));
@ -1523,7 +1523,7 @@ class Level implements ChunkManager, Metadatable{
return false; return false;
} }
if($player instanceof Player){ if($player !== null){
$ev = new PlayerInteractEvent($player, $item, $target, $face, $target->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK); $ev = new PlayerInteractEvent($player, $item, $target, $face, $target->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK);
if(!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1){ if(!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1){
$t = new Vector2($target->x, $target->z); $t = new Vector2($target->x, $target->z);
@ -1590,7 +1590,7 @@ class Level implements ChunkManager, Metadatable{
} }
if($player instanceof Player){ if($player !== null){
$ev = new BlockPlaceEvent($player, $hand, $block, $target, $item); $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item);
if(!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1){ if(!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1){
$t = new Vector2($target->x, $target->z); $t = new Vector2($target->x, $target->z);
@ -1620,7 +1620,7 @@ class Level implements ChunkManager, Metadatable{
"Text3" => new String("Text3", ""), "Text3" => new String("Text3", ""),
"Text4" => new String("Text4", "") "Text4" => new String("Text4", "")
])); ]));
if($player instanceof Player){ if($player !== null){
$tile->namedtag->Creator = new String("Creator", $player->getUniqueId()); $tile->namedtag->Creator = new String("Creator", $player->getUniqueId());
} }
} }

View File

@ -207,7 +207,7 @@ class Vector3{
*/ */
public function normalize(){ public function normalize(){
$len = $this->lengthSquared(); $len = $this->lengthSquared();
if($len != 0){ if($len > 0){
return $this->divide(sqrt($len)); return $this->divide(sqrt($len));
} }