Use class names to better find custom entities.

This commit is contained in:
GJ
2013-09-24 12:24:59 -04:00
committed by TfT_02
parent cf90236e57
commit 4a0fee5796
5 changed files with 76 additions and 70 deletions

View File

@ -44,17 +44,24 @@ public final class ModUtils {
}
public static CustomEntity getCustomEntity(Entity entity) {
if (!CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId()) && !CustomEntityConfig.getInstance().customEntityTypes.contains(entity.getType())) {
return null;
}
CustomEntity customEntity = CustomEntityConfig.getInstance().customEntityTypeMap.get(entity.getType().toString());
for (CustomEntity customEntity : CustomEntityConfig.getInstance().customEntities) {
if ((customEntity.getEntityID() == entity.getEntityId()) && (customEntity.getEntityType() == entity.getType())) {
return customEntity;
if (customEntity == null) {
try {
customEntity = CustomEntityConfig.getInstance().customEntityClassMap.get(((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName());
}
catch (NoSuchFieldException e){
return null;
}
catch (IllegalArgumentException e) {
return null;
}
catch (IllegalAccessException e) {
return null;
}
}
return null;
return customEntity;
}
/**
@ -158,7 +165,26 @@ public final class ModUtils {
}
public static boolean isCustomEntity(Entity entity) {
return customEntitiesEnabled && CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId());
if (!customEntitiesEnabled) {
return false;
}
if (CustomEntityConfig.getInstance().customEntityTypeMap.containsKey(entity.getType().toString())) {
return true;
}
try {
return CustomEntityConfig.getInstance().customEntityClassMap.containsKey(((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName());
}
catch (NoSuchFieldException e){
return false;
}
catch (IllegalArgumentException e) {
return false;
}
catch (IllegalAccessException e) {
return false;
}
}
/**

View File

@ -453,7 +453,7 @@ public final class CombatUtils {
* @param target The defending entity
* @param skillType The skill being used
*/
public static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, SkillType skillType, double multiplier) {
private static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, SkillType skillType, double multiplier) {
double baseXP = 0;
if (target instanceof Player) {
@ -468,13 +468,11 @@ public final class CombatUtils {
}
}
else {
if (target instanceof Animals) {
if (ModUtils.isCustomEntity(target)) {
baseXP = ModUtils.getCustomEntity(target).getXpMultiplier();
}
else {
baseXP = ExperienceConfig.getInstance().getAnimalsXP();
}
if (ModUtils.isCustomEntity(target)) {
baseXP = ModUtils.getCustomEntity(target).getXpMultiplier();
}
else if (target instanceof Animals) {
baseXP = ExperienceConfig.getInstance().getAnimalsXP();
}
else {
EntityType type = target.getType();
@ -500,7 +498,6 @@ public final class CombatUtils {
baseXP = ExperienceConfig.getInstance().getCombatXP(type);
break;
// Temporary workaround for custom entities
case UNKNOWN:
baseXP = 1.0;
break;
@ -523,9 +520,6 @@ public final class CombatUtils {
break;
default:
if (ModUtils.isCustomEntity(target)) {
baseXP = ModUtils.getCustomEntity(target).getXpMultiplier();
}
break;
}
}