]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Fixes for Custom NPCs, version 1.17.2.4 1.17.2.4
authorStephen Seo <seo.disparate@gmail.com>
Fri, 2 Sep 2022 02:20:27 +0000 (11:20 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Fri, 2 Sep 2022 02:37:13 +0000 (11:37 +0900)
Previous code worked against a different Custom NPCs API. This commit fixes the
previous namespaces to the publically available Custom NPCs "NpcAPI" namespaces.

Changelog.md
build.gradle
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/OtherModHandler.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java
src/main/resources/META-INF/mods.toml
src/main/resources/mcmod.info

index 6f54b5481cb809273e9fe6a7df8d87f641116477..40aeca3e24e3e8c4257f11ac31ff01e9bd31c030 100644 (file)
@@ -1,5 +1,9 @@
 # Upcoming changes
 
+# Version 1.17.2.4
+
+Fix usage of NpcAPI.
+
 # Version 1.17.2.3
 
 Fix potential unhandled exception crash bug related to handling CustomNPCs
index 7e826b358c7369b8c84d0b1cc91b9c5b5af08e34..40207618fced2253b66119a8e86981be205f35c7 100644 (file)
@@ -14,7 +14,7 @@ apply plugin: 'eclipse'
 //apply plugin: 'maven-publish'\r
 apply plugin: 'com.github.johnrengelman.shadow'\r
 \r
-version = "1.17.2.3"\r
+version = "1.17.2.4"\r
 group = "com.burnedkirby.TurnBasedMinecraft"\r
 archivesBaseName = "TurnBasedMinecraft"\r
 \r
index d0e63962abf8a7ba7b8c10e7111091655cf49844..e47c78e30eb0d4880af986d7deacd5d1990ab33b 100644 (file)
@@ -14,9 +14,10 @@ public class OtherModHandler {
     public void postInit() {
         // Check if CustomNPCs is available, and handle player damage events if it is.
         for (int i = 0; i < 1; ++i) {
+            // Check if required classes exist
             Class<?> customNPCsAPI = null;
             try {
-                customNPCsAPI = Class.forName("noppes.npcs.scripted.NpcAPI");
+                customNPCsAPI = Class.forName("noppes.npcs.api.NpcAPI");
             } catch (ClassNotFoundException e) {
                 TurnBasedMinecraftMod.logger.info("NpcAPI not found, not handling it.");
             }
@@ -26,7 +27,7 @@ public class OtherModHandler {
 
             Class<?> customNPCsPlayerHurtEvent = null;
             try {
-                customNPCsPlayerHurtEvent = Class.forName("noppes.npcs.scripted.event.PlayerEvent.DamagedEvent");
+                customNPCsPlayerHurtEvent = Class.forName("noppes.npcs.api.event.PlayerEvent$DamagedEvent");
             } catch (ClassNotFoundException e) {
                 TurnBasedMinecraftMod.logger.info("CustomNPCs Player Hurt Event class not found, not handling it.");
             }
@@ -36,7 +37,7 @@ public class OtherModHandler {
 
             Class<?> customNPCsIDamageSource = null;
             try {
-                customNPCsIDamageSource = Class.forName("noppes.npcs.scripted.interfaces.IDamageSource");
+                customNPCsIDamageSource = Class.forName("noppes.npcs.api.IDamageSource");
             } catch (ClassNotFoundException e) {
                 TurnBasedMinecraftMod.logger.info("CustomNPCs IDamageSource not found, not handling it.");
             }
@@ -46,7 +47,7 @@ public class OtherModHandler {
 
             Class<?> customNPCsIEntity = null;
             try {
-                customNPCsIEntity = Class.forName("noppes.npcs.scripted.interfaces.entity.IEntity");
+                customNPCsIEntity = Class.forName("noppes.npcs.api.entity.IEntity");
             } catch (ClassNotFoundException e) {
                 TurnBasedMinecraftMod.logger.info("CustomNPCs IEntity not found, not handling it.");
             }
@@ -54,6 +55,44 @@ public class OtherModHandler {
                 break;
             }
 
+            // Check if available
+            Object instance = null;
+            try {
+                Method instanceMethod = customNPCsAPI.getMethod("Instance");
+                instance = instanceMethod.invoke(null);
+                if (!customNPCsAPI.isInstance(instance)) {
+                    instance = null;
+                    TurnBasedMinecraftMod.logger.error("NpcAPI.Instance() is not NpcAPI!");
+                }
+            } catch (NoSuchMethodException e) {
+                TurnBasedMinecraftMod.logger.warn("NpcAPI.Instance() does not exist!");
+            } catch (InvocationTargetException e) {
+                TurnBasedMinecraftMod.logger.error("Failed to call NpcAPI.Instance(), InvocationTargetException!");
+            } catch (IllegalAccessException e) {
+                TurnBasedMinecraftMod.logger.error("Failed to call NpcAPI.Instance(), IllegalAccessException!");
+            }
+            if (instance == null) {
+                break;
+            }
+
+            Boolean isAvailable = false;
+            try {
+                Method isAvailableMethod = customNPCsAPI.getMethod("IsAvailable");
+                isAvailable = (Boolean)isAvailableMethod.invoke(instance);
+            } catch (NoSuchMethodException e) {
+                TurnBasedMinecraftMod.logger.warn("NpcAPI.IsAvailable() does not exist!");
+            } catch (InvocationTargetException e) {
+                TurnBasedMinecraftMod.logger.warn("Failed to call NpcAPI.IsAvailable(), InvocationTargetException!");
+            } catch (IllegalAccessException e) {
+                TurnBasedMinecraftMod.logger.warn("Failed to call NpcAPI.IsAvailable(), IllegalAccessException!");
+            } catch (ClassCastException e) {
+                TurnBasedMinecraftMod.logger.warn("Result of NpcAPI.IsAvailable() is not a Boolean!");
+            }
+            if (!isAvailable) {
+                TurnBasedMinecraftMod.logger.warn("NpcAPI is not available!");
+                break;
+            }
+
             TurnBasedMinecraftMod.logger.info("NpcAPI found, setting up player-not-getting-hurt workaround...");
 
             Method getNPCsEventBusMethod = null;
@@ -68,7 +107,7 @@ public class OtherModHandler {
 
             IEventBus customNPCsEventBus = null;
             try {
-                customNPCsEventBus = (IEventBus) getNPCsEventBusMethod.invoke(customNPCsAPI);
+                customNPCsEventBus = (IEventBus) getNPCsEventBusMethod.invoke(instance);
             } catch (InvocationTargetException e) {
                 TurnBasedMinecraftMod.logger.warn("Failed to invoke NpcAPI.events(), InvocationTargetException!");
             } catch (IllegalAccessException e) {
@@ -127,17 +166,22 @@ public class OtherModHandler {
                         return;
                     }
 
-                    Method getEntityIDMethod;
+                    if (!finalCustomNPCsIEntity.isInstance(iEntityObject)) {
+                        TurnBasedMinecraftMod.logger.error("IDamageSource.getTrueSource() is not IEntity!");
+                        return;
+                    }
+
+                    Method getEntityUUIDMethod;
                     try {
-                        getEntityIDMethod = finalCustomNPCsIEntity.getMethod("getEntityId");
+                        getEntityUUIDMethod = finalCustomNPCsIEntity.getMethod("getUUID");
                     } catch (NoSuchMethodException e) {
                         TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs \".getEntityId()\"!");
                         return;
                     }
 
-                    Integer entityId;
+                    String entityUUID;
                     try {
-                        entityId = (Integer)getEntityIDMethod.invoke(iEntityObject);
+                        entityUUID = (String)getEntityUUIDMethod.invoke(iEntityObject);
                     } catch (InvocationTargetException e) {
                         TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs IEntity ID, InvocationTargetException!");
                         return;
@@ -149,13 +193,13 @@ public class OtherModHandler {
                         return;
                     }
 
-                    if (entityId != TurnBasedMinecraftMod.proxy.getAttackingEntity().getId()) {
+                    if (!TurnBasedMinecraftMod.proxy.getAttackingEntity().getStringUUID().equals(entityUUID)) {
                         return;
                     }
 
                     Method getCanceledMethod;
                     try {
-                        getCanceledMethod = finalCustomNPCsPlayerHurtEvent.getMethod("setCanceled", Boolean.class);
+                        getCanceledMethod = finalCustomNPCsPlayerHurtEvent.getMethod("setCanceled", boolean.class);
                     } catch (NoSuchMethodException e) {
                         TurnBasedMinecraftMod.logger.error("CustomNPCs PlayerHurtEvent does not have setCanceled(...)!");
                         return;
index 99c4ffed78216e00f210d63769087dc0c44be960..754c941277da0f23331cc1ecd71d205bd59ae104 100644 (file)
@@ -35,7 +35,7 @@ public class TurnBasedMinecraftMod
 {
     public static final String MODID = "com_burnedkirby_turnbasedminecraft";
     public static final String NAME = "Turn Based Minecraft Mod";
-    public static final String VERSION = "1.17.2.3";
+    public static final String VERSION = "1.17.2.4";
     public static final String CONFIG_FILENAME = "TBM_Config.toml";
     public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
     public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
index 4c77eeb5e633ccc61aeaeecb0b49e91eebf58d09..509d24d44eed11fd928162b4c6ada91e6e205b3e 100644 (file)
@@ -15,7 +15,7 @@ license="MIT"
 # The modid of the mod
 modId="com_burnedkirby_turnbasedminecraft" #mandatory
 # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
-version="1.17.2.3" #mandatory
+version="1.17.2.4" #mandatory
  # A display name for the mod
 displayName="TurnBasedMinecraftMod" #mandatory
 # A URL to query for updates for this mod. See the JSON update specification <here>
index b2db4eb0e50a893417db8f2ff7c294075e134c57..7bc5388bbc01bccf699eb5a82b2eb18c4b88d3cb 100644 (file)
@@ -3,7 +3,7 @@
   "modid": "com_burnedkirby_turnbasedminecraft",
   "name": "Turn Based Minecraft",
   "description": "Changes battles to be turn-based.",
-  "version": "1.17.2.3",
+  "version": "1.17.2.4",
   "mcversion": "1.16.3",
   "url": "",
   "updateUrl": "",