code style fix

This commit is contained in:
Sunch 2025-04-27 20:36:24 +08:00
parent fc5c5625cb
commit 5e8e9330e2
361 changed files with 4766 additions and 4650 deletions

View file

@ -3,7 +3,7 @@
class Arrow extends Entity{
const TYPE = OBJECT_ARROW;
const CLASS_TYPE = ENTITY_OBJECT;
public $shooterEID = 0;
public $xTile, $yTile, $zTile;
public $inTile, $inData;
@ -13,7 +13,7 @@ class Arrow extends Entity{
public $criticial = false;
public $groundTicks = 0;
public $shotByPlayer = false;
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->gravity = 0.05;
@ -32,12 +32,12 @@ class Arrow extends Entity{
$this->yTile = $data["yTile"] ?? $this->yTile;
$this->zTile = $data["zTile"] ?? $this->zTile;
$this->shotByPlayer = $data["shotByPlayer"] ?? $this->shotByPlayer;
//$this->server->schedule(1210, array($this, "update")); //Despawn
}
public function createSaveData(){
$data = parent::createSaveData();
$data["inTile"] = $this->inTile;
$data["inData"] = $this->inData;
$data["inGround"] = $this->inGround;
@ -57,7 +57,7 @@ class Arrow extends Entity{
$pk->pitch = $this->pitch;
$this->server->api->player->broadcastPacket($this->level->players, $pk);
}
public function shoot($d, $d1, $d2, $f, $f1){ //original name from 0.8.1 IDA decompilation, var names are taken from b1.7.3
$f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2);
$d /= $f2;
@ -79,7 +79,7 @@ class Arrow extends Entity{
//$this->update();
$this->groundTicks = 0;
}
public function update($now){
$this->lastX = $this->x;
$this->lastY = $this->y;
@ -101,40 +101,39 @@ class Arrow extends Entity{
$this->fire -= 4;
if($this->fire <= 0) $this->fire = 0;
}
if($this->fire <= 0){
$this->updateMetadata();
}
}
if($this->handleLavaMovement()){
if(!$this->isImmuneToFire){
$this->harm(4, "fire");
$oldOnFire = $this->fire;
if($oldOnFire < 20*30) $this->fire = 20*30; //30 seconds
if($oldOnFire < 20 * 30) $this->fire = 20 * 30; //30 seconds
}
}
if($this->isInVoid()){
$this->outOfWorld();
}
//Entity::update end
if($this->lastPitch == $this->lastYaw && $this->lastYaw == 0){
$v1 = sqrt($this->speedX*$this->speedX + $this->speedZ*$this->speedZ);
$v1 = sqrt($this->speedX * $this->speedX + $this->speedZ * $this->speedZ);
$this->lastYaw = $this->yaw = atan2($this->speedX, $this->speedZ) * 180 / M_PI;
$this->lastPitch = $this->pitch = atan2($this->speedY, $v1) * 180 / M_PI;
}
if($this->shake > 0){
--$this->shake;
}
if($this->inGround){
[$blockID, $blockMeta] = $this->level->level->getBlock($this->xTile, $this->yTile, $this->zTile);
$this->speedZ = $this->speedX = $this->speedY = 0;
if($blockID == $this->inTile && $blockMeta == $this->inData){
++$this->groundTicks;
if($this->groundTicks >= 1200){ //TODO customizeable?
@ -147,7 +146,7 @@ class Arrow extends Entity{
$this->speedZ *= lcg_value() * 0.2;
$this->groundTicks = $this->airTicks = 0;
}
}else{
++$this->airTicks;
$start = new Vector3($this->x, $this->y, $this->z);
@ -162,42 +161,40 @@ class Arrow extends Entity{
}else{
$end = new Vector3($this->x + $this->speedX, $this->y + $this->speedY, $this->z + $this->speedZ);
}
$entities = $this->level->getEntitiesInAABB($this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ)->expand(1, 1, 1));
$bestDist = 0;
$bestEnt = null;
foreach($entities as $eid => $ent){
if($eid != $this->eid && $ent->isPickable() && ($eid != $this->shooterEID || $this->airTicks >= 5)){
$v12 = $ent->boundingBox->expand(0.3, 0.3, 0.3);
$v13 = $v12->calculateIntercept($start, $end);
if($v13 != null){
$dist = $start->distance($v13->hitVector);
if($dist < $bestDist || $bestDist == 0){
$bestEnt = $ent;
}
}
}
}
if($bestEnt != null){
$v4 = MovingObjectPosition::fromEntity($bestEnt);
}
if($v4 != null){
if($v4->entityHit != null){
$v49 = sqrt($this->speedY*$this->speedY + $this->speedX*$this->speedX + $this->speedZ*$this->speedZ);
$damage = ceil($v49+$v49);
$v49 = sqrt($this->speedY * $this->speedY + $this->speedX * $this->speedX + $this->speedZ * $this->speedZ);
$damage = ceil($v49 + $v49);
if($this->criticial){
$damage += mt_rand(0, $damage / 2 + 1);
}
if($v4->entityHit->harm($damage, $this->eid)){
//vanilla seems to increase arrow count if $v4->entity is mob
$this->close();
@ -213,36 +210,36 @@ class Arrow extends Entity{
$this->xTile = $v4->blockX;
$this->yTile = $v4->blockY;
$this->zTile = $v4->blockZ;
[$this->inTile, $this->inData] = $this->level->level->getBlock($this->xTile, $this->yTile, $this->zTile);
$this->speedX = $v4->hitVector->x - $this->x;
$this->speedY = $v4->hitVector->y - $this->y;
$this->speedZ = $v4->hitVector->z - $this->z;
$v21 = sqrt($this->speedX*$this->speedX + $this->speedY*$this->speedY + $this->speedZ*$this->speedZ);
$v21 = sqrt($this->speedX * $this->speedX + $this->speedY * $this->speedY + $this->speedZ * $this->speedZ);
if($v21 != 0){
$this->x -= $this->speedX / $v21 * 0.05;
$this->y -= $this->speedY / $v21 * 0.05;
$this->z -= $this->speedZ / $v21 * 0.05;
}
$this->inGround = true;
$this->shake = 7;
$this->criticial = false;
}
}
$this->x += $this->speedX;
$this->y += $this->speedY;
$this->z += $this->speedZ;
$v21 = sqrt($this->speedX*$this->speedX + $this->speedZ*$this->speedZ);
$v21 = sqrt($this->speedX * $this->speedX + $this->speedZ * $this->speedZ);
$this->yaw = atan2($this->speedX, $this->speedZ) * 180 / M_PI;
$this->pitch = atan2($this->speedY, $v21) * 180 / M_PI;
$this->pitch = $this->lastPitch + ($this->pitch - $this->lastPitch) * 0.2;
$this->yaw = $this->lastYaw + ($this->yaw - $this->lastYaw) * 0.2;
$v24 = $this->inWater ? 0.8 : 0.99;
$this->speedX *= $v24;
$this->speedY *= $v24;
@ -252,14 +249,12 @@ class Arrow extends Entity{
$v7 = $this->width / 2;
$v8 = $this->height;
$this->boundingBox->setBounds($this->x - $v7, $this->y - $this->yOffset /*+ $this->ySize*/, $this->z - $v7, $this->x + $v7, $this->y - $this->yOffset + $v8 /*+ $this->ySize*/, $this->z + $v7);
$this->doBlocksCollision();
}
}
public function spawn($player){
if($this->type === OBJECT_ARROW){
$pk = new AddEntityPacket;
@ -268,7 +263,7 @@ class Arrow extends Entity{
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->did = 1;
$pk->did = 1;
$pk->speedX = $this->speedX;
$pk->speedY = $this->speedY;
$pk->speedZ = $this->speedZ;