StaticBlock class, entities performance boost(i think)

This commit is contained in:
GameHerobrine 2023-07-07 22:49:57 +03:00
parent 5d79c23c6a
commit 9cb7fbafaa
11 changed files with 232 additions and 58 deletions

View file

@ -413,7 +413,7 @@ class Entity extends Position
$blockY = (int) ($this->y + $this->getEyeHeight() + $y);
$blockZ = (int) ($this->z + $z);
if(!$this->level->getBlockWithoutVector($blockX, $blockY, $blockZ)->isTransparent){
if(!StaticBlock::getIsTransparent($this->level->level->getBlockID($blockX, $blockY, $blockZ))){
$this->harm(1, "suffocation"); // Suffocation
$hasUpdate = true;
break;
@ -424,8 +424,10 @@ class Entity extends Position
for ($x = $startX; $x <= $endX; ++$x){
for ($z = $startZ; $z <= $endZ; ++$z){
$pos = new Vector3($x, $y, $z);
$b = $this->level->getBlock($pos);
switch ($b->getID()) {
$b = $this->level->level->getBlock($x, $y, $z);
$id = $b[0];
$meta = $b[1];
switch ($id) {
case WATER:
case STILL_WATER: // Drowing
if ($this->fire > 0 and $this->inBlock($pos)) {
@ -436,7 +438,7 @@ class Entity extends Position
$this->harm(2, "water");
$hasUpdate = true;
$waterDone = true;
} elseif ($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1 - (($b->getMetadata() % 8) / 9)) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER) and !$waterDone) {
} elseif ($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1 - (($meta % 8) / 9)) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER) and !$waterDone) {
$this->air -= 1;
$waterDone = true;
$this->updateMetadata();
@ -520,7 +522,7 @@ class Entity extends Position
}
++$this->counter;
if($this->isStatic === false){
$startX = floor($this->x - 0.5 - $this->width - 1);
/*$startX = floor($this->x - 0.5 - $this->width - 1);
// prefix for flying when player on fence
$y = floor($this->y - 1);
$yC = ceil($this->y - 1);
@ -536,12 +538,12 @@ class Entity extends Position
$v = new Vector3($x, $y, $z);
$v1 = new Vector3($x, $yC, $z);
if($this->isSupport($v, $this->width)){
$b = $this->level->getBlock($v);
if($b->isSolid === true){
$b = $this->level->level->getBlockID($x, $y, $z);
if(StaticBlock::getIsSolid($b) === true){
$support = true;
$isFlying = false;
break;
} elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){
} elseif(StaticBlock::getIsLiquid($b) or $b === COBWEB or $b === LADDER or $b === FENCE or $b=== STONE_WALL or $b === IRON_BARS){
$isFlying = false;
}
} elseif($this->isSupport($v1, $this->width)){
@ -559,7 +561,7 @@ class Entity extends Position
break;
}
}
}
}*/ //this one is not neccessary anymore?
if(!$this->isPlayer()){
$update = false;
if(Utils::in_range($this->speedX, -0.01, 0.01)){
@ -594,16 +596,16 @@ class Entity extends Position
for($x = $x0; $x < $x1; ++$x){
for($y = $y0; $y < $y1; ++$y){
for($z = $z0; $z < $z1; ++$z){
$pos = new Vector3($x, $y, $z);
$b = $this->level->getBlock($pos);
if(($b->getID() === WATER || $b->getID() === STILL_WATER)){
$water = $b->y == ($y1 - 1);
$b = $this->level->level->getBlockID($x, $y, $z);
if(($b === WATER || $b === STILL_WATER)){
$water = $y == ($y1 - 1);
$this->fallDistance = 0;
}
if($b != false && $b->isSolid){
$this->speedY = $b->boundingBox->calculateYOffset($this->boundingBox, $this->speedY);
$this->speedX = $b->boundingBox->calculateXOffset($this->boundingBox, $this->speedX);
$this->speedZ = $b->boundingBox->calculateZOffset($this->boundingBox, $this->speedZ);
if(StaticBlock::getIsSolid($b)){
$blockBounds = StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z);
$this->speedY = $blockBounds->calculateYOffset($this->boundingBox, $this->speedY);
$this->speedX = $blockBounds->calculateXOffset($this->boundingBox, $this->speedX);
$this->speedZ = $blockBounds->calculateZOffset($this->boundingBox, $this->speedZ);
}
}
}
@ -615,9 +617,9 @@ class Entity extends Position
$horizontalMultiplyFactor = 0.91;
if($support){
$horizontalMultiplyFactor = 0.54;
$b = $this->level->getBlockWithoutVector(floor($this->x), floor($this->boundingBox->minX) - 1, floor($this->z));
if($b instanceof Block){
$horizontalMultiplyFactor = $b->slipperiness * 0.91;
$b = $this->level->level->getBlockID(floor($this->x), floor($this->boundingBox->minX) - 1, floor($this->z));
if($b > 0){
$horizontalMultiplyFactor = StaticBlock::getSlipperiness($b) * 0.91;
}
}
if($this->inWater){
@ -644,7 +646,7 @@ class Entity extends Position
$z = (int) ($this->z - 0.5);
$lim = (int) floor($ny);
for($y = (int) ceil($this->y) - 1; $y >= $lim; -- $y){
if($this->level->getBlockWithoutVector($x, $y, $z)->isSolid === true){
if(StaticBlock::getIsSolid($this->level->level->getBlockID($x, $y, $z))){
//$support = true;
$this->y = $ny;
$fall = $this->level->getBlock(new Vector3(intval($this->x - 0.5), intval(ceil($this->y)), intval($this->z - 0.5)));
@ -697,8 +699,7 @@ class Entity extends Position
for($z = floor($this->boundingBox->minZ); $z < ceil($this->boundingBox->maxZ); ++$z){
for($y = floor($this->boundingBox->minY - 1); $y < ceil($this->boundingBox->maxY); ++$y){
if($y <= floor($this->boundingBox->minY) && !$this->onGround){
$id = $this->level->getBlockWithoutVector($x, $y, $z);
$this->onGround = $id->isSolid;
$this->onGround = StaticBlock::getIsSolid($this->level->level->getBlockID($x, $y, $z));
}else{
$block = $this->level->level->getBlock($x, $y, $z);
$id = $block[0];

View file

@ -29,7 +29,6 @@ class EntityAI
* @param TaskBase $task
*/
public function addTask(TaskBase $task){
console("[DEBUG] Adding new task...",true, true, 2);
$this->tasks[$task->__toString()] = $task;
}
public function removeTask($name){

View file

@ -35,20 +35,20 @@ class MobController
$xf = $this->entity->x + ($this->entity->getSpeedModifer() * $ox * $this->entity->getSpeed());
$zf = $this->entity->z + ($this->entity->getSpeedModifer() * $oz * $this->entity->getSpeed());
if($this->entity->onGround){
$bs = [ //TODO simplify(somehow)
$this->entity->level->getBlockWithoutVector(ceil($xf), floor($this->entity->y), ceil($zf)),
$this->entity->level->getBlockWithoutVector(ceil($xf), floor($this->entity->y), $zf - ($oz < 0 ? 1 : 0)),
$this->entity->level->getBlockWithoutVector($xf - ($ox < 0 ? 1 : 0), floor($this->entity->y), $zf - ($oz < 0 ? 1 : 0)),
$this->entity->level->getBlockWithoutVector($xf - ($ox < 0 ? 1 : 0), floor($this->entity->y), ceil($zf)),
];
foreach($bs as $b){
if($b->isSolid){
if(!$b->getSide(1)->isSolid){
$oy = 1;
break;
}
}
}
$oy =
StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), floor($this->entity->y), ceil($zf))) &&
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), floor($this->entity->y) + 1, ceil($zf)))
||
StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), floor($this->entity->y), $zf - ($oz < 0))) &&
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), floor($this->entity->y) + 1, $zf - ($oz < 0)))
||
StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), floor($this->entity->y), $zf - ($oz < 0))) &&
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), floor($this->entity->y) + 1, $zf - ($oz < 0)))
||
StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), floor($this->entity->y), ceil($zf))) &&
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), floor($this->entity->y) + 1, ceil($zf)))
;
}
$this->faceEntity($this->entity->add($ox, $oy, $oz));
if($this->entity->knockbackTime <= 0){

View file

@ -7,7 +7,7 @@ class Skeleton extends Monster{
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
$this->setName("Skeleton");
$this->ai->removeTask("TaskAttackPlayer");
$this->ai->addTask(new TaskDestroyServerPerformance());
//$this->ai->addTask(new TaskDestroyServerPerformance());
$this->setSpeed(0.25);
$this->update();
}
@ -22,12 +22,12 @@ class Skeleton extends Monster{
}
for($y = $this->y; $y < 129; $y++){
$block = $this->level->getBlockWithoutVector($this->x, $y, $this->z);
if($block->isSolid){
$block = $this->level->level->getBlockID($this->x, $y, $this->z);
if(StaticBlock::getIsSolid($block)){
return false;
}
}
if($block->getID() === AIR){
if($block === AIR){
$this->fire = 160; //Value from 0.8.1
$this->updateMetadata();
return true;

View file

@ -20,12 +20,12 @@ class Zombie extends Monster{
}
for($y = $this->y; $y < 129; $y++){
$block = $this->level->getBlockWithoutVector($this->x, $y, $this->z);
if($block->isSolid){
$block = $this->level->level->getBlockID($this->x, $y, $this->z);
if(StaticBlock::getIsSolid($block)){
return false;
}
}
if($block->getID() === AIR){
if($block === AIR){
$this->fire = 160; //Value from 0.8.1
$this->updateMetadata();
return true;

View file

@ -67,6 +67,8 @@ class Arrow extends Projectile{
}
}
public function update(){
$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);
@ -83,11 +85,10 @@ class Arrow extends Projectile{
$this->yaw = (atan2($this->speedX, $this->speedZ) * 180 / M_PI);
$this->pitch = (atan2($this->speedY, $f) * 180 / M_PI);
}
$rt = $this->boundingBox->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 = floor($rt->minY); $y <= ceil($rt->maxY); ++$y){
$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){
$pos = new Vector3($x, $y, $z);
$b = $this->level->getBlock($pos);
if($b != false && $b->isSolid){
@ -95,11 +96,11 @@ class Arrow extends Projectile{
$this->speedX = $b->boundingBox->calculateXOffset($this->boundingBox, $this->speedX);
$this->speedZ = $b->boundingBox->calculateZOffset($this->boundingBox, $this->speedZ);
$this->inWall = true;
break;
}
}
}
}
if(!$this->inWall){
$bbexp = $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ)->expand(0, 0.2, 0);
foreach($this->level->entityList as $e){
@ -129,7 +130,6 @@ class Arrow extends Projectile{
$this->sendMotion();
$this->updatePosition();
$bb = $this->boundingBox->grow(0.1, 0.1, 0.1);
}