diff --git a/build.gradle b/build.gradle index 85bae901d..23376c30a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'org.screamingsandals.plugin-builder' version '1.0.84' apply false - id 'me.kcra.takenaka.accessor' version '1.1.0' apply false + id 'me.kcra.takenaka.accessor' version '1.1.2' apply false id 'com.github.gmazzo.buildconfig' version '3.0.0' apply false } diff --git a/nms/build.gradle b/nms/build.gradle index c48e06fa0..34498a877 100644 --- a/nms/build.gradle +++ b/nms/build.gradle @@ -6,7 +6,7 @@ import java.util.function.Supplier apply plugin: 'me.kcra.takenaka.accessor' dependencies { - mappingBundle "me.kcra.takenaka:mappings:1.8.8+1.20.4" + mappingBundle "me.kcra.takenaka:mappings:1.8.8+1.20.5" api "me.kcra.takenaka:generator-accessor-runtime:${BuildConfig.BUILD_VERSION}" } @@ -15,7 +15,7 @@ dependencies { accessors { // uncomment this and remove the mappingBundle dependency, // if you want to develop against custom versions - /*versionRange('1.8.8', '1.20.4') { + /*versionRange('1.8.8', '1.20.5') { // exclude 1.16 and 1.10.1, they don't have most mappings and are basically not used at all // exclude 1.8.9, client-only update - no Spigot mappings, no thank you // exclude 1.9.1 and 1.9.3 - no mappings at all @@ -38,9 +38,13 @@ accessors { getter String, 'string' } var Attribute = mapClass 'net.minecraft.world.entity.ai.attributes.Attribute' + mapClass('net.minecraft.core.RegistryAccess') { + field 'net.minecraft.core.RegistryAccess$Frozen', 'EMPTY' + } mapClass('net.minecraft.network.chat.Component$Serializer') { method Component, 'fromJson', String // 1.16 and below method 'net.minecraft.network.chat.MutableComponent', 'fromJson', String // 1.16.1 and higher + method 'net.minecraft.network.chat.MutableComponent', 'fromJsonLenient', String, 'net.minecraft.core.HolderLookup$Provider' // 1.20.5+ } var SynchedEntityData = mapClass('net.minecraft.network.syncher.SynchedEntityData') { method void, 'watch', int, Object @@ -100,6 +104,7 @@ accessors { } var AttributeInstance = mapClass('net.minecraft.world.entity.ai.attributes.AttributeInstance') { constructor Attribute, Consumer + constructor 'net.minecraft.core.Holder', Consumer // 1.20.5+ getter double, 'value' setter double, 'baseValue' } @@ -109,6 +114,7 @@ accessors { } var LivingEntity = mapClass('net.minecraft.world.entity.LivingEntity') { method AttributeInstance, 'getAttribute', Attribute + method AttributeInstance, 'getAttribute', 'net.minecraft.core.Holder' getter AttributeMap, 'attributes' getter 'net.minecraft.world.damagesource.CombatTracker', 'combatTracker' } @@ -142,17 +148,50 @@ accessors { setter Entity, 'camera' } mapClass('net.minecraft.world.entity.ai.attributes.Attributes') { - field Attribute, 'MAX_HEALTH' - field Attribute, 'FOLLOW_RANGE' - field Attribute, 'KNOCKBACK_RESISTANCE' - field Attribute, 'MOVEMENT_SPEED' - field Attribute, 'FLYING_SPEED' - field Attribute, 'ATTACK_DAMAGE' - field Attribute, 'ATTACK_KNOCKBACK' - field Attribute, 'ATTACK_SPEED' - field Attribute, 'ARMOR' - field Attribute, 'ARMOR_TOUGHNESS' - field Attribute, 'LUCK' + fieldChain { + it.item Attribute, 'MAX_HEALTH' + it.item 'net.minecraft.core.Holder', 'MAX_HEALTH' + } + fieldChain { + it.item Attribute, 'FOLLOW_RANGE' + it.item 'net.minecraft.core.Holder', 'FOLLOW_RANGE' + } + fieldChain { + it.item Attribute, 'KNOCKBACK_RESISTANCE' + it.item 'net.minecraft.core.Holder', 'KNOCKBACK_RESISTANCE' + } + fieldChain { + it.item Attribute, 'MOVEMENT_SPEED' + it.item 'net.minecraft.core.Holder', 'MOVEMENT_SPEED' + } + fieldChain { + it.item Attribute, 'FLYING_SPEED' + it.item 'net.minecraft.core.Holder', 'FLYING_SPEED' + } + fieldChain { + it.item Attribute, 'ATTACK_DAMAGE' + it.item 'net.minecraft.core.Holder', 'ATTACK_DAMAGE' + } + fieldChain { + it.item Attribute, 'ATTACK_KNOCKBACK' + it.item 'net.minecraft.core.Holder', 'ATTACK_KNOCKBACK' + } + fieldChain { + it.item Attribute, 'ATTACK_SPEED' + it.item 'net.minecraft.core.Holder', 'ATTACK_SPEED' + } + fieldChain { + it.item Attribute, 'ARMOR' + it.item 'net.minecraft.core.Holder', 'ARMOR' + } + fieldChain { + it.item Attribute, 'ARMOR_TOUGHNESS' + it.item 'net.minecraft.core.Holder', 'ARMOR_TOUGHNESS' + } + fieldChain { + it.item Attribute, 'LUCK' + it.item 'net.minecraft.core.Holder', 'LUCK' + } } mapClass('net.minecraft.network.protocol.game.ServerboundInteractPacket') { field int, 'entityId' diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityLivingNMS.java b/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityLivingNMS.java index 9961111bd..61089305b 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityLivingNMS.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityLivingNMS.java @@ -56,8 +56,14 @@ public boolean hasAttribute(Attribute attribute) { public boolean hasAttribute(Object attr) { try { - Object attr0 = getMethod(handler, METHOD_GET_ATTRIBUTE.get()) - .invoke(attr); + Object attr0; + if (METHOD_GET_ATTRIBUTE.get() != null) { + attr0 = getMethod(handler, METHOD_GET_ATTRIBUTE.get()) + .invoke(attr); + } else { + attr0 = getMethod(handler, METHOD_GET_ATTRIBUTE_1.get()) + .invoke(attr); + } return attr0 != null; } catch (Throwable t) { } @@ -70,8 +76,14 @@ public double getAttribute(Attribute attribute) { public double getAttribute(Object attr) { try { - Object attr0 = getMethod(handler, METHOD_GET_ATTRIBUTE.get()) - .invoke(attr); + Object attr0; + if (METHOD_GET_ATTRIBUTE.get() != null) { + attr0 = getMethod(handler, METHOD_GET_ATTRIBUTE.get()) + .invoke(attr); + } else { + attr0 = getMethod(handler, METHOD_GET_ATTRIBUTE_1.get()) + .invoke(attr); + } return (double) getMethod(attr0, AttributeInstanceAccessor.METHOD_GET_VALUE.get()).invoke(); } catch (Throwable t) { } @@ -85,8 +97,14 @@ public void setAttribute(Attribute attribute, double value) { public void setAttribute(Object attr, double value) { try { if (value >= 0) { - Object attr0 = getMethod(handler, METHOD_GET_ATTRIBUTE.get()) - .invoke(attr); + Object attr0; + if (METHOD_GET_ATTRIBUTE.get() != null) { + attr0 = getMethod(handler, METHOD_GET_ATTRIBUTE.get()) + .invoke(attr); + } else { + attr0 = getMethod(handler, METHOD_GET_ATTRIBUTE_1.get()) + .invoke(attr); + } if (attr0 == null) { Object attrMap = getMethod(handler, METHOD_GET_ATTRIBUTES.get()).invoke(); // Pre 1.16 @@ -96,9 +114,15 @@ public void setAttribute(Object attr, double value) { Object provider = getField(attrMap, AttributeMapAccessor.FIELD_SUPPLIER.get()); Map all = Maps .newHashMap((Map) getField(provider, AttributeSupplierAccessor.FIELD_INSTANCES.get())); - attr0 = AttributeInstanceAccessor.CONSTRUCTOR_0.get().newInstance(attr, (Consumer) o -> { - // do nothing - }); + if (AttributeInstanceAccessor.CONSTRUCTOR_0.get() != null) { + attr0 = AttributeInstanceAccessor.CONSTRUCTOR_0.get().newInstance(attr, (Consumer) o -> { + // do nothing + }); + } else { + attr0 = AttributeInstanceAccessor.CONSTRUCTOR_1.get().newInstance(attr, (Consumer) o -> { + // do nothing + }); + } all.put(attr, attr0); setField(provider, AttributeSupplierAccessor.FIELD_INSTANCES.get(), ImmutableMap.copyOf(all)); } diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityNMS.java b/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityNMS.java index c1c578751..3de519e4a 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityNMS.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityNMS.java @@ -100,8 +100,7 @@ public Object getDataWatcher() { public void setCustomName(String name) { InstanceMethod method = ClassStorage.getMethod(handler, METHOD_SET_CUSTOM_NAME.get()); if (method.getReflectedMethod() != null) { - method.invoke(ClassStorage.getMethod(TabManager.getCorrectSerializingMethod()) - .invokeStatic("{\"text\": \"" + name + "\"}")); + method.invoke(TabManager.serialize("{\"text\": \"" + name + "\"}")); } else { ClassStorage.getMethod(handler, METHOD_SET_CUSTOM_NAME_1.get()).invoke(name); } diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityTextDisplayNMS.java b/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityTextDisplayNMS.java index b1a837612..6d54ba73d 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityTextDisplayNMS.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/lib/nms/entity/EntityTextDisplayNMS.java @@ -43,7 +43,7 @@ public EntityTextDisplayNMS(Location loc) throws Throwable { public void setText(String name) { InstanceMethod method = ClassStorage.getMethod(handler, METHOD_SET_TEXT.get()); - method.invoke(ClassStorage.getMethod(TabManager.getCorrectSerializingMethod()).invokeStatic("{\"text\": \"" + name + "\"}")); + method.invoke(TabManager.serialize("{\"text\": \"" + name + "\"}")); } public String getText() { diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/tab/TabManager.java b/plugin/src/main/java/org/screamingsandals/bedwars/tab/TabManager.java index 4880a7b9e..4f5afd787 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/tab/TabManager.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/tab/TabManager.java @@ -25,6 +25,8 @@ import org.screamingsandals.bedwars.game.GamePlayer; import org.screamingsandals.bedwars.lib.nms.accessors.ClientboundTabListPacketAccessor; import org.screamingsandals.bedwars.lib.nms.accessors.Component$SerializerAccessor; +import org.screamingsandals.bedwars.lib.nms.accessors.RegistryAccessAccessor; +import org.screamingsandals.bedwars.lib.nms.utils.ClassStorage; import java.lang.reflect.Method; import java.util.ArrayList; @@ -54,20 +56,16 @@ public void modifyForPlayer(GamePlayer player) { try { Object headerComponent; if (header != null) { - headerComponent = getMethod(getCorrectSerializingMethod()) - .invokeStatic("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', String.join("\n", translate(player, header))) + "\"}"); + headerComponent = serialize("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', String.join("\n", translate(player, header))) + "\"}"); } else { - headerComponent = getMethod(getCorrectSerializingMethod()) - .invokeStatic("{\"text\": \"\"}"); + headerComponent = serialize("{\"text\": \"\"}"); } Object footerComponent; if (footer != null) { - footerComponent = getMethod(getCorrectSerializingMethod()) - .invokeStatic("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', String.join("\n", translate(player, footer))) + "\"}"); + footerComponent = serialize("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', String.join("\n", translate(player, footer))) + "\"}"); } else { - footerComponent = getMethod(getCorrectSerializingMethod()) - .invokeStatic("{\"text\": \"\"}"); + footerComponent = serialize("{\"text\": \"\"}"); } Object packet; @@ -94,8 +92,7 @@ public void clear(GamePlayer player) { } else { clearString = "{\"translate\": \"\"}"; } - Object blankComponent = getMethod(getCorrectSerializingMethod()) - .invokeStatic(clearString); + Object blankComponent = serialize(clearString); Object packet; if (ClientboundTabListPacketAccessor.CONSTRUCTOR_1.get() != null) { packet = ClientboundTabListPacketAccessor.CONSTRUCTOR_1.get().newInstance(blankComponent, blankComponent); @@ -122,10 +119,13 @@ public List translate(GamePlayer gamePlayer, List origin) { return list; } - public static Method getCorrectSerializingMethod() { + public static Object serialize(String text) { if (Component$SerializerAccessor.METHOD_FROM_JSON.get() != null) { - return Component$SerializerAccessor.METHOD_FROM_JSON.get(); + return ClassStorage.getMethod(Component$SerializerAccessor.METHOD_FROM_JSON.get()).invokeStatic(text); } - return Component$SerializerAccessor.METHOD_FROM_JSON_1.get(); + if (Component$SerializerAccessor.METHOD_FROM_JSON_1.get() != null) { + return ClassStorage.getMethod(Component$SerializerAccessor.METHOD_FROM_JSON_1.get()).invokeStatic(text); + } + return ClassStorage.getMethod(Component$SerializerAccessor.METHOD_FROM_JSON_LENIENT.get()).invokeStatic(text, RegistryAccessAccessor.FIELD_EMPTY.get()); } }