From 39662bdc3bc1c0f9498d5c70ebf5fed2b4d34d0a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 4 Dec 2024 16:13:21 +0000 Subject: [PATCH] moar changes --- src/block/BaseSign.php | 4 ++-- src/block/Bed.php | 2 +- src/block/Bell.php | 4 ++-- src/block/BigDripleafHead.php | 6 +++--- src/block/Block.php | 2 +- src/block/Button.php | 4 ++-- src/block/CakeWithCandle.php | 2 +- src/block/Campfire.php | 10 +++++----- src/block/Cauldron.php | 4 ++-- src/block/CaveVines.php | 4 ++-- src/block/ChorusFlower.php | 4 ++-- src/block/Dirt.php | 4 ++-- src/block/Door.php | 2 +- src/block/DragonEgg.php | 2 +- src/block/FenceGate.php | 2 +- src/block/FillableCauldron.php | 4 ++-- src/block/FlowerPot.php | 2 +- src/block/Furnace.php | 2 +- src/block/Grass.php | 6 +++--- src/block/ItemFrame.php | 8 ++++---- src/block/Jukebox.php | 4 ++-- src/block/Lectern.php | 4 ++-- src/block/Lever.php | 2 +- src/block/Liquid.php | 2 +- src/block/PinkPetals.php | 2 +- src/block/PotionCauldron.php | 2 +- src/block/PressurePlate.php | 2 +- src/block/Pumpkin.php | 2 +- src/block/SweetBerryBush.php | 2 +- src/block/Trapdoor.php | 2 +- src/block/WaterCauldron.php | 12 ++++++------ src/block/Wood.php | 2 +- .../inventory/AnimatedBlockInventoryTrait.php | 4 ++-- src/block/inventory/ChestInventory.php | 2 +- src/block/inventory/EnderChestInventory.php | 3 +-- src/block/inventory/ShulkerBoxInventory.php | 3 +-- src/block/tile/BrewingStand.php | 2 +- src/block/tile/ContainerTrait.php | 2 +- src/block/tile/Jukebox.php | 2 +- src/block/utils/AmethystTrait.php | 4 ++-- src/block/utils/CandleTrait.php | 6 +++--- src/block/utils/CopperTrait.php | 6 +++--- src/item/Bucket.php | 2 +- src/item/FireCharge.php | 2 +- src/item/FlintSteel.php | 2 +- src/item/LiquidBucket.php | 2 +- src/item/PaintingItem.php | 5 ++--- .../mcpe/handler/InGamePacketHandler.php | 2 +- src/player/Player.php | 6 +++--- src/player/SurvivalBlockBreakHandler.php | 14 ++++++-------- src/world/Explosion.php | 2 +- src/world/World.php | 18 +++++++++++------- 52 files changed, 102 insertions(+), 103 deletions(-) diff --git a/src/block/BaseSign.php b/src/block/BaseSign.php index 8613ddbc6..b30a626aa 100644 --- a/src/block/BaseSign.php +++ b/src/block/BaseSign.php @@ -145,7 +145,7 @@ abstract class BaseSign extends Transparent{ 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)){ - $this->position->getWorld()->addSound($this->position->asVector3(), new InkSacUseSound()); + $this->position->getWorld()->addSound($this->position->center(), new InkSacUseSound()); return true; } return false; @@ -183,7 +183,7 @@ abstract class BaseSign extends Transparent{ $color->toARGB() !== $this->text->getBaseColor()->toARGB() && $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; } }elseif(match($item->getTypeId()){ diff --git a/src/block/Bed.php b/src/block/Bed.php index ebc31ded2..6606d75d6 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -128,7 +128,7 @@ class Bed extends Transparent{ $player->sendMessage(TextFormat::GRAY . "This bed is incomplete"); 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)); return true; } diff --git a/src/block/Bell.php b/src/block/Bell.php index 0c677f347..5b5d1c7db 100644 --- a/src/block/Bell.php +++ b/src/block/Bell.php @@ -143,10 +143,10 @@ final class Bell extends Transparent{ public function ring(int $faceHit) : void{ $world = $this->position->getWorld(); - $world->addSound($this->position->asVector3(), new BellRingSound()); + $world->addSound($this->position->center(), new BellRingSound()); $tile = $world->getTile($this->position); if($tile instanceof TileBell){ - $world->broadcastPacketToViewers($this->position->asVector3(), $tile->createFakeUpdatePacket($faceHit)); + $world->broadcastPacketOnBlock($this->position, $tile->createFakeUpdatePacket($faceHit)); } } diff --git a/src/block/BigDripleafHead.php b/src/block/BigDripleafHead.php index 948afc717..b2180fd03 100644 --- a/src/block/BigDripleafHead.php +++ b/src/block/BigDripleafHead.php @@ -93,7 +93,7 @@ class BigDripleafHead extends BaseBigDripleaf{ public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{ if($this->leafState !== 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::FULL_TILT){ $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{ $this->setTiltAndScheduleTick(match($this->leafState){ DripleafState::UNSTABLE => DripleafState::PARTIAL_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()); } } } diff --git a/src/block/Block.php b/src/block/Block.php index d27ffccc0..4d0a3399c 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -398,7 +398,7 @@ class Block{ * @var Tile $tile * @see Tile::__construct() */ - $tile = new $tileType($world, $this->position->asVector3()); + $tile = new $tileType($this->position); $world->addTile($tile); } } diff --git a/src/block/Button.php b/src/block/Button.php index caa557610..8b94d3f40 100644 --- a/src/block/Button.php +++ b/src/block/Button.php @@ -67,7 +67,7 @@ abstract class Button extends Flowable{ $world = $this->position->getWorld(); $world->setBlock($this->position, $this); $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; @@ -78,7 +78,7 @@ abstract class Button extends Flowable{ $this->pressed = false; $world = $this->position->getWorld(); $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()); } } diff --git a/src/block/CakeWithCandle.php b/src/block/CakeWithCandle.php index df558739b..5c936d864 100644 --- a/src/block/CakeWithCandle.php +++ b/src/block/CakeWithCandle.php @@ -76,6 +76,6 @@ class CakeWithCandle extends BaseCake{ public function onConsume(Living $consumer) : void{ 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()); } } diff --git a/src/block/Campfire.php b/src/block/Campfire.php index a9bbfdda7..2ed57e636 100644 --- a/src/block/Campfire.php +++ b/src/block/Campfire.php @@ -185,7 +185,7 @@ class Campfire extends Transparent{ if($item->getTypeId() === ItemTypeIds::FIRE_CHARGE){ $item->pop(); $this->ignite(); - $this->position->getWorld()->addSound($this->position->asVector3(), new BlazeShootSound()); + $this->position->getWorld()->addSound($this->position->center(), new BlazeShootSound()); return true; }elseif($item->getTypeId() === ItemTypeIds::FLINT_AND_STEEL || $item->hasEnchantment(VanillaEnchantments::FIRE_ASPECT())){ if($item instanceof Durable){ @@ -205,7 +205,7 @@ class Campfire extends Transparent{ $ingredient->setCount(1); if(count($this->inventory->addItem($ingredient)) === 0){ $item->pop(); - $this->position->getWorld()->addSound($this->position->asVector3(), new ItemFrameAddItemSound()); + $this->position->getWorld()->addSound($this->position->center(), new ItemFrameAddItemSound()); return true; } } @@ -266,19 +266,19 @@ class Campfire extends Transparent{ $this->position->getWorld()->setBlock($this->position, $this); } 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); } } 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)); } 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()->scheduleDelayedBlockUpdate($this->position, self::UPDATE_INTERVAL_TICKS); } diff --git a/src/block/Cauldron.php b/src/block/Cauldron.php index 1d696bdb7..4029ede2e 100644 --- a/src/block/Cauldron.php +++ b/src/block/Cauldron.php @@ -69,7 +69,7 @@ final class Cauldron extends Transparent{ */ 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()->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), $result->getFillSound()); + $this->position->getWorld()->addSound($this->position->center(), $result->getFillSound()); $usedItem->pop(); $returnedItems[] = $returnedItem; @@ -98,7 +98,7 @@ final class Cauldron extends Transparent{ if($this->getSide(Facing::UP)->getTypeId() === BlockTypeIds::WATER){ $cauldron = VanillaBlocks::WATER_CAULDRON()->setFillLevel(FillableCauldron::MAX_FILL_LEVEL); $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()); } } } diff --git a/src/block/CaveVines.php b/src/block/CaveVines.php index 5f961defc..9608b6053 100644 --- a/src/block/CaveVines.php +++ b/src/block/CaveVines.php @@ -90,8 +90,8 @@ class CaveVines extends Flowable{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($this->berries){ - $this->position->getWorld()->dropItem($this->position->asVector3(), $this->asItem()); - $this->position->getWorld()->addSound($this->position->asVector3(), new GlowBerriesPickSound()); + $this->position->getWorld()->dropItem($this->position->center(), $this->asItem()); + $this->position->getWorld()->addSound($this->position->center(), new GlowBerriesPickSound()); $this->position->getWorld()->setBlock($this->position, $this->setBerries(false)); return true; diff --git a/src/block/ChorusFlower.php b/src/block/ChorusFlower.php index 478f1af4b..0f35fea81 100644 --- a/src/block/ChorusFlower.php +++ b/src/block/ChorusFlower.php @@ -192,10 +192,10 @@ final class ChorusFlower extends Flowable{ $ev = new StructureGrowEvent($this, $tx, null); $ev->call(); 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{ - $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)); } } diff --git a/src/block/Dirt.php b/src/block/Dirt.php index 286b83f80..979c9a9d9 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -63,7 +63,7 @@ class Dirt extends Opaque{ $item->applyDamage(1); $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->setBlock($this->position, $newBlock); if($this->dirtType === DirtType::ROOTED){ @@ -83,7 +83,7 @@ class Dirt extends Opaque{ }elseif(($item instanceof Potion || $item instanceof SplashPotion) && $item->getType() === PotionType::WATER){ $item->pop(); $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; } diff --git a/src/block/Door.php b/src/block/Door.php index 7a214a9da..4d75fc0bb 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -152,7 +152,7 @@ class Door extends Transparent{ } $world->setBlock($this->position, $this); - $world->addSound($this->position->asVector3(), new DoorSound()); + $world->addSound($this->position->center(), new DoorSound()); return true; } diff --git a/src/block/DragonEgg.php b/src/block/DragonEgg.php index 2ff36934b..48d895544 100644 --- a/src/block/DragonEgg.php +++ b/src/block/DragonEgg.php @@ -74,7 +74,7 @@ class DragonEgg extends Transparent implements Fallable{ } $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->setBlockAt($blockPos->getFloorX(), $blockPos->getFloorY(), $blockPos->getFloorZ(), $this); break; diff --git a/src/block/FenceGate.php b/src/block/FenceGate.php index 011e88c67..b5478dc96 100644 --- a/src/block/FenceGate.php +++ b/src/block/FenceGate.php @@ -111,7 +111,7 @@ class FenceGate extends Transparent{ $world = $this->position->getWorld(); $world->setBlock($this->position, $this); - $world->addSound($this->position->asVector3(), new DoorSound()); + $world->addSound($this->position->center(), new DoorSound()); return true; } diff --git a/src/block/FillableCauldron.php b/src/block/FillableCauldron.php index 42f03fdad..00f74e6fe 100644 --- a/src/block/FillableCauldron.php +++ b/src/block/FillableCauldron.php @@ -79,7 +79,7 @@ abstract class FillableCauldron extends Transparent{ return; } $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(); $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()->addSound($this->position->asVector3()->add(0.5, 0.5, 0.5), $this->getEmptySound()); + $this->position->getWorld()->addSound($this->position->center(), $this->getEmptySound()); $usedItem->pop(); $returnedItems[] = $returnedItem; diff --git a/src/block/FlowerPot.php b/src/block/FlowerPot.php index a5ea85c1f..c1d99af7d 100644 --- a/src/block/FlowerPot.php +++ b/src/block/FlowerPot.php @@ -111,7 +111,7 @@ class FlowerPot extends Flowable{ $removedItems = $player->getInventory()->addItem(...$removedItems); } 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); diff --git a/src/block/Furnace.php b/src/block/Furnace.php index 00a5edbb3..bef1e394f 100644 --- a/src/block/Furnace.php +++ b/src/block/Furnace.php @@ -73,7 +73,7 @@ class Furnace extends Opaque{ $furnace = $world->getTile($this->position); 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 - $world->addSound($this->position->asVector3(), $furnace->getFurnaceType()->getCookSound()); + $world->addSound($this->position->center(), $furnace->getFurnaceType()->getCookSound()); } $world->scheduleDelayedBlockUpdate($this->position, 1); //TODO: check this } diff --git a/src/block/Grass.php b/src/block/Grass.php index bc879e234..19eb28d85 100644 --- a/src/block/Grass.php +++ b/src/block/Grass.php @@ -88,7 +88,7 @@ class Grass extends Opaque{ $world = $this->position->getWorld(); if($item instanceof Fertilizer){ $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; } @@ -96,14 +96,14 @@ class Grass extends Opaque{ if($item instanceof Hoe){ $item->applyDamage(1); $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); return true; }elseif($item instanceof Shovel){ $item->applyDamage(1); $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); return true; diff --git a/src/block/ItemFrame.php b/src/block/ItemFrame.php index 7550db272..feb7caa7f 100644 --- a/src/block/ItemFrame.php +++ b/src/block/ItemFrame.php @@ -135,11 +135,11 @@ class ItemFrame extends Flowable{ if($this->framedItem !== null){ $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()){ $this->framedItem = $item->pop(); - $this->position->getWorld()->addSound($this->position->asVector3(), new ItemFrameAddItemSound()); + $this->position->getWorld()->addSound($this->position->center(), new ItemFrameAddItemSound()); }else{ return true; } @@ -155,8 +155,8 @@ class ItemFrame extends Flowable{ } $world = $this->position->getWorld(); if(Utils::getRandomFloat() <= $this->itemDropChance){ - $world->dropItem($this->position->asVector3()->add(0.5, 0.5, 0.5), clone $this->framedItem); - $world->addSound($this->position->asVector3(), new ItemFrameRemoveItemSound()); + $world->dropItem($this->position->center(), clone $this->framedItem); + $world->addSound($this->position->center(), new ItemFrameRemoveItemSound()); } $this->setFramedItem(null); $world->setBlock($this->position, $this); diff --git a/src/block/Jukebox.php b/src/block/Jukebox.php index 15e44f87b..b395941f3 100644 --- a/src/block/Jukebox.php +++ b/src/block/Jukebox.php @@ -76,12 +76,12 @@ class Jukebox extends Opaque{ public function startSound() : void{ 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{ - $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{ diff --git a/src/block/Lectern.php b/src/block/Lectern.php index c6461fda3..ff0de83ce 100644 --- a/src/block/Lectern.php +++ b/src/block/Lectern.php @@ -123,7 +123,7 @@ class Lectern extends Transparent{ if($this->book === null && $item instanceof WritableBookBase){ $world = $this->position->getWorld(); $world->setBlock($this->position, $this->setBook($item)); - $world->addSound($this->position->asVector3(), new LecternPlaceBookSound()); + $world->addSound($this->position->center(), new LecternPlaceBookSound()); $item->pop(); } return true; @@ -132,7 +132,7 @@ class Lectern extends Transparent{ public function onAttack(Item $item, int $face, ?Player $player = null) : bool{ if($this->book !== null){ $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)); } return false; diff --git a/src/block/Lever.php b/src/block/Lever.php index 3389d18f0..0416d2557 100644 --- a/src/block/Lever.php +++ b/src/block/Lever.php @@ -95,7 +95,7 @@ class Lever extends Flowable{ $world = $this->position->getWorld(); $world->setBlock($this->position, $this); $world->addSound( - $this->position->asVector3()->add(0.5, 0.5, 0.5), + $this->position->center(), $this->activated ? new RedstonePowerOnSound() : new RedstonePowerOffSound() ); return true; diff --git a/src/block/Liquid.php b/src/block/Liquid.php index 5def61d1b..821d83d43 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -368,7 +368,7 @@ abstract class Liquid extends Transparent{ protected function liquidCollide(Block $cause, Block $result) : bool{ 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; } diff --git a/src/block/PinkPetals.php b/src/block/PinkPetals.php index 97a4dee04..64eb62aca 100644 --- a/src/block/PinkPetals.php +++ b/src/block/PinkPetals.php @@ -89,7 +89,7 @@ class PinkPetals extends Flowable{ if($this->count < self::MAX_COUNT){ $grew = BlockEventHelper::grow($this, (clone $this)->setCount($this->count + 1), $player); }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; } if($grew){ diff --git a/src/block/PotionCauldron.php b/src/block/PotionCauldron.php index 27cf69c6d..eadc256a0 100644 --- a/src/block/PotionCauldron.php +++ b/src/block/PotionCauldron.php @@ -111,7 +111,7 @@ final class PotionCauldron extends FillableCauldron{ if($this->getSide(Facing::UP)->getTypeId() === BlockTypeIds::WATER){ $cauldron = VanillaBlocks::WATER_CAULDRON()->setFillLevel(FillableCauldron::MAX_FILL_LEVEL); $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()); } } } diff --git a/src/block/PressurePlate.php b/src/block/PressurePlate.php index e4292fd97..201088412 100644 --- a/src/block/PressurePlate.php +++ b/src/block/PressurePlate.php @@ -139,7 +139,7 @@ abstract class PressurePlate extends Transparent{ if($newState !== null){ $world->setBlock($this->position, $newState); if($pressedChange !== null){ - $world->addSound($this->position->asVector3(), $pressedChange ? + $world->addSound($this->position->center(), $pressedChange ? new PressurePlateActivateSound($this) : new PressurePlateDeactivateSound($this) ); diff --git a/src/block/Pumpkin.php b/src/block/Pumpkin.php index 039cd3a10..5c0599c40 100644 --- a/src/block/Pumpkin.php +++ b/src/block/Pumpkin.php @@ -38,7 +38,7 @@ class Pumpkin extends Opaque{ $item->applyDamage(1); $world = $this->position->getWorld(); $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 false; diff --git a/src/block/SweetBerryBush.php b/src/block/SweetBerryBush.php index 9dfb71a9e..90d0beb0e 100644 --- a/src/block/SweetBerryBush.php +++ b/src/block/SweetBerryBush.php @@ -81,7 +81,7 @@ class SweetBerryBush extends Flowable{ } }elseif(($dropAmount = $this->getBerryDropAmount()) > 0){ $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->addSound($posV3, new SweetBerriesPickSound()); } diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index 015fd4cf3..f26d526b1 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -88,7 +88,7 @@ class Trapdoor extends Transparent{ $this->open = !$this->open; $world = $this->position->getWorld(); $world->setBlock($this->position, $this); - $world->addSound($this->position->asVector3(), new DoorSound()); + $world->addSound($this->position->center(), new DoorSound()); return true; } } diff --git a/src/block/WaterCauldron.php b/src/block/WaterCauldron.php index 087dd010e..b097caa2a 100644 --- a/src/block/WaterCauldron.php +++ b/src/block/WaterCauldron.php @@ -120,7 +120,7 @@ final class WaterCauldron extends FillableCauldron{ }) !== null && ($newColor = $dyeColor->getRgbValue())->toRGBA() !== $this->customWaterColor?->toRGBA() ){ $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(); }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->setCustomColor($this->customWaterColor); $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){ $item->clearCustomColor(); $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){ $patterns = $item->getPatterns(); @@ -154,7 +154,7 @@ final class WaterCauldron extends FillableCauldron{ $item->setPatterns($patterns); $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){ if($this->customWaterColor === null){ @@ -165,7 +165,7 @@ final class WaterCauldron extends FillableCauldron{ $returnedItems[] = $newItem; $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{ match($item->getTypeId()){ @@ -202,7 +202,7 @@ final class WaterCauldron extends FillableCauldron{ } $world = $this->position->getWorld(); $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()); } } } diff --git a/src/block/Wood.php b/src/block/Wood.php index 1531a16a1..8aa20baab 100644 --- a/src/block/Wood.php +++ b/src/block/Wood.php @@ -67,7 +67,7 @@ class Wood extends Opaque{ $item->applyDamage(1); $this->stripped = true; $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 false; diff --git a/src/block/inventory/AnimatedBlockInventoryTrait.php b/src/block/inventory/AnimatedBlockInventoryTrait.php index b1fdc10a0..6f91b0578 100644 --- a/src/block/inventory/AnimatedBlockInventoryTrait.php +++ b/src/block/inventory/AnimatedBlockInventoryTrait.php @@ -50,7 +50,7 @@ trait AnimatedBlockInventoryTrait{ if($this->holder->isValid() && $this->getViewerCount() === 1){ //TODO: this crap really shouldn't be managed by the inventory $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){ //TODO: this crap really shouldn't be managed by the inventory $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); } diff --git a/src/block/inventory/ChestInventory.php b/src/block/inventory/ChestInventory.php index 219f243b5..cd207e847 100644 --- a/src/block/inventory/ChestInventory.php +++ b/src/block/inventory/ChestInventory.php @@ -51,6 +51,6 @@ class ChestInventory extends SimpleInventory implements BlockInventory{ $holder = $this->getHolder(); //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)); } } diff --git a/src/block/inventory/EnderChestInventory.php b/src/block/inventory/EnderChestInventory.php index e6eeca3e9..861802eda 100644 --- a/src/block/inventory/EnderChestInventory.php +++ b/src/block/inventory/EnderChestInventory.php @@ -75,8 +75,7 @@ class EnderChestInventory extends DelegateInventory implements BlockInventory{ $holder = $this->getHolder(); //event ID is always 1 for a chest - //TODO: maybe broadcast should use BlockPosition - $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)); } public function onClose(Player $who) : void{ diff --git a/src/block/inventory/ShulkerBoxInventory.php b/src/block/inventory/ShulkerBoxInventory.php index 90c9fa604..849d0bf2b 100644 --- a/src/block/inventory/ShulkerBoxInventory.php +++ b/src/block/inventory/ShulkerBoxInventory.php @@ -63,7 +63,6 @@ class ShulkerBoxInventory extends SimpleInventory implements BlockInventory{ $holder = $this->getHolder(); //event ID is always 1 for a chest - //TODO: maybe broadcast should use block position - $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)); } } diff --git a/src/block/tile/BrewingStand.php b/src/block/tile/BrewingStand.php index be6e380fd..8dc363710 100644 --- a/src/block/tile/BrewingStand.php +++ b/src/block/tile/BrewingStand.php @@ -214,7 +214,7 @@ class BrewingStand extends Spawnable implements Container, Nameable{ } 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(); diff --git a/src/block/tile/ContainerTrait.php b/src/block/tile/ContainerTrait.php index 566804d24..29e8e4960 100644 --- a/src/block/tile/ContainerTrait.php +++ b/src/block/tile/ContainerTrait.php @@ -102,7 +102,7 @@ trait ContainerTrait{ $pos = $this->getPosition(); $world = $pos->getWorld(); - $dropPos = $pos->asVector3()->add(0.5, 0.5, 0.5); + $dropPos = $pos->center(); foreach($inv->getContents() as $k => $item){ $world->dropItem($dropPos, $item); } diff --git a/src/block/tile/Jukebox.php b/src/block/tile/Jukebox.php index 729db99ee..eb4c27b30 100644 --- a/src/block/tile/Jukebox.php +++ b/src/block/tile/Jukebox.php @@ -65,6 +65,6 @@ class Jukebox extends Spawnable{ } protected function onBlockDestroyedHook() : void{ - $this->position->getWorld()->addSound($this->position->asVector3(), new RecordStopSound()); + $this->position->getWorld()->addSound($this->position->center(), new RecordStopSound()); } } diff --git a/src/block/utils/AmethystTrait.php b/src/block/utils/AmethystTrait.php index 94abadb71..20be2ae92 100644 --- a/src/block/utils/AmethystTrait.php +++ b/src/block/utils/AmethystTrait.php @@ -34,7 +34,7 @@ trait AmethystTrait{ * @see Block::onProjectileHit() */ public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{ - $this->position->getWorld()->addSound($this->position->asVector3(), new AmethystBlockChimeSound()); - $this->position->getWorld()->addSound($this->position->asVector3(), new BlockPunchSound($this)); + $this->position->getWorld()->addSound($this->position->center(), new AmethystBlockChimeSound()); + $this->position->getWorld()->addSound($this->position->center(), new BlockPunchSound($this)); } } diff --git a/src/block/utils/CandleTrait.php b/src/block/utils/CandleTrait.php index 1fff5a7ec..b11ce79af 100644 --- a/src/block/utils/CandleTrait.php +++ b/src/block/utils/CandleTrait.php @@ -54,9 +54,9 @@ trait CandleTrait{ }elseif($item->getTypeId() === ItemTypeIds::FIRE_CHARGE){ $item->pop(); //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)); return true; @@ -65,7 +65,7 @@ trait CandleTrait{ if(!$this->lit){ 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)); return true; diff --git a/src/block/utils/CopperTrait.php b/src/block/utils/CopperTrait.php index f9a003fe6..d270192f1 100644 --- a/src/block/utils/CopperTrait.php +++ b/src/block/utils/CopperTrait.php @@ -63,7 +63,7 @@ trait CopperTrait{ $this->waxed = true; $this->position->getWorld()->setBlock($this->position, $this); //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(); return true; } @@ -73,7 +73,7 @@ trait CopperTrait{ $this->waxed = false; $this->position->getWorld()->setBlock($this->position, $this); //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); return true; } @@ -83,7 +83,7 @@ trait CopperTrait{ $this->oxidation = $previousOxidation; $this->position->getWorld()->setBlock($this->position, $this); //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); return true; } diff --git a/src/item/Bucket.php b/src/item/Bucket.php index e27937843..3bb1587da 100644 --- a/src/item/Bucket.php +++ b/src/item/Bucket.php @@ -56,7 +56,7 @@ class Bucket extends Item{ $ev->call(); if(!$ev->isCancelled()){ $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(); $returnedItems[] = $ev->getItem(); diff --git a/src/item/FireCharge.php b/src/item/FireCharge.php index a80a5ad46..d4d8ea5b5 100644 --- a/src/item/FireCharge.php +++ b/src/item/FireCharge.php @@ -36,7 +36,7 @@ class FireCharge extends Item{ if($blockReplace->getTypeId() === BlockTypeIds::AIR){ $world = $player->getWorld(); $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(); diff --git a/src/item/FlintSteel.php b/src/item/FlintSteel.php index b5da77838..8d6021ea3 100644 --- a/src/item/FlintSteel.php +++ b/src/item/FlintSteel.php @@ -36,7 +36,7 @@ class FlintSteel extends Tool{ if($blockReplace->getTypeId() === BlockTypeIds::AIR){ $world = $player->getWorld(); $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); diff --git a/src/item/LiquidBucket.php b/src/item/LiquidBucket.php index c6e1ecc53..729e0ad2f 100644 --- a/src/item/LiquidBucket.php +++ b/src/item/LiquidBucket.php @@ -66,7 +66,7 @@ class LiquidBucket extends Item{ $ev->call(); if(!$ev->isCancelled()){ $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(); $returnedItems[] = $ev->getItem(); diff --git a/src/item/PaintingItem.php b/src/item/PaintingItem.php index f70e7894f..f08308d38 100644 --- a/src/item/PaintingItem.php +++ b/src/item/PaintingItem.php @@ -74,14 +74,13 @@ class PaintingItem extends Item{ $motive = $motives[array_rand($motives)]; $replacePos = $blockReplace->getPosition(); - $replaceVec3 = $replacePos->asVector3(); $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(); $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; } } diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index 558b24855..0ec350930 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -1004,7 +1004,7 @@ class InGamePacketHandler extends PacketHandler{ $lectern = $world->getBlockAt($pos->getX(), $pos->getY(), $pos->getZ()); $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)){ $this->syncBlocksNearby($lecternPos, null); } diff --git a/src/player/Player.php b/src/player/Player.php index ad4347b95..46af93828 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -1834,7 +1834,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $block = $target->getSide($face); if($block->hasTypeTag(BlockTypeTags::FIRE)){ $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; } @@ -1865,7 +1865,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ public function breakBlock(BlockPosition $pos) : bool{ $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->stopBreakBlock($pos); $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{ $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()); $item = $this->inventory->getItemInHand(); //this is a copy of the real item $oldItem = clone $item; diff --git a/src/player/SurvivalBlockBreakHandler.php b/src/player/SurvivalBlockBreakHandler.php index 472b6dcc9..eacbdac7e 100644 --- a/src/player/SurvivalBlockBreakHandler.php +++ b/src/player/SurvivalBlockBreakHandler.php @@ -51,10 +51,9 @@ final class SurvivalBlockBreakHandler{ ){ $this->breakSpeed = $this->calculateBreakProgressPerTick(); if($this->breakSpeed > 0){ - $vector3 = $this->blockPos->asVector3(); - $this->player->getWorld()->broadcastPacketToViewers( - $vector3, - LevelEventPacket::create(LevelEvent::BLOCK_START_BREAK, (int) (65535 * $this->breakSpeed), $vector3) + $this->player->getWorld()->broadcastPacketOnBlock( + $this->blockPos, + LevelEventPacket::create(LevelEvent::BLOCK_START_BREAK, (int) (65535 * $this->breakSpeed), $this->blockPos->asVector3()) ); } } @@ -120,11 +119,10 @@ final class SurvivalBlockBreakHandler{ } public function __destruct(){ - $vector3 = $this->blockPos->asVector3(); if($this->player->getWorld()->isInLoadedTerrain($vector3)){ - $this->player->getWorld()->broadcastPacketToViewers( - $vector3, - LevelEventPacket::create(LevelEvent::BLOCK_STOP_BREAK, 0, $vector3) + $this->player->getWorld()->broadcastPacketOnBlock( + $this->blockPos, + LevelEventPacket::create(LevelEvent::BLOCK_STOP_BREAK, 0, $this->blockPos->asVector3()) ); } } diff --git a/src/world/Explosion.php b/src/world/Explosion.php index af0fa274c..e8c3e8f53 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -206,7 +206,7 @@ class Explosion{ }else{ if(mt_rand(0, 100) < $yield){ 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){ diff --git a/src/world/World.php b/src/world/World.php index 1fff94426..f932ee0b8 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -712,7 +712,7 @@ class World implements ChunkManager{ if(count($pk) > 0){ if($players === $this->getViewersForPosition($pos)){ foreach($pk as $e){ - $this->broadcastPacketToViewers($pos, $e); + $this->broadcastPacketOnPosition($pos, $e); } }else{ NetworkBroadcastUtils::broadcastPackets($this->filterViewersForPosition($pos, $players), $pk); @@ -741,7 +741,7 @@ class World implements ChunkManager{ if(count($pk) > 0){ if($players === $this->getViewersForPosition($pos)){ foreach($pk as $e){ - $this->broadcastPacketToViewers($pos, $e); + $this->broadcastPacketOnPosition($pos, $e); } }else{ 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. */ - 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); } + 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{ if(!isset($this->packetBuffersByChunk[$index = World::chunkHash($chunkX, $chunkZ)])){ $this->packetBuffersByChunk[$index] = [$packet]; @@ -2101,7 +2105,7 @@ class World implements ChunkManager{ $item->onDestroyBlock($target, $returnedItems); if(count($drops) > 0){ - $dropPos = $vector->asVector3()->add(0.5, 0.5, 0.5); + $dropPos = $vector->center(); foreach($drops as $drop){ if(!$drop->isNull()){ $this->dropItem($dropPos, $drop); @@ -2110,7 +2114,7 @@ class World implements ChunkManager{ } if($xpDrop > 0){ - $this->dropExperience($vector->asVector3()->add(0.5, 0.5, 0.5), $xpDrop); + $this->dropExperience($vector->center(), $xpDrop); } return true; @@ -2121,7 +2125,7 @@ class World implements ChunkManager{ */ private function destroyBlockInternal(Block $target, Item $item, ?Player $player, bool $createParticles, array &$returnedItems) : void{ 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); @@ -2269,7 +2273,7 @@ class World implements ChunkManager{ } if($playSound){ - $this->addSound($hand->getPosition()->asVector3(), new BlockPlaceSound($hand)); + $this->addSound($hand->getPosition()->center(), new BlockPlaceSound($hand)); } $item->pop();