Skip to content

Commit

Permalink
IronGolem: Broadcast throw sound on attacks
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanCraft623 committed Apr 19, 2024
1 parent 2a94357 commit 2e0b64e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/IvanCraft623/MobPlugin/entity/Mob.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ public function getPerceivedDistanceSqrForMeleeAttack(Entity $target) : float{
return $this->location->distanceSquared($target->getPosition());
}

protected function doAttackAnimation() : void{
$this->broadcastAnimation(new ArmSwingAnimation($this));
}

/**
* Attacks the given entity with the currently-held item.
* TODO: make a PR that implements this un PM core.
Expand Down Expand Up @@ -492,7 +496,7 @@ public function attackEntity(Entity $entity) : bool{

$entity->attack($ev);

$this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers());
$this->doAttackAnimation();

if ($this->isOnFire()) {
$entity->setOnFire(8);
Expand Down
7 changes: 7 additions & 0 deletions src/IvanCraft623/MobPlugin/entity/golem/IronGolem.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use IvanCraft623\MobPlugin\pattern\BlockPatternBuilder;
use IvanCraft623\MobPlugin\sound\IronGolemCrackSound;
use IvanCraft623\MobPlugin\sound\IronGolemRepairSound;
use IvanCraft623\MobPlugin\sound\ThrowSound;
use IvanCraft623\MobPlugin\utils\Utils;

use pocketmine\block\Block;
Expand Down Expand Up @@ -214,6 +215,12 @@ protected function entityBaseTick(int $tickDiff = 1) : bool{
return $hasUpdate;
}

protected function doAttackAnimation() : void{
parent::doAttackAnimation();

$this->broadcastSound(new ThrowSound($this));
}

public function attack(EntityDamageEvent $source) : void{
$crackiness = $this->getCrackiness();

Expand Down
46 changes: 46 additions & 0 deletions src/IvanCraft623/MobPlugin/sound/ThrowSound.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* __ __ _ _____ _ _
* | \/ | | | | __ \| | (_)
* | \ / | ___ | |__ | |__) | |_ _ __ _ _ _ __
* | |\/| |/ _ \| '_ \| ___/| | | | |/ _` | | '_ \
* | | | | (_) | |_) | | | | |_| | (_| | | | | |
* |_| |_|\___/|_.__/|_| |_|\__,_|\__, |_|_| |_|
* __/ |
* |___/
*
* A PocketMine-MP plugin that implements mobs AI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* @author IvanCraft623
*/

declare(strict_types=1);

namespace IvanCraft623\MobPlugin\sound;

use pocketmine\entity\Entity;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
use pocketmine\world\sound\Sound;

class ThrowSound implements Sound{

public function __construct(private Entity $entity){}

public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::create(
LevelSoundEvent::THROW,
$pos,
-1,
$this->entity::getNetworkTypeId(),
false,
false
)];
}
}

0 comments on commit 2e0b64e

Please sign in to comment.