From 641a5a5e23c8abd524768315d3a6f854bce25e7c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 22 Jun 2018 09:57:39 +0100 Subject: [PATCH 1/3] fixed damaged anvils dropping the wrong items they changed this in 1.2.13 to use regular masks instead of bitshifts. The item was fixed, but not the block. --- src/pocketmine/block/Anvil.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index d4b09eae6..73aceebb5 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -25,7 +25,6 @@ namespace pocketmine\block; use pocketmine\inventory\AnvilInventory; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; use pocketmine\item\TieredTool; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; @@ -55,13 +54,17 @@ class Anvil extends Fallable{ return 6000; } + public function getVariantBitmask() : int{ + return 0x0c; + } + public function getName() : string{ static $names = [ self::TYPE_NORMAL => "Anvil", self::TYPE_SLIGHTLY_DAMAGED => "Slightly Damaged Anvil", self::TYPE_VERY_DAMAGED => "Very Damaged Anvil" ]; - return $names[$this->meta & 0x0c] ?? "Anvil"; + return $names[$this->getVariant()] ?? "Anvil"; } public function getToolType() : int{ @@ -106,13 +109,7 @@ class Anvil extends Fallable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $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); } - - public function getDropsForCompatibleTool(Item $item) : array{ - return [ - ItemFactory::get($this->getItemId(), $this->getDamage() >> 2) - ]; - } } From 98ac5348208d61e3e4b8032808235b3e9a82060f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 22 Jun 2018 13:22:11 +0100 Subject: [PATCH 2/3] bump version --- src/pocketmine/PocketMine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 9db840ee1..eac6212ae 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -37,7 +37,7 @@ namespace pocketmine { use pocketmine\wizard\SetupWizard; const NAME = "PocketMine-MP"; - const BASE_VERSION = "3.0.3"; + const BASE_VERSION = "3.1.0"; const IS_DEVELOPMENT_BUILD = true; const BUILD_NUMBER = 0; From 390db976e5808256f0f2d9a4b1109fe9548d2aa9 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 22 Jun 2018 13:39:46 +0100 Subject: [PATCH 3/3] Arrow: allow controlling pickup mode (like PC) This allows controlling how arrows are picked up: - by anything - by only creative players - by nothing This adds new API methods to Arrow: - getPickupMode() - setPickupMode() This adds new public constants to Arrow: - PICKUP_NONE - PICKUP_ANY - PICKUP_CREATIVE --- src/pocketmine/entity/projectile/Arrow.php | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/entity/projectile/Arrow.php b/src/pocketmine/entity/projectile/Arrow.php index 9bfab053b..bfe45c412 100644 --- a/src/pocketmine/entity/projectile/Arrow.php +++ b/src/pocketmine/entity/projectile/Arrow.php @@ -40,6 +40,12 @@ use pocketmine\Player; class Arrow extends Projectile{ 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 $height = 0.25; @@ -48,11 +54,26 @@ class Arrow extends Projectile{ protected $damage = 2; + /** @var int */ + protected $pickupMode = self::PICKUP_ANY; + public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null, bool $critical = false){ parent::__construct($level, $nbt, $shootingEntity); $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{ return $this->getGenericFlag(self::DATA_FLAG_CRITICAL); } @@ -95,6 +116,20 @@ class Arrow extends Projectile{ $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{ if($this->blockHit === null){ return; @@ -107,7 +142,12 @@ class Arrow extends Projectile{ 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()){ return; }