mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 01:39:52 +00:00
Merge branch 'release/3.1'
This commit is contained in:
commit
78aa1ee22e
@ -25,7 +25,6 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\inventory\AnvilInventory;
|
use pocketmine\inventory\AnvilInventory;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
|
||||||
use pocketmine\item\TieredTool;
|
use pocketmine\item\TieredTool;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
@ -55,13 +54,17 @@ class Anvil extends Fallable{
|
|||||||
return 6000;
|
return 6000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getVariantBitmask() : int{
|
||||||
|
return 0x0c;
|
||||||
|
}
|
||||||
|
|
||||||
public function getName() : string{
|
public function getName() : string{
|
||||||
static $names = [
|
static $names = [
|
||||||
self::TYPE_NORMAL => "Anvil",
|
self::TYPE_NORMAL => "Anvil",
|
||||||
self::TYPE_SLIGHTLY_DAMAGED => "Slightly Damaged Anvil",
|
self::TYPE_SLIGHTLY_DAMAGED => "Slightly Damaged Anvil",
|
||||||
self::TYPE_VERY_DAMAGED => "Very Damaged Anvil"
|
self::TYPE_VERY_DAMAGED => "Very Damaged Anvil"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x0c] ?? "Anvil";
|
return $names[$this->getVariant()] ?? "Anvil";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getToolType() : int{
|
public function getToolType() : int{
|
||||||
@ -92,13 +95,7 @@ class Anvil extends Fallable{
|
|||||||
|
|
||||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||||
$direction = ($player !== null ? $player->getDirection() : 0) & 0x03;
|
$direction = ($player !== null ? $player->getDirection() : 0) & 0x03;
|
||||||
$this->meta = ($this->meta & 0x0c) | $direction;
|
$this->meta = $this->getVariant() | $direction;
|
||||||
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
|
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDropsForCompatibleTool(Item $item) : array{
|
|
||||||
return [
|
|
||||||
ItemFactory::get($this->getItemId(), $this->getDamage() >> 2)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,12 @@ use pocketmine\Player;
|
|||||||
class Arrow extends Projectile{
|
class Arrow extends Projectile{
|
||||||
public const NETWORK_ID = self::ARROW;
|
public const NETWORK_ID = self::ARROW;
|
||||||
|
|
||||||
|
public const PICKUP_NONE = 0;
|
||||||
|
public const PICKUP_ANY = 1;
|
||||||
|
public const PICKUP_CREATIVE = 2;
|
||||||
|
|
||||||
|
private const TAG_PICKUP = "pickup"; //TAG_Byte
|
||||||
|
|
||||||
public $width = 0.25;
|
public $width = 0.25;
|
||||||
public $height = 0.25;
|
public $height = 0.25;
|
||||||
|
|
||||||
@ -48,11 +54,26 @@ class Arrow extends Projectile{
|
|||||||
|
|
||||||
protected $damage = 2;
|
protected $damage = 2;
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
|
protected $pickupMode = self::PICKUP_ANY;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null, bool $critical = false){
|
public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null, bool $critical = false){
|
||||||
parent::__construct($level, $nbt, $shootingEntity);
|
parent::__construct($level, $nbt, $shootingEntity);
|
||||||
$this->setCritical($critical);
|
$this->setCritical($critical);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function initEntity() : void{
|
||||||
|
parent::initEntity();
|
||||||
|
|
||||||
|
$this->pickupMode = $this->namedtag->getByte(self::TAG_PICKUP, self::PICKUP_ANY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveNBT() : void{
|
||||||
|
parent::saveNBT();
|
||||||
|
|
||||||
|
$this->namedtag->setByte(self::TAG_PICKUP, $this->pickupMode, true);
|
||||||
|
}
|
||||||
|
|
||||||
public function isCritical() : bool{
|
public function isCritical() : bool{
|
||||||
return $this->getGenericFlag(self::DATA_FLAG_CRITICAL);
|
return $this->getGenericFlag(self::DATA_FLAG_CRITICAL);
|
||||||
}
|
}
|
||||||
@ -95,6 +116,20 @@ class Arrow extends Projectile{
|
|||||||
$this->broadcastEntityEvent(EntityEventPacket::ARROW_SHAKE, 7); //7 ticks
|
$this->broadcastEntityEvent(EntityEventPacket::ARROW_SHAKE, 7); //7 ticks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getPickupMode() : int{
|
||||||
|
return $this->pickupMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $pickupMode
|
||||||
|
*/
|
||||||
|
public function setPickupMode(int $pickupMode) : void{
|
||||||
|
$this->pickupMode = $pickupMode;
|
||||||
|
}
|
||||||
|
|
||||||
public function onCollideWithPlayer(Player $player) : void{
|
public function onCollideWithPlayer(Player $player) : void{
|
||||||
if($this->blockHit === null){
|
if($this->blockHit === null){
|
||||||
return;
|
return;
|
||||||
@ -107,7 +142,12 @@ class Arrow extends Projectile{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($playerInventory, $this));
|
$ev = new InventoryPickupArrowEvent($playerInventory, $this);
|
||||||
|
if($this->pickupMode === self::PICKUP_NONE or ($this->pickupMode === self::PICKUP_CREATIVE and !$player->isCreative())){
|
||||||
|
$ev->setCancelled();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->server->getPluginManager()->callEvent($ev);
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user