Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implements mace item #6468

Open
wants to merge 5 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/block/BlockToolType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ private function __construct(){
public const AXE = 1 << 3;
public const SHEARS = 1 << 4;
public const HOE = 1 << 5;
public const MACE = 1 << 6;

}
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ private function register1to1ItemMappings() : void{
$this->map1to1Item(Ids::WRITABLE_BOOK, Items::WRITABLE_BOOK());
$this->map1to1Item(Ids::WRITTEN_BOOK, Items::WRITTEN_BOOK());
$this->map1to1Item(Ids::ZOMBIE_SPAWN_EGG, Items::ZOMBIE_SPAWN_EGG());
$this->map1to1Item(Ids::MACE, Items::MACE());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/item/ItemTypeIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ private function __construct(){
public const SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE = 20285;
public const PITCHER_POD = 20286;
public const NAME_TAG = 20287;
public const MACE = 20289;

public const FIRST_UNUSED_ITEM_ID = 20288;
public const FIRST_UNUSED_ITEM_ID = 20290;

private static int $nextDynamicId = self::FIRST_UNUSED_ITEM_ID;

Expand Down
61 changes: 61 additions & 0 deletions src/item/Mace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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\item;

use pocketmine\block\Block;
use pocketmine\block\BlockToolType;
use pocketmine\entity\Entity;

class Mace extends TieredTool {
public function getBlockToolType() : int{
return BlockToolType::MACE;
}

public function getAttackPoints() : int{
return $this->tier->getBaseAttackPoints();
}

public function getBlockToolHarvestLevel() : int{
return 1;
}

public function getMiningEfficiency(bool $isCorrectTool) : float{
return parent::getMiningEfficiency($isCorrectTool) * 1.5; //swords break any block 1.5x faster than hand
}

protected function getBaseMiningEfficiency() : float{
return 10;
}

public function onDestroyBlock(Block $block, array &$returnedItems) : bool{
if(!$block->getBreakInfo()->breaksInstantly()){
return $this->applyDamage(2);
}
return false;
}

public function onAttackEntity(Entity $victim, array &$returnedItems) : bool{
return $this->applyDamage(1);
}
}
5 changes: 4 additions & 1 deletion src/item/ToolTier.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @method static ToolTier NETHERITE()
* @method static ToolTier STONE()
* @method static ToolTier WOOD()
* @method static ToolTier MACE()
*
* @phpstan-type TMetadata array{0: int, 1: int, 2: int, 3: int, 4: int}
*/
Expand All @@ -47,6 +48,7 @@ enum ToolTier{
case IRON;
case DIAMOND;
case NETHERITE;
case MACE;

/**
* This function exists only to permit the use of named arguments and to make the code easier to read in PhpStorm.
Expand All @@ -66,7 +68,8 @@ private function getMetadata() : array{
self::STONE => self::meta(3, 132, 6, 4, 5),
self::IRON => self::meta(4, 251, 7, 6, 14),
self::DIAMOND => self::meta(5, 1562, 8, 8, 10),
self::NETHERITE => self::meta(6, 2032, 9, 9, 15)
self::NETHERITE => self::meta(6, 2032, 9, 9, 15),
self::MACE => self::meta(7, 501, 7, 9, 10)
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/item/VanillaItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
* @method static Armor LEATHER_CAP()
* @method static Armor LEATHER_PANTS()
* @method static Armor LEATHER_TUNIC()
* @method static Mace MACE()
* @method static Item MAGMA_CREAM()
* @method static Boat MANGROVE_BOAT()
* @method static ItemBlockWallOrFloor MANGROVE_SIGN()
Expand Down Expand Up @@ -633,6 +634,7 @@ private static function registerTierToolItems() : void{
self::register("netherite_sword", new Sword(new IID(Ids::NETHERITE_SWORD), "Netherite Sword", ToolTier::NETHERITE, [EnchantmentTags::SWORD]));
self::register("stone_sword", new Sword(new IID(Ids::STONE_SWORD), "Stone Sword", ToolTier::STONE, [EnchantmentTags::SWORD]));
self::register("wooden_sword", new Sword(new IID(Ids::WOODEN_SWORD), "Wooden Sword", ToolTier::WOOD, [EnchantmentTags::SWORD]));
self::register("mace", new Mace(new IID(Ids::MACE), "Mace", ToolTier::MACE, [EnchantmentTags::MACE]));
}

private static function registerArmorItems() : void{
Expand Down
1 change: 1 addition & 0 deletions src/item/enchantment/ItemEnchantmentTagRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private function __construct(){
Tags::BOW,
Tags::CROSSBOW,
Tags::BLOCK_TOOLS,
Tags::MACE,
]);
}

Expand Down
1 change: 1 addition & 0 deletions src/item/enchantment/ItemEnchantmentTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ final class ItemEnchantmentTags{
public const ELYTRA = "elytra";
public const BRUSH = "brush";
public const WEAPONS = "weapons";
public const MACE = "mace";
}