Skip to content

Commit

Permalink
Experimental | Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFloodDragon committed Jul 21, 2024
1 parent 133fc91 commit 2ae8990
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cn.fd.ratziel.core.Identifier
import cn.fd.ratziel.function.ArgumentContext
import cn.fd.ratziel.module.item.api.NeoItem
import cn.fd.ratziel.module.item.api.builder.ItemGenerator
import cn.fd.ratziel.module.item.api.event.ItemEvent

/**
* ItemBuildEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.fd.ratziel.module.item.event
package cn.fd.ratziel.module.item.api.event

import cn.fd.ratziel.core.Identifier
import taboolib.platform.type.BukkitProxyEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import cn.fd.ratziel.module.item.api.NeoItem
import cn.fd.ratziel.module.item.api.builder.ItemGenerator
import cn.fd.ratziel.module.item.api.builder.ItemResolver
import cn.fd.ratziel.module.item.api.builder.ItemSerializer
import cn.fd.ratziel.module.item.api.event.ItemResolvedEvent
import cn.fd.ratziel.module.item.event.ItemBuildEvent
import cn.fd.ratziel.module.item.event.ItemResolvedEvent
import cn.fd.ratziel.module.item.impl.SimpleItemData
import cn.fd.ratziel.module.item.impl.ItemInfo
import cn.fd.ratziel.module.item.impl.RatzielItem
import cn.fd.ratziel.module.item.impl.SimpleItemData
import cn.fd.ratziel.module.item.util.toApexDataUncheck
import kotlinx.serialization.json.JsonElement
import taboolib.common.platform.function.severe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import cn.fd.ratziel.function.util.uncheck
import cn.fd.ratziel.module.item.nbt.NMSUtil
import com.mojang.serialization.Codec
import com.mojang.serialization.DynamicOps
import net.minecraft.core.IRegistryCustom
import net.minecraft.core.component.DataComponentMap
import net.minecraft.core.component.DataComponentPatch
import net.minecraft.nbt.DynamicOpsNBT
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.resources.RegistryOps
import net.minecraft.server.MinecraftServer
import org.bukkit.Bukkit
import org.bukkit.craftbukkit.v1_20_R4.CraftServer
import taboolib.library.reflex.ReflexClass
import taboolib.module.nms.MinecraftVersion
import taboolib.module.nms.minecraftServerObject
import taboolib.module.nms.nmsClass
import taboolib.module.nms.nmsProxy

Expand Down Expand Up @@ -103,7 +106,7 @@ class NMS12005Impl : NMS12005() {

override fun saveMap(dcm: Any): Any? = save(DataComponentMap.CODEC, dcm as DataComponentMap)

val access by lazy { (Bukkit.getServer() as CraftServer).server.registryAccess() }
val access: IRegistryCustom.Dimension by lazy { minecraftServerObject as MinecraftServer.registryAccess() }

val method by lazy {
val ref = ReflexClass.of(net.minecraft.core.HolderLookup.a::class.java, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import cn.fd.ratziel.module.item.nbt.NBTCompound
import cn.fd.ratziel.module.item.nbt.NMSUtil
import org.bukkit.inventory.meta.ItemMeta
import org.bukkit.inventory.meta.SkullMeta
import taboolib.library.reflex.Reflex.Companion.getProperty
import taboolib.library.reflex.ReflexClass
import taboolib.module.nms.MinecraftVersion
import taboolib.module.nms.obcClass
Expand Down Expand Up @@ -81,7 +80,7 @@ class RefItemMeta<T : ItemMeta>(raw: T) {
* CraftMetaItem(DataComponentPatch tag)
* @return CraftMetaItem
*/
private val constructor by lazy {
private val craftMetaConstructor by lazy {
ReflexClass.of(clazz, false).structure.getConstructorByType(
if (MinecraftVersion.majorLegacy >= 12005) NMS12005.DATA_COMPONENT_PATCH_CLASS else NMSUtil.NtCompound.nmsClass
)
Expand All @@ -99,7 +98,7 @@ class RefItemMeta<T : ItemMeta>(raw: T) {
if (MinecraftVersion.majorLegacy >= 12005)
NMS12005.INSTANCE.parsePatch(tag.getData())!!
else tag
return uncheck(constructor.instance(handled)!!)
return uncheck(craftMetaConstructor.instance(handled)!!)
}

internal fun applyToItem(meta: ItemMeta, tag: NBTCompound) {
Expand Down Expand Up @@ -137,19 +136,10 @@ class RefItemMeta<T : ItemMeta>(raw: T) {

fun applicatorToDcp(applicator: Any): Any = applicatorBuildMethod.invoke(applicator)!!

val customDataKey by lazy {
ReflexClass.of(META_ITEM.clazz, false).getField("CUSTOM_DATA")
}

val applicatorConstructor by lazy {
ReflexClass.of(applicatorClass, false).getConstructor()
}

val applicatorPutMethod by lazy {
ReflexClass.of(applicatorClass, false).structure.methods.firstOrNull { it.name == "put" }
?: throw NoSuchMethodException("${applicatorClass.name}#put")
}

val applicatorBuildMethod by lazy {
ReflexClass.of(applicatorClass, false).getMethod("build")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public SimpleScript(@NotNull String content, @NotNull ScriptExecutor executor) {
// 直接用编译后的脚本评估
return compiled.eval(environment.getBindings());
} else {
// 尝试编译脚本 (compile是异步执行的, 不然也不敢放在这)
compile(getExecutor());
// 尝试编译脚本, 如果没有编译过的话 (compile是异步执行的, 不然也不敢放在这)
if (future == null) compile(getExecutor());
// 通过执行器评估脚本
return getExecutor().evaluate(this, environment);
}
Expand Down

0 comments on commit 2ae8990

Please sign in to comment.