diff --git a/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java b/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java index db791784f..6efa7b97b 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java +++ b/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java @@ -37,11 +37,20 @@ public class Prerequisite { "Requires server to have ProtocolLib" ); + /** + * Requires the server to be running 1.21. + */ + public static final Prerequisite HAS_1_21 = new Prerequisite( + () -> ProxyConstants.NMS_VERSION.contains("1_21"), + "Requires server to be running 1.21+" + ); + /** * Requires the server to be running 1.20.5. */ public static final Prerequisite HAS_1_20_5 = new Prerequisite( - () -> ProxyConstants.NMS_VERSION.contains("1_20_") && !ProxyConstants.NMS_VERSION.contains("R"), + () -> (ProxyConstants.NMS_VERSION.contains("1_20_") && !ProxyConstants.NMS_VERSION.contains("R")) + || HAS_1_21.isMet(), "Requires server to be running 1.20.5+" ); diff --git a/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java b/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java index 9751395da..3c9f05fa3 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java +++ b/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java @@ -28,7 +28,8 @@ public final class ProxyConstants { "v1_20_R1", "v1_20_R2", "v1_20_R3", - "v1_20_6" + "v1_20_6", + "v1_21" ); private ProxyConstants() { diff --git a/eco-core/core-nms/nms-common/build.gradle.kts b/eco-core/core-nms/nms-common/build.gradle.kts index 11d4fe3bb..4646a6e7f 100644 --- a/eco-core/core-nms/nms-common/build.gradle.kts +++ b/eco-core/core-nms/nms-common/build.gradle.kts @@ -7,6 +7,7 @@ version = rootProject.version dependencies { paperweight.paperDevBundle("1.17.1-R0.1-SNAPSHOT") + pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat") } java { diff --git a/eco-core/core-nms/v1_18_R1/build.gradle.kts b/eco-core/core-nms/v1_18_R1/build.gradle.kts index 746ee752e..9ff3aa778 100644 --- a/eco-core/core-nms/v1_18_R1/build.gradle.kts +++ b/eco-core/core-nms/v1_18_R1/build.gradle.kts @@ -8,6 +8,7 @@ version = rootProject.version dependencies { implementation(project(":eco-core:core-nms:nms-common")) paperweight.paperDevBundle("1.18.1-R0.1-SNAPSHOT") + pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat") implementation("net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT") { version { diff --git a/eco-core/core-nms/v1_18_R2/build.gradle.kts b/eco-core/core-nms/v1_18_R2/build.gradle.kts index 677647fa4..75841efe0 100644 --- a/eco-core/core-nms/v1_18_R2/build.gradle.kts +++ b/eco-core/core-nms/v1_18_R2/build.gradle.kts @@ -8,6 +8,7 @@ version = rootProject.version dependencies { implementation(project(":eco-core:core-nms:nms-common")) paperweight.paperDevBundle("1.18.2-R0.1-SNAPSHOT") + pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat") implementation("net.kyori:adventure-text-minimessage:4.10.0") { version { diff --git a/eco-core/core-nms/v1_19_R1/build.gradle.kts b/eco-core/core-nms/v1_19_R1/build.gradle.kts index b683cb3d5..8f7b30447 100644 --- a/eco-core/core-nms/v1_19_R1/build.gradle.kts +++ b/eco-core/core-nms/v1_19_R1/build.gradle.kts @@ -8,6 +8,7 @@ version = rootProject.version dependencies { implementation(project(":eco-core:core-nms:nms-common")) paperweight.paperDevBundle("1.19-R0.1-SNAPSHOT") + pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat") implementation("net.kyori:adventure-text-minimessage:4.11.0") { version { diff --git a/eco-core/core-nms/v1_19_R2/build.gradle.kts b/eco-core/core-nms/v1_19_R2/build.gradle.kts index ca227f515..308d72c6d 100644 --- a/eco-core/core-nms/v1_19_R2/build.gradle.kts +++ b/eco-core/core-nms/v1_19_R2/build.gradle.kts @@ -8,6 +8,7 @@ version = rootProject.version dependencies { implementation(project(":eco-core:core-nms:nms-common")) paperweight.paperDevBundle("1.19.3-R0.1-SNAPSHOT") + pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat") implementation("net.kyori:adventure-text-minimessage:4.11.0") { version { diff --git a/eco-core/core-nms/v1_19_R3/build.gradle.kts b/eco-core/core-nms/v1_19_R3/build.gradle.kts index 22a13883a..4a07a0c51 100644 --- a/eco-core/core-nms/v1_19_R3/build.gradle.kts +++ b/eco-core/core-nms/v1_19_R3/build.gradle.kts @@ -8,6 +8,7 @@ version = rootProject.version dependencies { implementation(project(":eco-core:core-nms:nms-common")) paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT") + pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat") implementation("net.kyori:adventure-text-minimessage:4.11.0") { version { diff --git a/eco-core/core-nms/v1_20_R1/build.gradle.kts b/eco-core/core-nms/v1_20_R1/build.gradle.kts index 4cff0a460..dac466c38 100644 --- a/eco-core/core-nms/v1_20_R1/build.gradle.kts +++ b/eco-core/core-nms/v1_20_R1/build.gradle.kts @@ -8,6 +8,7 @@ version = rootProject.version dependencies { implementation(project(":eco-core:core-nms:nms-common")) paperweight.paperDevBundle("1.20-R0.1-SNAPSHOT") + pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat") implementation("net.kyori:adventure-text-minimessage:4.11.0") { version { diff --git a/eco-core/core-nms/v1_20_R2/build.gradle.kts b/eco-core/core-nms/v1_20_R2/build.gradle.kts index 977dee0f1..f0d2e6c41 100644 --- a/eco-core/core-nms/v1_20_R2/build.gradle.kts +++ b/eco-core/core-nms/v1_20_R2/build.gradle.kts @@ -8,6 +8,7 @@ version = rootProject.version dependencies { implementation(project(":eco-core:core-nms:nms-common")) paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT") + pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat") implementation("net.kyori:adventure-text-minimessage:4.11.0") { version { diff --git a/eco-core/core-nms/v1_20_R3/build.gradle.kts b/eco-core/core-nms/v1_20_R3/build.gradle.kts index d10e0a8ef..023c955f9 100644 --- a/eco-core/core-nms/v1_20_R3/build.gradle.kts +++ b/eco-core/core-nms/v1_20_R3/build.gradle.kts @@ -8,6 +8,7 @@ version = rootProject.version dependencies { implementation(project(":eco-core:core-nms:nms-common")) paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT") + pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat") implementation("net.kyori:adventure-text-minimessage:4.11.0") { version { diff --git a/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/FastItemStackFactory.kt b/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/FastItemStackFactory.kt index b714f5955..e56fbd2d1 100644 --- a/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/FastItemStackFactory.kt +++ b/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/FastItemStackFactory.kt @@ -17,20 +17,27 @@ import com.willfp.eco.util.toComponent import com.willfp.eco.util.toLegacy import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.TextDecoration +import net.minecraft.core.Holder import net.minecraft.core.component.DataComponentType import net.minecraft.core.component.DataComponents +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.core.registries.Registries import net.minecraft.nbt.CompoundTag import net.minecraft.util.Unit import net.minecraft.world.item.component.CustomData import net.minecraft.world.item.component.CustomModelData import net.minecraft.world.item.component.ItemLore +import net.minecraft.world.item.enchantment.EnchantmentHelper +import org.bukkit.Bukkit import org.bukkit.craftbukkit.CraftRegistry +import org.bukkit.craftbukkit.CraftServer import org.bukkit.craftbukkit.enchantments.CraftEnchantment import org.bukkit.enchantments.Enchantment import org.bukkit.inventory.ItemFlag import org.bukkit.inventory.ItemStack import org.bukkit.persistence.PersistentDataContainer import kotlin.math.max +import kotlin.math.min private val unstyledComponent = Component.empty().style { it.color(null).decoration(TextDecoration.ITALIC, false) @@ -72,12 +79,17 @@ class FastItemStackFactory : FastItemStackFactoryProxy { val minecraft = CraftRegistry .bukkitToMinecraft(enchantment) + val server = Bukkit.getServer() as CraftServer + val access = server.server.registryAccess() + + val holder = access.registryOrThrow(Registries.ENCHANTMENT).wrapAsHolder(minecraft) + val enchantments = handle.get(DataComponents.ENCHANTMENTS) ?: return 0 - var level = enchantments.getLevel(minecraft) + var level = enchantments.getLevel(holder) if (checkStored) { val storedEnchantments = handle.get(DataComponents.STORED_ENCHANTMENTS) ?: return 0 - level = max(level, storedEnchantments.getLevel(minecraft)) + level = max(level, storedEnchantments.getLevel(holder)) } return level @@ -260,7 +272,7 @@ class FastItemStackFactory : FastItemStackFactoryProxy { override fun getItemFlags(): Set { val currentFlags = mutableSetOf() - for (f in ItemFlag.values()) { + for (f in ItemFlag.entries) { if (hasItemFlag(f)) { currentFlags.add(f) }