From f828749052606aeba65fbba1a2f43406f77faa2e Mon Sep 17 00:00:00 2001 From: CJ <80650734+CJMustard1452@users.noreply.github.com> Date: Fri, 16 Aug 2024 00:22:49 -0500 Subject: [PATCH 1/7] feat: implmented wind charges --- src/WindCharges | 1 + src/block/Bell.php | 7 + src/block/Block.php | 9 ++ src/block/Button.php | 23 ++- src/block/CakeWithCandle.php | 15 ++ src/block/Candle.php | 13 ++ src/block/ChorusFlower.php | 7 + src/block/Door.php | 39 +++-- src/block/Lever.php | 15 +- src/block/Trapdoor.php | 20 ++- .../ItemSerializerDeserializerRegistrar.php | 1 + src/entity/EntityFactory.php | 5 + src/entity/projectile/WindCharge.php | 144 ++++++++++++++++++ src/item/ItemTypeIds.php | 3 +- src/item/StringToItemParser.php | 1 + src/item/VanillaItems.php | 2 + src/item/WindCharge.php | 48 ++++++ src/world/particle/WindExplosionParticle.php | 35 +++++ src/world/sound/WindChargeBurstSound.php | 34 +++++ 19 files changed, 403 insertions(+), 19 deletions(-) create mode 160000 src/WindCharges create mode 100644 src/entity/projectile/WindCharge.php create mode 100644 src/item/WindCharge.php create mode 100644 src/world/particle/WindExplosionParticle.php create mode 100644 src/world/sound/WindChargeBurstSound.php diff --git a/src/WindCharges b/src/WindCharges new file mode 160000 index 00000000000..994fa5f792d --- /dev/null +++ b/src/WindCharges @@ -0,0 +1 @@ +Subproject commit 994fa5f792d03ad925577b8235afec8ef411b388 diff --git a/src/block/Bell.php b/src/block/Bell.php index 53a6fc7fbb4..55bda65533e 100644 --- a/src/block/Bell.php +++ b/src/block/Bell.php @@ -29,6 +29,7 @@ use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\entity\projectile\Projectile; +use pocketmine\entity\projectile\WindCharge; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -134,6 +135,12 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player return false; } + public function onProjectileInteraction(Projectile $projectile) : void{ + if($projectile instanceof WindCharge) { + $this->ring($this->facing); + } + } + public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{ $faceHit = Facing::opposite($projectile->getHorizontalFacing()); if($this->isValidFaceToRing($faceHit)){ diff --git a/src/block/Block.php b/src/block/Block.php index dbc269c6301..8a2d9244f2d 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -513,6 +513,15 @@ public function onScheduledUpdate() : void{ } + /** + * Called when this block is updated by a state altering projectile in the world. + * + * @param Projectile $projectile The projectile affecting the block + */ + public function onProjectileInteraction(Projectile $projectile) : void { + + } + /** * Do actions when interacted by Item. Returns if it has done anything * diff --git a/src/block/Button.php b/src/block/Button.php index 73bd1d556bd..1f975830d26 100644 --- a/src/block/Button.php +++ b/src/block/Button.php @@ -25,6 +25,8 @@ use pocketmine\block\utils\AnyFacingTrait; use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\entity\projectile\Projectile; +use pocketmine\entity\projectile\WindCharge; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -63,11 +65,7 @@ abstract protected function getActivationTime() : int; public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if(!$this->pressed){ - $this->pressed = true; - $world = $this->position->getWorld(); - $world->setBlock($this->position, $this); - $world->scheduleDelayedBlockUpdate($this->position, $this->getActivationTime()); - $world->addSound($this->position->add(0.5, 0.5, 0.5), new RedstonePowerOnSound()); + $this->press(); } return true; @@ -91,4 +89,19 @@ public function onNearbyBlockChange() : void{ private function canBeSupportedAt(Block $block, int $face) : bool{ return $block->getAdjacentSupportType(Facing::opposite($face))->hasCenterSupport(); } + + public function onProjectileInteraction(Projectile $projectile) : void{ + if($projectile instanceof WindCharge) { + $this->press(); + } + } + + public function press() : void { + $this->pressed = true; + + $world = $this->position->getWorld(); + $world->setBlock($this->position, $this); + $world->scheduleDelayedBlockUpdate($this->position, $this->getActivationTime()); + $world->addSound($this->position->add(0.5, 0.5, 0.5), new RedstonePowerOnSound()); + } } diff --git a/src/block/CakeWithCandle.php b/src/block/CakeWithCandle.php index 4479faee103..a786f1356d5 100644 --- a/src/block/CakeWithCandle.php +++ b/src/block/CakeWithCandle.php @@ -25,11 +25,14 @@ use pocketmine\block\utils\CandleTrait; use pocketmine\entity\Living; +use pocketmine\entity\projectile\Projectile; +use pocketmine\entity\projectile\WindCharge; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; +use pocketmine\world\sound\FlintSteelSound; class CakeWithCandle extends BaseCake{ use CandleTrait { @@ -59,6 +62,18 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player return parent::onInteract($item, $face, $clickVector, $player, $returnedItems); } + public function onProjectileInteraction(Projectile $projectile) : void{ + if($projectile instanceof WindCharge) { + if(!$this->lit) { + return; + } + + $world = $this->position->getWorld(); + $world->setBlock($this->position, $this->setLit(false)); + $world->addSound($this->position, new FlintSteelSound()); + } + } + public function getDropsForCompatibleTool(Item $item) : array{ return [$this->getCandle()->asItem()]; } diff --git a/src/block/Candle.php b/src/block/Candle.php index 7f22641e118..cf9ffc9fa6c 100644 --- a/src/block/Candle.php +++ b/src/block/Candle.php @@ -26,6 +26,7 @@ use pocketmine\block\utils\CandleTrait; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\entity\projectile\Projectile; use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\AxisAlignedBB; @@ -34,6 +35,7 @@ use pocketmine\player\Player; use pocketmine\utils\AssumptionFailedError; use pocketmine\world\BlockTransaction; +use pocketmine\world\sound\FlintSteelSound; class Candle extends Transparent{ use CandleTrait { @@ -98,6 +100,17 @@ protected function getCandleIfCompatibleType(Block $block) : ?Candle{ return $block instanceof Candle && $block->hasSameTypeId($this) ? $block : null; } + public function onProjectileInteraction(Projectile $projectile) : void{ + if(!$this->lit) { + return; + } + + $newCandle = $this->setLit(false); + $world = $this->position->getWorld(); + $world->setBlock($this->position, $newCandle); + $world->addSound($this->position, new FlintSteelSound()); + } + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ $candle = $this->getCandleIfCompatibleType($blockReplace); return $candle !== null ? $candle->count < self::MAX_COUNT : parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); diff --git a/src/block/ChorusFlower.php b/src/block/ChorusFlower.php index cc3c606d92d..c08fd1a2a7a 100644 --- a/src/block/ChorusFlower.php +++ b/src/block/ChorusFlower.php @@ -26,6 +26,7 @@ use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\StaticSupportTrait; use pocketmine\entity\projectile\Projectile; +use pocketmine\entity\projectile\WindCharge; use pocketmine\event\block\StructureGrowEvent; use pocketmine\math\Axis; use pocketmine\math\AxisAlignedBB; @@ -118,6 +119,12 @@ private function allHorizontalBlocksEmpty(World $world, Vector3 $position, ?int return true; } + public function onProjectileInteraction(Projectile $projectile) : void{ + if($projectile instanceof WindCharge) { + $this->position->getWorld()->useBreakOn($this->position); + } + } + private function canGrowUpwards(int $stemHeight, bool $endStoneBelow) : bool{ $world = $this->position->getWorld(); diff --git a/src/block/Door.php b/src/block/Door.php index 82ddaab518b..910b7e72e21 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -26,6 +26,8 @@ use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\entity\projectile\Projectile; +use pocketmine\entity\projectile\WindCharge; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -142,17 +144,7 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ - $this->open = !$this->open; - - $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); - $world = $this->position->getWorld(); - if($other instanceof Door && $other->hasSameTypeId($this)){ - $other->open = $this->open; - $world->setBlock($other->position, $other); - } - - $world->setBlock($this->position, $this); - $world->addSound($this->position, new DoorSound()); + $this->toggle(); return true; } @@ -176,4 +168,29 @@ public function getAffectedBlocks() : array{ private function canBeSupportedAt(Block $block) : bool{ return $block->getAdjacentSupportType(Facing::DOWN)->hasEdgeSupport(); } + + public function onProjectileInteraction(Projectile $projectile) : void{ + if($projectile instanceof WindCharge) { + if($this->getTypeId() === BlockTypeIds::IRON_DOOR) { + return; + } + + $this->toggle(); + } + } + + public function toggle() : void { + $this->open = !$this->open; + + $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); + $world = $this->position->getWorld(); + + if($other instanceof Door && $other->hasSameTypeId($this)){ + $other->open = $this->open; + $world->setBlock($other->position, $other); + } + + $world->setBlock($this->position, $this); + $world->addSound($this->position, new DoorSound()); + } } diff --git a/src/block/Lever.php b/src/block/Lever.php index d2b98efc34f..f4f0f959a2c 100644 --- a/src/block/Lever.php +++ b/src/block/Lever.php @@ -25,6 +25,8 @@ use pocketmine\block\utils\LeverFacing; use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\entity\projectile\Projectile; +use pocketmine\entity\projectile\WindCharge; use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\Facing; @@ -91,6 +93,18 @@ public function onNearbyBlockChange() : void{ } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + $this->toggle(); + + return true; + } + + public function onProjectileInteraction(Projectile $projectile) : void{ + if($projectile instanceof WindCharge) { + $this->toggle(); + } + } + + public function toggle() : void { $this->activated = !$this->activated; $world = $this->position->getWorld(); $world->setBlock($this->position, $this); @@ -98,7 +112,6 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $this->position->add(0.5, 0.5, 0.5), $this->activated ? new RedstonePowerOnSound() : new RedstonePowerOffSound() ); - return true; } private function canBeSupportedAt(Block $block, int $face) : bool{ diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index 20b6af2abdc..e205e8c034f 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -26,6 +26,8 @@ use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\entity\projectile\Projectile; +use pocketmine\entity\projectile\WindCharge; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -85,10 +87,26 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + $this->toggle(); + + return true; + } + + public function onProjectileInteraction(Projectile $projectile) : void{ + if($projectile instanceof WindCharge){ + if($this->getTypeId() === BlockTypeIds::IRON_TRAPDOOR) { + return; + } + + $this->toggle(); + } + } + + public function toggle() : void { $this->open = !$this->open; + $world = $this->position->getWorld(); $world->setBlock($this->position, $this); $world->addSound($this->position, new DoorSound()); - return true; } } diff --git a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php index de9b5ae5e60..f52ef0723c3 100644 --- a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php +++ b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php @@ -389,6 +389,7 @@ private function register1to1ItemMappings() : void{ $this->map1to1Item(Ids::WHEAT, Items::WHEAT()); $this->map1to1Item(Ids::WHEAT_SEEDS, Items::WHEAT_SEEDS()); $this->map1to1Item(Ids::WILD_ARMOR_TRIM_SMITHING_TEMPLATE, Items::WILD_ARMOR_TRIM_SMITHING_TEMPLATE()); + $this->map1to1Item(Ids::WIND_CHARGE, Items::WIND_CHARGE()); $this->map1to1Item(Ids::WOODEN_AXE, Items::WOODEN_AXE()); $this->map1to1Item(Ids::WOODEN_HOE, Items::WOODEN_HOE()); $this->map1to1Item(Ids::WOODEN_PICKAXE, Items::WOODEN_PICKAXE()); diff --git a/src/entity/EntityFactory.php b/src/entity/EntityFactory.php index d8d189cffc1..d26306b12e2 100644 --- a/src/entity/EntityFactory.php +++ b/src/entity/EntityFactory.php @@ -44,6 +44,7 @@ use pocketmine\entity\projectile\ExperienceBottle; use pocketmine\entity\projectile\Snowball; use pocketmine\entity\projectile\SplashPotion; +use pocketmine\entity\projectile\WindCharge; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -169,6 +170,10 @@ public function __construct(){ return new Villager(Helper::parseLocation($nbt, $world), $nbt); }, ['Villager', 'minecraft:villager']); + $this->register(WindCharge::class, function(World $world, CompoundTag $nbt) : WindCharge { + return new WindCharge(Helper::parseLocation($nbt, $world), null, $nbt); + }, ['Wind Charge', 'minecraft:wind_charge']); + $this->register(Zombie::class, function(World $world, CompoundTag $nbt) : Zombie{ return new Zombie(Helper::parseLocation($nbt, $world), $nbt); }, ['Zombie', 'minecraft:zombie']); diff --git a/src/entity/projectile/WindCharge.php b/src/entity/projectile/WindCharge.php new file mode 100644 index 00000000000..030d70a55ad --- /dev/null +++ b/src/entity/projectile/WindCharge.php @@ -0,0 +1,144 @@ +getDamager()) === null){ + return; + } + + $this->setOwningEntity($entity); + + $this->setMotion($entity->getDirectionVector()->multiply(1.5)); + } + + protected function onHitEntity(Entity $entityHit, RayTraceResult $hitResult) : void{ + if($this->getOwningEntity() === null) { + $ev = new EntityDamageByEntityEvent($this, $entityHit, EntityDamageEvent::CAUSE_PROJECTILE, self::DAMAGE); + } else { + $ev = new EntityDamageByChildEntityEvent($this->getOwningEntity(), $this, $entityHit, EntityDamageEvent::CAUSE_PROJECTILE, self::DAMAGE); + } + + $entityHit->attack($ev); + + $this->flagForDespawn(); + } + + protected function entityBaseTick(int $tickDiff = 1) : bool{ + parent::entityBaseTick($tickDiff); + + if($this->ticksLived >= 6000) { + $this->flagForDespawn(); + } + + return true; + } + + protected function onHit(ProjectileHitEvent $event) : void{ + $source = $this->getLocation(); + + $this->getWorld()->addSound($event->getRayTraceResult()->getHitVector(), new WindChargeBurstSound()); + $this->getWorld()->addParticle($source, new WindExplosionParticle()); + + $bound = $this->getBound($this->getPosition(), self::RADIUS - 1); + for($x = $bound->minX; $x <= $bound->maxX; $x++) { + for($y = $bound->minY; $y <= $bound->maxY; $y++) { + for($z = $bound->minZ; $z <= $bound->maxZ; $z++) { + $block = $this->getWorld()->getBlockAt((int) floor($x), (int) floor($y), (int) floor($z)); + + // This is to avoid calling Door::onProjectileInteraction() twice due to two tiles. + if($block instanceof Door) { + if($block->isTop()) { + continue; + } + } + + $block->onProjectileInteraction($this); + } + } + } + + foreach($source->getWorld()->getCollidingEntities($this->getBound($source, self::RADIUS), $this) as $entity){ + + $entityPos = $entity->getPosition(); + $distance = $entityPos->distance($source) / 2.5; + $motion = $entityPos->subtractVector($source)->normalize(); + + $exposure = 1; + if ($entity->isUnderwater()){ + $exposure = 0.5; + } + + $impact = (1 - $distance) * $exposure; + if ($impact <= 0) { + continue; + } + + if (round($entityPos->getX(), 1) == round($source->getX(), 1) && round($entityPos->getZ(), 1) == round($source->getZ(), 1)) { + $entity->setMotion($entity->getMotion()->add(0, 0.75 * $exposure, 0)); + + return; + } + + $entity->setMotion($entity->getMotion()->add(0, $impact * 0.4, 0)->addVector($motion->multiply($impact * $exposure))); + } + } + + private function getBound(Vector3 $source, float $radius) : AxisAlignedBB { + return new AxisAlignedBB( + (int) floor($source->x - $radius - 1), + (int) floor($source->y - $radius - 1), + (int) floor($source->z - $radius - 1), + (int) ceil($source->x + $radius + 1), + (int) ceil($source->y + $radius + 1), + (int) ceil($source->z + $radius + 1) + ); + } +} diff --git a/src/item/ItemTypeIds.php b/src/item/ItemTypeIds.php index 66eebed744c..3688663922e 100644 --- a/src/item/ItemTypeIds.php +++ b/src/item/ItemTypeIds.php @@ -324,8 +324,9 @@ private function __construct(){ public const SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE = 20285; public const PITCHER_POD = 20286; public const NAME_TAG = 20287; + public const WIND_CHARGE = 20288; - public const FIRST_UNUSED_ITEM_ID = 20288; + public const FIRST_UNUSED_ITEM_ID = 20289; private static int $nextDynamicId = self::FIRST_UNUSED_ITEM_ID; diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index 9f5db6950c6..0843d0d564f 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -1515,6 +1515,7 @@ private static function registerItems(self $result) : void{ $result->register("wheat", fn() => Items::WHEAT()); $result->register("wheat_seeds", fn() => Items::WHEAT_SEEDS()); $result->register("wild_armor_trim_smithing_template", fn() => Items::WILD_ARMOR_TRIM_SMITHING_TEMPLATE()); + $result->register("wind_charge", fn() => Items::WIND_CHARGE()); $result->register("wooden_axe", fn() => Items::WOODEN_AXE()); $result->register("wooden_hoe", fn() => Items::WOODEN_HOE()); $result->register("wooden_pickaxe", fn() => Items::WOODEN_PICKAXE()); diff --git a/src/item/VanillaItems.php b/src/item/VanillaItems.php index 5115ee48a8b..c1b0b5c20d5 100644 --- a/src/item/VanillaItems.php +++ b/src/item/VanillaItems.php @@ -323,6 +323,7 @@ * @method static Item WHEAT() * @method static WheatSeeds WHEAT_SEEDS() * @method static Item WILD_ARMOR_TRIM_SMITHING_TEMPLATE() + * @method static WindCharge WIND_CHARGE() * @method static Axe WOODEN_AXE() * @method static Hoe WOODEN_HOE() * @method static Pickaxe WOODEN_PICKAXE() @@ -567,6 +568,7 @@ public function isFireProof() : bool{ return true; } self::register("water_bucket", new LiquidBucket(new IID(Ids::WATER_BUCKET), "Water Bucket", Blocks::WATER())); self::register("wheat", new Item(new IID(Ids::WHEAT), "Wheat")); self::register("wheat_seeds", new WheatSeeds(new IID(Ids::WHEAT_SEEDS), "Wheat Seeds")); + self::register("wind_charge", new WindCharge(new IID(Ids::WIND_CHARGE), "Wind Charge")); self::register("writable_book", new WritableBook(new IID(Ids::WRITABLE_BOOK), "Book & Quill")); self::register("written_book", new WrittenBook(new IID(Ids::WRITTEN_BOOK), "Written Book")); diff --git a/src/item/WindCharge.php b/src/item/WindCharge.php new file mode 100644 index 00000000000..7571774bcf5 --- /dev/null +++ b/src/item/WindCharge.php @@ -0,0 +1,48 @@ + Date: Fri, 16 Aug 2024 00:27:32 -0500 Subject: [PATCH 2/7] fix: submodule nonsence --- src/WindCharges | 1 - 1 file changed, 1 deletion(-) delete mode 160000 src/WindCharges diff --git a/src/WindCharges b/src/WindCharges deleted file mode 160000 index 994fa5f792d..00000000000 --- a/src/WindCharges +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 994fa5f792d03ad925577b8235afec8ef411b388 From 54caeb485987ccd986b77b5b36a91ef9f5737786 Mon Sep 17 00:00:00 2001 From: CJ <80650734+CJMustard1452@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:56:43 -0500 Subject: [PATCH 3/7] feat: edit to ipad54 reveiw --- src/block/Candle.php | 17 ++++++++++------- src/block/Door.php | 5 +++++ src/entity/projectile/WindCharge.php | 8 -------- src/item/WindCharge.php | 4 ---- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/block/Candle.php b/src/block/Candle.php index cf9ffc9fa6c..a95088da9f9 100644 --- a/src/block/Candle.php +++ b/src/block/Candle.php @@ -27,6 +27,7 @@ use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\entity\projectile\Projectile; +use pocketmine\entity\projectile\WindCharge; use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\AxisAlignedBB; @@ -101,14 +102,16 @@ protected function getCandleIfCompatibleType(Block $block) : ?Candle{ } public function onProjectileInteraction(Projectile $projectile) : void{ - if(!$this->lit) { - return; - } + if($projectile instanceof WindCharge) { + if(!$this->lit) { + return; + } - $newCandle = $this->setLit(false); - $world = $this->position->getWorld(); - $world->setBlock($this->position, $newCandle); - $world->addSound($this->position, new FlintSteelSound()); + $newCandle = $this->setLit(false); + $world = $this->position->getWorld(); + $world->setBlock($this->position, $newCandle); + $world->addSound($this->position, new FlintSteelSound()); + } } public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ diff --git a/src/block/Door.php b/src/block/Door.php index 910b7e72e21..3c88502203f 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -175,6 +175,11 @@ public function onProjectileInteraction(Projectile $projectile) : void{ return; } + // This is to avoid calling Door::onProjectileInteraction() twice due to two tiles. + if($this->top) { + return; + } + $this->toggle(); } } diff --git a/src/entity/projectile/WindCharge.php b/src/entity/projectile/WindCharge.php index 030d70a55ad..8b2bf1aa407 100644 --- a/src/entity/projectile/WindCharge.php +++ b/src/entity/projectile/WindCharge.php @@ -23,7 +23,6 @@ namespace pocketmine\entity\projectile; -use pocketmine\block\Door; use pocketmine\entity\Entity; use pocketmine\event\entity\EntityDamageByChildEntityEvent; use pocketmine\event\entity\EntityDamageByEntityEvent; @@ -93,13 +92,6 @@ protected function onHit(ProjectileHitEvent $event) : void{ for($z = $bound->minZ; $z <= $bound->maxZ; $z++) { $block = $this->getWorld()->getBlockAt((int) floor($x), (int) floor($y), (int) floor($z)); - // This is to avoid calling Door::onProjectileInteraction() twice due to two tiles. - if($block instanceof Door) { - if($block->isTop()) { - continue; - } - } - $block->onProjectileInteraction($this); } } diff --git a/src/item/WindCharge.php b/src/item/WindCharge.php index 7571774bcf5..784abd53a28 100644 --- a/src/item/WindCharge.php +++ b/src/item/WindCharge.php @@ -30,10 +30,6 @@ class WindCharge extends ProjectileItem{ - public function getMaxStackSize() : int{ - return 64; - } - protected function createEntity(Location $location, Player $thrower) : Throwable{ return new WindChargeEntity($location, $thrower); } From d1e5f8c58ec0908524cae97f4bfe18cff9eab2f8 Mon Sep 17 00:00:00 2001 From: CJ <80650734+CJMustard1452@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:02:06 -0500 Subject: [PATCH 4/7] fix: chours flower issue --- src/block/ChorusFlower.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/block/ChorusFlower.php b/src/block/ChorusFlower.php index c08fd1a2a7a..cc3c606d92d 100644 --- a/src/block/ChorusFlower.php +++ b/src/block/ChorusFlower.php @@ -26,7 +26,6 @@ use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\StaticSupportTrait; use pocketmine\entity\projectile\Projectile; -use pocketmine\entity\projectile\WindCharge; use pocketmine\event\block\StructureGrowEvent; use pocketmine\math\Axis; use pocketmine\math\AxisAlignedBB; @@ -119,12 +118,6 @@ private function allHorizontalBlocksEmpty(World $world, Vector3 $position, ?int return true; } - public function onProjectileInteraction(Projectile $projectile) : void{ - if($projectile instanceof WindCharge) { - $this->position->getWorld()->useBreakOn($this->position); - } - } - private function canGrowUpwards(int $stemHeight, bool $endStoneBelow) : bool{ $world = $this->position->getWorld(); From 3b16dd7e875d1a098c734f96583d074ea81c2a50 Mon Sep 17 00:00:00 2001 From: CJ <80650734+CJMustard1452@users.noreply.github.com> Date: Sun, 18 Aug 2024 23:54:08 -0500 Subject: [PATCH 5/7] tweek: edit $impact value to simulate vanilla mechs --- src/entity/projectile/WindCharge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entity/projectile/WindCharge.php b/src/entity/projectile/WindCharge.php index 8b2bf1aa407..20a2a64656c 100644 --- a/src/entity/projectile/WindCharge.php +++ b/src/entity/projectile/WindCharge.php @@ -108,7 +108,7 @@ protected function onHit(ProjectileHitEvent $event) : void{ $exposure = 0.5; } - $impact = (1 - $distance) * $exposure; + $impact = (1.3 - $distance) * $exposure; if ($impact <= 0) { continue; } From 10ac7300ea6261caeed526be2dc43b3f9ce458c5 Mon Sep 17 00:00:00 2001 From: CJ <80650734+CJMustard1452@users.noreply.github.com> Date: Mon, 19 Aug 2024 17:27:28 -0500 Subject: [PATCH 6/7] tweak: edit to some ShockedPlot7560 comments --- src/block/CakeWithCandle.php | 5 +---- src/block/Candle.php | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/block/CakeWithCandle.php b/src/block/CakeWithCandle.php index a786f1356d5..d08ee0335b9 100644 --- a/src/block/CakeWithCandle.php +++ b/src/block/CakeWithCandle.php @@ -63,10 +63,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player } public function onProjectileInteraction(Projectile $projectile) : void{ - if($projectile instanceof WindCharge) { - if(!$this->lit) { - return; - } + if($projectile instanceof WindCharge && $this->lit) { $world = $this->position->getWorld(); $world->setBlock($this->position, $this->setLit(false)); diff --git a/src/block/Candle.php b/src/block/Candle.php index a95088da9f9..a77b7c63a15 100644 --- a/src/block/Candle.php +++ b/src/block/Candle.php @@ -102,10 +102,7 @@ protected function getCandleIfCompatibleType(Block $block) : ?Candle{ } public function onProjectileInteraction(Projectile $projectile) : void{ - if($projectile instanceof WindCharge) { - if(!$this->lit) { - return; - } + if($projectile instanceof WindCharge && $this->lit) { $newCandle = $this->setLit(false); $world = $this->position->getWorld(); From 7117617e7761e114480233b3dbd4e902afc2c68f Mon Sep 17 00:00:00 2001 From: CJ <80650734+CJMustard1452@users.noreply.github.com> Date: Mon, 19 Aug 2024 17:30:10 -0500 Subject: [PATCH 7/7] fix: trapdoor.php visual edit --- src/block/Trapdoor.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index e205e8c034f..23c6e078112 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -93,11 +93,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player } public function onProjectileInteraction(Projectile $projectile) : void{ - if($projectile instanceof WindCharge){ - if($this->getTypeId() === BlockTypeIds::IRON_TRAPDOOR) { - return; - } - + if($projectile instanceof WindCharge && $this->getTypeId() !== BlockTypeIds::IRON_TRAPDOOR){ $this->toggle(); } }