mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 12:39:43 +00:00
better collisions between entities
This commit is contained in:
parent
869b8b111a
commit
fc334e7c99
4 changed files with 14 additions and 14 deletions
|
|
@ -1216,7 +1216,7 @@ class Player{
|
||||||
$moveSent = false;
|
$moveSent = false;
|
||||||
$headSent = 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->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)){
|
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 = new SetEntityMotionPacket();
|
||||||
$motion->eid = $e->eid;
|
$motion->eid = $e->eid;
|
||||||
$motion->speedX = $e->speedX;
|
$motion->speedX = $e->speedX;
|
||||||
|
|
|
||||||
|
|
@ -622,6 +622,7 @@ class PocketMinecraftServer{
|
||||||
try{
|
try{
|
||||||
$return = @call_user_func($this->schedule[$cid][0] ?? function(){}, $this->schedule[$cid][1], $this->schedule[$cid][2]); //somehow args can be null
|
$return = @call_user_func($this->schedule[$cid][0] ?? function(){}, $this->schedule[$cid][1], $this->schedule[$cid][2]); //somehow args can be null
|
||||||
}catch(TypeError $e){
|
}catch(TypeError $e){
|
||||||
|
ConsoleAPI::error($e->getTraceAsString());
|
||||||
$return = false;
|
$return = false;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,11 @@ abstract class Living extends Entity implements Pathfindable{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public function collideHandler(){
|
public function collideHandler(){
|
||||||
$rd = ceil($this->radius);
|
$bb = $this->boundingBox->expand(0.2, 0, 0.2);
|
||||||
$minChunkX = ((int)($this->x - $rd)) >> 4;
|
$minChunkX = ((int)($bb->minX)) >> 4;
|
||||||
$minChunkZ = ((int)($this->z - $rd)) >> 4;
|
$minChunkZ = ((int)($bb->minZ)) >> 4;
|
||||||
$maxChunkX = ((int)($this->x + $rd)) >> 4;
|
$maxChunkX = ((int)($bb->minX)) >> 4;
|
||||||
$maxChunkZ = ((int)($this->z + $rd)) >> 4;
|
$maxChunkZ = ((int)($bb->minZ)) >> 4;
|
||||||
|
|
||||||
//TODO also index by chunkY?
|
//TODO also index by chunkY?
|
||||||
for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){
|
for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){
|
||||||
|
|
@ -75,7 +75,9 @@ abstract class Living extends Entity implements Pathfindable{
|
||||||
$ind = "$chunkX $chunkZ";
|
$ind = "$chunkX $chunkZ";
|
||||||
foreach($this->level->entityListPositioned[$ind] ?? [] as $entid){
|
foreach($this->level->entityListPositioned[$ind] ?? [] as $entid){
|
||||||
if($this->level->entityList[$entid] instanceof Entity){
|
if($this->level->entityList[$entid] instanceof Entity){
|
||||||
$this->applyCollision($this->level->entityList[$entid]);
|
if($bb->intersectsWith($this->level->entityList[$entid]->boundingBox)){
|
||||||
|
$this->applyCollision($this->level->entityList[$entid]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -83,7 +85,7 @@ abstract class Living extends Entity implements Pathfindable{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyCollision(Entity $collided){
|
public function applyCollision(Entity $collided){
|
||||||
if($collided->boundingBox->intersectsWith($this->boundingBox) && !($this->isPlayer() && $collided->isPlayer()) && $this->eid != $collided->eid){
|
if(!($this->isPlayer() && $collided->isPlayer()) && $this->eid != $collided->eid){
|
||||||
$diffX = $collided->x - $this->x;
|
$diffX = $collided->x - $this->x;
|
||||||
$diffZ = $collided->z - $this->z;
|
$diffZ = $collided->z - $this->z;
|
||||||
$maxDiff = max(abs($diffX), abs($diffZ));
|
$maxDiff = max(abs($diffX), abs($diffZ));
|
||||||
|
|
@ -154,15 +156,12 @@ abstract class Living extends Entity implements Pathfindable{
|
||||||
$this->landMovementFactor *= $this->getSpeedModifer();
|
$this->landMovementFactor *= $this->getSpeedModifer();
|
||||||
$this->moveEntityWithHeading($this->moveStrafing, $this->moveForward);
|
$this->moveEntityWithHeading($this->moveStrafing, $this->moveForward);
|
||||||
$this->landMovementFactor = $savedLandFactor;
|
$this->landMovementFactor = $savedLandFactor;
|
||||||
|
//Yaw rotation in 1.5 is handled in a bit different place but hopefully this will work too
|
||||||
|
$this->ai->mobController->updateHeadYaw();
|
||||||
|
|
||||||
if(self::$entityPushing){
|
if(self::$entityPushing){
|
||||||
$this->collideHandler();
|
$this->collideHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Yaw rotation in 1.5 is handled in a bit different place but hopefully this will work too
|
|
||||||
$this->ai->mobController->updateHeadYaw();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jump(){
|
public function jump(){
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class Zombie extends Monster{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateBurning(){
|
public function updateBurning(){
|
||||||
if($this->fire > 0 or !$this->level->isDay() || $this->inWater){ //TODO fix burning in water
|
if($this->fire > 0 || !$this->level->isDay() || $this->inWater){ //TODO fix burning in water
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue