Compare commits
8 commits
neoforge
...
CustomNPCs
Author | SHA1 | Date | |
---|---|---|---|
Stephen Seo | 8242e2ae01 | ||
Stephen Seo | f58a1942ca | ||
Stephen Seo | a89adbc624 | ||
Stephen Seo | 6aebe3eb82 | ||
Stephen Seo | c41938ada2 | ||
Stephen Seo | e2e7254f1d | ||
Stephen Seo | 3362f69cab | ||
Stephen Seo | c565eb24f4 |
27
Changelog.md
27
Changelog.md
|
@ -1,5 +1,32 @@
|
|||
# Upcoming changes
|
||||
|
||||
# Version 1.17.2.6
|
||||
|
||||
Implemented getting EntityInfo for CustomNPCs that have the same name as a
|
||||
"custom entry" in the "server\_config.entity" array in the config.
|
||||
|
||||
# Version 1.17.2.5
|
||||
|
||||
Refactored OtherModHandling.java to be more efficient when handling CustomNPCs
|
||||
DamagedEvent.
|
||||
|
||||
# Version 1.17.2.4
|
||||
|
||||
Fix usage of NpcAPI.
|
||||
|
||||
# Version 1.17.2.3
|
||||
|
||||
Fix potential unhandled exception crash bug related to handling CustomNPCs
|
||||
Player hurt events.
|
||||
|
||||
# Version 1.17.2.2
|
||||
|
||||
Fix potential NullPointerException crash bug.
|
||||
|
||||
# Version 1.17.2.1
|
||||
|
||||
Attempt to fix CustomNPCs mods not damaging players in TurnBased combat.
|
||||
|
||||
# Version 1.17.2
|
||||
|
||||
(try to) Fix potential freeze bug when an entity leaves battle.
|
||||
|
|
|
@ -14,7 +14,7 @@ apply plugin: 'eclipse'
|
|||
//apply plugin: 'maven-publish'
|
||||
apply plugin: 'com.github.johnrengelman.shadow'
|
||||
|
||||
version = "1.17.2"
|
||||
version = "1.17.2.6"
|
||||
group = "com.burnedkirby.TurnBasedMinecraft"
|
||||
archivesBaseName = "TurnBasedMinecraft"
|
||||
|
||||
|
|
|
@ -151,7 +151,11 @@ public class BattleGui extends Screen {
|
|||
for (Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle()
|
||||
.getSideAEntrySet()) {
|
||||
if (e.getValue().entity != null) {
|
||||
addButton(new EntitySelectionButton(width / 4 - 60, y, 120, 20, e.getValue().entity.getName().getString(), e.getKey(), true, (button) -> {
|
||||
String name = e.getValue().entity.getName().getString();
|
||||
if (name.isEmpty()) {
|
||||
name = "Unknown";
|
||||
}
|
||||
addButton(new EntitySelectionButton(width / 4 - 60, y, 120, 20, name, e.getKey(), true, (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
|
||||
}));
|
||||
} else {
|
||||
|
@ -169,7 +173,11 @@ public class BattleGui extends Screen {
|
|||
for (Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle()
|
||||
.getSideBEntrySet()) {
|
||||
if (e.getValue().entity != null) {
|
||||
addButton(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, e.getValue().entity.getName().getString(), e.getKey(), false, (button) -> {
|
||||
String name = e.getValue().entity.getName().getString();
|
||||
if (name.isEmpty()) {
|
||||
name = "Unknown";
|
||||
}
|
||||
addButton(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, name, e.getKey(), false, (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
|
||||
}));
|
||||
} else {
|
||||
|
|
|
@ -142,6 +142,14 @@ public class Battle
|
|||
} catch(NullPointerException exception) {
|
||||
entityInfo = null;
|
||||
}
|
||||
if (entityInfo == null) {
|
||||
// Check if is CustomNPC with matching name entry.
|
||||
try {
|
||||
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(OtherModHandler.getCustomNPCName(e));
|
||||
} catch(NullPointerException exception) {
|
||||
entityInfo = null;
|
||||
}
|
||||
}
|
||||
if(entityInfo == null)
|
||||
{
|
||||
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
|
||||
|
@ -180,6 +188,14 @@ public class Battle
|
|||
} catch(NullPointerException exception) {
|
||||
entityInfo = null;
|
||||
}
|
||||
if (entityInfo == null) {
|
||||
// Check if is CustomNPC with matching name entry.
|
||||
try {
|
||||
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(OtherModHandler.getCustomNPCName(e));
|
||||
} catch(NullPointerException exception) {
|
||||
entityInfo = null;
|
||||
}
|
||||
}
|
||||
if(entityInfo == null)
|
||||
{
|
||||
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
|
||||
|
@ -311,12 +327,20 @@ public class Battle
|
|||
} catch(NullPointerException exception) {
|
||||
entityInfo = null;
|
||||
}
|
||||
if (entityInfo == null) {
|
||||
// Check if entity is CustomNPC entity.
|
||||
try {
|
||||
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(OtherModHandler.getCustomNPCName(e));
|
||||
} catch(NullPointerException exception) {
|
||||
entityInfo = null;
|
||||
}
|
||||
}
|
||||
if(entityInfo == null)
|
||||
{
|
||||
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
|
||||
}
|
||||
|
||||
if(entityInfo == null && !(e instanceof PlayerEntity) && TurnBasedMinecraftMod.proxy.isServerRunning())
|
||||
if(isServer && entityInfo == null && !(e instanceof PlayerEntity) && TurnBasedMinecraftMod.proxy.isServerRunning())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -374,12 +398,20 @@ public class Battle
|
|||
} catch(NullPointerException exception) {
|
||||
entityInfo = null;
|
||||
}
|
||||
if (entityInfo == null) {
|
||||
// Check if entity is CustomNPC entity.
|
||||
try {
|
||||
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(OtherModHandler.getCustomNPCName(e));
|
||||
} catch(NullPointerException exception) {
|
||||
entityInfo = null;
|
||||
}
|
||||
}
|
||||
if(entityInfo == null)
|
||||
{
|
||||
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
|
||||
}
|
||||
|
||||
if(entityInfo == null && !(e instanceof PlayerEntity) && TurnBasedMinecraftMod.proxy.isServerRunning())
|
||||
if(isServer && entityInfo == null && !(e instanceof PlayerEntity) && TurnBasedMinecraftMod.proxy.isServerRunning())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -61,6 +61,11 @@ public class BattleManager
|
|||
} catch (NullPointerException e) {
|
||||
receiverCustomName = null;
|
||||
}
|
||||
if (receiverCustomName == null) {
|
||||
// If entity does not have a "custom name", see if it is a CustomNPC and get its name.
|
||||
receiverCustomName = OtherModHandler.getCustomNPCName(event.getEntity());
|
||||
}
|
||||
|
||||
String attackerClassName;
|
||||
try {
|
||||
attackerClassName = event.getSource().getEntity().getClass().getName();
|
||||
|
@ -73,6 +78,10 @@ public class BattleManager
|
|||
} catch (NullPointerException e) {
|
||||
attackerCustomName = null;
|
||||
}
|
||||
if (attackerCustomName == null) {
|
||||
// If entity does not have a "custom name", see if it is a CustomNPC and get its name.
|
||||
attackerCustomName = OtherModHandler.getCustomNPCName(event.getSource().getEntity());
|
||||
}
|
||||
|
||||
// verify that both entities are EntityPlayer and not in creative or has a corresponding EntityInfo
|
||||
if(!((event.getEntity() instanceof PlayerEntity && !((PlayerEntity)event.getEntity()).isCreative())
|
||||
|
@ -190,12 +199,20 @@ public class BattleManager
|
|||
} catch (NullPointerException e) {
|
||||
targetedCustomName = null;
|
||||
}
|
||||
if (targetedCustomName == null) {
|
||||
// If entity does not have a "custom name", see if it is a CustomNPC and get its name.
|
||||
targetedCustomName = OtherModHandler.getCustomNPCName(event.getEntity());
|
||||
}
|
||||
String attackerCustomName;
|
||||
try {
|
||||
attackerCustomName = event.getEntity().getCustomName().getString();
|
||||
} catch (NullPointerException e) {
|
||||
attackerCustomName = null;
|
||||
}
|
||||
if (attackerCustomName == null) {
|
||||
// If entity does not have a "custom name", see if it is a CustomNPC and get its name.
|
||||
attackerCustomName = OtherModHandler.getCustomNPCName(event.getEntity());
|
||||
}
|
||||
|
||||
EntityInfo attackerInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(attackerCustomName);
|
||||
if(attackerInfo == null)
|
||||
|
@ -366,4 +383,4 @@ public class BattleManager
|
|||
public static Collection<ItemGroup> getOtherFoodItemGroups() {
|
||||
return otherFoodItemGroups;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,15 @@ public class CommonProxy
|
|||
private Config config = null;
|
||||
protected Logger logger = null;
|
||||
private Map<Integer, EditingInfo> editingPlayers;
|
||||
|
||||
private OtherModHandler otherModHandler;
|
||||
|
||||
public final void initialize()
|
||||
{
|
||||
attackerViaBow = new HashSet<AttackerViaBow>();
|
||||
editingPlayers = new Hashtable<Integer, EditingInfo>();
|
||||
initializeClient();
|
||||
otherModHandler = new OtherModHandler();
|
||||
logger.debug("Init proxy for com_burnedkirby_turnbasedminecraft");
|
||||
}
|
||||
|
||||
|
@ -77,6 +80,8 @@ public class CommonProxy
|
|||
postInitClient();
|
||||
pamsFoodIntegrationLoading();
|
||||
logger.debug("postInit proxy for com_burnedkirby_turnbasedminecraft");
|
||||
|
||||
otherModHandler.postInit();
|
||||
}
|
||||
|
||||
protected void postInitClient() {}
|
||||
|
|
|
@ -0,0 +1,340 @@
|
|||
package com.burnedkirby.TurnBasedMinecraft.common;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
|
||||
public class OtherModHandler {
|
||||
|
||||
private static boolean customNPCsExists = false;
|
||||
private static Object NpcAPIObject = null;
|
||||
private static Class<?> NpcAPIClass = null;
|
||||
private static Method NpcAPI_getEntity = null;
|
||||
private static Class<?> ICustomNPCClass = null;
|
||||
private static Method ICustomNPC_getDisplayMethod = null;
|
||||
private static Class<?> INPCDisplayClass = null;
|
||||
private static Method INPCDisplay_getNameMethod = null;
|
||||
|
||||
public 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
|
||||
try {
|
||||
NpcAPIClass = Class.forName("noppes.npcs.api.NpcAPI");
|
||||
} catch (ClassNotFoundException e) {
|
||||
TurnBasedMinecraftMod.logger.info("NpcAPI not found, not handling it.");
|
||||
}
|
||||
if (NpcAPIClass == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
Class<?> customNPCsPlayerHurtEvent = null;
|
||||
try {
|
||||
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.");
|
||||
}
|
||||
if (customNPCsPlayerHurtEvent == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
Field damageSourceField = null;
|
||||
try {
|
||||
damageSourceField = customNPCsPlayerHurtEvent.getField("damageSource");
|
||||
} catch (NoSuchFieldException e) {
|
||||
TurnBasedMinecraftMod.logger.error("CustomNPCs PlayerHurtEvent does not have \".damageSource\"!");
|
||||
}
|
||||
if (damageSourceField == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
Class<?> customNPCsIDamageSource = null;
|
||||
try {
|
||||
customNPCsIDamageSource = Class.forName("noppes.npcs.api.IDamageSource");
|
||||
} catch (ClassNotFoundException e) {
|
||||
TurnBasedMinecraftMod.logger.info("CustomNPCs IDamageSource not found, not handling it.");
|
||||
}
|
||||
if (customNPCsIDamageSource == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
Method trueSourceMethod = null;
|
||||
try {
|
||||
trueSourceMethod = customNPCsIDamageSource.getMethod("getTrueSource");
|
||||
} catch (NoSuchMethodException e) {
|
||||
TurnBasedMinecraftMod.logger.error("CustomNPCs IDamageSource does not have \".getTrueSource()\"!");
|
||||
}
|
||||
if (trueSourceMethod == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
Class<?> customNPCsIEntity = null;
|
||||
try {
|
||||
customNPCsIEntity = Class.forName("noppes.npcs.api.entity.IEntity");
|
||||
} catch (ClassNotFoundException e) {
|
||||
TurnBasedMinecraftMod.logger.info("CustomNPCs IEntity not found, not handling it.");
|
||||
}
|
||||
if (customNPCsIEntity == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
Method getEntityUUIDMethod = null;
|
||||
try {
|
||||
getEntityUUIDMethod = customNPCsIEntity.getMethod("getUUID");
|
||||
} catch (NoSuchMethodException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs \".getEntityId()\"!");
|
||||
}
|
||||
if (getEntityUUIDMethod == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
Method getCanceledMethod = null;
|
||||
try {
|
||||
getCanceledMethod = customNPCsPlayerHurtEvent.getMethod("setCanceled", boolean.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
TurnBasedMinecraftMod.logger.error("CustomNPCs PlayerHurtEvent does not have setCanceled(...)!");
|
||||
}
|
||||
if (getCanceledMethod == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Check if available
|
||||
try {
|
||||
Method instanceMethod = NpcAPIClass.getMethod("Instance");
|
||||
NpcAPIObject = instanceMethod.invoke(null);
|
||||
if (!NpcAPIClass.isInstance(NpcAPIObject)) {
|
||||
NpcAPIObject = 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 (NpcAPIObject == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
Boolean isAvailable = false;
|
||||
try {
|
||||
Method isAvailableMethod = NpcAPIClass.getMethod("IsAvailable");
|
||||
isAvailable = (Boolean)isAvailableMethod.invoke(NpcAPIObject);
|
||||
} 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;
|
||||
try {
|
||||
getNPCsEventBusMethod = NpcAPIClass.getMethod("events");
|
||||
} catch (NoSuchMethodException e) {
|
||||
TurnBasedMinecraftMod.logger.warn("NpcAPI.events() could not be found!");
|
||||
}
|
||||
if (getNPCsEventBusMethod == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
IEventBus customNPCsEventBus = null;
|
||||
try {
|
||||
customNPCsEventBus = (IEventBus) getNPCsEventBusMethod.invoke(NpcAPIObject);
|
||||
} catch (InvocationTargetException e) {
|
||||
TurnBasedMinecraftMod.logger.warn("Failed to invoke NpcAPI.events(), InvocationTargetException!");
|
||||
} catch (IllegalAccessException e) {
|
||||
TurnBasedMinecraftMod.logger.warn("Failed to invoke NpcAPI.events(), IllegalAccessException!");
|
||||
} catch (ClassCastException e) {
|
||||
TurnBasedMinecraftMod.logger.warn("Failed to cast NpcAPI.events(), ClassCastException!");
|
||||
}
|
||||
if (customNPCsEventBus == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
final Class<?> finalCustomNPCsPlayerHurtEvent = customNPCsPlayerHurtEvent;
|
||||
final Field finalDamageSourceField = damageSourceField;
|
||||
final Class<?> finalCustomNPCsIDamageSource = customNPCsIDamageSource;
|
||||
final Method finalTrueSourceMethod = trueSourceMethod;
|
||||
final Class<?> finalCustomNPCsIEntity = customNPCsIEntity;
|
||||
final Method finalGetEntityUUIDMethod = getEntityUUIDMethod;
|
||||
final Method finalGetCanceledMethod = getCanceledMethod;
|
||||
|
||||
customNPCsEventBus.addListener(EventPriority.LOWEST, true, (event) -> {
|
||||
if (finalCustomNPCsPlayerHurtEvent.isInstance(event)
|
||||
&& TurnBasedMinecraftMod.proxy.getAttackingEntity() != null) {
|
||||
Object damageSourceObject;
|
||||
try {
|
||||
damageSourceObject = finalDamageSourceField.get(event);
|
||||
} catch (IllegalAccessException e) {
|
||||
TurnBasedMinecraftMod.logger.error("CustomNPCs PlayerHurtEvent failed to get \".damageSource\"!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!finalCustomNPCsIDamageSource.isInstance(damageSourceObject)) {
|
||||
TurnBasedMinecraftMod.logger.error("CustomNPCs PlayerHurtEvent damageSource is not IDamageSource!");
|
||||
return;
|
||||
}
|
||||
|
||||
Object iEntityObject;
|
||||
try {
|
||||
iEntityObject = finalTrueSourceMethod.invoke(damageSourceObject);
|
||||
} catch (IllegalAccessException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs IEntity from IDamageSource, IllegalAccessException!");
|
||||
return;
|
||||
} catch (InvocationTargetException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs IEntity from IDamageSource, InvocationTargetException!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!finalCustomNPCsIEntity.isInstance(iEntityObject)) {
|
||||
TurnBasedMinecraftMod.logger.error("IDamageSource.getTrueSource() is not IEntity!");
|
||||
return;
|
||||
}
|
||||
|
||||
String entityUUID;
|
||||
try {
|
||||
entityUUID = (String)finalGetEntityUUIDMethod.invoke(iEntityObject);
|
||||
} catch (InvocationTargetException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs IEntity ID, InvocationTargetException!");
|
||||
return;
|
||||
} catch (IllegalAccessException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs IEntity ID, IllegalAccessException!");
|
||||
return;
|
||||
} catch (ClassCastException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to get CustomNPCs IEntity ID, ClassCastException!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TurnBasedMinecraftMod.proxy.getAttackingEntity().getStringUUID().equals(entityUUID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
finalGetCanceledMethod.invoke(event, false);
|
||||
} catch (IllegalAccessException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to un-cancel Player hurt event, IllegalAccessException!");
|
||||
} catch (InvocationTargetException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to un-cancel Player hurt event, InvocationTargetException!");
|
||||
}
|
||||
}
|
||||
});
|
||||
TurnBasedMinecraftMod.logger.info("Enabled NpcAPI handling of Player damaged event");
|
||||
|
||||
try {
|
||||
NpcAPI_getEntity = NpcAPIClass.getMethod("getIEntity", Entity.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
TurnBasedMinecraftMod.logger.warn("Failed to reflect NpcAPI.getIEntity() method");
|
||||
}
|
||||
if (NpcAPI_getEntity == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
ICustomNPCClass = Class.forName("noppes.npcs.api.entity.ICustomNpc");
|
||||
} catch (ClassNotFoundException e) {
|
||||
TurnBasedMinecraftMod.logger.warn("Failed to reflect ICustomNPC class");
|
||||
}
|
||||
if (ICustomNPCClass == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
ICustomNPC_getDisplayMethod = ICustomNPCClass.getMethod("getDisplay");
|
||||
} catch (NoSuchMethodException e) {
|
||||
TurnBasedMinecraftMod.logger.warn("Failed to reflect ICustomNPC.getDisplay() method");
|
||||
}
|
||||
if (ICustomNPC_getDisplayMethod == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
INPCDisplayClass = Class.forName("noppes.npcs.api.entity.data.INPCDisplay");
|
||||
} catch (ClassNotFoundException e) {
|
||||
TurnBasedMinecraftMod.logger.warn("Failed to reflect INPCDisplay class");
|
||||
}
|
||||
if (INPCDisplayClass == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
INPCDisplay_getNameMethod = INPCDisplayClass.getMethod("getName");
|
||||
} catch (NoSuchMethodException e) {
|
||||
TurnBasedMinecraftMod.logger.warn("Failed to reflect INPCDisplay.getName() method");
|
||||
}
|
||||
if (INPCDisplay_getNameMethod == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
customNPCsExists = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCustomNPCName(Entity entity) {
|
||||
if (customNPCsExists) {
|
||||
Object ientity = null;
|
||||
try {
|
||||
ientity = NpcAPI_getEntity.invoke(NpcAPIObject, entity);
|
||||
} catch (InvocationTargetException e) {
|
||||
TurnBasedMinecraftMod.logger.debug("Cannot getCustomNPCName, NpcAPI.getEntity(...) InvocationTargetException");
|
||||
} catch (IllegalAccessException e) {
|
||||
TurnBasedMinecraftMod.logger.debug("Cannot getCustomNPCName, NpcAPI.getEntity(...) IllegalAccessException");
|
||||
}
|
||||
if (ientity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!ICustomNPCClass.isInstance(ientity)) {
|
||||
TurnBasedMinecraftMod.logger.debug("Cannot getCustomNPCName, entity is not ICustomNPC!");
|
||||
return null;
|
||||
}
|
||||
Object objINPCDisplay = null;
|
||||
try {
|
||||
objINPCDisplay = ICustomNPC_getDisplayMethod.invoke(ientity);
|
||||
} catch (InvocationTargetException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to get INPCDisplay object, InvocationTargetException!");
|
||||
} catch (IllegalAccessException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to get INPCDisplay object, IllegalAccessException!");
|
||||
}
|
||||
if (!INPCDisplayClass.isInstance(objINPCDisplay)) {
|
||||
TurnBasedMinecraftMod.logger.debug("Cannot getCustomNPCName, ientity object is not ICustomNPC!");
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = null;
|
||||
try {
|
||||
name = (String)INPCDisplay_getNameMethod.invoke(objINPCDisplay);
|
||||
} catch (InvocationTargetException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to get INPCDisplay name, InvocationTargetException!");
|
||||
} catch (IllegalAccessException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to get INPCDisplay name, IllegalAccessException!");
|
||||
} catch (ClassCastException e) {
|
||||
TurnBasedMinecraftMod.logger.error("Failed to get INPCDisplay name, ClassCastException!");
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
TurnBasedMinecraftMod.logger.debug("Cannot getCustomNPCName, got null name!");
|
||||
}
|
||||
return name;
|
||||
} else {
|
||||
TurnBasedMinecraftMod.logger.debug("Cannot getCustomNPCName, reflected classes/methods not loaded!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
public static final String VERSION = "1.17.2.6";
|
||||
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/";
|
||||
|
|
|
@ -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" #mandatory
|
||||
version="1.17.2.6" #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>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"modid": "com_burnedkirby_turnbasedminecraft",
|
||||
"name": "Turn Based Minecraft",
|
||||
"description": "Changes battles to be turn-based.",
|
||||
"version": "1.17.2",
|
||||
"version": "1.17.2.6",
|
||||
"mcversion": "1.16.3",
|
||||
"url": "",
|
||||
"updateUrl": "",
|
||||
|
|
Loading…
Reference in a new issue