Skip to content

Commit

Permalink
Added 1.21 support and fixed paperweight issues for Java 17 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Jun 18, 2024
1 parent 80afa91 commit 3a0e1ea
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 5 deletions.
11 changes: 10 additions & 1 deletion eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java
Original file line number Diff line number Diff line change
Expand Up @@ -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+"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions eco-core/core-nms/nms-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions eco-core/core-nms/v1_18_R1/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions eco-core/core-nms/v1_18_R2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions eco-core/core-nms/v1_19_R1/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions eco-core/core-nms/v1_19_R2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions eco-core/core-nms/v1_19_R3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions eco-core/core-nms/v1_20_R1/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions eco-core/core-nms/v1_20_R2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions eco-core/core-nms/v1_20_R3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -72,12 +79,17 @@ class FastItemStackFactory : FastItemStackFactoryProxy {
val minecraft = CraftRegistry
.bukkitToMinecraft<Enchantment, net.minecraft.world.item.enchantment.Enchantment>(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
Expand Down Expand Up @@ -260,7 +272,7 @@ class FastItemStackFactory : FastItemStackFactoryProxy {

override fun getItemFlags(): Set<ItemFlag> {
val currentFlags = mutableSetOf<ItemFlag>()
for (f in ItemFlag.values()) {
for (f in ItemFlag.entries) {
if (hasItemFlag(f)) {
currentFlags.add(f)
}
Expand Down

0 comments on commit 3a0e1ea

Please sign in to comment.