refactor to allow adding enchants to arbitrary tags

This commit is contained in:
2024-10-28 16:01:51 +01:00
parent deb4d0d67a
commit 3752a9e31a
8 changed files with 93 additions and 89 deletions
@@ -1,14 +1,17 @@
package me.youhavetrouble.enchantio.enchants;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
import io.papermc.paper.registry.keys.tags.EnchantmentTagKeys;
import io.papermc.paper.registry.tag.TagKey;
import io.papermc.paper.tag.TagEntry;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@SuppressWarnings("UnstableApiUsage")
@@ -19,8 +22,8 @@ public class ReplantingEnchant implements EnchantioEnchant {
private final int anvilCost, weight;
private final EnchantmentRegistryEntry.EnchantmentCost minimumCost;
private final EnchantmentRegistryEntry.EnchantmentCost maximumCost;
private final boolean canGetFromEnchantingTable;
private final Set<TagEntry<ItemType>> supportedItemTags;
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
public ReplantingEnchant(
int anvilCost,
@@ -34,8 +37,10 @@ public class ReplantingEnchant implements EnchantioEnchant {
this.weight = weight;
this.minimumCost = minimumCost;
this.maximumCost = maximumCost;
this.canGetFromEnchantingTable = canGetFromEnchantingTable;
this.supportedItemTags = supportedItemTags;
if (canGetFromEnchantingTable) {
enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE);
}
}
@Override
@@ -78,19 +83,14 @@ public class ReplantingEnchant implements EnchantioEnchant {
return Set.of(EquipmentSlotGroup.HAND);
}
@Override
public boolean canGetFromEnchantingTable() {
return canGetFromEnchantingTable;
}
@Override
public TagKey<ItemType> getTagForSupportedItems() {
return TagKey.create(RegistryKey.ITEM, Key.key("enchantio:replanting_enchantable"));
}
@Override
public Set<TagEntry<ItemType>> getSupportedItems() {
return supportedItemTags;
}
@Override
public Set<TagKey<Enchantment>> getEnchantTagKeys() {
return Collections.unmodifiableSet(enchantTagKeys);
}
}