Fixed tool handler
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.willfp.ecoitems.compat.modern.components
|
package com.willfp.ecoitems.compat.modern.components
|
||||||
|
|
||||||
import com.willfp.eco.core.config.interfaces.Config
|
import com.willfp.eco.core.config.interfaces.Config
|
||||||
|
import com.willfp.eco.core.items.toSNBT
|
||||||
import com.willfp.ecoitems.items.components.ToolComponentHandler
|
import com.willfp.ecoitems.items.components.ToolComponentHandler
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.Tag
|
import org.bukkit.Tag
|
||||||
@@ -17,20 +18,19 @@ class ToolComponentHandlerImpl : ToolComponentHandler() {
|
|||||||
tool.damagePerBlock = config.getInt("damage-per-block")
|
tool.damagePerBlock = config.getInt("damage-per-block")
|
||||||
|
|
||||||
if (config.has("rules")) {
|
if (config.has("rules")) {
|
||||||
tool.rules = mutableListOf()
|
|
||||||
|
|
||||||
for (rule in config.getSubsections("rules")) {
|
for (rule in config.getSubsections("rules")) {
|
||||||
val speed = config.getDoubleOrNull("speed")?.toFloat()
|
val speed = rule.getDoubleOrNull("speed")?.toFloat()
|
||||||
val drops = config.getBoolOrNull("drops")
|
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 materials = mutableSetOf<Material>()
|
||||||
|
val tags = mutableSetOf<Tag<Material>>()
|
||||||
|
|
||||||
for (id in materialIds) {
|
for (id in materialIds) {
|
||||||
if (id.startsWith("#")) {
|
if (id.startsWith("#")) {
|
||||||
val tag = getTagByName(id.substring(1))
|
val tag = getTagByName(id.substring(1))
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
materials.addAll(tag.values)
|
tags.add(tag)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val material = Material.getMaterial(id.uppercase())
|
val material = Material.getMaterial(id.uppercase())
|
||||||
@@ -40,7 +40,15 @@ class ToolComponentHandlerImpl : ToolComponentHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tool.addRule(materials, speed, drops)
|
// 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,9 @@ class ItemsDisplay(plugin: EcoPlugin) : DisplayModule(plugin, DisplayPriority.LO
|
|||||||
|
|
||||||
lore.addAll(fis.lore)
|
lore.addAll(fis.lore)
|
||||||
|
|
||||||
fis.displayName = ecoItem.displayName.formatEco(context)
|
if (ecoItem.displayName != null) {
|
||||||
|
fis.displayName = ecoItem.displayName.formatEco(context)
|
||||||
|
}
|
||||||
fis.addItemFlags(*itemFast.itemFlags.toTypedArray())
|
fis.addItemFlags(*itemFast.itemFlags.toTypedArray())
|
||||||
fis.lore = lore
|
fis.lore = lore
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class EcoItem(
|
|||||||
|
|
||||||
val lore: List<String> = config.getStrings("item.lore")
|
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
|
val slot = SlotTypes[config.getString("slot")] ?: SlotTypeMainhand
|
||||||
|
|
||||||
@@ -47,7 +47,9 @@ class EcoItem(
|
|||||||
private val _itemStack: ItemStack = run {
|
private val _itemStack: ItemStack = run {
|
||||||
val itemConfig = config.getSubsection("item")
|
val itemConfig = config.getSubsection("item")
|
||||||
ItemStackBuilder(Items.lookup(itemConfig.getString("item")).item).apply {
|
ItemStackBuilder(Items.lookup(itemConfig.getString("item")).item).apply {
|
||||||
setDisplayName(itemConfig.getFormattedString("display-name"))
|
if (itemConfig.has("display-name")) {
|
||||||
|
setDisplayName(itemConfig.getFormattedString("display-name"))
|
||||||
|
}
|
||||||
addLoreLines(
|
addLoreLines(
|
||||||
itemConfig.getFormattedStrings("lore").map { "${Display.PREFIX}$it" }
|
itemConfig.getFormattedStrings("lore").map { "${Display.PREFIX}$it" }
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
# An example food item (requires Paper 1.21+)
|
# An example food item (requires Paper 1.21+)
|
||||||
|
|
||||||
|
|
||||||
item:
|
item:
|
||||||
item: cooked_beef glint
|
item: cooked_beef glint item_name:"Enchanted Steak"
|
||||||
display-name: "Enchanted Steak"
|
|
||||||
lore: [ ]
|
lore: [ ]
|
||||||
craftable: true
|
craftable: true
|
||||||
recipe:
|
recipe:
|
||||||
@@ -18,6 +16,7 @@ item:
|
|||||||
- ""
|
- ""
|
||||||
|
|
||||||
# Options for the food
|
# Options for the food
|
||||||
|
# These options do not update existing foods, only new ones
|
||||||
food:
|
food:
|
||||||
# Read here: https://minecraft.fandom.com/wiki/Food#Hunger_and_saturation
|
# Read here: https://minecraft.fandom.com/wiki/Food#Hunger_and_saturation
|
||||||
nutrition: 12
|
nutrition: 12
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
# An example tool (Requires Paper 1.21+)
|
# An example tool (Requires Paper 1.21+)
|
||||||
|
|
||||||
item:
|
item:
|
||||||
item: netherite_pickaxe glint max_damage:4096
|
item: netherite_pickaxe glint max_damage:4096 item_name:"Hardened Netherite Pickaxe"
|
||||||
display-name: "Hardened Netherite Pickaxe"
|
|
||||||
lore: [ ]
|
lore: [ ]
|
||||||
craftable: true
|
craftable: true
|
||||||
recipe:
|
recipe:
|
||||||
@@ -19,6 +18,7 @@ item:
|
|||||||
- netherite_ingot
|
- netherite_ingot
|
||||||
|
|
||||||
# Options for the tool
|
# Options for the tool
|
||||||
|
# These options do not update existing tools, only new ones
|
||||||
tool:
|
tool:
|
||||||
# The default mining speed, if not overridden by any rules
|
# The default mining speed, if not overridden by any rules
|
||||||
mining-speed: 1.0
|
mining-speed: 1.0
|
||||||
@@ -33,7 +33,7 @@ tool:
|
|||||||
rules:
|
rules:
|
||||||
- blocks:
|
- blocks:
|
||||||
- "#mineable_pickaxe" # Tags start with a #
|
- "#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:
|
- blocks:
|
||||||
- "#incorrect_for_netherite_tool"
|
- "#incorrect_for_netherite_tool"
|
||||||
speed: 1
|
speed: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user