Skip to content

Commit

Permalink
簡素なツールチップを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
Quarri6343 committed Aug 14, 2023
1 parent fa898b9 commit 67ebc35
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/main/java/net/riblab/tradecore/item/TCTool.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package net.riblab.tradecore.item;

import lombok.Getter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.riblab.tradecore.ItemCreator;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.List;

/**
* プラグインのツールクラス
*/
Expand Down Expand Up @@ -61,7 +67,25 @@ public double getActualMiningSpeed(){

@Override
protected ItemCreator createItem() {
return super.createItem().setIntNBT(durabilityTag, baseDurability);
return super.createItem().setIntNBT(durabilityTag, baseDurability)
.setLores(getLore(baseDurability));
}

/**
* ツールの説明を生成する
* @param durability インスタンスが持つ耐久値
* @return ツールの説明
*/
protected List<Component> getLore(int durability){
List<Component> texts = new ArrayList<>();
if(baseDurability != -1){
texts.add(Component.text("耐久値: ").decoration(TextDecoration.ITALIC, false).color(NamedTextColor.WHITE)
.append(Component.text(durability).color(durability == baseDurability ? NamedTextColor.WHITE : NamedTextColor.YELLOW))
.append(Component.text("/" + baseDurability).color(NamedTextColor.WHITE)));
}
texts.add(Component.text("採掘速度: ").decoration(TextDecoration.ITALIC, false).color(NamedTextColor.WHITE)
.append(Component.text((Math.floor(baseMiningSpeed * 10)) / 10)));
return texts;
}

/**
Expand All @@ -85,7 +109,7 @@ public ItemStack reduceDurability(ItemStack instance){

int damageToSet = (int)(instance.getType().getMaxDurability() * ((float)durability / (float) baseDurability));
int damageToDeal = (instance.getType().getMaxDurability() - instance.getDurability()) - damageToSet;
return new ItemCreator(instance).damage(damageToDeal).setIntNBT(durabilityTag, durability).create();
return new ItemCreator(instance).setLores(getLore(durability)).damage(damageToDeal).setIntNBT(durabilityTag, durability).create();
}

public enum ToolType {
Expand Down

0 comments on commit 67ebc35

Please sign in to comment.