Implemented a proper way to handle items cooldown (#6405)

This commit is contained in:
ipad54
2024-09-25 21:28:17 +03:00
committed by GitHub
parent 4e6b34f573
commit f6e6f15c63
6 changed files with 86 additions and 4 deletions

View File

@ -88,4 +88,8 @@ class ChorusFruit extends Food{
public function getCooldownTicks() : int{
return 20;
}
public function getCooldownTag() : ?string{
return ItemCooldownTags::CHORUS_FRUIT;
}
}

View File

@ -45,4 +45,8 @@ class EnderPearl extends ProjectileItem{
public function getCooldownTicks() : int{
return 20;
}
public function getCooldownTag() : ?string{
return ItemCooldownTags::ENDER_PEARL;
}
}

View File

@ -654,6 +654,20 @@ class Item implements \JsonSerializable{
return 0;
}
/**
* Returns a tag that identifies a group of items that should have cooldown at the same time
* regardless of their state or type.
* When cooldown starts, any other items with the same cooldown tag can't be used until the cooldown expires.
* Such behaviour can be seen in goat horns and shields.
*
* If tag is null, item state id will be used to store cooldown.
*
* @see ItemCooldownTags
*/
public function getCooldownTag() : ?string{
return null;
}
/**
* Compares an Item to this Item and check if they match.
*

View File

@ -0,0 +1,45 @@
<?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;
/**
* Tags used by items to determine their cooldown group.
*
* These tag values are not related to Minecraft internal IDs.
* They only share a visual similarity because these are the most obvious values to use.
* Any arbitrary string can be used.
*
* @see Item::getCooldownTag()
*/
final class ItemCooldownTags{
private function __construct(){
//NOOP
}
public const CHORUS_FRUIT = "chorus_fruit";
public const ENDER_PEARL = "ender_pearl";
public const SHIELD = "shield";
public const GOAT_HORN = "goat_horn";
}