From d08a8f5bf46cfa27c55053c6aabd1842e655b055 Mon Sep 17 00:00:00 2001 From: alvin0319 Date: Mon, 4 Jan 2021 11:03:51 +0900 Subject: [PATCH] Release 1.3.0 Now Item durablity appears well Now item can be eat Closes #9 Closes #5 Closes #6 --- example/config.yml | 10 ++-- plugin.yml | 2 +- .../CustomItemLoader/CustomItemLoader.php | 38 +++++++++++---- .../CustomItemLoader/item/CustomFoodItem.php | 46 +++++++++++++++++++ 4 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 src/alvin0319/CustomItemLoader/item/CustomFoodItem.php diff --git a/example/config.yml b/example/config.yml index 03a5538..a1e07c3 100644 --- a/example/config.yml +++ b/example/config.yml @@ -6,7 +6,11 @@ items: name: facebook allow_off_hand: true max_stack_size: 64 - texture: ccc - durable: true + texture: facebook + durable: false max_durability: 64 - mining_speed: 10 \ No newline at end of file + mining_speed: 10 + food: true + can_always_eat: true + nutrition: 10 + saturation: 2 \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index 91d25d5..806ee68 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: CustomItemLoader author: alvin0319 main: alvin0319\CustomItemLoader\CustomItemLoader -version: 1.2.1 +version: 1.3.0 api: 3.0.0 mcpe-protocol: 422 diff --git a/src/alvin0319/CustomItemLoader/CustomItemLoader.php b/src/alvin0319/CustomItemLoader/CustomItemLoader.php index 036c383..7764ca3 100644 --- a/src/alvin0319/CustomItemLoader/CustomItemLoader.php +++ b/src/alvin0319/CustomItemLoader/CustomItemLoader.php @@ -20,6 +20,7 @@ use alvin0319\CustomItemLoader\command\ResourcePackCreateCommand; use alvin0319\CustomItemLoader\item\CustomDurableItem; +use alvin0319\CustomItemLoader\item\CustomFoodItem; use alvin0319\CustomItemLoader\item\CustomItem; use pocketmine\event\Listener; use pocketmine\event\player\PlayerJoinEvent; @@ -129,17 +130,26 @@ public function parseTag(string $name, array $data) : CompoundTag{ $max_stack_size = (int) ($data["max_stack_size"] ?? 64); $mining_speed = (float) ($data["mining_speed"] ?? 1); + $food = (int) ($data["food"] ?? false); + $can_always_eat = (int) ($data["can_always_eat"] ?? false); + $nutrition = (int) ($data["nutrition"] ?? 1); + $saturation = (float) ($data["saturation"] ?? 1); + $nbt = new CompoundTag("", [ new CompoundTag("components", [ - new ByteTag("allow_off_hand", $allow_off_hand), - new ByteTag("can_destroy_in_creative", $can_destroy_in_creative), - new ByteTag("creative_category", $creative_category), - new ByteTag("hand_equipped", $hand_equipped), - new IntTag("max_stack_size", $max_stack_size), - new FloatTag("mining_speed", $mining_speed), - new ByteTag("animates_in_toolbar", 1), new CompoundTag("minecraft:icon", [ new StringTag("texture", $data["texture"]) + ]), + new CompoundTag("item_properties", [ + new IntTag("use_duration", 32), + new IntTag("use_animation", ($food === 1 ? 1 : 0)), // 2 is potion, but not now + new ByteTag("allow_off_hand", $allow_off_hand), + new ByteTag("can_destroy_in_creative", $can_destroy_in_creative), + new ByteTag("creative_category", $creative_category), + new ByteTag("hand_equipped", $hand_equipped), + new IntTag("max_stack_size", $max_stack_size), + new FloatTag("mining_speed", $mining_speed), + new ByteTag("animates_in_toolbar", 1), ]) ]), new ShortTag("minecraft:identifier", $runtimeId), @@ -155,12 +165,22 @@ public function parseTag(string $name, array $data) : CompoundTag{ ]); $durable = false; if(isset($data["durable"]) && (bool) ($data["durable"]) !== false){ - $nbt->setTag(new CompoundTag("minecraft:durability", [ + $nbt->getCompoundTag("components")->setTag(new CompoundTag("minecraft:durability", [ new ShortTag("damage_change", 1), new ShortTag("max_durable", $data["max_durability"]) ])); $durable = true; } + if($food === 1){ + $nbt->getCompoundTag("components")->setTag(new CompoundTag("minecraft:food", [ + new ByteTag("can_always_eat", $can_always_eat), + new FloatTag("nutrition", $nutrition), + new StringTag("saturation_modifier", "low") + ])); + $nbt->getCompoundTag("components")->setTag(new CompoundTag("minecraft:use_duration", [ + new IntTag("value", 1) + ])); + } $runtimeId = $id + ($id > 0 ? 5000 : -5000); $this->coreToNetValues[$id] = $runtimeId; $this->netToCoreValues[$runtimeId] = $id; @@ -170,6 +190,8 @@ public function parseTag(string $name, array $data) : CompoundTag{ try{ if($durable){ ItemFactory::registerItem(new CustomDurableItem($id, $meta, $name, $data["max_stack_size"], $data["max_durability"], $mining_speed)); + }elseif($food){ + ItemFactory::registerItem(new CustomFoodItem($id, $meta, $name, $data["max_stack_size"], $nutrition, $can_always_eat === 1, $saturation)); }else{ ItemFactory::registerItem(new CustomItem($id, $meta, $name, $data["max_stack_size"], $mining_speed)); } diff --git a/src/alvin0319/CustomItemLoader/item/CustomFoodItem.php b/src/alvin0319/CustomItemLoader/item/CustomFoodItem.php new file mode 100644 index 0000000..0a89dea --- /dev/null +++ b/src/alvin0319/CustomItemLoader/item/CustomFoodItem.php @@ -0,0 +1,46 @@ +maxStackSize = $maxStackSize; + $this->nutrition = $nutrition; + $this->canAlwaysEat = $canAlwaysEat; + $this->saturation = $saturation; + } + + public function getMaxStackSize() : int{ + return $this->maxStackSize; + } + + public function getFoodRestore() : int{ + return $this->nutrition; + } + + public function requiresHunger() : bool{ + return $this->canAlwaysEat; + } + + public function getSaturationRestore() : float{ + return $this->saturation; + } + + public function getResidue(){ + return parent::getResidue(); // TODO: Find out the components + } +} \ No newline at end of file