moar changes

This commit is contained in:
Dylan K. Taylor 2024-12-04 16:13:21 +00:00
parent 224fa09327
commit 39662bdc3b
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
52 changed files with 102 additions and 103 deletions

View File

@ -145,7 +145,7 @@ abstract class BaseSign extends Transparent{
private function changeSignGlowingState(bool $glowing, Player $player, Item $item) : bool{ private function changeSignGlowingState(bool $glowing, Player $player, Item $item) : bool{
if($this->text->isGlowing() !== $glowing && $this->doSignChange(new SignText($this->text->getLines(), $this->text->getBaseColor(), $glowing), $player, $item)){ if($this->text->isGlowing() !== $glowing && $this->doSignChange(new SignText($this->text->getLines(), $this->text->getBaseColor(), $glowing), $player, $item)){
$this->position->getWorld()->addSound($this->position->asVector3(), new InkSacUseSound()); $this->position->getWorld()->addSound($this->position->center(), new InkSacUseSound());
return true; return true;
} }
return false; return false;
@ -183,7 +183,7 @@ abstract class BaseSign extends Transparent{
$color->toARGB() !== $this->text->getBaseColor()->toARGB() && $color->toARGB() !== $this->text->getBaseColor()->toARGB() &&
$this->doSignChange(new SignText($this->text->getLines(), $color, $this->text->isGlowing()), $player, $item) $this->doSignChange(new SignText($this->text->getLines(), $color, $this->text->isGlowing()), $player, $item)
){ ){
$this->position->getWorld()->addSound($this->position->asVector3(), new DyeUseSound()); $this->position->getWorld()->addSound($this->position->center(), new DyeUseSound());
return true; return true;
} }
}elseif(match($item->getTypeId()){ }elseif(match($item->getTypeId()){

View File

@ -128,7 +128,7 @@ class Bed extends Transparent{
$player->sendMessage(TextFormat::GRAY . "This bed is incomplete"); $player->sendMessage(TextFormat::GRAY . "This bed is incomplete");
return true; return true;
}elseif($playerPos->distanceSquared($this->position->asVector3()) > 4 && $playerPos->distanceSquared($other->position->asVector3()) > 4){ }elseif($playerPos->distanceSquared($this->position->center()) > 4 && $playerPos->distanceSquared($other->position->center()) > 4){
$player->sendMessage(KnownTranslationFactory::tile_bed_tooFar()->prefix(TextFormat::GRAY)); $player->sendMessage(KnownTranslationFactory::tile_bed_tooFar()->prefix(TextFormat::GRAY));
return true; return true;
} }

View File

@ -143,10 +143,10 @@ final class Bell extends Transparent{
public function ring(int $faceHit) : void{ public function ring(int $faceHit) : void{
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$world->addSound($this->position->asVector3(), new BellRingSound()); $world->addSound($this->position->center(), new BellRingSound());
$tile = $world->getTile($this->position); $tile = $world->getTile($this->position);
if($tile instanceof TileBell){ if($tile instanceof TileBell){
$world->broadcastPacketToViewers($this->position->asVector3(), $tile->createFakeUpdatePacket($faceHit)); $world->broadcastPacketOnBlock($this->position, $tile->createFakeUpdatePacket($faceHit));
} }
} }

View File

@ -93,7 +93,7 @@ class BigDripleafHead extends BaseBigDripleaf{
public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{ public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{
if($this->leafState !== DripleafState::FULL_TILT){ if($this->leafState !== DripleafState::FULL_TILT){
$this->setTiltAndScheduleTick(DripleafState::FULL_TILT); $this->setTiltAndScheduleTick(DripleafState::FULL_TILT);
$this->position->getWorld()->addSound($this->position->asVector3(), new DripleafTiltDownSound()); $this->position->getWorld()->addSound($this->position->center(), new DripleafTiltDownSound());
} }
} }
@ -101,13 +101,13 @@ class BigDripleafHead extends BaseBigDripleaf{
if($this->leafState !== DripleafState::STABLE){ if($this->leafState !== DripleafState::STABLE){
if($this->leafState === DripleafState::FULL_TILT){ if($this->leafState === DripleafState::FULL_TILT){
$this->position->getWorld()->setBlock($this->position, $this->setLeafState(DripleafState::STABLE)); $this->position->getWorld()->setBlock($this->position, $this->setLeafState(DripleafState::STABLE));
$this->position->getWorld()->addSound($this->position->asVector3(), new DripleafTiltUpSound()); $this->position->getWorld()->addSound($this->position->center(), new DripleafTiltUpSound());
}else{ }else{
$this->setTiltAndScheduleTick(match($this->leafState){ $this->setTiltAndScheduleTick(match($this->leafState){
DripleafState::UNSTABLE => DripleafState::PARTIAL_TILT, DripleafState::UNSTABLE => DripleafState::PARTIAL_TILT,
DripleafState::PARTIAL_TILT => DripleafState::FULL_TILT, DripleafState::PARTIAL_TILT => DripleafState::FULL_TILT,
}); });
$this->position->getWorld()->addSound($this->position->asVector3(), new DripleafTiltDownSound()); $this->position->getWorld()->addSound($this->position->center(), new DripleafTiltDownSound());
} }
} }
} }

View File

@ -398,7 +398,7 @@ class Block{
* @var Tile $tile * @var Tile $tile
* @see Tile::__construct() * @see Tile::__construct()
*/ */
$tile = new $tileType($world, $this->position->asVector3()); $tile = new $tileType($this->position);
$world->addTile($tile); $world->addTile($tile);
} }
} }

View File

@ -67,7 +67,7 @@ abstract class Button extends Flowable{
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$world->setBlock($this->position, $this); $world->setBlock($this->position, $this);
$world->scheduleDelayedBlockUpdate($this->position, $this->getActivationTime()); $world->scheduleDelayedBlockUpdate($this->position, $this->getActivationTime());
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new RedstonePowerOnSound()); $world->addSound($this->position->center(), new RedstonePowerOnSound());
} }
return true; return true;
@ -78,7 +78,7 @@ abstract class Button extends Flowable{
$this->pressed = false; $this->pressed = false;
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$world->setBlock($this->position, $this); $world->setBlock($this->position, $this);
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new RedstonePowerOffSound()); $world->addSound($this->position->center(), new RedstonePowerOffSound());
} }
} }

View File

@ -76,6 +76,6 @@ class CakeWithCandle extends BaseCake{
public function onConsume(Living $consumer) : void{ public function onConsume(Living $consumer) : void{
parent::onConsume($consumer); parent::onConsume($consumer);
$this->position->getWorld()->dropItem($this->position->asVector3()->add(0.5, 0.5, 0.5), $this->getCandle()->asItem()); $this->position->getWorld()->dropItem($this->position->center(), $this->getCandle()->asItem());
} }
} }

View File

@ -185,7 +185,7 @@ class Campfire extends Transparent{
if($item->getTypeId() === ItemTypeIds::FIRE_CHARGE){ if($item->getTypeId() === ItemTypeIds::FIRE_CHARGE){
$item->pop(); $item->pop();
$this->ignite(); $this->ignite();
$this->position->getWorld()->addSound($this->position->asVector3(), new BlazeShootSound()); $this->position->getWorld()->addSound($this->position->center(), new BlazeShootSound());
return true; return true;
}elseif($item->getTypeId() === ItemTypeIds::FLINT_AND_STEEL || $item->hasEnchantment(VanillaEnchantments::FIRE_ASPECT())){ }elseif($item->getTypeId() === ItemTypeIds::FLINT_AND_STEEL || $item->hasEnchantment(VanillaEnchantments::FIRE_ASPECT())){
if($item instanceof Durable){ if($item instanceof Durable){
@ -205,7 +205,7 @@ class Campfire extends Transparent{
$ingredient->setCount(1); $ingredient->setCount(1);
if(count($this->inventory->addItem($ingredient)) === 0){ if(count($this->inventory->addItem($ingredient)) === 0){
$item->pop(); $item->pop();
$this->position->getWorld()->addSound($this->position->asVector3(), new ItemFrameAddItemSound()); $this->position->getWorld()->addSound($this->position->center(), new ItemFrameAddItemSound());
return true; return true;
} }
} }
@ -266,19 +266,19 @@ class Campfire extends Transparent{
$this->position->getWorld()->setBlock($this->position, $this); $this->position->getWorld()->setBlock($this->position, $this);
} }
if(mt_rand(1, 6) === 1){ if(mt_rand(1, 6) === 1){
$this->position->getWorld()->addSound($this->position->asVector3(), $furnaceType->getCookSound()); $this->position->getWorld()->addSound($this->position->center(), $furnaceType->getCookSound());
} }
$this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, self::UPDATE_INTERVAL_TICKS); $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, self::UPDATE_INTERVAL_TICKS);
} }
} }
private function extinguish() : void{ private function extinguish() : void{
$this->position->getWorld()->addSound($this->position->asVector3(), new FireExtinguishSound()); $this->position->getWorld()->addSound($this->position->center(), new FireExtinguishSound());
$this->position->getWorld()->setBlock($this->position, $this->setLit(false)); $this->position->getWorld()->setBlock($this->position, $this->setLit(false));
} }
private function ignite() : void{ private function ignite() : void{
$this->position->getWorld()->addSound($this->position->asVector3(), new FlintSteelSound()); $this->position->getWorld()->addSound($this->position->center(), new FlintSteelSound());
$this->position->getWorld()->setBlock($this->position, $this->setLit(true)); $this->position->getWorld()->setBlock($this->position, $this->setLit(true));
$this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, self::UPDATE_INTERVAL_TICKS); $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, self::UPDATE_INTERVAL_TICKS);
} }

View File

@ -69,7 +69,7 @@ final class Cauldron extends Transparent{
*/ */
private function fill(int $amount, FillableCauldron $result, Item $usedItem, Item $returnedItem, array &$returnedItems) : void{ private function fill(int $amount, FillableCauldron $result, Item $usedItem, Item $returnedItem, array &$returnedItems) : void{
$this->position->getWorld()->setBlock($this->position, $result->setFillLevel($amount)); $this->position->getWorld()->setBlock($this->position, $result->setFillLevel($amount));
$this->position->getWorld()->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), $result->getFillSound()); $this->position->getWorld()->addSound($this->position->center(), $result->getFillSound());
$usedItem->pop(); $usedItem->pop();
$returnedItems[] = $returnedItem; $returnedItems[] = $returnedItem;
@ -98,7 +98,7 @@ final class Cauldron extends Transparent{
if($this->getSide(Facing::UP)->getTypeId() === BlockTypeIds::WATER){ if($this->getSide(Facing::UP)->getTypeId() === BlockTypeIds::WATER){
$cauldron = VanillaBlocks::WATER_CAULDRON()->setFillLevel(FillableCauldron::MAX_FILL_LEVEL); $cauldron = VanillaBlocks::WATER_CAULDRON()->setFillLevel(FillableCauldron::MAX_FILL_LEVEL);
$world->setBlock($this->position, $cauldron); $world->setBlock($this->position, $cauldron);
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), $cauldron->getFillSound()); $world->addSound($this->position->center(), $cauldron->getFillSound());
} }
} }
} }

View File

@ -90,8 +90,8 @@ class CaveVines extends Flowable{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if($this->berries){ if($this->berries){
$this->position->getWorld()->dropItem($this->position->asVector3(), $this->asItem()); $this->position->getWorld()->dropItem($this->position->center(), $this->asItem());
$this->position->getWorld()->addSound($this->position->asVector3(), new GlowBerriesPickSound()); $this->position->getWorld()->addSound($this->position->center(), new GlowBerriesPickSound());
$this->position->getWorld()->setBlock($this->position, $this->setBerries(false)); $this->position->getWorld()->setBlock($this->position, $this->setBerries(false));
return true; return true;

View File

@ -192,10 +192,10 @@ final class ChorusFlower extends Flowable{
$ev = new StructureGrowEvent($this, $tx, null); $ev = new StructureGrowEvent($this, $tx, null);
$ev->call(); $ev->call();
if(!$ev->isCancelled() && $tx->apply()){ if(!$ev->isCancelled() && $tx->apply()){
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new ChorusFlowerGrowSound()); $world->addSound($this->position->center(), new ChorusFlowerGrowSound());
} }
}else{ }else{
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new ChorusFlowerDieSound()); $world->addSound($this->position->center(), new ChorusFlowerDieSound());
$this->position->getWorld()->setBlock($this->position, $this->setAge(self::MAX_AGE)); $this->position->getWorld()->setBlock($this->position, $this->setAge(self::MAX_AGE));
} }
} }

View File

@ -63,7 +63,7 @@ class Dirt extends Opaque{
$item->applyDamage(1); $item->applyDamage(1);
$newBlock = $this->dirtType === DirtType::NORMAL ? VanillaBlocks::FARMLAND() : VanillaBlocks::DIRT(); $newBlock = $this->dirtType === DirtType::NORMAL ? VanillaBlocks::FARMLAND() : VanillaBlocks::DIRT();
$center = $this->position->asVector3()->add(0.5, 0.5, 0.5); $center = $this->position->center();
$world->addSound($center, new ItemUseOnBlockSound($newBlock)); $world->addSound($center, new ItemUseOnBlockSound($newBlock));
$world->setBlock($this->position, $newBlock); $world->setBlock($this->position, $newBlock);
if($this->dirtType === DirtType::ROOTED){ if($this->dirtType === DirtType::ROOTED){
@ -83,7 +83,7 @@ class Dirt extends Opaque{
}elseif(($item instanceof Potion || $item instanceof SplashPotion) && $item->getType() === PotionType::WATER){ }elseif(($item instanceof Potion || $item instanceof SplashPotion) && $item->getType() === PotionType::WATER){
$item->pop(); $item->pop();
$world->setBlock($this->position, VanillaBlocks::MUD()); $world->setBlock($this->position, VanillaBlocks::MUD());
$world->addSound($this->position->asVector3(), new WaterSplashSound(0.5)); $world->addSound($this->position->center(), new WaterSplashSound(0.5));
return true; return true;
} }

View File

@ -152,7 +152,7 @@ class Door extends Transparent{
} }
$world->setBlock($this->position, $this); $world->setBlock($this->position, $this);
$world->addSound($this->position->asVector3(), new DoorSound()); $world->addSound($this->position->center(), new DoorSound());
return true; return true;
} }

View File

@ -74,7 +74,7 @@ class DragonEgg extends Transparent implements Fallable{
} }
$blockPos = $ev->getTo(); $blockPos = $ev->getTo();
$world->addParticle($this->position->asVector3(), new DragonEggTeleportParticle($this->position->x - $blockPos->getFloorX(), $this->position->y - $blockPos->getFloorY(), $this->position->z - $blockPos->getFloorZ())); $world->addParticle($this->position->center(), new DragonEggTeleportParticle($this->position->x - $blockPos->getFloorX(), $this->position->y - $blockPos->getFloorY(), $this->position->z - $blockPos->getFloorZ()));
$world->setBlock($this->position, VanillaBlocks::AIR()); $world->setBlock($this->position, VanillaBlocks::AIR());
$world->setBlockAt($blockPos->getFloorX(), $blockPos->getFloorY(), $blockPos->getFloorZ(), $this); $world->setBlockAt($blockPos->getFloorX(), $blockPos->getFloorY(), $blockPos->getFloorZ(), $this);
break; break;

View File

@ -111,7 +111,7 @@ class FenceGate extends Transparent{
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$world->setBlock($this->position, $this); $world->setBlock($this->position, $this);
$world->addSound($this->position->asVector3(), new DoorSound()); $world->addSound($this->position->center(), new DoorSound());
return true; return true;
} }

View File

@ -79,7 +79,7 @@ abstract class FillableCauldron extends Transparent{
return; return;
} }
$this->position->getWorld()->setBlock($this->position, $this->withFillLevel($this->fillLevel + $amount)); $this->position->getWorld()->setBlock($this->position, $this->withFillLevel($this->fillLevel + $amount));
$this->position->getWorld()->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), $this->getFillSound()); $this->position->getWorld()->addSound($this->position->center(), $this->getFillSound());
$usedItem->pop(); $usedItem->pop();
$returnedItems[] = $returnedItem; $returnedItems[] = $returnedItem;
@ -94,7 +94,7 @@ abstract class FillableCauldron extends Transparent{
} }
$this->position->getWorld()->setBlock($this->position, $this->withFillLevel($this->fillLevel - $amount)); $this->position->getWorld()->setBlock($this->position, $this->withFillLevel($this->fillLevel - $amount));
$this->position->getWorld()->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), $this->getEmptySound()); $this->position->getWorld()->addSound($this->position->center(), $this->getEmptySound());
$usedItem->pop(); $usedItem->pop();
$returnedItems[] = $returnedItem; $returnedItems[] = $returnedItem;

View File

@ -111,7 +111,7 @@ class FlowerPot extends Flowable{
$removedItems = $player->getInventory()->addItem(...$removedItems); $removedItems = $player->getInventory()->addItem(...$removedItems);
} }
foreach($removedItems as $drops){ foreach($removedItems as $drops){
$world->dropItem($this->position->asVector3()->add(0.5, 0.5, 0.5), $drops); $world->dropItem($this->position->center(), $drops);
} }
$this->setPlant(null); $this->setPlant(null);

View File

@ -73,7 +73,7 @@ class Furnace extends Opaque{
$furnace = $world->getTile($this->position); $furnace = $world->getTile($this->position);
if($furnace instanceof TileFurnace && $furnace->onUpdate()){ if($furnace instanceof TileFurnace && $furnace->onUpdate()){
if(mt_rand(1, 60) === 1){ //in vanilla this is between 1 and 5 seconds; try to average about 3 if(mt_rand(1, 60) === 1){ //in vanilla this is between 1 and 5 seconds; try to average about 3
$world->addSound($this->position->asVector3(), $furnace->getFurnaceType()->getCookSound()); $world->addSound($this->position->center(), $furnace->getFurnaceType()->getCookSound());
} }
$world->scheduleDelayedBlockUpdate($this->position, 1); //TODO: check this $world->scheduleDelayedBlockUpdate($this->position, 1); //TODO: check this
} }

View File

@ -88,7 +88,7 @@ class Grass extends Opaque{
$world = $this->position->getWorld(); $world = $this->position->getWorld();
if($item instanceof Fertilizer){ if($item instanceof Fertilizer){
$item->pop(); $item->pop();
TallGrassObject::growGrass($world, $this->position->asVector3(), new Random(mt_rand()), 8, 2); TallGrassObject::growGrass($world, $this->position->center(), new Random(mt_rand()), 8, 2);
return true; return true;
} }
@ -96,14 +96,14 @@ class Grass extends Opaque{
if($item instanceof Hoe){ if($item instanceof Hoe){
$item->applyDamage(1); $item->applyDamage(1);
$newBlock = VanillaBlocks::FARMLAND(); $newBlock = VanillaBlocks::FARMLAND();
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock)); $world->addSound($this->position->center(), new ItemUseOnBlockSound($newBlock));
$world->setBlock($this->position, $newBlock); $world->setBlock($this->position, $newBlock);
return true; return true;
}elseif($item instanceof Shovel){ }elseif($item instanceof Shovel){
$item->applyDamage(1); $item->applyDamage(1);
$newBlock = VanillaBlocks::GRASS_PATH(); $newBlock = VanillaBlocks::GRASS_PATH();
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock)); $world->addSound($this->position->center(), new ItemUseOnBlockSound($newBlock));
$world->setBlock($this->position, $newBlock); $world->setBlock($this->position, $newBlock);
return true; return true;

View File

@ -135,11 +135,11 @@ class ItemFrame extends Flowable{
if($this->framedItem !== null){ if($this->framedItem !== null){
$this->itemRotation = ($this->itemRotation + 1) % self::ROTATIONS; $this->itemRotation = ($this->itemRotation + 1) % self::ROTATIONS;
$this->position->getWorld()->addSound($this->position->asVector3(), new ItemFrameRotateItemSound()); $this->position->getWorld()->addSound($this->position->center(), new ItemFrameRotateItemSound());
}elseif(!$item->isNull()){ }elseif(!$item->isNull()){
$this->framedItem = $item->pop(); $this->framedItem = $item->pop();
$this->position->getWorld()->addSound($this->position->asVector3(), new ItemFrameAddItemSound()); $this->position->getWorld()->addSound($this->position->center(), new ItemFrameAddItemSound());
}else{ }else{
return true; return true;
} }
@ -155,8 +155,8 @@ class ItemFrame extends Flowable{
} }
$world = $this->position->getWorld(); $world = $this->position->getWorld();
if(Utils::getRandomFloat() <= $this->itemDropChance){ if(Utils::getRandomFloat() <= $this->itemDropChance){
$world->dropItem($this->position->asVector3()->add(0.5, 0.5, 0.5), clone $this->framedItem); $world->dropItem($this->position->center(), clone $this->framedItem);
$world->addSound($this->position->asVector3(), new ItemFrameRemoveItemSound()); $world->addSound($this->position->center(), new ItemFrameRemoveItemSound());
} }
$this->setFramedItem(null); $this->setFramedItem(null);
$world->setBlock($this->position, $this); $world->setBlock($this->position, $this);

View File

@ -76,12 +76,12 @@ class Jukebox extends Opaque{
public function startSound() : void{ public function startSound() : void{
if($this->record !== null){ if($this->record !== null){
$this->position->getWorld()->addSound($this->position->asVector3(), new RecordSound($this->record->getRecordType())); $this->position->getWorld()->addSound($this->position->center(), new RecordSound($this->record->getRecordType()));
} }
} }
public function stopSound() : void{ public function stopSound() : void{
$this->position->getWorld()->addSound($this->position->asVector3(), new RecordStopSound()); $this->position->getWorld()->addSound($this->position->center(), new RecordStopSound());
} }
public function onBreak(Item $item, ?Player $player = null, array &$returnedItems = []) : bool{ public function onBreak(Item $item, ?Player $player = null, array &$returnedItems = []) : bool{

View File

@ -123,7 +123,7 @@ class Lectern extends Transparent{
if($this->book === null && $item instanceof WritableBookBase){ if($this->book === null && $item instanceof WritableBookBase){
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$world->setBlock($this->position, $this->setBook($item)); $world->setBlock($this->position, $this->setBook($item));
$world->addSound($this->position->asVector3(), new LecternPlaceBookSound()); $world->addSound($this->position->center(), new LecternPlaceBookSound());
$item->pop(); $item->pop();
} }
return true; return true;
@ -132,7 +132,7 @@ class Lectern extends Transparent{
public function onAttack(Item $item, int $face, ?Player $player = null) : bool{ public function onAttack(Item $item, int $face, ?Player $player = null) : bool{
if($this->book !== null){ if($this->book !== null){
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$world->dropItem($this->position->getSide(Facing::UP)->asVector3(), $this->book); $world->dropItem($this->position->getSide(Facing::UP)->center(), $this->book);
$world->setBlock($this->position, $this->setBook(null)); $world->setBlock($this->position, $this->setBook(null));
} }
return false; return false;

View File

@ -95,7 +95,7 @@ class Lever extends Flowable{
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$world->setBlock($this->position, $this); $world->setBlock($this->position, $this);
$world->addSound( $world->addSound(
$this->position->asVector3()->add(0.5, 0.5, 0.5), $this->position->center(),
$this->activated ? new RedstonePowerOnSound() : new RedstonePowerOffSound() $this->activated ? new RedstonePowerOnSound() : new RedstonePowerOffSound()
); );
return true; return true;

View File

@ -368,7 +368,7 @@ abstract class Liquid extends Transparent{
protected function liquidCollide(Block $cause, Block $result) : bool{ protected function liquidCollide(Block $cause, Block $result) : bool{
if(BlockEventHelper::form($this, $result, $cause)){ if(BlockEventHelper::form($this, $result, $cause)){
$this->position->getWorld()->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (Utils::getRandomFloat() - Utils::getRandomFloat()) * 0.8)); $this->position->getWorld()->addSound($this->position->center(), new FizzSound(2.6 + (Utils::getRandomFloat() - Utils::getRandomFloat()) * 0.8));
} }
return true; return true;
} }

View File

@ -89,7 +89,7 @@ class PinkPetals extends Flowable{
if($this->count < self::MAX_COUNT){ if($this->count < self::MAX_COUNT){
$grew = BlockEventHelper::grow($this, (clone $this)->setCount($this->count + 1), $player); $grew = BlockEventHelper::grow($this, (clone $this)->setCount($this->count + 1), $player);
}else{ }else{
$this->position->getWorld()->dropItem($this->position->asVector3()->add(0, 0.5, 0), $this->asItem()); $this->position->getWorld()->dropItem($this->position->center(), $this->asItem());
$grew = true; $grew = true;
} }
if($grew){ if($grew){

View File

@ -111,7 +111,7 @@ final class PotionCauldron extends FillableCauldron{
if($this->getSide(Facing::UP)->getTypeId() === BlockTypeIds::WATER){ if($this->getSide(Facing::UP)->getTypeId() === BlockTypeIds::WATER){
$cauldron = VanillaBlocks::WATER_CAULDRON()->setFillLevel(FillableCauldron::MAX_FILL_LEVEL); $cauldron = VanillaBlocks::WATER_CAULDRON()->setFillLevel(FillableCauldron::MAX_FILL_LEVEL);
$world->setBlock($this->position, $cauldron); $world->setBlock($this->position, $cauldron);
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), $cauldron->getFillSound()); $world->addSound($this->position->center(), $cauldron->getFillSound());
} }
} }
} }

View File

@ -139,7 +139,7 @@ abstract class PressurePlate extends Transparent{
if($newState !== null){ if($newState !== null){
$world->setBlock($this->position, $newState); $world->setBlock($this->position, $newState);
if($pressedChange !== null){ if($pressedChange !== null){
$world->addSound($this->position->asVector3(), $pressedChange ? $world->addSound($this->position->center(), $pressedChange ?
new PressurePlateActivateSound($this) : new PressurePlateActivateSound($this) :
new PressurePlateDeactivateSound($this) new PressurePlateDeactivateSound($this)
); );

View File

@ -38,7 +38,7 @@ class Pumpkin extends Opaque{
$item->applyDamage(1); $item->applyDamage(1);
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$world->setBlock($this->position, VanillaBlocks::CARVED_PUMPKIN()->setFacing($face)); $world->setBlock($this->position, VanillaBlocks::CARVED_PUMPKIN()->setFacing($face));
$world->dropItem($this->position->asVector3()->add(0.5, 0.5, 0.5), VanillaItems::PUMPKIN_SEEDS()->setCount(1)); $world->dropItem($this->position->center(), VanillaItems::PUMPKIN_SEEDS()->setCount(1));
return true; return true;
} }
return false; return false;

View File

@ -81,7 +81,7 @@ class SweetBerryBush extends Flowable{
} }
}elseif(($dropAmount = $this->getBerryDropAmount()) > 0){ }elseif(($dropAmount = $this->getBerryDropAmount()) > 0){
$world->setBlock($this->position, $this->setAge(self::STAGE_BUSH_NO_BERRIES)); $world->setBlock($this->position, $this->setAge(self::STAGE_BUSH_NO_BERRIES));
$posV3 = $this->position->asVector3(); $posV3 = $this->position->center();
$world->dropItem($posV3, $this->asItem()->setCount($dropAmount)); $world->dropItem($posV3, $this->asItem()->setCount($dropAmount));
$world->addSound($posV3, new SweetBerriesPickSound()); $world->addSound($posV3, new SweetBerriesPickSound());
} }

View File

@ -88,7 +88,7 @@ class Trapdoor extends Transparent{
$this->open = !$this->open; $this->open = !$this->open;
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$world->setBlock($this->position, $this); $world->setBlock($this->position, $this);
$world->addSound($this->position->asVector3(), new DoorSound()); $world->addSound($this->position->center(), new DoorSound());
return true; return true;
} }
} }

View File

@ -120,7 +120,7 @@ final class WaterCauldron extends FillableCauldron{
}) !== null && ($newColor = $dyeColor->getRgbValue())->toRGBA() !== $this->customWaterColor?->toRGBA() }) !== null && ($newColor = $dyeColor->getRgbValue())->toRGBA() !== $this->customWaterColor?->toRGBA()
){ ){
$world->setBlock($this->position, $this->setCustomWaterColor($this->customWaterColor === null ? $newColor : Color::mix($this->customWaterColor, $newColor))); $world->setBlock($this->position, $this->setCustomWaterColor($this->customWaterColor === null ? $newColor : Color::mix($this->customWaterColor, $newColor)));
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new CauldronAddDyeSound()); $world->addSound($this->position->center(), new CauldronAddDyeSound());
$item->pop(); $item->pop();
}elseif($item instanceof Potion || $item instanceof SplashPotion){ //TODO: lingering potion }elseif($item instanceof Potion || $item instanceof SplashPotion){ //TODO: lingering potion
@ -140,12 +140,12 @@ final class WaterCauldron extends FillableCauldron{
} && $item->getCustomColor()?->toRGBA() !== $this->customWaterColor->toRGBA()){ } && $item->getCustomColor()?->toRGBA() !== $this->customWaterColor->toRGBA()){
$item->setCustomColor($this->customWaterColor); $item->setCustomColor($this->customWaterColor);
$world->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::DYE_ARMOR_USE_AMOUNT)); $world->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::DYE_ARMOR_USE_AMOUNT));
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new CauldronDyeItemSound()); $world->addSound($this->position->center(), new CauldronDyeItemSound());
} }
}elseif($item->getCustomColor() !== null){ }elseif($item->getCustomColor() !== null){
$item->clearCustomColor(); $item->clearCustomColor();
$world->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::CLEAN_ARMOR_USE_AMOUNT)); $world->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::CLEAN_ARMOR_USE_AMOUNT));
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new CauldronCleanItemSound()); $world->addSound($this->position->center(), new CauldronCleanItemSound());
} }
}elseif($item instanceof Banner){ }elseif($item instanceof Banner){
$patterns = $item->getPatterns(); $patterns = $item->getPatterns();
@ -154,7 +154,7 @@ final class WaterCauldron extends FillableCauldron{
$item->setPatterns($patterns); $item->setPatterns($patterns);
$world->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::CLEAN_BANNER_USE_AMOUNT)); $world->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::CLEAN_BANNER_USE_AMOUNT));
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new CauldronCleanItemSound()); $world->addSound($this->position->center(), new CauldronCleanItemSound());
} }
}elseif(ItemTypeIds::toBlockTypeId($item->getTypeId()) === BlockTypeIds::DYED_SHULKER_BOX){ }elseif(ItemTypeIds::toBlockTypeId($item->getTypeId()) === BlockTypeIds::DYED_SHULKER_BOX){
if($this->customWaterColor === null){ if($this->customWaterColor === null){
@ -165,7 +165,7 @@ final class WaterCauldron extends FillableCauldron{
$returnedItems[] = $newItem; $returnedItems[] = $newItem;
$world->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::CLEAN_SHULKER_BOX_USE_AMOUNT)); $world->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::CLEAN_SHULKER_BOX_USE_AMOUNT));
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new CauldronCleanItemSound()); $world->addSound($this->position->center(), new CauldronCleanItemSound());
} }
}else{ }else{
match($item->getTypeId()){ match($item->getTypeId()){
@ -202,7 +202,7 @@ final class WaterCauldron extends FillableCauldron{
} }
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$world->setBlock($this->position, $this->setCustomWaterColor(null)->setFillLevel(FillableCauldron::MAX_FILL_LEVEL)); $world->setBlock($this->position, $this->setCustomWaterColor(null)->setFillLevel(FillableCauldron::MAX_FILL_LEVEL));
$world->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), $this->getFillSound()); $world->addSound($this->position->center(), $this->getFillSound());
} }
} }
} }

View File

@ -67,7 +67,7 @@ class Wood extends Opaque{
$item->applyDamage(1); $item->applyDamage(1);
$this->stripped = true; $this->stripped = true;
$this->position->getWorld()->setBlock($this->position, $this); $this->position->getWorld()->setBlock($this->position, $this);
$this->position->getWorld()->addSound($this->position->asVector3(), new ItemUseOnBlockSound($this)); $this->position->getWorld()->addSound($this->position->center(), new ItemUseOnBlockSound($this));
return true; return true;
} }
return false; return false;

View File

@ -50,7 +50,7 @@ trait AnimatedBlockInventoryTrait{
if($this->holder->isValid() && $this->getViewerCount() === 1){ if($this->holder->isValid() && $this->getViewerCount() === 1){
//TODO: this crap really shouldn't be managed by the inventory //TODO: this crap really shouldn't be managed by the inventory
$this->animateBlock(true); $this->animateBlock(true);
$this->holder->getWorld()->addSound($this->holder->asVector3()->add(0.5, 0.5, 0.5), $this->getOpenSound()); $this->holder->getWorld()->addSound($this->holder->center(), $this->getOpenSound());
} }
} }
@ -60,7 +60,7 @@ trait AnimatedBlockInventoryTrait{
if($this->holder->isValid() && $this->getViewerCount() === 1){ if($this->holder->isValid() && $this->getViewerCount() === 1){
//TODO: this crap really shouldn't be managed by the inventory //TODO: this crap really shouldn't be managed by the inventory
$this->animateBlock(false); $this->animateBlock(false);
$this->holder->getWorld()->addSound($this->holder->asVector3()->add(0.5, 0.5, 0.5), $this->getCloseSound()); $this->holder->getWorld()->addSound($this->holder->center(), $this->getCloseSound());
} }
parent::onClose($who); parent::onClose($who);
} }

View File

@ -51,6 +51,6 @@ class ChestInventory extends SimpleInventory implements BlockInventory{
$holder = $this->getHolder(); $holder = $this->getHolder();
//event ID is always 1 for a chest //event ID is always 1 for a chest
$holder->getWorld()->broadcastPacketToViewers($holder->asVector3(), BlockEventPacket::create(new ProtocolBlockPosition($holder->x, $holder->y, $holder->z), 1, $isOpen ? 1 : 0)); $holder->getWorld()->broadcastPacketOnBlock($holder, BlockEventPacket::create(new ProtocolBlockPosition($holder->x, $holder->y, $holder->z), 1, $isOpen ? 1 : 0));
} }
} }

View File

@ -75,8 +75,7 @@ class EnderChestInventory extends DelegateInventory implements BlockInventory{
$holder = $this->getHolder(); $holder = $this->getHolder();
//event ID is always 1 for a chest //event ID is always 1 for a chest
//TODO: maybe broadcast should use BlockPosition $holder->getWorld()->broadcastPacketOnBlock($holder, BlockEventPacket::create(new ProtocolBlockPosition($holder->x, $holder->y, $holder->z), 1, $isOpen ? 1 : 0));
$holder->getWorld()->broadcastPacketToViewers($holder->asVector3(), BlockEventPacket::create(new ProtocolBlockPosition($holder->x, $holder->y, $holder->z), 1, $isOpen ? 1 : 0));
} }
public function onClose(Player $who) : void{ public function onClose(Player $who) : void{

View File

@ -63,7 +63,6 @@ class ShulkerBoxInventory extends SimpleInventory implements BlockInventory{
$holder = $this->getHolder(); $holder = $this->getHolder();
//event ID is always 1 for a chest //event ID is always 1 for a chest
//TODO: maybe broadcast should use block position $holder->getWorld()->broadcastPacketOnBlock($holder, BlockEventPacket::create(new ProtocolBlockPosition($holder->x, $holder->y, $holder->z), 1, $isOpen ? 1 : 0));
$holder->getWorld()->broadcastPacketToViewers($holder->asVector3(), BlockEventPacket::create(new ProtocolBlockPosition($holder->x, $holder->y, $holder->z), 1, $isOpen ? 1 : 0));
} }
} }

View File

@ -214,7 +214,7 @@ class BrewingStand extends Spawnable implements Container, Nameable{
} }
if($anythingBrewed){ if($anythingBrewed){
$this->position->getWorld()->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), new PotionFinishBrewingSound()); $this->position->getWorld()->addSound($this->position->center(), new PotionFinishBrewingSound());
} }
$ingredient->pop(); $ingredient->pop();

View File

@ -102,7 +102,7 @@ trait ContainerTrait{
$pos = $this->getPosition(); $pos = $this->getPosition();
$world = $pos->getWorld(); $world = $pos->getWorld();
$dropPos = $pos->asVector3()->add(0.5, 0.5, 0.5); $dropPos = $pos->center();
foreach($inv->getContents() as $k => $item){ foreach($inv->getContents() as $k => $item){
$world->dropItem($dropPos, $item); $world->dropItem($dropPos, $item);
} }

View File

@ -65,6 +65,6 @@ class Jukebox extends Spawnable{
} }
protected function onBlockDestroyedHook() : void{ protected function onBlockDestroyedHook() : void{
$this->position->getWorld()->addSound($this->position->asVector3(), new RecordStopSound()); $this->position->getWorld()->addSound($this->position->center(), new RecordStopSound());
} }
} }

View File

@ -34,7 +34,7 @@ trait AmethystTrait{
* @see Block::onProjectileHit() * @see Block::onProjectileHit()
*/ */
public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{ public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{
$this->position->getWorld()->addSound($this->position->asVector3(), new AmethystBlockChimeSound()); $this->position->getWorld()->addSound($this->position->center(), new AmethystBlockChimeSound());
$this->position->getWorld()->addSound($this->position->asVector3(), new BlockPunchSound($this)); $this->position->getWorld()->addSound($this->position->center(), new BlockPunchSound($this));
} }
} }

View File

@ -54,9 +54,9 @@ trait CandleTrait{
}elseif($item->getTypeId() === ItemTypeIds::FIRE_CHARGE){ }elseif($item->getTypeId() === ItemTypeIds::FIRE_CHARGE){
$item->pop(); $item->pop();
//TODO: not sure if this is intentional, but it's what Bedrock currently does as of 1.20.10 //TODO: not sure if this is intentional, but it's what Bedrock currently does as of 1.20.10
$this->position->getWorld()->addSound($this->position->asVector3(), new BlazeShootSound()); $this->position->getWorld()->addSound($this->position->center(), new BlazeShootSound());
} }
$this->position->getWorld()->addSound($this->position->asVector3(), new FlintSteelSound()); $this->position->getWorld()->addSound($this->position->center(), new FlintSteelSound());
$this->position->getWorld()->setBlock($this->position, $this->setLit(true)); $this->position->getWorld()->setBlock($this->position, $this->setLit(true));
return true; return true;
@ -65,7 +65,7 @@ trait CandleTrait{
if(!$this->lit){ if(!$this->lit){
return true; return true;
} }
$this->position->getWorld()->addSound($this->position->asVector3(), new FireExtinguishSound()); $this->position->getWorld()->addSound($this->position->center(), new FireExtinguishSound());
$this->position->getWorld()->setBlock($this->position, $this->setLit(false)); $this->position->getWorld()->setBlock($this->position, $this->setLit(false));
return true; return true;

View File

@ -63,7 +63,7 @@ trait CopperTrait{
$this->waxed = true; $this->waxed = true;
$this->position->getWorld()->setBlock($this->position, $this); $this->position->getWorld()->setBlock($this->position, $this);
//TODO: orange particles are supposed to appear when applying wax //TODO: orange particles are supposed to appear when applying wax
$this->position->getWorld()->addSound($this->position->asVector3(), new CopperWaxApplySound()); $this->position->getWorld()->addSound($this->position->center(), new CopperWaxApplySound());
$item->pop(); $item->pop();
return true; return true;
} }
@ -73,7 +73,7 @@ trait CopperTrait{
$this->waxed = false; $this->waxed = false;
$this->position->getWorld()->setBlock($this->position, $this); $this->position->getWorld()->setBlock($this->position, $this);
//TODO: white particles are supposed to appear when removing wax //TODO: white particles are supposed to appear when removing wax
$this->position->getWorld()->addSound($this->position->asVector3(), new CopperWaxRemoveSound()); $this->position->getWorld()->addSound($this->position->center(), new CopperWaxRemoveSound());
$item->applyDamage(1); $item->applyDamage(1);
return true; return true;
} }
@ -83,7 +83,7 @@ trait CopperTrait{
$this->oxidation = $previousOxidation; $this->oxidation = $previousOxidation;
$this->position->getWorld()->setBlock($this->position, $this); $this->position->getWorld()->setBlock($this->position, $this);
//TODO: turquoise particles are supposed to appear when removing oxidation //TODO: turquoise particles are supposed to appear when removing oxidation
$this->position->getWorld()->addSound($this->position->asVector3(), new ScrapeSound()); $this->position->getWorld()->addSound($this->position->center(), new ScrapeSound());
$item->applyDamage(1); $item->applyDamage(1);
return true; return true;
} }

View File

@ -56,7 +56,7 @@ class Bucket extends Item{
$ev->call(); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$player->getWorld()->setBlock($blockClicked->getPosition(), VanillaBlocks::AIR()); $player->getWorld()->setBlock($blockClicked->getPosition(), VanillaBlocks::AIR());
$player->getWorld()->addSound($blockClicked->getPosition()->asVector3()->add(0.5, 0.5, 0.5), $blockClicked->getBucketFillSound()); $player->getWorld()->addSound($blockClicked->getPosition()->center(), $blockClicked->getBucketFillSound());
$this->pop(); $this->pop();
$returnedItems[] = $ev->getItem(); $returnedItems[] = $ev->getItem();

View File

@ -36,7 +36,7 @@ class FireCharge extends Item{
if($blockReplace->getTypeId() === BlockTypeIds::AIR){ if($blockReplace->getTypeId() === BlockTypeIds::AIR){
$world = $player->getWorld(); $world = $player->getWorld();
$world->setBlock($blockReplace->getPosition(), VanillaBlocks::FIRE()); $world->setBlock($blockReplace->getPosition(), VanillaBlocks::FIRE());
$world->addSound($blockReplace->getPosition()->asVector3()->add(0.5, 0.5, 0.5), new BlazeShootSound()); $world->addSound($blockReplace->getPosition()->center(), new BlazeShootSound());
$this->pop(); $this->pop();

View File

@ -36,7 +36,7 @@ class FlintSteel extends Tool{
if($blockReplace->getTypeId() === BlockTypeIds::AIR){ if($blockReplace->getTypeId() === BlockTypeIds::AIR){
$world = $player->getWorld(); $world = $player->getWorld();
$world->setBlock($blockReplace->getPosition(), VanillaBlocks::FIRE()); $world->setBlock($blockReplace->getPosition(), VanillaBlocks::FIRE());
$world->addSound($blockReplace->getPosition()->asVector3()->add(0.5, 0.5, 0.5), new FlintSteelSound()); $world->addSound($blockReplace->getPosition()->center(), new FlintSteelSound());
$this->applyDamage(1); $this->applyDamage(1);

View File

@ -66,7 +66,7 @@ class LiquidBucket extends Item{
$ev->call(); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$player->getWorld()->setBlock($blockReplace->getPosition(), $resultBlock->getFlowingForm()); $player->getWorld()->setBlock($blockReplace->getPosition(), $resultBlock->getFlowingForm());
$player->getWorld()->addSound($blockReplace->getPosition()->asVector3()->add(0.5, 0.5, 0.5), $resultBlock->getBucketEmptySound()); $player->getWorld()->addSound($blockReplace->getPosition()->center(), $resultBlock->getBucketEmptySound());
$this->pop(); $this->pop();
$returnedItems[] = $ev->getItem(); $returnedItems[] = $ev->getItem();

View File

@ -74,14 +74,13 @@ class PaintingItem extends Item{
$motive = $motives[array_rand($motives)]; $motive = $motives[array_rand($motives)];
$replacePos = $blockReplace->getPosition(); $replacePos = $blockReplace->getPosition();
$replaceVec3 = $replacePos->asVector3();
$clickedPos = $blockClicked->getPosition(); $clickedPos = $blockClicked->getPosition();
$entity = new Painting(Location::fromObject($replaceVec3, $replacePos->getWorld()), $clickedPos, $face, $motive); $entity = new Painting(Location::fromObject($replacePos->asVector3(), $replacePos->getWorld()), $clickedPos, $face, $motive);
$this->pop(); $this->pop();
$entity->spawnToAll(); $entity->spawnToAll();
$player->getWorld()->addSound($replaceVec3->add(0.5, 0.5, 0.5), new PaintingPlaceSound()); $player->getWorld()->addSound($replacePos->center(), new PaintingPlaceSound());
return ItemUseResult::SUCCESS; return ItemUseResult::SUCCESS;
} }
} }

View File

@ -1004,7 +1004,7 @@ class InGamePacketHandler extends PacketHandler{
$lectern = $world->getBlockAt($pos->getX(), $pos->getY(), $pos->getZ()); $lectern = $world->getBlockAt($pos->getX(), $pos->getY(), $pos->getZ());
$lecternPos = $lectern->getPosition(); $lecternPos = $lectern->getPosition();
if($lectern instanceof Lectern && $this->player->canInteract($lecternPos->asVector3(), 15)){ if($lectern instanceof Lectern && $this->player->canInteract($lecternPos->center(), 15)){
if(!$lectern->onPageTurn($packet->page)){ if(!$lectern->onPageTurn($packet->page)){
$this->syncBlocksNearby($lecternPos, null); $this->syncBlocksNearby($lecternPos, null);
} }

View File

@ -1834,7 +1834,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$block = $target->getSide($face); $block = $target->getSide($face);
if($block->hasTypeTag(BlockTypeTags::FIRE)){ if($block->hasTypeTag(BlockTypeTags::FIRE)){
$this->getWorld()->setBlock($block->getPosition(), VanillaBlocks::AIR()); $this->getWorld()->setBlock($block->getPosition(), VanillaBlocks::AIR());
$this->getWorld()->addSound($block->getPosition()->asVector3()->add(0.5, 0.5, 0.5), new FireExtinguishSound()); $this->getWorld()->addSound($block->getPosition()->center(), new FireExtinguishSound());
return true; return true;
} }
@ -1865,7 +1865,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
public function breakBlock(BlockPosition $pos) : bool{ public function breakBlock(BlockPosition $pos) : bool{
$this->removeCurrentWindow(); $this->removeCurrentWindow();
if($this->canInteract($pos->asVector3()->add(0.5, 0.5, 0.5), $this->isCreative() ? self::MAX_REACH_DISTANCE_CREATIVE : self::MAX_REACH_DISTANCE_SURVIVAL)){ if($this->canInteract($pos->center(), $this->isCreative() ? self::MAX_REACH_DISTANCE_CREATIVE : self::MAX_REACH_DISTANCE_SURVIVAL)){
$this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers()); $this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers());
$this->stopBreakBlock($pos); $this->stopBreakBlock($pos);
$item = $this->inventory->getItemInHand(); $item = $this->inventory->getItemInHand();
@ -1891,7 +1891,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
public function interactBlock(BlockPosition $pos, int $face, Vector3 $clickOffset) : bool{ public function interactBlock(BlockPosition $pos, int $face, Vector3 $clickOffset) : bool{
$this->setUsingItem(false); $this->setUsingItem(false);
if($this->canInteract($pos->asVector3()->add(0.5, 0.5, 0.5), $this->isCreative() ? self::MAX_REACH_DISTANCE_CREATIVE : self::MAX_REACH_DISTANCE_SURVIVAL)){ if($this->canInteract($pos->center(), $this->isCreative() ? self::MAX_REACH_DISTANCE_CREATIVE : self::MAX_REACH_DISTANCE_SURVIVAL)){
$this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers()); $this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers());
$item = $this->inventory->getItemInHand(); //this is a copy of the real item $item = $this->inventory->getItemInHand(); //this is a copy of the real item
$oldItem = clone $item; $oldItem = clone $item;

View File

@ -51,10 +51,9 @@ final class SurvivalBlockBreakHandler{
){ ){
$this->breakSpeed = $this->calculateBreakProgressPerTick(); $this->breakSpeed = $this->calculateBreakProgressPerTick();
if($this->breakSpeed > 0){ if($this->breakSpeed > 0){
$vector3 = $this->blockPos->asVector3(); $this->player->getWorld()->broadcastPacketOnBlock(
$this->player->getWorld()->broadcastPacketToViewers( $this->blockPos,
$vector3, LevelEventPacket::create(LevelEvent::BLOCK_START_BREAK, (int) (65535 * $this->breakSpeed), $this->blockPos->asVector3())
LevelEventPacket::create(LevelEvent::BLOCK_START_BREAK, (int) (65535 * $this->breakSpeed), $vector3)
); );
} }
} }
@ -120,11 +119,10 @@ final class SurvivalBlockBreakHandler{
} }
public function __destruct(){ public function __destruct(){
$vector3 = $this->blockPos->asVector3();
if($this->player->getWorld()->isInLoadedTerrain($vector3)){ if($this->player->getWorld()->isInLoadedTerrain($vector3)){
$this->player->getWorld()->broadcastPacketToViewers( $this->player->getWorld()->broadcastPacketOnBlock(
$vector3, $this->blockPos,
LevelEventPacket::create(LevelEvent::BLOCK_STOP_BREAK, 0, $vector3) LevelEventPacket::create(LevelEvent::BLOCK_STOP_BREAK, 0, $this->blockPos->asVector3())
); );
} }
} }

View File

@ -206,7 +206,7 @@ class Explosion{
}else{ }else{
if(mt_rand(0, 100) < $yield){ if(mt_rand(0, 100) < $yield){
foreach($block->getDrops($air) as $drop){ foreach($block->getDrops($air) as $drop){
$this->world->dropItem($pos->asVector3()->add(0.5, 0.5, 0.5), $drop); $this->world->dropItem($pos->center(), $drop);
} }
} }
if(($t = $this->world->getTileAt($pos->x, $pos->y, $pos->z)) !== null){ if(($t = $this->world->getTileAt($pos->x, $pos->y, $pos->z)) !== null){

View File

@ -712,7 +712,7 @@ class World implements ChunkManager{
if(count($pk) > 0){ if(count($pk) > 0){
if($players === $this->getViewersForPosition($pos)){ if($players === $this->getViewersForPosition($pos)){
foreach($pk as $e){ foreach($pk as $e){
$this->broadcastPacketToViewers($pos, $e); $this->broadcastPacketOnPosition($pos, $e);
} }
}else{ }else{
NetworkBroadcastUtils::broadcastPackets($this->filterViewersForPosition($pos, $players), $pk); NetworkBroadcastUtils::broadcastPackets($this->filterViewersForPosition($pos, $players), $pk);
@ -741,7 +741,7 @@ class World implements ChunkManager{
if(count($pk) > 0){ if(count($pk) > 0){
if($players === $this->getViewersForPosition($pos)){ if($players === $this->getViewersForPosition($pos)){
foreach($pk as $e){ foreach($pk as $e){
$this->broadcastPacketToViewers($pos, $e); $this->broadcastPacketOnPosition($pos, $e);
} }
}else{ }else{
NetworkBroadcastUtils::broadcastPackets($this->filterViewersForPosition($pos, $players), $pk); NetworkBroadcastUtils::broadcastPackets($this->filterViewersForPosition($pos, $players), $pk);
@ -793,10 +793,14 @@ class World implements ChunkManager{
/** /**
* Broadcasts a packet to every player who has the target position within their view distance. * Broadcasts a packet to every player who has the target position within their view distance.
*/ */
public function broadcastPacketToViewers(Vector3 $pos, ClientboundPacket $packet) : void{ public function broadcastPacketOnPosition(Vector3 $pos, ClientboundPacket $packet) : void{
$this->broadcastPacketToPlayersUsingChunk($pos->getFloorX() >> Chunk::COORD_BIT_SIZE, $pos->getFloorZ() >> Chunk::COORD_BIT_SIZE, $packet); $this->broadcastPacketToPlayersUsingChunk($pos->getFloorX() >> Chunk::COORD_BIT_SIZE, $pos->getFloorZ() >> Chunk::COORD_BIT_SIZE, $packet);
} }
public function broadcastPacketOnBlock(BlockPosition $pos, ClientboundPacket $packet) : void{
$this->broadcastPacketToPlayersUsingChunk($pos->x >> Chunk::COORD_BIT_SIZE, $pos->z >> Chunk::COORD_BIT_SIZE, $packet);
}
private function broadcastPacketToPlayersUsingChunk(int $chunkX, int $chunkZ, ClientboundPacket $packet) : void{ private function broadcastPacketToPlayersUsingChunk(int $chunkX, int $chunkZ, ClientboundPacket $packet) : void{
if(!isset($this->packetBuffersByChunk[$index = World::chunkHash($chunkX, $chunkZ)])){ if(!isset($this->packetBuffersByChunk[$index = World::chunkHash($chunkX, $chunkZ)])){
$this->packetBuffersByChunk[$index] = [$packet]; $this->packetBuffersByChunk[$index] = [$packet];
@ -2101,7 +2105,7 @@ class World implements ChunkManager{
$item->onDestroyBlock($target, $returnedItems); $item->onDestroyBlock($target, $returnedItems);
if(count($drops) > 0){ if(count($drops) > 0){
$dropPos = $vector->asVector3()->add(0.5, 0.5, 0.5); $dropPos = $vector->center();
foreach($drops as $drop){ foreach($drops as $drop){
if(!$drop->isNull()){ if(!$drop->isNull()){
$this->dropItem($dropPos, $drop); $this->dropItem($dropPos, $drop);
@ -2110,7 +2114,7 @@ class World implements ChunkManager{
} }
if($xpDrop > 0){ if($xpDrop > 0){
$this->dropExperience($vector->asVector3()->add(0.5, 0.5, 0.5), $xpDrop); $this->dropExperience($vector->center(), $xpDrop);
} }
return true; return true;
@ -2121,7 +2125,7 @@ class World implements ChunkManager{
*/ */
private function destroyBlockInternal(Block $target, Item $item, ?Player $player, bool $createParticles, array &$returnedItems) : void{ private function destroyBlockInternal(Block $target, Item $item, ?Player $player, bool $createParticles, array &$returnedItems) : void{
if($createParticles){ if($createParticles){
$this->addParticle($target->getPosition()->asVector3()->add(0.5, 0.5, 0.5), new BlockBreakParticle($target)); $this->addParticle($target->getPosition()->center(), new BlockBreakParticle($target));
} }
$target->onBreak($item, $player, $returnedItems); $target->onBreak($item, $player, $returnedItems);
@ -2269,7 +2273,7 @@ class World implements ChunkManager{
} }
if($playSound){ if($playSound){
$this->addSound($hand->getPosition()->asVector3(), new BlockPlaceSound($hand)); $this->addSound($hand->getPosition()->center(), new BlockPlaceSound($hand));
} }
$item->pop(); $item->pop();