mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
Block: rework addVelocityToEntity() to avoid vector3 mutation
This commit is contained in:
parent
ff00595a48
commit
f1048aeaa3
8
composer.lock
generated
8
composer.lock
generated
@ -552,12 +552,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pmmp/Math.git",
|
||||
"reference": "d46310a42ab5535296ded0b9368e5642af723f47"
|
||||
"reference": "a0118ce3026929e11cc05cdf776bb18cdcd1b822"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/pmmp/Math/zipball/d46310a42ab5535296ded0b9368e5642af723f47",
|
||||
"reference": "d46310a42ab5535296ded0b9368e5642af723f47",
|
||||
"url": "https://api.github.com/repos/pmmp/Math/zipball/a0118ce3026929e11cc05cdf776bb18cdcd1b822",
|
||||
"reference": "a0118ce3026929e11cc05cdf776bb18cdcd1b822",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -579,7 +579,7 @@
|
||||
"LGPL-3.0"
|
||||
],
|
||||
"description": "PHP library containing math related code used in PocketMine-MP",
|
||||
"time": "2020-06-19T10:25:24+00:00"
|
||||
"time": "2020-06-27T19:45:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "pocketmine/nbt",
|
||||
|
@ -338,8 +338,8 @@ class Block{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addVelocityToEntity(Entity $entity, Vector3 $vector) : void{
|
||||
|
||||
public function addVelocityToEntity(Entity $entity) : ?Vector3{
|
||||
return null;
|
||||
}
|
||||
|
||||
final public function getPos() : Position{
|
||||
|
@ -234,13 +234,11 @@ abstract class Liquid extends Transparent{
|
||||
return $this->flowVector = $vector->normalize();
|
||||
}
|
||||
|
||||
public function addVelocityToEntity(Entity $entity, Vector3 $vector) : void{
|
||||
public function addVelocityToEntity(Entity $entity) : ?Vector3{
|
||||
if($entity->canBeMovedByCurrents()){
|
||||
$flow = $this->getFlowVector();
|
||||
$vector->x += $flow->x;
|
||||
$vector->y += $flow->y;
|
||||
$vector->z += $flow->z;
|
||||
return $this->getFlowVector();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
abstract public function tickRate() : int;
|
||||
|
@ -1262,13 +1262,16 @@ abstract class Entity{
|
||||
}
|
||||
|
||||
protected function checkBlockCollision() : void{
|
||||
$vector = new Vector3(0, 0, 0);
|
||||
$vectors = [];
|
||||
|
||||
foreach($this->getBlocksAround() as $block){
|
||||
$block->onEntityInside($this);
|
||||
$block->addVelocityToEntity($this, $vector);
|
||||
if(($v = $block->addVelocityToEntity($this)) !== null){
|
||||
$vectors[] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$vector = Vector3::sum(...$vectors);
|
||||
if($vector->lengthSquared() > 0){
|
||||
$d = 0.014;
|
||||
$this->motion = $this->motion->addVector($vector->normalize()->multiply($d));
|
||||
|
Loading…
x
Reference in New Issue
Block a user