mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Item factory refactor and added capability to register custom items
This commit is contained in:
@ -66,6 +66,7 @@ use pocketmine\event\player\PlayerInteractEvent;
|
||||
use pocketmine\event\Timings;
|
||||
use pocketmine\inventory\InventoryHolder;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\level\format\Chunk;
|
||||
use pocketmine\level\format\io\BaseLevelProvider;
|
||||
use pocketmine\level\format\io\LevelProvider;
|
||||
@ -1585,7 +1586,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$target = $this->getBlock($vector);
|
||||
|
||||
if($item === null){
|
||||
$item = Item::get(Item::AIR, 0, 0);
|
||||
$item = ItemFactory::get(Item::AIR, 0, 0);
|
||||
}
|
||||
|
||||
if($player !== null){
|
||||
@ -1607,7 +1608,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
if($tag instanceof ListTag){
|
||||
foreach($tag as $v){
|
||||
if($v instanceof StringTag){
|
||||
$entry = Item::fromString($v->getValue());
|
||||
$entry = ItemFactory::fromString($v->getValue());
|
||||
if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){
|
||||
$canBreak = true;
|
||||
break;
|
||||
@ -1685,7 +1686,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
if($item !== null){
|
||||
$item->useOn($target);
|
||||
if($item->isTool() and $item->getDamage() >= $item->getMaxDurability()){
|
||||
$item = Item::get(Item::AIR, 0, 0);
|
||||
$item = ItemFactory::get(Item::AIR, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1745,7 +1746,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
if($tag instanceof ListTag){
|
||||
foreach($tag as $v){
|
||||
if($v instanceof StringTag){
|
||||
$entry = Item::fromString($v->getValue());
|
||||
$entry = ItemFactory::fromString($v->getValue());
|
||||
if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){
|
||||
$canPlace = true;
|
||||
break;
|
||||
@ -1766,7 +1767,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
if(!$player->isSneaking() and $item->onActivate($this, $player, $block, $target, $face, $facePos)){
|
||||
if($item->getCount() <= 0){
|
||||
$item = Item::get(Item::AIR, 0, 0);
|
||||
$item = ItemFactory::get(Item::AIR, 0, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1842,7 +1843,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
$item->setCount($item->getCount() - 1);
|
||||
if($item->getCount() <= 0){
|
||||
$item = Item::get(Item::AIR, 0, 0);
|
||||
$item = ItemFactory::get(Item::AIR, 0, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user