mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
get item type via name
This commit is contained in:
parent
ce8bda9f63
commit
25b4ea51e0
2 changed files with 19 additions and 35 deletions
|
|
@ -2,8 +2,9 @@ package xyz.alexcrea.cuanvil.dependency.datapack
|
|||
|
||||
import io.delilaheve.CustomAnvil
|
||||
import io.papermc.paper.datapack.Datapack
|
||||
import io.papermc.paper.registry.RegistryAccess
|
||||
import io.papermc.paper.registry.RegistryKey
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.configuration.file.FileConfiguration
|
||||
import org.bukkit.configuration.file.YamlConfiguration
|
||||
|
|
@ -135,8 +136,7 @@ object DataPackDependency {
|
|||
// Order matter for this file
|
||||
// Could rewrite to not matter but not really important, so I keep it like that
|
||||
private fun handleItemGroups(yml: YamlConfiguration) {
|
||||
//TODO see below todo
|
||||
//val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
||||
val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
||||
|
||||
for (groupName in yml.getKeys(false)) {
|
||||
val section = yml.getConfigurationSection(groupName) ?: continue
|
||||
|
|
@ -147,19 +147,15 @@ object DataPackDependency {
|
|||
if (group == null) group = IncludeGroup(groupName)
|
||||
|
||||
for (name in section.getStringList("items")) {
|
||||
//TODO get item key from
|
||||
/*val key = NamespacedKey.fromString(name.lowercase())
|
||||
if (key == null) throw IllegalStateException("Invalid item type: " + name)
|
||||
val type = itemRegistry.get(key)*/
|
||||
val key = NamespacedKey.fromString(name.lowercase())
|
||||
if (key == null) throw IllegalStateException("Invalid item type: $name")
|
||||
|
||||
val mat = Material.getMaterial(name.uppercase())
|
||||
|
||||
|
||||
if (mat == null) {
|
||||
CustomAnvil.instance.logger.warning("Could not find material $name for item group $groupName")
|
||||
continue
|
||||
val type = itemRegistry.get(key)
|
||||
if (type == null) {
|
||||
throw IllegalStateException("Could not find item type $name for item group $groupName")
|
||||
}
|
||||
group.addToPolicy(mat.asItemType()!!)
|
||||
|
||||
group.addToPolicy(type)
|
||||
}
|
||||
for (name in section.getStringList("groups")) {
|
||||
val otherGroup = MaterialGroupApi.getGroup(name)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package xyz.alexcrea.cuanvil.group
|
||||
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.Material
|
||||
import io.papermc.paper.registry.RegistryAccess
|
||||
import io.papermc.paper.registry.RegistryKey
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
import java.util.*
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
class ItemGroupManager {
|
||||
|
||||
companion object {
|
||||
|
|
@ -76,14 +79,12 @@ class ItemGroupManager {
|
|||
config: ConfigurationSection,
|
||||
keys: Set<String>
|
||||
) {
|
||||
//TODO see below todo
|
||||
//val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
||||
val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
||||
|
||||
// Read material to include in this group policy
|
||||
val materialList = groupSection.getStringList(MATERIAL_LIST_PATH)
|
||||
for (typeName in materialList) {
|
||||
//TODO get item key from
|
||||
/*val key = NamespacedKey.fromString(typeName.lowercase())
|
||||
val key = NamespacedKey.fromString(typeName.lowercase())
|
||||
if (key == null) {
|
||||
CustomAnvil.instance.logger.warning(
|
||||
"Malformed item type $typeName on group ${group.getName()}"
|
||||
|
|
@ -102,22 +103,9 @@ class ItemGroupManager {
|
|||
|
||||
}
|
||||
continue
|
||||
}*/
|
||||
|
||||
|
||||
val materialName = typeName.uppercase(Locale.getDefault())
|
||||
val material = Material.getMaterial(materialName)
|
||||
if (material == null) {
|
||||
// Check if we should warn the user
|
||||
if (materialName !in FUTURE_MATERIAL) {
|
||||
CustomAnvil.instance.logger.warning(
|
||||
"Unknown material $materialName on group ${group.getName()}"
|
||||
)
|
||||
|
||||
}
|
||||
continue
|
||||
}
|
||||
group.addToPolicy(material.asItemType()!!)
|
||||
|
||||
group.addToPolicy(type)
|
||||
}
|
||||
|
||||
// Read group to include in this group policy.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue