-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
315 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?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\block; | ||
|
||
use pocketmine\block\tile\Barrel as TileBarrel; | ||
use pocketmine\block\utils\AnyFacingTrait; | ||
use pocketmine\block\utils\BlockDataSerializer; | ||
use pocketmine\item\Item; | ||
use pocketmine\math\Facing; | ||
use pocketmine\math\Vector3; | ||
use pocketmine\player\Player; | ||
use pocketmine\world\BlockTransaction; | ||
|
||
class Barrel extends Opaque{ | ||
use AnyFacingTrait; | ||
|
||
/** @var bool */ | ||
protected $open = false; | ||
|
||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){ | ||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.5, BlockToolType::AXE)); | ||
} | ||
|
||
protected function writeStateToMeta() : int{ | ||
return BlockDataSerializer::writeFacing($this->facing) | ($this->open ? BlockLegacyMetadata::BARREL_FLAG_OPEN : 0); | ||
} | ||
|
||
public function readStateFromData(int $id, int $stateMeta) : void{ | ||
$this->facing = BlockDataSerializer::readFacing($stateMeta & 0x07); | ||
$this->open = ($stateMeta & BlockLegacyMetadata::BARREL_FLAG_OPEN) === BlockLegacyMetadata::BARREL_FLAG_OPEN; | ||
} | ||
|
||
public function getStateBitmask() : int{ | ||
return 0b1111; | ||
} | ||
|
||
public function isOpen() : bool{ | ||
return $this->open; | ||
} | ||
|
||
public function setOpen(bool $open) : Barrel{ | ||
$this->open = $open; | ||
return $this; | ||
} | ||
|
||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ | ||
if($player !== null){ | ||
if(abs($player->getPosition()->getX() - $this->pos->getX()) < 2 && abs($player->getPosition()->getZ() - $this->pos->getZ()) < 2){ | ||
$y = $player->getEyePos()->getY(); | ||
|
||
if($y - $this->pos->getY() > 2){ | ||
$this->facing = Facing::UP; | ||
}elseif($this->pos->getY() - $y > 0){ | ||
$this->facing = Facing::DOWN; | ||
}else{ | ||
$this->facing = Facing::opposite($player->getHorizontalFacing()); | ||
} | ||
}else{ | ||
$this->facing = Facing::opposite($player->getHorizontalFacing()); | ||
} | ||
} | ||
|
||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); | ||
} | ||
|
||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ | ||
if($player instanceof Player){ | ||
$barrel = $this->pos->getWorld()->getTile($this->pos); | ||
if($barrel instanceof TileBarrel){ | ||
if(!$barrel->canOpenWith($item->getCustomName())){ | ||
return true; | ||
} | ||
|
||
$player->setCurrentWindow($barrel->getInventory()); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function getFuelTime() : int{ | ||
return 300; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?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\block\inventory; | ||
|
||
use pocketmine\block\Barrel; | ||
use pocketmine\world\Position; | ||
use pocketmine\world\sound\BarrelCloseSound; | ||
use pocketmine\world\sound\BarrelOpenSound; | ||
use pocketmine\world\sound\Sound; | ||
|
||
class BarrelInventory extends AnimatedBlockInventory{ | ||
|
||
public function __construct(Position $holder){ | ||
parent::__construct($holder, 27); | ||
} | ||
|
||
protected function getOpenSound() : Sound{ | ||
return new BarrelOpenSound(); | ||
} | ||
|
||
protected function getCloseSound() : Sound{ | ||
return new BarrelCloseSound(); | ||
} | ||
|
||
protected function animateBlock(bool $isOpen) : void{ | ||
$holder = $this->getHolder(); | ||
$block = $holder->getWorld()->getBlock($holder); | ||
if($block instanceof Barrel){ | ||
$holder->getWorld()->setBlock($holder, $block->setOpen($isOpen)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?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\block\tile; | ||
|
||
use pocketmine\block\inventory\BarrelInventory; | ||
use pocketmine\math\Vector3; | ||
use pocketmine\nbt\tag\CompoundTag; | ||
use pocketmine\world\World; | ||
|
||
class Barrel extends Spawnable implements Container, Nameable{ | ||
use NameableTrait; | ||
use ContainerTrait; | ||
|
||
/** @var BarrelInventory */ | ||
protected $inventory; | ||
|
||
public function __construct(World $world, Vector3 $pos){ | ||
parent::__construct($world, $pos); | ||
$this->inventory = new BarrelInventory($this->pos); | ||
} | ||
|
||
public function readSaveData(CompoundTag $nbt) : void{ | ||
$this->loadName($nbt); | ||
$this->loadItems($nbt); | ||
} | ||
|
||
protected function writeSaveData(CompoundTag $nbt) : void{ | ||
$this->saveName($nbt); | ||
$this->saveItems($nbt); | ||
} | ||
|
||
public function close() : void{ | ||
if(!$this->closed){ | ||
$this->inventory->removeAllViewers(); | ||
$this->inventory = null; | ||
parent::close(); | ||
} | ||
} | ||
|
||
/** | ||
* @return BarrelInventory | ||
*/ | ||
public function getInventory(){ | ||
return $this->inventory; | ||
} | ||
|
||
/** | ||
* @return BarrelInventory | ||
*/ | ||
public function getRealInventory(){ | ||
return $this->inventory; | ||
} | ||
|
||
public function getDefaultName() : string{ | ||
return "Barrel"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
class BarrelCloseSound implements Sound{ | ||
|
||
public function encode(?Vector3 $pos) : array{ | ||
return [LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_BLOCK_BARREL_CLOSE, $pos)]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
class BarrelOpenSound implements Sound{ | ||
|
||
public function encode(?Vector3 $pos) : array{ | ||
return [LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_BLOCK_BARREL_OPEN, $pos)]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.