fixed packet spam, removed item merging, various fixes

This commit is contained in:
GameHerobrine 2024-02-14 04:22:20 +03:00
parent dee744e709
commit 908cff1317
7 changed files with 46 additions and 24 deletions

View file

@ -594,8 +594,6 @@ class Player{
}
public function sendInventorySlot($s){
$this->sendInventory();
return;
$s = (int) $s;
if(!isset($this->inventory[$s])){
$pk = new ContainerSetSlotPacket;
@ -754,7 +752,7 @@ class Player{
$pk->target = $data["entity"]->eid;
$this->dataPacket($pk);
if(($this->gamemode & 0x01) === 0x00){
$this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack, false);
$this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack, true);
}
switch($data["entity"]->type){
case WOOD:
@ -916,6 +914,15 @@ class Player{
}
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->source = ($author instanceof Player) ? $author->username : $author;
$pk->message = TextFormat::clean($m); //Colors not implemented :(
@ -1207,15 +1214,17 @@ class Player{
$moveSent = false;
$headSent = false;
if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){
$motion = new SetEntityMotionPacket();
$motion->eid = $e->eid;
$motion->speedX = $e->speedX;
$motion->speedY = $e->speedY;
$motion->speedZ = $e->speedZ;
$motion->encode();
$len += 1 + strlen($motion->buffer);
++$packets;
$motionSent = true;
if(!($e->speedY < 0 && $e->onGround)){
$motion = new SetEntityMotionPacket();
$motion->eid = $e->eid;
$motion->speedX = $e->speedX;
$motion->speedY = $e->speedY;
$motion->speedZ = $e->speedZ;
$motion->encode();
$len += 1 + strlen($motion->buffer);
++$packets;
$motionSent = true;
}
}
if($e->x != $e->lastX || $e->y != $e->lastY || $e->z != $e->lastZ || $e->yaw != $e->lastYaw || $e->pitch != $e->lastPitch){
$move = new MoveEntityPacket_PosRot();

View file

@ -441,7 +441,7 @@ class Entity extends Position
if(!($this instanceof Painting) && !($this->isPlayer() && $this->player->isSleeping !== false)){ //TODO better way to fix
for($i = 0; $i < 8; ++$i){
$x = ((($i >> 0) % 2) - 0.5) * $this->width * 0.8;
$y= ((($i >> 1) % 2) - 0.5) * 0.1;
$y = ((($i >> 1) % 2) - 0.5) * 0.1;
$z = ((($i >> 2) % 2) - 0.5) * $this->width * 0.8;
$blockX = (int) ($this->x + $x);
@ -609,8 +609,8 @@ class Entity extends Position
$z1 = floor($aABB->maxZ + 1);
for($x = $x0; $x < $x1; ++$x){
for($y = $y0; $y < $y1; ++$y){
for($z = $z0; $z < $z1; ++$z){
for($z = $z0; $z < $z1; ++$z){
for($y = $y0 - 1; $y < $y1; ++$y){
$b = $this->level->level->getBlockID($x, $y, $z);
if($b != 0){
$blockBounds = Block::$class[$b]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this);

View file

@ -24,7 +24,7 @@ class Chicken extends Animal{
public function updateEntityMovement(){
parent::updateEntityMovement();
if($this->onGround && $this->speedY < 0) $this->speedY *= 0.6;
if(!$this->onGround && $this->speedY < 0) $this->speedY *= 0.6;
if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){
$this->dropAnEgg();

View file

@ -94,7 +94,7 @@ class ItemEntity extends Entity{
$this->speedZ = (lcg_value() - lcg_value()) * 0.2;
}
$this->searchForOtherItemsNearby(); //not in vanilla 0.8.1
//$this->searchForOtherItemsNearby(); //not in vanilla 0.8.1, TODO reenable after fixing not correct count in inv
}
if($this->closed) return;
@ -112,6 +112,10 @@ class ItemEntity extends Entity{
if($this->onGround) $this->speedY *= -0.5;
if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0;
if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0;
if(abs($this->speedY) < self::MIN_POSSIBLE_SPEED) $this->speedY = 0;
++$this->age;
//TODO despawn after age >= 6000 ?;
}

View file

@ -1,6 +1,10 @@
<?php
class LevelEventPacket extends RakNetDataPacket{
const EVENT_OPEN_DOOR_SOUND = 1003;
const EVENT_ALL_PLAYERS_SLEEPING = 9800;
public $evid;
public $x;
public $y;

View file

@ -25,6 +25,8 @@ class Level{
public $randInt1, $randInt2;
public $queuedBlockUpdates = [];
public $forceDisableBlockQueue = false;
public static $randomUpdateBlocks = [
FIRE => true,
FARMLAND => true,
@ -150,15 +152,15 @@ class Level{
public function getCubes(Entity $e, AxisAlignedBB $aABB) {
$aABBs = [];
$x0 = floor($aABB->minX);
$x1 = ceil($aABB->maxX);
$x1 = floor($aABB->maxX + 1);
$y0 = floor($aABB->minY);
$y1 = ceil($aABB->maxY);
$y1 = floor($aABB->maxY + 1);
$z0 = floor($aABB->minZ);
$z1 = ceil($aABB->maxZ);
$z1 = floor($aABB->maxZ + 1);
for($x = $x0; $x <= $x1; ++$x) {
for($y = $y0; $y <= $y1; ++$y) {
for($z = $z0; $z <= $z1; ++$z) {
for($x = $x0; $x < $x1; ++$x) {
for($z = $z0; $z < $z1; ++$z) {
for($y = $y0 - 1; $y < $y1; ++$y) {
$bid = $this->level->getBlockID($x, $y, $z);
if($bid > 0){
$blockBounds = Block::$class[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z);
@ -541,7 +543,8 @@ class Level{
}
public function addBlockToSendQueue($x, $y, $z, $id, $meta){
$this->queuedBlockUpdates["$x $y $z"] = [$x, $y, $z, $id, $meta];
if(!$this->forceDisableBlockQueue)
$this->queuedBlockUpdates["$x $y $z"] = [$x, $y, $z, $id, $meta];
}
public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){

View file

@ -29,6 +29,7 @@ class WorldGenerator{
}
public function generate(){
$this->level->forceDisableBlockQueue = true;
$this->generator->init($this->level, $this->random);
for($Z = 0; $Z < $this->width; ++$Z){
for($X = 0; $X < $this->width; ++$X){
@ -49,6 +50,7 @@ class WorldGenerator{
$this->level->setSpawn($this->generator->getSpawn());
$this->level->save(true, true);
$this->level->forceDisableBlockQueue = false;
}
public function close(){