tnt will not regenerate you now + will add knockback to players

This commit is contained in:
GameHerobrine 2024-03-26 06:26:32 +03:00
parent a10c6a1d57
commit 2678243d8b
4 changed files with 50 additions and 32 deletions

View file

@ -13,7 +13,6 @@ class PrimedTNT extends Entity{
$this->setSize(0.98, 0.98); $this->setSize(0.98, 0.98);
$this->yOffset = $this->height / 2; $this->yOffset = $this->height / 2;
$this->setHealth(10000000, "generic"); $this->setHealth(10000000, "generic");
//$this->server->schedule(5, [$this, "updateFuse"], [], true);
} }
public function isPickable(){ public function isPickable(){
@ -66,20 +65,6 @@ class PrimedTNT extends Entity{
$this->lastUpdate = $now; $this->lastUpdate = $now;
} }
/*public function updateFuse(){
if($this->closed === true){
return false;
}
if($this->type === OBJECT_PRIMEDTNT){
$this->updateMetadata();
if(((microtime(true) - $this->spawntime) * 20) >= $this->data["fuse"]){
$this->close();
$explosion = new Explosion($this, $this->data["power"]);
$explosion->explode();
}
}
}*/
public function spawn($player){ public function spawn($player){
$pk = new AddEntityPacket; $pk = new AddEntityPacket;
$pk->eid = $this->eid; $pk->eid = $this->eid;

View file

@ -60,10 +60,32 @@ class Explosion{
$radius = 2 * $this->size; $radius = 2 * $this->size;
$server = ServerAPI::request(); $server = ServerAPI::request();
if(!Explosion::$enableExplosions){ /*Disable Explosions*/ if(!Explosion::$enableExplosions){ /*Disable Explosions*/
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){ foreach($server->api->entity->getRadius($this->source, $radius+1) as $entity){
$impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //pla> $distance = $this->source->distance($entity);
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1); $distByRad = $distance / $this->size;
$entity->harm($damage, "explosion"); if($distByRad <= 1 && $distance != 0){
$diffX = ($entity->x - $this->source->x) / $distance;
$diffY = ($entity->y + $entity->getEyeHeight() - $this->source->y) / $distance;
$diffZ = ($entity->z - $this->source->z) / $distance;
$impact = (1 - $distByRad) * 0.5; //TODO calculate block density around the entity instead of 0.5
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
if($damage > 0){
$entity->harm($damage, "explosion");
$entity->speedX = $diffX * $impact;
$entity->speedY = $diffY * $impact;
$entity->speedZ = $diffZ * $impact;
if($entity->isPlayer()){
$pk = new SetEntityMotionPacket();
$pk->eid = 0; //XXX change
$pk->speedX = $entity->speedX;
$pk->speedY = $entity->speedY;
$pk->speedZ = $entity->speedZ;
$entity->player->dataPacket($pk);
}
}
}
} }
$pk = new ExplodePacket; //sound fix $pk = new ExplodePacket; //sound fix
$pk->x = $this->source->x; $pk->x = $this->source->x;
@ -136,10 +158,21 @@ class Explosion{
$impact = (1 - $distByRad) * 0.5; //TODO calculate block density around the entity instead of 0.5 $impact = (1 - $distByRad) * 0.5; //TODO calculate block density around the entity instead of 0.5
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1); $damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
$entity->harm($damage, "explosion"); if($damage > 0){
$entity->speedX = $diffX * $impact; //TODO check is needed for player? $entity->harm($damage, "explosion");
$entity->speedY = $diffY * $impact; $entity->speedX = $diffX * $impact;
$entity->speedZ = $diffZ * $impact; $entity->speedY = $diffY * $impact;
$entity->speedZ = $diffZ * $impact;
if($entity->isPlayer()){
$pk = new SetEntityMotionPacket();
$pk->eid = 0; //XXX change
$pk->speedX = $entity->speedX;
$pk->speedY = $entity->speedY;
$pk->speedZ = $entity->speedZ;
$entity->player->dataPacket($pk);
}
}
} }
} }

View file

@ -494,8 +494,15 @@ class Level{
} }
$this->totalMobsAmount = 0; $this->totalMobsAmount = 0;
$post = []; $post = [];
//console($this->getName());
foreach($this->entityList as $k => $e){ foreach($this->entityList as $k => $e){
if(!($e instanceof Entity)){
unset($this->entityList[$k]);
unset($this->server->entities[$k]);
//TODO try to remove from $entityListPositioned?
continue;
}
$dd = CORRECT_ENTITY_CLASSES[$e->class] ?? false; $dd = CORRECT_ENTITY_CLASSES[$e->class] ?? false;
if($dd === false || ($dd !== true && !isset($dd[$e->type]))){ if($dd === false || ($dd !== true && !isset($dd[$e->type]))){
ConsoleAPI::warn("Entity $k has invalid entity! {$e->class} {$e->type}"); ConsoleAPI::warn("Entity $k has invalid entity! {$e->class} {$e->type}");
@ -514,13 +521,6 @@ class Level{
continue; continue;
} }
if(!($e instanceof Entity)){
unset($this->entityList[$k]);
unset($this->server->entities[$k]);
//TODO try to remove from $entityListPositioned?
continue;
}
$curChunkX = (int)$e->x >> 4; $curChunkX = (int)$e->x >> 4;
$curChunkZ = (int)$e->z >> 4; $curChunkZ = (int)$e->z >> 4;
if($e->class === ENTITY_MOB && !$e->isPlayer()){ if($e->class === ENTITY_MOB && !$e->isPlayer()){

View file

@ -58,7 +58,7 @@ class MobSpawner{
$type = mt_rand(10, 13); $type = mt_rand(10, 13);
$baby = false; $baby = false;
$grassOnly = true; $grassOnly = true;
}elseif(self::$spawnMobs && ($phase == "night" || $phase == "sunset")){ //Monster, true night }elseif(self::$spawnMobs && ($phase == "night" || $phase == "sunset") && $this->server->difficulty > 0){ //Monster, true night
$type = mt_rand(32, 35); $type = mt_rand(32, 35);
$grassOnly = false; $grassOnly = false;
$baby = 2; $baby = 2;