mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-24 15:25:18 +01:00
Added 1.20.6 support for testing environments only.
This commit is contained in:
parent
bae3809cc2
commit
8adad9a935
@ -3,7 +3,7 @@ plugins {
|
|||||||
`java-library`
|
`java-library`
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
kotlin("jvm") version "1.9.20"
|
kotlin("jvm") version "1.9.20"
|
||||||
id("com.github.johnrengelman.shadow") version "8.0.0"
|
id("io.github.goooler.shadow") version "8.1.7"
|
||||||
id("com.willfp.libreforge-gradle-plugin") version "1.0.0"
|
id("com.willfp.libreforge-gradle-plugin") version "1.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,13 +26,14 @@ dependencies {
|
|||||||
implementation(project(":eco-core:core-nms:v1_20_R1"))
|
implementation(project(":eco-core:core-nms:v1_20_R1"))
|
||||||
implementation(project(":eco-core:core-nms:v1_20_R2"))
|
implementation(project(":eco-core:core-nms:v1_20_R2"))
|
||||||
implementation(project(":eco-core:core-nms:v1_20_R3", configuration = "reobf"))
|
implementation(project(":eco-core:core-nms:v1_20_R3", configuration = "reobf"))
|
||||||
|
implementation(project(":eco-core:core-nms:v1_20_6", configuration = "reobf"))
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
apply(plugin = "kotlin")
|
apply(plugin = "kotlin")
|
||||||
apply(plugin = "maven-publish")
|
apply(plugin = "maven-publish")
|
||||||
apply(plugin = "com.github.johnrengelman.shadow")
|
apply(plugin = "io.github.goooler.shadow")
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
@ -47,17 +48,12 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.willfp:eco:6.67.1")
|
compileOnly("com.willfp:eco:6.70.0")
|
||||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||||
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.9.20")
|
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.9.20")
|
||||||
compileOnly("com.github.ben-manes.caffeine:caffeine:3.1.5")
|
compileOnly("com.github.ben-manes.caffeine:caffeine:3.1.5")
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
|
||||||
withSourcesJar()
|
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
shadowJar {
|
shadowJar {
|
||||||
relocate("com.willfp.libreforge.loader", "com.willfp.ecoenchants.libreforge.loader")
|
relocate("com.willfp.libreforge.loader", "com.willfp.ecoenchants.libreforge.loader")
|
||||||
@ -69,6 +65,12 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
compileJava {
|
compileJava {
|
||||||
options.isDeprecation = true
|
options.isDeprecation = true
|
||||||
options.encoding = "UTF-8"
|
options.encoding = "UTF-8"
|
||||||
@ -91,3 +93,10 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Root is Java 21 to support 1.20.6+, rest use Java 17
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_21
|
||||||
|
targetCompatibility = JavaVersion.VERSION_21
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("io.papermc.paperweight.userdev") version "1.5.3" apply false
|
id("io.papermc.paperweight.userdev") version "1.6.2" apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_17_R1
|
||||||
|
|
||||||
|
import com.willfp.eco.core.fast.FastItemStack
|
||||||
|
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
|
||||||
|
import org.bukkit.inventory.ItemFlag
|
||||||
|
|
||||||
|
class HideStoredEnchants: HideStoredEnchantsProxy {
|
||||||
|
override fun hideStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean {
|
||||||
|
return fis.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_18_R1
|
||||||
|
|
||||||
|
import com.willfp.eco.core.fast.FastItemStack
|
||||||
|
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
|
||||||
|
import org.bukkit.inventory.ItemFlag
|
||||||
|
|
||||||
|
class HideStoredEnchants: HideStoredEnchantsProxy {
|
||||||
|
override fun hideStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean {
|
||||||
|
return fis.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_18_R2
|
||||||
|
|
||||||
|
import com.willfp.eco.core.fast.FastItemStack
|
||||||
|
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
|
||||||
|
import org.bukkit.inventory.ItemFlag
|
||||||
|
|
||||||
|
class HideStoredEnchants: HideStoredEnchantsProxy {
|
||||||
|
override fun hideStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean {
|
||||||
|
return fis.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_19_R1
|
||||||
|
|
||||||
|
import com.willfp.eco.core.fast.FastItemStack
|
||||||
|
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
|
||||||
|
import org.bukkit.inventory.ItemFlag
|
||||||
|
|
||||||
|
class HideStoredEnchants: HideStoredEnchantsProxy {
|
||||||
|
override fun hideStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean {
|
||||||
|
return fis.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_19_R2
|
||||||
|
|
||||||
|
import com.willfp.eco.core.fast.FastItemStack
|
||||||
|
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
|
||||||
|
import org.bukkit.inventory.ItemFlag
|
||||||
|
|
||||||
|
class HideStoredEnchants: HideStoredEnchantsProxy {
|
||||||
|
override fun hideStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean {
|
||||||
|
return fis.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_19_R3
|
||||||
|
|
||||||
|
import com.willfp.eco.core.fast.FastItemStack
|
||||||
|
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
|
||||||
|
import org.bukkit.inventory.ItemFlag
|
||||||
|
|
||||||
|
class HideStoredEnchants: HideStoredEnchantsProxy {
|
||||||
|
override fun hideStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean {
|
||||||
|
return fis.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
}
|
28
eco-core/core-nms/v1_20_6/build.gradle.kts
Normal file
28
eco-core/core-nms/v1_20_6/build.gradle.kts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
plugins {
|
||||||
|
id("io.papermc.paperweight.userdev")
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "com.willfp"
|
||||||
|
version = rootProject.version
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
build {
|
||||||
|
dependsOn(reobfJar)
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_21
|
||||||
|
targetCompatibility = JavaVersion.VERSION_21
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
compileKotlin {
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "21"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,229 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_20_6
|
||||||
|
|
||||||
|
import com.willfp.eco.core.Prerequisite
|
||||||
|
import com.willfp.ecoenchants.CodecReplacerProxy
|
||||||
|
import com.willfp.ecoenchants.proxy.v1_20_6.registration.VanillaEcoEnchantsEnchantment
|
||||||
|
import com.willfp.ecoenchants.setStaticFinal
|
||||||
|
import net.minecraft.core.Holder
|
||||||
|
import net.minecraft.core.NonNullList
|
||||||
|
import net.minecraft.core.component.DataComponentPatch
|
||||||
|
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.nbt.ListTag
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.network.chat.ComponentSerialization
|
||||||
|
import net.minecraft.network.codec.ByteBufCodecs
|
||||||
|
import net.minecraft.network.codec.StreamCodec
|
||||||
|
import net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.world.item.Item
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
|
import net.minecraft.world.item.component.CustomData
|
||||||
|
import net.minecraft.world.item.enchantment.Enchantment
|
||||||
|
import net.minecraft.world.item.enchantment.ItemEnchantments
|
||||||
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers
|
||||||
|
|
||||||
|
class CodecReplacer : CodecReplacerProxy {
|
||||||
|
override fun replaceItemCodec() {
|
||||||
|
ItemStack::class.java
|
||||||
|
.getDeclaredField("OPTIONAL_STREAM_CODEC")
|
||||||
|
.setStaticFinal(PatchedStreamCodec)
|
||||||
|
|
||||||
|
ItemStack::class.java
|
||||||
|
.getDeclaredField("OPTIONAL_LIST_STREAM_CODEC")
|
||||||
|
.setStaticFinal(
|
||||||
|
PatchedStreamCodec.apply(ByteBufCodecs.collection { size ->
|
||||||
|
NonNullList.createWithCapacity(size)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
ServerboundSetCreativeModeSlotPacket.STREAM_CODEC::class.java
|
||||||
|
.getDeclaredField("val\$codec2")
|
||||||
|
.apply {
|
||||||
|
isAccessible = true
|
||||||
|
set(
|
||||||
|
ServerboundSetCreativeModeSlotPacket.STREAM_CODEC,
|
||||||
|
ItemStack.validatedStreamCodec(PatchedStreamCodec)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private object PatchedStreamCodec : StreamCodec<RegistryFriendlyByteBuf, ItemStack> {
|
||||||
|
private const val nbtKey = "ecoenchants:client_enchs_patch"
|
||||||
|
private const val nbtKeyShow = "ecoenchants:client_enchs_patch_show"
|
||||||
|
private const val nbtKeyGlint = "ecoenchants:client_enchs_patch_glint"
|
||||||
|
|
||||||
|
private val itemStreamCodec = ByteBufCodecs.holderRegistry(Registries.ITEM)
|
||||||
|
|
||||||
|
fun Enchantment.isEco() = this is VanillaEcoEnchantsEnchantment
|
||||||
|
|
||||||
|
fun Map<Enchantment, Int>.toComponent(): ItemEnchantments {
|
||||||
|
val component = ItemEnchantments.Mutable(ItemEnchantments.EMPTY)
|
||||||
|
for ((enchant, level) in this) {
|
||||||
|
component.set(enchant, level)
|
||||||
|
}
|
||||||
|
return component.toImmutable()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun serialize(itemStack: ItemStack): ItemStack {
|
||||||
|
val enchantments = itemStack.get(DataComponents.ENCHANTMENTS) ?: return itemStack
|
||||||
|
|
||||||
|
// Separate out enchantments into vanilla and custom
|
||||||
|
val vanillaEnchantments = mutableMapOf<Enchantment, Int>()
|
||||||
|
val customEnchantments = mutableMapOf<Enchantment, Int>()
|
||||||
|
|
||||||
|
for ((holder, level) in enchantments.entrySet()) {
|
||||||
|
val enchant = holder.value()
|
||||||
|
if (enchant.isEco()) {
|
||||||
|
customEnchantments[enchant] = level
|
||||||
|
} else {
|
||||||
|
vanillaEnchantments[enchant] = level
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customEnchantments.isEmpty()) {
|
||||||
|
return itemStack
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only keep vanilla enchants in NBT
|
||||||
|
itemStack.set(
|
||||||
|
DataComponents.ENCHANTMENTS,
|
||||||
|
vanillaEnchantments
|
||||||
|
.toComponent()
|
||||||
|
.withTooltip(enchantments.showInTooltip)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Override glint
|
||||||
|
val hasGlint = itemStack.get(DataComponents.ENCHANTMENT_GLINT_OVERRIDE)
|
||||||
|
itemStack.set(DataComponents.ENCHANTMENT_GLINT_OVERRIDE, true)
|
||||||
|
|
||||||
|
// Put custom enchants in custom data
|
||||||
|
val customData = itemStack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).update {
|
||||||
|
it.remove(nbtKey)
|
||||||
|
|
||||||
|
val tag = ListTag()
|
||||||
|
|
||||||
|
for ((enchant, level) in customEnchantments) {
|
||||||
|
val id = BuiltInRegistries.ENCHANTMENT.getKey(enchant) ?: continue
|
||||||
|
|
||||||
|
tag.add(CompoundTag().apply {
|
||||||
|
putString("id", id.toString())
|
||||||
|
putInt("lvl", level)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
it.put(nbtKey, tag)
|
||||||
|
it.putBoolean(nbtKeyShow, enchantments.showInTooltip)
|
||||||
|
if (hasGlint != null) {
|
||||||
|
it.putBoolean(nbtKeyGlint, hasGlint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemStack.set(DataComponents.CUSTOM_DATA, customData)
|
||||||
|
|
||||||
|
return itemStack
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deserialize(itemStack: ItemStack): ItemStack {
|
||||||
|
val customData = itemStack.get(DataComponents.CUSTOM_DATA) ?: return itemStack
|
||||||
|
|
||||||
|
// Fetch enchantments from custom data
|
||||||
|
val enchantments = ItemEnchantments.Mutable(
|
||||||
|
itemStack.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY)
|
||||||
|
)
|
||||||
|
|
||||||
|
val customDataTag = customData.copyTag()
|
||||||
|
|
||||||
|
customDataTag.getList(nbtKey, CraftMagicNumbers.NBT.TAG_COMPOUND)
|
||||||
|
.filterIsInstance<CompoundTag>()
|
||||||
|
.forEach { tag ->
|
||||||
|
val id = tag.getString("id")
|
||||||
|
val level = tag.getInt("lvl")
|
||||||
|
|
||||||
|
val enchant = BuiltInRegistries.ENCHANTMENT.get(
|
||||||
|
ResourceLocation(id)
|
||||||
|
) ?: return@forEach
|
||||||
|
|
||||||
|
enchantments.set(enchant, level)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enchantments.keySet().isEmpty()) {
|
||||||
|
return itemStack
|
||||||
|
}
|
||||||
|
|
||||||
|
enchantments.showInTooltip = customDataTag.getBoolean(nbtKeyShow)
|
||||||
|
|
||||||
|
// Remove extra data
|
||||||
|
val cleaned = customData.update {
|
||||||
|
it.remove(nbtKey)
|
||||||
|
it.remove(nbtKeyShow)
|
||||||
|
it.remove(nbtKeyGlint)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set to item
|
||||||
|
itemStack.set(DataComponents.ENCHANTMENTS, enchantments.toImmutable())
|
||||||
|
|
||||||
|
// Reset glint
|
||||||
|
val hasGlint = if (customDataTag.contains(nbtKeyGlint)) {
|
||||||
|
customDataTag.getBoolean(nbtKeyGlint)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
itemStack.set(DataComponents.ENCHANTMENT_GLINT_OVERRIDE, hasGlint)
|
||||||
|
|
||||||
|
// Set cleaned data
|
||||||
|
if (cleaned.isEmpty) {
|
||||||
|
itemStack.remove(DataComponents.CUSTOM_DATA)
|
||||||
|
} else {
|
||||||
|
itemStack.set(DataComponents.CUSTOM_DATA, cleaned)
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemStack
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decode(buf: RegistryFriendlyByteBuf): ItemStack {
|
||||||
|
val i = buf.readVarInt()
|
||||||
|
return if (i <= 0) {
|
||||||
|
ItemStack.EMPTY
|
||||||
|
} else {
|
||||||
|
val holder: Holder<Item> =
|
||||||
|
itemStreamCodec.decode(buf) as Holder<Item>
|
||||||
|
val dataComponentPatch =
|
||||||
|
DataComponentPatch.STREAM_CODEC.decode(buf) as DataComponentPatch
|
||||||
|
|
||||||
|
deserialize(ItemStack(holder, i, dataComponentPatch))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun encode(buf: RegistryFriendlyByteBuf, itemStack: ItemStack) {
|
||||||
|
@Suppress("SENSELESS_COMPARISON")
|
||||||
|
if (itemStack.isEmpty || itemStack.item == null) {
|
||||||
|
buf.writeVarInt(0)
|
||||||
|
} else {
|
||||||
|
val remapped = serialize(itemStack)
|
||||||
|
|
||||||
|
buf.writeVarInt(remapped.count)
|
||||||
|
|
||||||
|
itemStreamCodec.encode(
|
||||||
|
buf,
|
||||||
|
remapped.itemHolder
|
||||||
|
)
|
||||||
|
|
||||||
|
if (Prerequisite.HAS_PAPER.isMet) {
|
||||||
|
// Paper start - adventure; conditionally render translatable components
|
||||||
|
val prev = ComponentSerialization.DONT_RENDER_TRANSLATABLES.get()
|
||||||
|
try {
|
||||||
|
ComponentSerialization.DONT_RENDER_TRANSLATABLES.set(true)
|
||||||
|
DataComponentPatch.STREAM_CODEC.encode(buf, remapped.componentsPatch)
|
||||||
|
} finally {
|
||||||
|
ComponentSerialization.DONT_RENDER_TRANSLATABLES.set(prev)
|
||||||
|
}
|
||||||
|
// Paper end - adventure; conditionally render translatable components
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_20_6
|
||||||
|
|
||||||
|
import com.willfp.eco.core.fast.FastItemStack
|
||||||
|
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
|
||||||
|
import org.bukkit.inventory.ItemFlag
|
||||||
|
|
||||||
|
class HideStoredEnchants: HideStoredEnchantsProxy {
|
||||||
|
override fun hideStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.addItemFlags(ItemFlag.HIDE_STORED_ENCHANTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean {
|
||||||
|
return fis.hasItemFlag(ItemFlag.HIDE_STORED_ENCHANTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.removeItemFlags(ItemFlag.HIDE_STORED_ENCHANTS)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_20_6
|
||||||
|
|
||||||
|
import com.willfp.ecoenchants.enchant.EcoEnchant
|
||||||
|
import com.willfp.ecoenchants.enchant.EcoEnchants
|
||||||
|
import com.willfp.ecoenchants.enchant.impl.EcoEnchantBase
|
||||||
|
import com.willfp.ecoenchants.enchant.registration.modern.ModernEnchantmentRegistererProxy
|
||||||
|
import com.willfp.ecoenchants.proxy.v1_20_6.registration.EcoEnchantsCraftEnchantment
|
||||||
|
import com.willfp.ecoenchants.proxy.v1_20_6.registration.ModifiedVanillaCraftEnchantment
|
||||||
|
import com.willfp.ecoenchants.proxy.v1_20_6.registration.VanillaEcoEnchantsEnchantment
|
||||||
|
import net.minecraft.core.Holder
|
||||||
|
import net.minecraft.core.MappedRegistry
|
||||||
|
import net.minecraft.core.Registry
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
|
import net.minecraft.world.item.enchantment.Enchantments
|
||||||
|
import org.bukkit.NamespacedKey
|
||||||
|
import org.bukkit.craftbukkit.CraftRegistry
|
||||||
|
import org.bukkit.craftbukkit.util.CraftNamespacedKey
|
||||||
|
import org.bukkit.enchantments.Enchantment
|
||||||
|
import java.util.IdentityHashMap
|
||||||
|
import java.util.function.BiFunction
|
||||||
|
|
||||||
|
class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy {
|
||||||
|
private val frozenField = MappedRegistry::class.java
|
||||||
|
.declaredFields
|
||||||
|
.filter { it.type.isPrimitive }[0]
|
||||||
|
.apply { isAccessible = true }
|
||||||
|
|
||||||
|
private val unregisteredIntrusiveHoldersField = MappedRegistry::class.java
|
||||||
|
.declaredFields
|
||||||
|
.last { it.type == Map::class.java }
|
||||||
|
.apply { isAccessible = true }
|
||||||
|
|
||||||
|
private val minecraftToBukkit = CraftRegistry::class.java
|
||||||
|
.getDeclaredField("minecraftToBukkit")
|
||||||
|
.apply { isAccessible = true }
|
||||||
|
|
||||||
|
private val vanillaEnchantments = Enchantments::class.java
|
||||||
|
.declaredFields
|
||||||
|
.filter { it.type == net.minecraft.world.item.enchantment.Enchantment::class.java }
|
||||||
|
.map { it.get(null) as net.minecraft.world.item.enchantment.Enchantment }
|
||||||
|
.mapNotNull { BuiltInRegistries.ENCHANTMENT.getKey(it) }
|
||||||
|
.map { CraftNamespacedKey.fromMinecraft(it) }
|
||||||
|
.toSet()
|
||||||
|
|
||||||
|
override fun replaceRegistry() {
|
||||||
|
val newRegistryMTB =
|
||||||
|
BiFunction<NamespacedKey, net.minecraft.world.item.enchantment.Enchantment, Enchantment> { key, registry ->
|
||||||
|
val isVanilla = vanillaEnchantments.contains(key)
|
||||||
|
val eco = EcoEnchants.getByID(key.key)
|
||||||
|
|
||||||
|
if (isVanilla) {
|
||||||
|
ModifiedVanillaCraftEnchantment(key, registry)
|
||||||
|
} else if (eco != null) {
|
||||||
|
eco as Enchantment
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update bukkit registry
|
||||||
|
minecraftToBukkit.set(org.bukkit.Registry.ENCHANTMENT, newRegistryMTB)
|
||||||
|
|
||||||
|
// Unfreeze NMS registry
|
||||||
|
frozenField.set(BuiltInRegistries.ENCHANTMENT, false)
|
||||||
|
unregisteredIntrusiveHoldersField.set(
|
||||||
|
BuiltInRegistries.ENCHANTMENT,
|
||||||
|
IdentityHashMap<net.minecraft.world.item.enchantment.Enchantment,
|
||||||
|
Holder.Reference<net.minecraft.world.item.enchantment.Enchantment>>()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun register(enchant: EcoEnchantBase): Enchantment {
|
||||||
|
if (BuiltInRegistries.ENCHANTMENT.containsKey(CraftNamespacedKey.toMinecraft(enchant.enchantmentKey))) {
|
||||||
|
val nms = BuiltInRegistries.ENCHANTMENT[CraftNamespacedKey.toMinecraft(enchant.enchantmentKey)]
|
||||||
|
|
||||||
|
if (nms != null) {
|
||||||
|
return EcoEnchantsCraftEnchantment(enchant, nms)
|
||||||
|
} else {
|
||||||
|
throw IllegalStateException("Enchantment ${enchant.id} wasn't registered")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Registry.register(BuiltInRegistries.ENCHANTMENT, enchant.id, VanillaEcoEnchantsEnchantment(enchant))
|
||||||
|
|
||||||
|
return register(enchant)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun unregister(enchant: EcoEnchant) {
|
||||||
|
/*
|
||||||
|
|
||||||
|
You can't unregister from a minecraft registry, so we simply leave the stale reference there.
|
||||||
|
This shouldn't cause many issues in production as the bukkit registry is replaced on each reload.
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_20_6
|
||||||
|
|
||||||
|
import com.willfp.ecoenchants.mechanics.OpenInventoryProxy
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftPlayer
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
|
class OpenInventory : OpenInventoryProxy {
|
||||||
|
override fun getOpenInventory(player: Player): Any {
|
||||||
|
return (player as CraftPlayer).handle.containerMenu
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_20_6.registration
|
||||||
|
|
||||||
|
import com.willfp.eco.util.toComponent
|
||||||
|
import com.willfp.ecoenchants.display.getFormattedName
|
||||||
|
import com.willfp.ecoenchants.enchant.EcoEnchant
|
||||||
|
import com.willfp.ecoenchants.enchant.impl.EcoEnchantBase
|
||||||
|
import net.kyori.adventure.text.Component
|
||||||
|
import net.minecraft.world.item.enchantment.Enchantment
|
||||||
|
import org.bukkit.craftbukkit.enchantments.CraftEnchantment
|
||||||
|
import org.bukkit.enchantments.EnchantmentTarget
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
|
||||||
|
class EcoEnchantsCraftEnchantment(
|
||||||
|
private val enchant: EcoEnchantBase,
|
||||||
|
nmsEnchantment: Enchantment
|
||||||
|
) : CraftEnchantment(enchant.enchantmentKey, nmsEnchantment), EcoEnchant by enchant {
|
||||||
|
init {
|
||||||
|
enchant.enchantment = this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRegister() {
|
||||||
|
// Fix for hardcoded enchantments
|
||||||
|
if (plugin.isLoaded) {
|
||||||
|
enchant.onRegister()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRemove() {
|
||||||
|
enchant.onRemove()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canEnchantItem(item: ItemStack): Boolean {
|
||||||
|
return enchant.canEnchantItem(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun conflictsWith(other: org.bukkit.enchantments.Enchantment): Boolean {
|
||||||
|
return enchant.conflictsWith(other)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun translationKey(): String {
|
||||||
|
return "ecoenchants:enchantment.$id"
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "getName is a legacy Spigot API",
|
||||||
|
replaceWith = ReplaceWith("this.displayName(level)")
|
||||||
|
)
|
||||||
|
override fun getName(): String = this.id.uppercase()
|
||||||
|
override fun getMaxLevel(): Int = enchant.maximumLevel
|
||||||
|
|
||||||
|
override fun getStartLevel(): Int = 1
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "getItemTargets is an incompatible Spigot API",
|
||||||
|
replaceWith = ReplaceWith("this.targets")
|
||||||
|
)
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
override fun getItemTarget(): EnchantmentTarget = EnchantmentTarget.ALL
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "Treasure enchantments do not exist in EcoEnchants",
|
||||||
|
replaceWith = ReplaceWith("this.isEnchantable")
|
||||||
|
)
|
||||||
|
override fun isTreasure(): Boolean = !enchant.isObtainableThroughEnchanting
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "Use EnchantmentType instead",
|
||||||
|
replaceWith = ReplaceWith("type.id")
|
||||||
|
)
|
||||||
|
override fun isCursed(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun displayName(level: Int): Component {
|
||||||
|
return enchant.getFormattedName(level).toComponent()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isTradeable(): Boolean {
|
||||||
|
return enchant.isObtainableThroughTrading
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isDiscoverable(): Boolean {
|
||||||
|
return enchant.isObtainableThroughDiscovery
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getMinModifiedCost(level: Int): Int {
|
||||||
|
return Int.MAX_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getMaxModifiedCost(level: Int): Int {
|
||||||
|
return Int.MAX_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
return other is EcoEnchant && this.enchantmentKey == other.enchantmentKey
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return this.enchantmentKey.hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "EcoEnchantsCraftEnchantment(key=$key)"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_20_6.registration
|
||||||
|
|
||||||
|
import com.willfp.ecoenchants.enchant.vanillaEnchantmentData
|
||||||
|
import net.minecraft.world.item.enchantment.Enchantment
|
||||||
|
import org.bukkit.NamespacedKey
|
||||||
|
import org.bukkit.craftbukkit.enchantments.CraftEnchantment
|
||||||
|
|
||||||
|
class ModifiedVanillaCraftEnchantment(
|
||||||
|
key: NamespacedKey,
|
||||||
|
target: Enchantment
|
||||||
|
) : CraftEnchantment(key, target) {
|
||||||
|
override fun getMaxLevel(): Int = this.vanillaEnchantmentData?.maxLevel ?: super.getMaxLevel()
|
||||||
|
|
||||||
|
override fun conflictsWith(other: org.bukkit.enchantments.Enchantment): Boolean {
|
||||||
|
val otherConflicts = when (other) {
|
||||||
|
is ModifiedVanillaCraftEnchantment -> other.vanillaEnchantmentData?.conflicts?.contains(this.key) == true
|
||||||
|
else -> other.conflictsWith(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.vanillaEnchantmentData?.conflicts?.contains(other.key) ?: super.conflictsWith(other)
|
||||||
|
|| otherConflicts
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_20_6.registration
|
||||||
|
|
||||||
|
import com.willfp.eco.core.Prerequisite
|
||||||
|
import com.willfp.eco.util.toComponent
|
||||||
|
import com.willfp.ecoenchants.display.getFormattedName
|
||||||
|
import com.willfp.ecoenchants.enchant.EcoEnchant
|
||||||
|
import com.willfp.ecoenchants.enchant.EcoEnchants
|
||||||
|
import io.papermc.paper.adventure.PaperAdventure
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.tags.ItemTags
|
||||||
|
import net.minecraft.world.entity.EquipmentSlot
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.inventory.AnvilMenu
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
|
import net.minecraft.world.item.enchantment.Enchantment
|
||||||
|
import org.bukkit.craftbukkit.enchantments.CraftEnchantment
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftItemStack
|
||||||
|
import java.util.Objects
|
||||||
|
|
||||||
|
class VanillaEcoEnchantsEnchantment(
|
||||||
|
enchant: EcoEnchant
|
||||||
|
) : Enchantment(
|
||||||
|
definition(
|
||||||
|
ItemTags.DURABILITY_ENCHANTABLE, 0, // Weight is 0, so we can use our own rarity system
|
||||||
|
enchant.maximumLevel,
|
||||||
|
constantCost(1),
|
||||||
|
constantCost(1),
|
||||||
|
0
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
private val id = enchant.id
|
||||||
|
|
||||||
|
// Fetch on each call to ensure we get the latest enchantment
|
||||||
|
private val enchant: EcoEnchant?
|
||||||
|
get() = EcoEnchants[id]
|
||||||
|
|
||||||
|
override fun canEnchant(stack: ItemStack): Boolean {
|
||||||
|
/*
|
||||||
|
|
||||||
|
This is the mother of all jank solutions.
|
||||||
|
|
||||||
|
Because I want the EcoEnchants anvil code to handle all custom enchantment logic,
|
||||||
|
I need to prevent the NMS anvil code from processing the EcoEnchants enchantments.
|
||||||
|
|
||||||
|
However, there's no API method that I can use to do this - **however**,
|
||||||
|
this method is called once in the NMS anvil code, and if it returns false then
|
||||||
|
the anvil will not allow this enchantment to be applied to the item.
|
||||||
|
|
||||||
|
So, I can check if the calling method is the anvil merge method, and if it is,
|
||||||
|
I can return false.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
val caller = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).callerClass
|
||||||
|
|
||||||
|
if (caller.name == AnvilMenu::class.java.name) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// End disgusting bodge
|
||||||
|
|
||||||
|
val item = CraftItemStack.asCraftMirror(stack)
|
||||||
|
return enchant?.canEnchantItem(item) ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isCurse(): Boolean {
|
||||||
|
return enchant?.type?.noGrindstone == true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isDiscoverable(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isTradeable(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isTreasureOnly(): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun checkCompatibility(other: Enchantment): Boolean {
|
||||||
|
val bukkit = CraftEnchantment.minecraftToBukkit(other)
|
||||||
|
|
||||||
|
if (enchant != null) {
|
||||||
|
return !enchant!!.conflictsWith(bukkit)
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getSlotItems(entity: LivingEntity): MutableMap<EquipmentSlot, ItemStack> {
|
||||||
|
return mutableMapOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getFullname(level: Int): Component {
|
||||||
|
val enchant = this.enchant
|
||||||
|
return if (Prerequisite.HAS_PAPER.isMet && enchant != null) {
|
||||||
|
PaperAdventure.asVanilla(enchant.getFormattedName(level).toComponent())
|
||||||
|
} else {
|
||||||
|
super.getFullname(level)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "VanillaEcoEnchantsEnchantment(id='$id')"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
return other is VanillaEcoEnchantsEnchantment && other.id == this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return Objects.hash(id)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_20_R1
|
||||||
|
|
||||||
|
import com.willfp.eco.core.fast.FastItemStack
|
||||||
|
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
|
||||||
|
import org.bukkit.inventory.ItemFlag
|
||||||
|
|
||||||
|
class HideStoredEnchants: HideStoredEnchantsProxy {
|
||||||
|
override fun hideStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean {
|
||||||
|
return fis.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_20_R2
|
||||||
|
|
||||||
|
import com.willfp.eco.core.fast.FastItemStack
|
||||||
|
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
|
||||||
|
import org.bukkit.inventory.ItemFlag
|
||||||
|
|
||||||
|
class HideStoredEnchants: HideStoredEnchantsProxy {
|
||||||
|
override fun hideStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean {
|
||||||
|
return fis.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.willfp.ecoenchants.proxy.v1_20_R3
|
||||||
|
|
||||||
|
import com.willfp.eco.core.fast.FastItemStack
|
||||||
|
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
|
||||||
|
import org.bukkit.inventory.ItemFlag
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
class HideStoredEnchants: HideStoredEnchantsProxy {
|
||||||
|
override fun hideStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean {
|
||||||
|
return fis.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showStoredEnchants(fis: FastItemStack) {
|
||||||
|
fis.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,6 @@ import org.bukkit.enchantments.EnchantmentTarget
|
|||||||
import org.bukkit.entity.EntityCategory
|
import org.bukkit.entity.EntityCategory
|
||||||
import org.bukkit.inventory.EquipmentSlot
|
import org.bukkit.inventory.EquipmentSlot
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import java.util.Objects
|
|
||||||
|
|
||||||
class EcoEnchantsCraftEnchantment(
|
class EcoEnchantsCraftEnchantment(
|
||||||
private val enchant: EcoEnchantBase,
|
private val enchant: EcoEnchantBase,
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.willfp.ecoenchants
|
||||||
|
|
||||||
|
interface CodecReplacerProxy {
|
||||||
|
fun replaceItemCodec()
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.willfp.eco.core.Prerequisite
|
|||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
import com.willfp.eco.core.command.impl.PluginCommand
|
||||||
import com.willfp.eco.core.display.DisplayModule
|
import com.willfp.eco.core.display.DisplayModule
|
||||||
import com.willfp.eco.core.integrations.IntegrationLoader
|
import com.willfp.eco.core.integrations.IntegrationLoader
|
||||||
|
import com.willfp.eco.core.packet.PacketListener
|
||||||
import com.willfp.ecoenchants.commands.CommandEcoEnchants
|
import com.willfp.ecoenchants.commands.CommandEcoEnchants
|
||||||
import com.willfp.ecoenchants.commands.CommandEnchant
|
import com.willfp.ecoenchants.commands.CommandEnchant
|
||||||
import com.willfp.ecoenchants.commands.CommandEnchantInfo
|
import com.willfp.ecoenchants.commands.CommandEnchantInfo
|
||||||
@ -65,6 +66,13 @@ class EcoEnchantsPlugin : LibreforgePlugin() {
|
|||||||
if (Prerequisite.HAS_1_20_3.isMet) {
|
if (Prerequisite.HAS_1_20_3.isMet) {
|
||||||
plugin.getProxy(ModernEnchantmentRegistererProxy::class.java).replaceRegistry()
|
plugin.getProxy(ModernEnchantmentRegistererProxy::class.java).replaceRegistry()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Prerequisite.HAS_1_20_5.isMet) {
|
||||||
|
if (!this.configYml.getBool("enable-1-20-6")) {
|
||||||
|
throw IllegalStateException("EcoEnchants should not be ran in production on 1.20.6. " +
|
||||||
|
"If this is a development environment, please set 'enable-1-20-6' to true in config.yml. ")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadConfigCategories(): List<ConfigCategory> {
|
override fun loadConfigCategories(): List<ConfigCategory> {
|
||||||
@ -85,6 +93,10 @@ class EcoEnchantsPlugin : LibreforgePlugin() {
|
|||||||
NamedValue("level", it.level),
|
NamedValue("level", it.level),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Prerequisite.HAS_1_20_5.isMet) {
|
||||||
|
getProxy(CodecReplacerProxy::class.java).replaceItemCodec()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleAfterLoad() {
|
override fun handleAfterLoad() {
|
||||||
|
@ -6,10 +6,12 @@ import com.willfp.eco.core.display.DisplayPriority
|
|||||||
import com.willfp.eco.core.display.DisplayProperties
|
import com.willfp.eco.core.display.DisplayProperties
|
||||||
import com.willfp.eco.core.fast.FastItemStack
|
import com.willfp.eco.core.fast.FastItemStack
|
||||||
import com.willfp.eco.core.fast.fast
|
import com.willfp.eco.core.fast.fast
|
||||||
|
import com.willfp.eco.core.items.builder.modify
|
||||||
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||||
import com.willfp.ecoenchants.commands.CommandToggleDescriptions.Companion.seesEnchantmentDescriptions
|
import com.willfp.ecoenchants.commands.CommandToggleDescriptions.Companion.seesEnchantmentDescriptions
|
||||||
import com.willfp.ecoenchants.display.EnchantSorter.sortForDisplay
|
import com.willfp.ecoenchants.display.EnchantSorter.sortForDisplay
|
||||||
import com.willfp.ecoenchants.enchant.EcoEnchant
|
import com.willfp.ecoenchants.enchant.EcoEnchant
|
||||||
|
import com.willfp.ecoenchants.enchant.EcoEnchants
|
||||||
import com.willfp.ecoenchants.enchant.wrap
|
import com.willfp.ecoenchants.enchant.wrap
|
||||||
import com.willfp.ecoenchants.target.EnchantmentTargets.isEnchantable
|
import com.willfp.ecoenchants.target.EnchantmentTargets.isEnchantable
|
||||||
import com.willfp.libreforge.ItemProvidedHolder
|
import com.willfp.libreforge.ItemProvidedHolder
|
||||||
@ -23,11 +25,20 @@ import kotlin.collections.component1
|
|||||||
import kotlin.collections.component2
|
import kotlin.collections.component2
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
|
|
||||||
|
// Works around HIDE_POTION_EFFECTS not existing in 1.20.5+
|
||||||
|
interface HideStoredEnchantsProxy {
|
||||||
|
fun hideStoredEnchants(fis: FastItemStack)
|
||||||
|
fun showStoredEnchants(fis: FastItemStack)
|
||||||
|
fun areStoredEnchantsHidden(fis: FastItemStack): Boolean
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plugin, DisplayPriority.HIGH) {
|
class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plugin, DisplayPriority.HIGH) {
|
||||||
private val hideStateKey =
|
private val hideStateKey =
|
||||||
plugin.namespacedKeyFactory.create("ecoenchantlore-skip") // Same for backwards compatibility
|
plugin.namespacedKeyFactory.create("ecoenchantlore-skip") // Same for backwards compatibility
|
||||||
|
|
||||||
|
private val hse = plugin.getProxy(HideStoredEnchantsProxy::class.java)
|
||||||
|
|
||||||
override fun display(
|
override fun display(
|
||||||
itemStack: ItemStack,
|
itemStack: ItemStack,
|
||||||
player: Player?,
|
player: Player?,
|
||||||
@ -45,7 +56,7 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug
|
|||||||
if (args[0] == true) {
|
if (args[0] == true) {
|
||||||
fast.addItemFlags(ItemFlag.HIDE_ENCHANTS)
|
fast.addItemFlags(ItemFlag.HIDE_ENCHANTS)
|
||||||
if (itemStack.type == Material.ENCHANTED_BOOK) {
|
if (itemStack.type == Material.ENCHANTED_BOOK) {
|
||||||
fast.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
hse.hideStoredEnchants(fast)
|
||||||
}
|
}
|
||||||
pdc.set(hideStateKey, PersistentDataType.INTEGER, 1)
|
pdc.set(hideStateKey, PersistentDataType.INTEGER, 1)
|
||||||
return
|
return
|
||||||
@ -114,7 +125,7 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug
|
|||||||
|
|
||||||
fast.addItemFlags(ItemFlag.HIDE_ENCHANTS)
|
fast.addItemFlags(ItemFlag.HIDE_ENCHANTS)
|
||||||
if (itemStack.type == Material.ENCHANTED_BOOK) {
|
if (itemStack.type == Material.ENCHANTED_BOOK) {
|
||||||
fast.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
hse.hideStoredEnchants(fast)
|
||||||
}
|
}
|
||||||
|
|
||||||
fast.lore = enchantLore + lore + notMetLines
|
fast.lore = enchantLore + lore + notMetLines
|
||||||
@ -132,7 +143,7 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug
|
|||||||
fast.removeItemFlags(ItemFlag.HIDE_ENCHANTS)
|
fast.removeItemFlags(ItemFlag.HIDE_ENCHANTS)
|
||||||
|
|
||||||
if (itemStack.type == Material.ENCHANTED_BOOK) {
|
if (itemStack.type == Material.ENCHANTED_BOOK) {
|
||||||
fast.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
hse.showStoredEnchants(fast)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +158,7 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug
|
|||||||
0 -> arrayOf(false)
|
0 -> arrayOf(false)
|
||||||
else -> arrayOf(
|
else -> arrayOf(
|
||||||
fast.hasItemFlag(ItemFlag.HIDE_ENCHANTS)
|
fast.hasItemFlag(ItemFlag.HIDE_ENCHANTS)
|
||||||
|| fast.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|
|| hse.areStoredEnchantsHidden(fast)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import com.willfp.eco.core.gui.slot.Slot
|
|||||||
import com.willfp.eco.core.items.Items
|
import com.willfp.eco.core.items.Items
|
||||||
import com.willfp.eco.core.items.builder.EnchantedBookBuilder
|
import com.willfp.eco.core.items.builder.EnchantedBookBuilder
|
||||||
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
||||||
|
import com.willfp.eco.core.items.isEcoEmpty
|
||||||
import com.willfp.eco.core.items.isEmpty
|
import com.willfp.eco.core.items.isEmpty
|
||||||
import com.willfp.eco.util.formatEco
|
import com.willfp.eco.util.formatEco
|
||||||
import com.willfp.eco.util.lineWrap
|
import com.willfp.eco.util.lineWrap
|
||||||
@ -72,7 +73,7 @@ object EnchantGUI {
|
|||||||
|
|
||||||
onRender { player, menu ->
|
onRender { player, menu ->
|
||||||
val atCaptive = menu.getCaptiveItem(player, captiveRow, captiveColumn)
|
val atCaptive = menu.getCaptiveItem(player, captiveRow, captiveColumn)
|
||||||
if (atCaptive.isEmpty || atCaptive == null || atCaptive.type == Material.BOOK) {
|
if (atCaptive.isEcoEmpty || atCaptive == null || atCaptive.type == Material.BOOK) {
|
||||||
menu.setState(player, "enchants", EcoEnchants.values().map { it.enchantment }.sortForDisplay())
|
menu.setState(player, "enchants", EcoEnchants.values().map { it.enchantment }.sortForDisplay())
|
||||||
} else {
|
} else {
|
||||||
menu.setState(
|
menu.setState(
|
||||||
|
@ -122,7 +122,7 @@ abstract class EcoEnchantBase(
|
|||||||
protected abstract fun createLevel(level: Int): EcoEnchantLevel
|
protected abstract fun createLevel(level: Int): EcoEnchantLevel
|
||||||
|
|
||||||
override fun conflictsWithDirectly(other: Enchantment): Boolean {
|
override fun conflictsWithDirectly(other: Enchantment): Boolean {
|
||||||
return other.key.key in conflictIds
|
return other.key.key in conflictIds || this.conflictsWithEverything
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun equals(other: Any?): Boolean {
|
final override fun equals(other: Any?): Boolean {
|
||||||
|
@ -124,8 +124,9 @@ class EnchantmentSoulbound(
|
|||||||
ignoreCancelled = true
|
ignoreCancelled = true
|
||||||
)
|
)
|
||||||
fun preventDroppingSoulboundItems(event: PlayerDeathEvent) {
|
fun preventDroppingSoulboundItems(event: PlayerDeathEvent) {
|
||||||
event.drops.removeIf { it.fast().persistentDataContainer.has(soulboundKey, PersistentDataType.INTEGER)
|
event.drops.removeIf {
|
||||||
&& it.itemMeta.hasEnchant(enchant.enchantment)
|
it.fast().persistentDataContainer.has(soulboundKey, PersistentDataType.INTEGER)
|
||||||
|
&& it.itemMeta.hasEnchant(enchant.enchantment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,3 +167,11 @@ enchant-gui:
|
|||||||
lore-conversion:
|
lore-conversion:
|
||||||
enabled: false # If lore conversion should be enabled
|
enabled: false # If lore conversion should be enabled
|
||||||
aggressive: false # Will convert all items in all inventories when opened, likely to use a lot of performance
|
aggressive: false # Will convert all items in all inventories when opened, likely to use a lot of performance
|
||||||
|
|
||||||
|
# DO NOT USE IN PRODUCTION!
|
||||||
|
# EcoEnchants should not be run on 1.20.6 in production environments. This is for testing purposes only.
|
||||||
|
# This will allow the plugin to run on 1.20.6, but it is not recommended.
|
||||||
|
# Enabling this option may cause irreversible damage to your server and may corrupt all items.
|
||||||
|
# If you want to use EcoEnchants on 1.20, please only run 1.20.4.
|
||||||
|
# 1.21 will work as expected when it releases.
|
||||||
|
enable-1-20-6: false
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
#Wed Apr 17 20:35:15 BST 2024
|
#Wed Apr 17 20:35:15 BST 2024
|
||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
libreforge-version=4.58.1
|
libreforge-version=4.58.1
|
||||||
version=12.5.1
|
version=12.6.0
|
||||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
29
gradlew
vendored
29
gradlew
vendored
@ -83,10 +83,8 @@ done
|
|||||||
# This is normally unused
|
# This is normally unused
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@ -133,10 +131,13 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
# double quotes to make sure that they get re-expanded; and
|
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
20
gradlew.bat
vendored
20
gradlew.bat
vendored
@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
|
|||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
|
@ -22,3 +22,4 @@ include(":eco-core:core-nms:v1_19_R3")
|
|||||||
include(":eco-core:core-nms:v1_20_R1")
|
include(":eco-core:core-nms:v1_20_R1")
|
||||||
include(":eco-core:core-nms:v1_20_R2")
|
include(":eco-core:core-nms:v1_20_R2")
|
||||||
include(":eco-core:core-nms:v1_20_R3")
|
include(":eco-core:core-nms:v1_20_R3")
|
||||||
|
include(":eco-core:core-nms:v1_20_6")
|
||||||
|
Loading…
Reference in New Issue
Block a user