PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
entity/projectile/IceBomb.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\entity\projectile;
25
37
38class IceBomb extends Throwable{
39 public static function getNetworkTypeId() : string{ return EntityIds::ICE_BOMB; }
40
41 public function getResultDamage() : int{
42 return -1;
43 }
44
45 protected function calculateInterceptWithBlock(Block $block, Vector3 $start, Vector3 $end) : ?RayTraceResult{
46 if($block->getTypeId() === BlockTypeIds::WATER){
47 $pos = $block->getPosition();
48
49 return AxisAlignedBB::one()->offset($pos->x, $pos->y, $pos->z)->calculateIntercept($start, $end);
50 }
51
52 return parent::calculateInterceptWithBlock($block, $start, $end);
53 }
54
55 protected function onHit(ProjectileHitEvent $event) : void{
56 $world = $this->getWorld();
57 $pos = $this->location;
58
59 $world->addSound($pos, new IceBombHitSound());
60 $itemBreakParticle = new ItemBreakParticle(VanillaItems::ICE_BOMB());
61 for($i = 0; $i < 6; ++$i){
62 $world->addParticle($pos, $itemBreakParticle);
63 }
64 }
65
66 protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{
67 parent::onHitBlock($blockHit, $hitResult);
68
69 $pos = $blockHit->getPosition();
70 $world = $pos->getWorld();
71 $posX = $pos->getFloorX();
72 $posY = $pos->getFloorY();
73 $posZ = $pos->getFloorZ();
74
75 $ice = VanillaBlocks::ICE();
76 for($x = $posX - 1; $x <= $posX + 1; $x++){
77 for($y = $posY - 1; $y <= $posY + 1; $y++){
78 for($z = $posZ - 1; $z <= $posZ + 1; $z++){
79 if($world->getBlockAt($x, $y, $z)->getTypeId() === BlockTypeIds::WATER){
80 $world->setBlockAt($x, $y, $z, $ice);
81 }
82 }
83 }
84 }
85 }
86}
onHitBlock(Block $blockHit, RayTraceResult $hitResult)
calculateInterceptWithBlock(Block $block, Vector3 $start, Vector3 $end)