Fixed tool handler

This commit is contained in:
Auxilor
2024-07-21 14:16:13 +01:00
parent 9fdd769af0
commit c4fa62577a
5 changed files with 27 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
package com.willfp.ecoitems.compat.modern.components
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.items.toSNBT
import com.willfp.ecoitems.items.components.ToolComponentHandler
import org.bukkit.Material
import org.bukkit.Tag
@@ -17,20 +18,19 @@ class ToolComponentHandlerImpl : ToolComponentHandler() {
tool.damagePerBlock = config.getInt("damage-per-block")
if (config.has("rules")) {
tool.rules = mutableListOf()
for (rule in config.getSubsections("rules")) {
val speed = config.getDoubleOrNull("speed")?.toFloat()
val drops = config.getBoolOrNull("drops")
val speed = rule.getDoubleOrNull("speed")?.toFloat()
val drops = rule.getBoolOrNull("drops") ?: true // Leaving null causes weird behavior
val materialIds = config.getStrings("blocks")
val materialIds = rule.getStrings("blocks")
val materials = mutableSetOf<Material>()
val tags = mutableSetOf<Tag<Material>>()
for (id in materialIds) {
if (id.startsWith("#")) {
val tag = getTagByName(id.substring(1))
if (tag != null) {
materials.addAll(tag.values)
tags.add(tag)
}
} else {
val material = Material.getMaterial(id.uppercase())
@@ -40,9 +40,17 @@ class ToolComponentHandlerImpl : ToolComponentHandler() {
}
}
// Add rules for each tag
for (tag in tags) {
tool.addRule(tag, speed, drops)
}
// Add rules for all materials
if (materials.isNotEmpty()) {
tool.addRule(materials, speed, drops)
}
}
}
meta.setTool(tool)
item.itemMeta = meta

View File

@@ -45,7 +45,9 @@ class ItemsDisplay(plugin: EcoPlugin) : DisplayModule(plugin, DisplayPriority.LO
lore.addAll(fis.lore)
if (ecoItem.displayName != null) {
fis.displayName = ecoItem.displayName.formatEco(context)
}
fis.addItemFlags(*itemFast.itemFlags.toTypedArray())
fis.lore = lore
}

View File

@@ -39,7 +39,7 @@ class EcoItem(
val lore: List<String> = config.getStrings("item.lore")
val displayName: String = config.getString("item.display-name")
val displayName: String? = config.getStringOrNull("item.display-name")
val slot = SlotTypes[config.getString("slot")] ?: SlotTypeMainhand
@@ -47,7 +47,9 @@ class EcoItem(
private val _itemStack: ItemStack = run {
val itemConfig = config.getSubsection("item")
ItemStackBuilder(Items.lookup(itemConfig.getString("item")).item).apply {
if (itemConfig.has("display-name")) {
setDisplayName(itemConfig.getFormattedString("display-name"))
}
addLoreLines(
itemConfig.getFormattedStrings("lore").map { "${Display.PREFIX}$it" }
)

View File

@@ -1,9 +1,7 @@
# An example food item (requires Paper 1.21+)
item:
item: cooked_beef glint
display-name: "Enchanted Steak"
item: cooked_beef glint item_name:"Enchanted Steak"
lore: [ ]
craftable: true
recipe:
@@ -18,6 +16,7 @@ item:
- ""
# Options for the food
# These options do not update existing foods, only new ones
food:
# Read here: https://minecraft.fandom.com/wiki/Food#Hunger_and_saturation
nutrition: 12

View File

@@ -1,8 +1,7 @@
# An example tool (Requires Paper 1.21+)
item:
item: netherite_pickaxe glint max_damage:4096
display-name: "Hardened Netherite Pickaxe"
item: netherite_pickaxe glint max_damage:4096 item_name:"Hardened Netherite Pickaxe"
lore: [ ]
craftable: true
recipe:
@@ -19,6 +18,7 @@ item:
- netherite_ingot
# Options for the tool
# These options do not update existing tools, only new ones
tool:
# The default mining speed, if not overridden by any rules
mining-speed: 1.0
@@ -33,7 +33,7 @@ tool:
rules:
- blocks:
- "#mineable_pickaxe" # Tags start with a #
speed: 5.2 # The mining speed for these blocks
speed: 45.8 # The mining speed for these blocks
- blocks:
- "#incorrect_for_netherite_tool"
speed: 1