Merge branch 'kotyaralih:master' into master

This commit is contained in:
yefengeeeeeeeeeee 2025-04-13 10:28:29 +08:00 • committed by GitHub
commit f2e82b77de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 90 additions and 60 deletions

View file

@ -502,10 +502,17 @@ class BlockAPI{
//$face = -1; //$face = -1;
} }
if($hand->isSolid === true and $block->boundingBox->intersectsWith($player->entity->boundingBox) && ($hand->getID() != BED_BLOCK && $hand->getID() != CARPET)){ if($hand->isSolid === true && ($hand->getID() != BED_BLOCK && $hand->getID() != CARPET)){
$aabb = $hand->getAABB($block->level, $block->x, $block->y, $block->z);
$playerbb = $player->entity->boundingBox;
//$aabb->intersectsWith($playerbb) is not good enough for this case
//minY+0.21 is used to stop sneaking from triggering action cancelling
if(($aabb->maxX > $playerbb->minX && $aabb->minX < $playerbb->maxX) && ($aabb->maxY > ($playerbb->minY+0.21) && $aabb->minY < $playerbb->maxY) && ($aabb->maxZ > $playerbb->minZ && $aabb->minZ < $playerbb->maxZ)){
return $this->cancelAction($block, $player, false); //Entity in block return $this->cancelAction($block, $player, false); //Entity in block
} }
}
if($this->server->api->dhandle("player.block.place", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) === false){ if($this->server->api->dhandle("player.block.place", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) === false){
return $this->cancelAction($block, $player); return $this->cancelAction($block, $player);
}elseif($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false){ }elseif($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false){

View file

@ -422,6 +422,8 @@ class Player{
public function sendBuffer(){ public function sendBuffer(){
if($this->bufferLen > 0 and $this->buffer instanceof RakNetPacket){ if($this->bufferLen > 0 and $this->buffer instanceof RakNetPacket){
$this->buffer->seqNumber = $this->counter[0]++; $this->buffer->seqNumber = $this->counter[0]++;
$this->recoveryQueue[$this->buffer->seqNumber] = $this->buffer;
$this->buffer->sendtime = microtime(true);
$this->send($this->buffer); $this->send($this->buffer);
} }
$this->bufferLen = 0; $this->bufferLen = 0;
@ -965,15 +967,6 @@ class Player{
} }
if($m !== ""){ if($m !== ""){
/*$pk = new LevelEventPacket();
$pk->evid = LevelEventPacket::EVENT_OPEN_DOOR_SOUND;
$pk->x = $this->entity->x;
$pk->y = $this->entity->y;
$pk->z = $this->entity->z;
$pk->data = 0;
$this->dataPacket($pk);*/
$pk = new MessagePacket; $pk = new MessagePacket;
$pk->source = ($author instanceof Player) ? $author->username : $author; $pk->source = ($author instanceof Player) ? $author->username : $author;
$pk->message = TextFormat::clean($m); //Colors not implemented :( $pk->message = TextFormat::clean($m); //Colors not implemented :(
@ -2989,6 +2982,7 @@ class Player{
switch($packet->pid()){ switch($packet->pid()){
case RakNetInfo::NACK: case RakNetInfo::NACK:
foreach($packet->packets as $count){ foreach($packet->packets as $count){
if(isset($this->recoveryQueue[$count])){ if(isset($this->recoveryQueue[$count])){
$this->resendQueue[$count] =& $this->recoveryQueue[$count]; $this->resendQueue[$count] =& $this->recoveryQueue[$count];
$this->lag[] = $time - $this->recoveryQueue[$count]->sendtime; $this->lag[] = $time - $this->recoveryQueue[$count]->sendtime;

View file

@ -23,8 +23,10 @@ class FallingSand extends Entity{
public function update($now){ public function update($now){
if($this->closed) return; if($this->closed) return;
if( $this->data["Tile"] == AIR) $this->close(); if( $this->data["Tile"] == AIR) {
else { $this->close();
return;
}
$this->lastX = $this->x; $this->lastX = $this->x;
$this->lastY = $this->y; $this->lastY = $this->y;
$this->lastZ = $this->z; $this->lastZ = $this->z;
@ -56,4 +58,3 @@ class FallingSand extends Entity{
} }
} }
} }
}

View file

@ -47,14 +47,17 @@ class GenericBlock extends Block{
return $this->level->setBlock($this, new AirBlock(), true, false, true); return $this->level->setBlock($this, new AirBlock(), true, false, true);
} }
/** public static function onPlace(Level $level, $x, $y, $z){
* @param integer $type [$id, $meta] = $level->level->getBlock($x, $y, $z);
* if(StaticBlock::getHasPhysics($id)){
* @return boolean ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, 2); //tick delay == 2
*/ }else{
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ parent::onPlace($level, $x, $y, $z);
}
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
[$id, $meta] = $level->level->getBlock($x, $y, $z); [$id, $meta] = $level->level->getBlock($x, $y, $z);
if(StaticBlock::getHasPhysics($id)){ //TODO move from here to different class
$down = $level->level->getBlockID($x, $y - 1, $z); $down = $level->level->getBlockID($x, $y - 1, $z);
if($down == AIR || StaticBlock::getIsLiquid($down)){ if($down == AIR || StaticBlock::getIsLiquid($down)){
$data = array( $data = array(
@ -69,6 +72,17 @@ class GenericBlock extends Block{
$server->api->entity->spawnToAll($e); $server->api->entity->spawnToAll($e);
} }
} }
/**
* @param integer $type
*
* @return boolean
*/
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
if(StaticBlock::getHasPhysics($id)){ //TODO move from here to different class
static::onUpdate($level, $x, $y, $z, BLOCK_UPDATE_NORMAL);
}
} }
/** /**

View file

@ -17,6 +17,19 @@ class FenceBlock extends TransparentBlock{
return true; return true;
} }
public static function getAABB(Level $level, $x, $y, $z){
$v9 = self::canConnectTo($level, $x, $y, $z - 1);
$v10 = self::canConnectTo($level, $x, $y, $z + 1);
$v11 = self::canConnectTo($level, $x - 1, $y, $z);
$v12 = self::canConnectTo($level, $x + 1, $y, $z);
$minX = $v11 ? 0 : 0.375;
$minZ = $v9 ? 0 : 0.375;
$maxZ = $v10 ? 1 : 0.625;
$maxX = !$v12 ? 0.625 : 1;
StaticBlock::setBlockBounds(static::$blockID, $minX, 0, $minZ, $maxX, 1.5, $maxZ);
return parent::getAABB($level, $x, $y, $z);
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
$v8 = self::canConnectTo($level, $x, $y, $z - 1); $v8 = self::canConnectTo($level, $x, $y, $z - 1);
$v9 = self::canConnectTo($level, $x, $y, $z + 1); $v9 = self::canConnectTo($level, $x, $y, $z + 1);

View file

@ -353,13 +353,14 @@ class PMFLevel extends PMF{
} }
public function getBlockID($x, $y, $z){ public function getBlockID($x, $y, $z){
if($y > 127 || $y < 0){
return 0;
}
if($x < 0 || $x > 255 || $z < 0 || $z > 255){ if($x < 0 || $x > 255 || $z < 0 || $z > 255){
return INVISIBLE_BEDROCK; return INVISIBLE_BEDROCK;
} }
if($y > 127 || $y < 0){
return 0;
}
$X = $x >> 4; $X = $x >> 4;
$Z = $z >> 4; $Z = $z >> 4;
$Y = $y >> 4; $Y = $y >> 4;
@ -460,12 +461,12 @@ class PMFLevel extends PMF{
} }
public function getBlock($x, $y, $z){ public function getBlock($x, $y, $z){
if($x < 0 || $x > 255 || $z < 0 || $z > 255){
return [INVISIBLE_BEDROCK, 0];
}
if($y < 0 || $y > 127){ if($y < 0 || $y > 127){
return [AIR, 0]; return [AIR, 0];
} }
if($x < 0 || $x > 255 || $z < 0 || $z > 255){
return [INVISIBLE_BEDROCK, 0];
}
$X = $x >> 4; $X = $x >> 4;
$Z = $z >> 4; $Z = $z >> 4;