mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-10 13:35:29 +00:00
Implement copper waxing, unwaxing and scraping, minus particles
there is a LevelEvent for the particles, but it's both particle and sound, which doesn't integrate well with the existing API.
This commit is contained in:
parent
a22276e679
commit
14933a731b
@ -27,6 +27,14 @@ use pocketmine\data\runtime\RuntimeDataReader;
|
||||
use pocketmine\data\runtime\RuntimeDataWriter;
|
||||
use pocketmine\data\runtime\RuntimeEnumDeserializer;
|
||||
use pocketmine\data\runtime\RuntimeEnumSerializer;
|
||||
use pocketmine\item\Axe;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemTypeIds;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\sound\CopperWaxApplySound;
|
||||
use pocketmine\world\sound\CopperWaxRemoveSound;
|
||||
use pocketmine\world\sound\ItemUseOnBlockSound;
|
||||
|
||||
trait CopperTrait{
|
||||
private CopperOxidation $oxidation;
|
||||
@ -59,4 +67,38 @@ trait CopperTrait{
|
||||
$this->waxed = $waxed;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||
if(!$this->waxed && $item->getTypeId() === ItemTypeIds::HONEYCOMB){
|
||||
$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, new CopperWaxApplySound());
|
||||
$item->pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
if($item instanceof Axe){
|
||||
if($this->waxed){
|
||||
$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, new CopperWaxRemoveSound());
|
||||
$item->applyDamage(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
$previousOxidation = $this->oxidation->getPrevious();
|
||||
if($previousOxidation !== null){
|
||||
$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, new ItemUseOnBlockSound($this));
|
||||
$item->applyDamage(1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
34
src/world/sound/CopperWaxApplySound.php
Normal file
34
src/world/sound/CopperWaxApplySound.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\sound;
|
||||
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
|
||||
|
||||
final class CopperWaxApplySound implements Sound{
|
||||
public function encode(Vector3 $pos) : array{
|
||||
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::COPPER_WAX_ON, $pos, false)];
|
||||
}
|
||||
}
|
34
src/world/sound/CopperWaxRemoveSound.php
Normal file
34
src/world/sound/CopperWaxRemoveSound.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\sound;
|
||||
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
|
||||
|
||||
final class CopperWaxRemoveSound implements Sound{
|
||||
public function encode(Vector3 $pos) : array{
|
||||
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::COPPER_WAX_OFF, $pos, false)];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user