26.2
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package xyz.fortern.forternhelper.nms.v26_R2
|
||||
|
||||
import org.bukkit.entity.Villager
|
||||
import xyz.fortern.forternhelper.reflection.NMSAdapter.PKG_NAME
|
||||
import xyz.fortern.forternhelper.reflection.NMSHandler
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
|
||||
// 26.2
|
||||
class NMSHandlerImpl : NMSHandler {
|
||||
|
||||
override fun setVillagerRestock(villager: Villager, restockToday: Int) {
|
||||
val mcVillager = villagerGetHandlerMethod.invoke(villager)
|
||||
villagerRestockTodayField.isAccessible = true
|
||||
villagerRestockTodayField.set(mcVillager, restockToday)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val craftVillagerClass: Class<*>
|
||||
private val villagerGetHandlerMethod: Method
|
||||
private val mcVillagerClass: Class<*>
|
||||
private val villagerRestockTodayField: Field
|
||||
|
||||
|
||||
init {
|
||||
try {
|
||||
craftVillagerClass = Class.forName("$PKG_NAME.entity.CraftVillager")
|
||||
villagerGetHandlerMethod = craftVillagerClass.getMethod("getHandle")
|
||||
mcVillagerClass = Class.forName("net.minecraft.world.entity.npc.villager.Villager")
|
||||
villagerRestockTodayField = mcVillagerClass.getField("numberOfRestocksToday")
|
||||
} catch (e: ReflectiveOperationException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ object NMSAdapter {
|
||||
"1.21.9", "1.21.10" -> "v1_21_R6"
|
||||
"1.21.11" -> "v1_21_R7"
|
||||
"26.1", "26.1.1", "26.1.2" -> "v26_R1"
|
||||
"26.2" -> "v26_R2"
|
||||
else -> throw Exception("Unknown NMS version")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user