mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 12:39:43 +00:00
Entity Gravity
This commit is contained in:
parent
fe3be181e8
commit
db9625b52f
2 changed files with 41 additions and 11 deletions
|
|
@ -502,7 +502,7 @@ class Player{
|
||||||
case MC_REQUEST_CHUNK:
|
case MC_REQUEST_CHUNK:
|
||||||
$x = $data["x"] * 16;
|
$x = $data["x"] * 16;
|
||||||
$z = $data["z"] * 16;
|
$z = $data["z"] * 16;
|
||||||
$this->actionQueue('
|
/*
|
||||||
$max = max(1, floor(($this->MTU - 16 - 255) / 192));
|
$max = max(1, floor(($this->MTU - 16 - 255) / 192));
|
||||||
$chunk = $this->server->api->level->getOrderedChunk('.$data["x"].', '.$data["z"].', $max);
|
$chunk = $this->server->api->level->getOrderedChunk('.$data["x"].', '.$data["z"].', $max);
|
||||||
foreach($chunk as $d){
|
foreach($chunk as $d){
|
||||||
|
|
@ -518,7 +518,8 @@ class Player{
|
||||||
$this->server->api->tileentity->spawnTo($tile["ID"], "'.$this->username.'", true);
|
$this->server->api->tileentity->spawnTo($tile["ID"], "'.$this->username.'", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
');
|
*/
|
||||||
|
$this->actionQueue('$max = max(1, floor(($this->MTU - 16 - 255) / 192));$chunk = $this->server->api->level->getOrderedChunk('.$data["x"].', '.$data["z"].', $max);foreach($chunk as $d){$this->dataPacket(MC_CHUNK_DATA, array("x" => '.$data["x"].',"z" => '.$data["z"].',"data" => $d,), true);}$tiles = $this->server->query("SELECT * FROM tileentities WHERE spawnable = 1 AND x >= '.$x.' AND x < '.($x + 16).' AND z >= '.$z.' AND z < '.($z + 16).';");if($tiles !== false and $tiles !== true){while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){$this->server->api->tileentity->spawnTo($tile["ID"], "'.$this->username.'", true);}}');
|
||||||
console("[INTERNAL] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 3);
|
console("[INTERNAL] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 3);
|
||||||
break;
|
break;
|
||||||
case MC_USE_ITEM:
|
case MC_USE_ITEM:
|
||||||
|
|
|
||||||
|
|
@ -98,9 +98,9 @@ class Entity extends stdClass{
|
||||||
$this->x = isset($this->data["x"]) ? $this->data["x"]:0;
|
$this->x = isset($this->data["x"]) ? $this->data["x"]:0;
|
||||||
$this->y = isset($this->data["y"]) ? $this->data["y"]:0;
|
$this->y = isset($this->data["y"]) ? $this->data["y"]:0;
|
||||||
$this->z = isset($this->data["z"]) ? $this->data["z"]:0;
|
$this->z = isset($this->data["z"]) ? $this->data["z"]:0;
|
||||||
$this->speedX = isset($this->data["speedX"]) ? $this->data["speedX"]:0;
|
$this->speedX = /*isset($this->data["speedX"]) ? $this->data["speedX"]:*/0;
|
||||||
$this->speedY = isset($this->data["speedY"]) ? $this->data["speedY"]:0;
|
$this->speedY = /*isset($this->data["speedY"]) ? $this->data["speedY"]:*/0;
|
||||||
$this->speedZ = isset($this->data["speedZ"]) ? $this->data["speedZ"]:0;
|
$this->speedZ = /*isset($this->data["speedZ"]) ? $this->data["speedZ"]:*/0;
|
||||||
$this->speed = 0;
|
$this->speed = 0;
|
||||||
$this->yaw = isset($this->data["yaw"]) ? $this->data["yaw"]:0;
|
$this->yaw = isset($this->data["yaw"]) ? $this->data["yaw"]:0;
|
||||||
$this->pitch = isset($this->data["pitch"]) ? $this->data["pitch"]:0;
|
$this->pitch = isset($this->data["pitch"]) ? $this->data["pitch"]:0;
|
||||||
|
|
@ -230,9 +230,35 @@ class Entity extends stdClass{
|
||||||
if($this->closed === true){
|
if($this->closed === true){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($this->last[0] !== $this->x or $this->last[1] !== $this->y or $this->last[2] !== $this->z){
|
if($this->class === ENTITY_ITEM or $this->class === ENTITY_MOB){
|
||||||
|
$x = (int) round($this->x - 0.5);
|
||||||
|
$y = (int) round($this->y - 1);
|
||||||
|
$z = (int) round($this->z - 0.5);
|
||||||
|
if($this->speedX != 0){
|
||||||
|
$this->x += $this->speedX;
|
||||||
|
}
|
||||||
|
if($this->speedY != 0){
|
||||||
|
$this->y += $this->speedY;
|
||||||
|
}
|
||||||
|
if($this->speedZ != 0){
|
||||||
|
$this->z += $this->speedZ;
|
||||||
|
}
|
||||||
|
$b = $this->server->api->level->getBlock($x, $y, $z);
|
||||||
|
if(isset(Material::$transparent[$b[0]])){
|
||||||
|
$this->speedY -= 0.32;
|
||||||
|
}elseif($this->speedY < 0){
|
||||||
|
var_dump($this->speedY);
|
||||||
|
$this->y = $y + 1.19;
|
||||||
|
$this->speedY = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z){
|
||||||
$this->server->api->dhandle("entity.move", $this);
|
$this->server->api->dhandle("entity.move", $this);
|
||||||
$this->calculateVelocity();
|
if($this->class === ENTITY_PLAYER){
|
||||||
|
$this->calculateVelocity();
|
||||||
|
}
|
||||||
|
$this->updateLast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -406,20 +432,23 @@ class Entity extends stdClass{
|
||||||
|
|
||||||
public function calculateVelocity(){
|
public function calculateVelocity(){
|
||||||
$diffTime = microtime(true) - $this->last[3];
|
$diffTime = microtime(true) - $this->last[3];
|
||||||
$this->last[3] = microtime(true);
|
|
||||||
$origin = new Vector3($this->last[0], $this->last[1], $this->last[2]);
|
$origin = new Vector3($this->last[0], $this->last[1], $this->last[2]);
|
||||||
$final = new Vector3($this->x, $this->y, $this->z);
|
$final = new Vector3($this->x, $this->y, $this->z);
|
||||||
$speedX = abs($this->x - $this->last[0]) / $diffTime;
|
$speedX = abs($this->x - $this->last[0]) / $diffTime;
|
||||||
$this->last[0] = $this->x;
|
|
||||||
$speedY = ($this->y - $this->last[1]) / $diffTime;
|
$speedY = ($this->y - $this->last[1]) / $diffTime;
|
||||||
$this->last[1] = $this->y;
|
|
||||||
$speedZ = abs($this->z - $this->last[2]) / $diffTime;
|
$speedZ = abs($this->z - $this->last[2]) / $diffTime;
|
||||||
$this->last[2] = $this->z;
|
|
||||||
$this->speedX = $speedX;
|
$this->speedX = $speedX;
|
||||||
$this->speedY = $speedY;
|
$this->speedY = $speedY;
|
||||||
$this->speedZ = $speedZ;
|
$this->speedZ = $speedZ;
|
||||||
$this->speed = $origin->distance($final) / $diffTime;
|
$this->speed = $origin->distance($final) / $diffTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateLast(){
|
||||||
|
$this->last[3] = microtime(true);
|
||||||
|
$this->last[0] = $this->x;
|
||||||
|
$this->last[1] = $this->y;
|
||||||
|
$this->last[2] = $this->z;
|
||||||
|
}
|
||||||
|
|
||||||
public function getPosition($round = false){
|
public function getPosition($round = false){
|
||||||
return !isset($this->position) ? false:($round === true ? array_map("floor", $this->position):$this->position);
|
return !isset($this->position) ? false:($round === true ? array_map("floor", $this->position):$this->position);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue