Fixes for Custom NPCs, version 1.17.2.4
Previous code worked against a different Custom NPCs API. This commit fixes the previous namespaces to the publically available Custom NPCs "NpcAPI" namespaces.
This commit is contained in:
parent
6aebe3eb82
commit
a89adbc624
6 changed files with 63 additions and 15 deletions
|
@ -1,5 +1,9 @@
|
||||||
# Upcoming changes
|
# Upcoming changes
|
||||||
|
|
||||||
|
# Version 1.17.2.4
|
||||||
|
|
||||||
|
Fix usage of NpcAPI.
|
||||||
|
|
||||||
# Version 1.17.2.3
|
# Version 1.17.2.3
|
||||||
|
|
||||||
Fix potential unhandled exception crash bug related to handling CustomNPCs
|
Fix potential unhandled exception crash bug related to handling CustomNPCs
|
||||||
|
|
|
@ -14,7 +14,7 @@ apply plugin: 'eclipse'
|
||||||
//apply plugin: 'maven-publish'
|
//apply plugin: 'maven-publish'
|
||||||
apply plugin: 'com.github.johnrengelman.shadow'
|
apply plugin: 'com.github.johnrengelman.shadow'
|
||||||
|
|
||||||
version = "1.17.2.3"
|
version = "1.17.2.4"
|
||||||
group = "com.burnedkirby.TurnBasedMinecraft"
|
group = "com.burnedkirby.TurnBasedMinecraft"
|
||||||
archivesBaseName = "TurnBasedMinecraft"
|
archivesBaseName = "TurnBasedMinecraft"
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,10 @@ public class OtherModHandler {
|
||||||
public void postInit() {
|
public void postInit() {
|
||||||
// Check if CustomNPCs is available, and handle player damage events if it is.
|
// Check if CustomNPCs is available, and handle player damage events if it is.
|
||||||
for (int i = 0; i < 1; ++i) {
|
for (int i = 0; i < 1; ++i) {
|
||||||
|
// Check if required classes exist
|
||||||
Class<?> customNPCsAPI = null;
|
Class<?> customNPCsAPI = null;
|
||||||
try {
|
try {
|
||||||
customNPCsAPI = Class.forName("noppes.npcs.scripted.NpcAPI");
|
customNPCsAPI = Class.forName("noppes.npcs.api.NpcAPI");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
TurnBasedMinecraftMod.logger.info("NpcAPI not found, not handling it.");
|
TurnBasedMinecraftMod.logger.info("NpcAPI not found, not handling it.");
|
||||||
}
|
}
|
||||||
|
@ -26,7 +27,7 @@ public class OtherModHandler {
|
||||||
|
|
||||||
Class<?> customNPCsPlayerHurtEvent = null;
|
Class<?> customNPCsPlayerHurtEvent = null;
|
||||||
try {
|
try {
|
||||||
customNPCsPlayerHurtEvent = Class.forName("noppes.npcs.scripted.event.PlayerEvent.DamagedEvent");
|
customNPCsPlayerHurtEvent = Class.forName("noppes.npcs.api.event.PlayerEvent$DamagedEvent");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
TurnBasedMinecraftMod.logger.info("CustomNPCs Player Hurt Event class not found, not handling it.");
|
TurnBasedMinecraftMod.logger.info("CustomNPCs Player Hurt Event class not found, not handling it.");
|
||||||
}
|
}
|
||||||
|
@ -36,7 +37,7 @@ public class OtherModHandler {
|
||||||
|
|
||||||
Class<?> customNPCsIDamageSource = null;
|
Class<?> customNPCsIDamageSource = null;
|
||||||
try {
|
try {
|
||||||
customNPCsIDamageSource = Class.forName("noppes.npcs.scripted.interfaces.IDamageSource");
|
customNPCsIDamageSource = Class.forName("noppes.npcs.api.IDamageSource");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
TurnBasedMinecraftMod.logger.info("CustomNPCs IDamageSource not found, not handling it.");
|
TurnBasedMinecraftMod.logger.info("CustomNPCs IDamageSource not found, not handling it.");
|
||||||
}
|
}
|
||||||
|
@ -46,7 +47,7 @@ public class OtherModHandler {
|
||||||
|
|
||||||
Class<?> customNPCsIEntity = null;
|
Class<?> customNPCsIEntity = null;
|
||||||
try {
|
try {
|
||||||
customNPCsIEntity = Class.forName("noppes.npcs.scripted.interfaces.entity.IEntity");
|
customNPCsIEntity = Class.forName("noppes.npcs.api.entity.IEntity");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
TurnBasedMinecraftMod.logger.info("CustomNPCs IEntity not found, not handling it.");
|
TurnBasedMinecraftMod.logger.info("CustomNPCs IEntity not found, not handling it.");
|
||||||
}
|
}
|
||||||
|
@ -54,6 +55,44 @@ public class OtherModHandler {
|
||||||
break;
|
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...");
|
TurnBasedMinecraftMod.logger.info("NpcAPI found, setting up player-not-getting-hurt workaround...");
|
||||||
|
|
||||||
Method getNPCsEventBusMethod = null;
|
Method getNPCsEventBusMethod = null;
|
||||||
|
@ -68,7 +107,7 @@ public class OtherModHandler {
|
||||||
|
|
||||||
IEventBus customNPCsEventBus = null;
|
IEventBus customNPCsEventBus = null;
|
||||||
try {
|
try {
|
||||||
customNPCsEventBus = (IEventBus) getNPCsEventBusMethod.invoke(customNPCsAPI);
|
customNPCsEventBus = (IEventBus) getNPCsEventBusMethod.invoke(instance);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
TurnBasedMinecraftMod.logger.warn("Failed to invoke NpcAPI.events(), InvocationTargetException!");
|
TurnBasedMinecraftMod.logger.warn("Failed to invoke NpcAPI.events(), InvocationTargetException!");
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
|
@ -127,17 +166,22 @@ public class OtherModHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Method getEntityIDMethod;
|
if (!finalCustomNPCsIEntity.isInstance(iEntityObject)) {
|
||||||
|
TurnBasedMinecraftMod.logger.error("IDamageSource.getTrueSource() is not IEntity!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Method getEntityUUIDMethod;
|
||||||
try {
|
try {
|
||||||
getEntityIDMethod = finalCustomNPCsIEntity.getMethod("getEntityId");
|
getEntityUUIDMethod = finalCustomNPCsIEntity.getMethod("getUUID");
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs \".getEntityId()\"!");
|
TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs \".getEntityId()\"!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer entityId;
|
String entityUUID;
|
||||||
try {
|
try {
|
||||||
entityId = (Integer)getEntityIDMethod.invoke(iEntityObject);
|
entityUUID = (String)getEntityUUIDMethod.invoke(iEntityObject);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs IEntity ID, InvocationTargetException!");
|
TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs IEntity ID, InvocationTargetException!");
|
||||||
return;
|
return;
|
||||||
|
@ -149,13 +193,13 @@ public class OtherModHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entityId != TurnBasedMinecraftMod.proxy.getAttackingEntity().getId()) {
|
if (!TurnBasedMinecraftMod.proxy.getAttackingEntity().getStringUUID().equals(entityUUID)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Method getCanceledMethod;
|
Method getCanceledMethod;
|
||||||
try {
|
try {
|
||||||
getCanceledMethod = finalCustomNPCsPlayerHurtEvent.getMethod("setCanceled", Boolean.class);
|
getCanceledMethod = finalCustomNPCsPlayerHurtEvent.getMethod("setCanceled", boolean.class);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
TurnBasedMinecraftMod.logger.error("CustomNPCs PlayerHurtEvent does not have setCanceled(...)!");
|
TurnBasedMinecraftMod.logger.error("CustomNPCs PlayerHurtEvent does not have setCanceled(...)!");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class TurnBasedMinecraftMod
|
||||||
{
|
{
|
||||||
public static final String MODID = "com_burnedkirby_turnbasedminecraft";
|
public static final String MODID = "com_burnedkirby_turnbasedminecraft";
|
||||||
public static final String NAME = "Turn Based Minecraft Mod";
|
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 CONFIG_FILENAME = "TBM_Config.toml";
|
||||||
public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
|
public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
|
||||||
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
|
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
|
||||||
|
|
|
@ -15,7 +15,7 @@ license="MIT"
|
||||||
# The modid of the mod
|
# The modid of the mod
|
||||||
modId="com_burnedkirby_turnbasedminecraft" #mandatory
|
modId="com_burnedkirby_turnbasedminecraft" #mandatory
|
||||||
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
# 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
|
# A display name for the mod
|
||||||
displayName="TurnBasedMinecraftMod" #mandatory
|
displayName="TurnBasedMinecraftMod" #mandatory
|
||||||
# A URL to query for updates for this mod. See the JSON update specification <here>
|
# A URL to query for updates for this mod. See the JSON update specification <here>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"modid": "com_burnedkirby_turnbasedminecraft",
|
"modid": "com_burnedkirby_turnbasedminecraft",
|
||||||
"name": "Turn Based Minecraft",
|
"name": "Turn Based Minecraft",
|
||||||
"description": "Changes battles to be turn-based.",
|
"description": "Changes battles to be turn-based.",
|
||||||
"version": "1.17.2.3",
|
"version": "1.17.2.4",
|
||||||
"mcversion": "1.16.3",
|
"mcversion": "1.16.3",
|
||||||
"url": "",
|
"url": "",
|
||||||
"updateUrl": "",
|
"updateUrl": "",
|
||||||
|
|
Loading…
Reference in a new issue