adjust costs and make enchants available from enchantment table

This commit is contained in:
2024-10-19 15:20:39 +02:00
parent 1ce0d200de
commit 8e7d95d7f8
5 changed files with 41 additions and 7 deletions
@@ -8,6 +8,7 @@ public final class Enchantio extends JavaPlugin {
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new SoulboundListener(), this);
getServer().getPluginManager().registerEvents(new TelepathyListener(), this);
}
@@ -3,15 +3,22 @@ package me.youhavetrouble.enchantio;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
import io.papermc.paper.plugin.bootstrap.PluginProviderContext;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.TypedKey;
import io.papermc.paper.registry.event.RegistryEvents;
import io.papermc.paper.registry.keys.tags.EnchantmentTagKeys;
import io.papermc.paper.tag.TagEntry;
import me.youhavetrouble.enchantio.enchants.EnchantioEnchant;
import me.youhavetrouble.enchantio.enchants.SoulboundEnchant;
import me.youhavetrouble.enchantio.enchants.TelepathyEnchant;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
@SuppressWarnings("all")
public class EnchantioBootstrap implements PluginBootstrap {
@Override
@@ -36,6 +43,15 @@ public class EnchantioBootstrap implements PluginBootstrap {
}
}));
context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ENCHANTMENT).newHandler((event) -> {
Set<TagEntry<Enchantment>> enchantTags = new HashSet<>(EnchantioEnchant.getEnchants().size());
for (EnchantioEnchant enchant : EnchantioEnchant.getEnchants().values()) {
if (!enchant.canGetFromEnchantingTable()) continue;
enchantTags.add(enchant.getTagEntry());
}
event.registrar().addToTag(EnchantmentTagKeys.IN_ENCHANTING_TABLE, enchantTags);
}));
}
@Override
@@ -1,9 +1,13 @@
package me.youhavetrouble.enchantio.enchants;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.TypedKey;
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
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;
@@ -27,6 +31,7 @@ public abstract class EnchantioEnchant {
private final TagKey<ItemType> supportedItems;
private final TagKey<ItemType> primaryItems;
private final Set<EquipmentSlotGroup> activeSlots;
private final boolean canGetFromEnchantingTable;
public EnchantioEnchant(
Key key,
@@ -38,7 +43,8 @@ public abstract class EnchantioEnchant {
EnchantmentRegistryEntry.EnchantmentCost maximumCost,
TagKey<ItemType> primaryItems,
TagKey<ItemType> supportedItems,
Set<EquipmentSlotGroup> activeSlots
Set<EquipmentSlotGroup> activeSlots,
boolean canGetFromEnchantingTable
) {
this.key = key;
this.description = description;
@@ -50,6 +56,7 @@ public abstract class EnchantioEnchant {
this.primaryItems = primaryItems;
this.supportedItems = supportedItems;
this.activeSlots = activeSlots;
this.canGetFromEnchantingTable = canGetFromEnchantingTable;
}
public Key getKey() {
@@ -92,6 +99,14 @@ public abstract class EnchantioEnchant {
return activeSlots;
}
public boolean canGetFromEnchantingTable() {
return canGetFromEnchantingTable;
}
public TagEntry<Enchantment> getTagEntry() {
return TagEntry.valueEntry(TypedKey.create(RegistryKey.ENCHANTMENT, getKey()));
}
protected static void registerEnchant(EnchantioEnchant enchant) {
enchantioEnchants.put(enchant.getKey().asString(), enchant);
}
@@ -18,11 +18,12 @@ public class SoulboundEnchant extends EnchantioEnchant {
1,
1,
10,
EnchantmentRegistryEntry.EnchantmentCost.of(1, 1),
EnchantmentRegistryEntry.EnchantmentCost.of(3, 1),
EnchantmentRegistryEntry.EnchantmentCost.of(10, 1),
EnchantmentRegistryEntry.EnchantmentCost.of(30, 1),
ItemTypeTagKeys.ENCHANTABLE_ARMOR,
ItemTypeTagKeys.ENCHANTABLE_ARMOR,
Set.of(EquipmentSlotGroup.ANY)
Set.of(EquipmentSlotGroup.ANY),
true
);
registerEnchant(this);
}
@@ -19,11 +19,12 @@ public class TelepathyEnchant extends EnchantioEnchant {
1,
1,
4,
EnchantmentRegistryEntry.EnchantmentCost.of(1, 1),
EnchantmentRegistryEntry.EnchantmentCost.of(3, 1),
EnchantmentRegistryEntry.EnchantmentCost.of(15, 1),
EnchantmentRegistryEntry.EnchantmentCost.of(30, 1),
ItemTypeTagKeys.ENCHANTABLE_MINING,
ItemTypeTagKeys.ENCHANTABLE_MINING,
Set.of(EquipmentSlotGroup.ANY)
Set.of(EquipmentSlotGroup.ANY),
true
);
registerEnchant(this);
}