diff --git a/src/main/java/electroblob/wizardry/Settings.java b/src/main/java/electroblob/wizardry/Settings.java index 674fe261..e8238e74 100644 --- a/src/main/java/electroblob/wizardry/Settings.java +++ b/src/main/java/electroblob/wizardry/Settings.java @@ -1,6 +1,7 @@ package electroblob.wizardry; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -102,20 +103,20 @@ public final class Settings { /** [Server-only] Whether summoned creatures can revenge attack their caster if their caster attacks them. */ public boolean minionRevengeTargeting = true; /** - * [Server-only] List of names of entities which summoned creatures are allowed to attack, in addition to the - * defaults. + * [Server-only] List of registry names of entities which summoned creatures are allowed to attack, in addition + * to the defaults. */ - public String[] summonedCreatureTargetsWhitelist = {}; + public ResourceLocation[] summonedCreatureTargetsWhitelist = {}; /** - * [Server-only] List of names of entities which summoned creatures are specifically not allowed to attack, - * overriding the defaults and the whitelist. + * [Server-only] List of registry names of entities which summoned creatures are specifically not allowed to + * attack, overriding the defaults and the whitelist. */ - public String[] summonedCreatureTargetsBlacklist = {"creeper"}; + public ResourceLocation[] summonedCreatureTargetsBlacklist = {new ResourceLocation("creeper")}; /** - * [Server-only] List of names of entities which are immune to the mind control spell, in addition to the - * defaults. + * [Server-only] List of registry names of entities which are immune to the mind control spell, in addition to + * the defaults. */ - public String[] mindControlTargetsBlacklist = {}; + public ResourceLocation[] mindControlTargetsBlacklist = {}; /** [Server-only] Global damage scaling factor for all player magic damage. */ public double playerDamageScale = 1.0f; /** [Server-only] Global damage scaling factor for all npc magic damage. */ @@ -451,12 +452,8 @@ public final class Settings { "List of names of entities which summoned creatures and wizards are allowed to attack, in addition to the defaults. Add mod creatures to this list if you want summoned creatures to attack them and they aren't already doing so. Entity names are not case sensitive. For mod entities, prefix with the mod ID (e.g. " + Wizardry.MODID + ":wizard)."); property.setLanguageKey("config." + Wizardry.MODID + ".summoned_creature_targets_whitelist"); property.setRequiresWorldRestart(true); - // Wizardry.proxy.setToEntityNameEntry(property); - summonedCreatureTargetsWhitelist = property.getStringList(); - // Converts all strings in the list to lower case, to ignore case sensitivity, and trims them. - for(int i = 0; i < summonedCreatureTargetsWhitelist.length; i++){ - summonedCreatureTargetsWhitelist[i] = summonedCreatureTargetsWhitelist[i].toLowerCase(Locale.ROOT).trim(); - } + // Converts all strings in the list to a ResourceLocation. + summonedCreatureTargetsWhitelist = Arrays.stream(property.getStringList()).map(s -> new ResourceLocation(s.toLowerCase(Locale.ROOT).trim())).toArray(ResourceLocation[]::new); propOrder.add(property.getName()); property = config.get(Configuration.CATEGORY_GENERAL, "summonedCreatureTargetsBlacklist", @@ -464,12 +461,8 @@ public final class Settings { "List of names of entities which summoned creatures and wizards are specifically not allowed to attack, overriding the defaults and the whitelist. Add creatures to this list if allowing them to be attacked causes problems or is too destructive (removing creepers from this list is done at your own risk!). Entity names are not case sensitive. For mod entities, prefix with the mod ID (e.g. " + Wizardry.MODID + ":wizard)."); property.setLanguageKey("config." + Wizardry.MODID + ".summoned_creature_targets_blacklist"); property.setRequiresWorldRestart(true); - // Wizardry.proxy.setToEntityNameEntry(property); - summonedCreatureTargetsBlacklist = property.getStringList(); - // Converts all strings in the list to lower case, to ignore case sensitivity, and trims them. - for(int i = 0; i < summonedCreatureTargetsBlacklist.length; i++){ - summonedCreatureTargetsBlacklist[i] = summonedCreatureTargetsBlacklist[i].toLowerCase(Locale.ROOT).trim(); - } + // Converts all strings in the list to a ResourceLocation. + summonedCreatureTargetsBlacklist = Arrays.stream(property.getStringList()).map(s -> new ResourceLocation(s.toLowerCase(Locale.ROOT).trim())).toArray(ResourceLocation[]::new); propOrder.add(property.getName()); property = config.get(Configuration.CATEGORY_GENERAL, "spellHUDPosition", GuiPosition.BOTTOM_LEFT.name, @@ -510,12 +503,9 @@ public final class Settings { "List of names of entities which cannot be mind controlled, in addition to the defaults. Add creatures to this list if allowing them to be mind-controlled causes problems or could be exploited. Entity names are not case sensitive. For mod entities, prefix with the mod ID (e.g. " + Wizardry.MODID + ":wizard)."); property.setLanguageKey("config." + Wizardry.MODID + ".mind_control_targets_blacklist"); property.setRequiresWorldRestart(true); - // Wizardry.proxy.setToEntityNameEntry(property); - mindControlTargetsBlacklist = property.getStringList(); - // Converts all strings in the list to lower case, to ignore case sensitivity, and trims them. - for(int i = 0; i < mindControlTargetsBlacklist.length; i++){ - mindControlTargetsBlacklist[i] = mindControlTargetsBlacklist[i].toLowerCase(Locale.ROOT).trim(); - } + // Converts all strings in the list to a ResourceLocation. + mindControlTargetsBlacklist = Arrays.stream(property.getStringList()).map(s -> new ResourceLocation(s.toLowerCase(Locale.ROOT).trim())).toArray(ResourceLocation[]::new); + propOrder.add(property.getName()); propOrder.add(property.getName()); config.setCategoryPropertyOrder(Configuration.CATEGORY_GENERAL, propOrder); diff --git a/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java b/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java index 020db8fb..674fc3e0 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntityEvilWizard.java @@ -3,7 +3,6 @@ package electroblob.wizardry.entity.living; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Locale; import com.google.common.base.Predicate; @@ -118,10 +117,10 @@ public class EntityEvilWizard extends EntityMob implements ISpellCaster, IEntity || (entity instanceof ISummonedCreature || entity instanceof EntityWizard // ... or in the whitelist ... || Arrays.asList(Wizardry.settings.summonedCreatureTargetsWhitelist) - .contains(EntityList.getKey(entity.getClass()).toString().toLowerCase(Locale.ROOT))) + .contains(EntityList.getKey(entity.getClass()))) // ... and isn't in the blacklist ... && !Arrays.asList(Wizardry.settings.summonedCreatureTargetsBlacklist) - .contains(EntityList.getKey(entity.getClass()).toString().toLowerCase(Locale.ROOT))){ + .contains(EntityList.getKey(entity.getClass()))){ // ... it can be attacked. return true; } diff --git a/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java b/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java index eb7ad7d3..748a410a 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntityWizard.java @@ -5,7 +5,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Random; import java.util.Set; @@ -162,10 +161,10 @@ public class EntityWizard extends EntityVillager implements ISpellCaster, IEntit if((entity instanceof IMob || entity instanceof ISummonedCreature // ... or in the whitelist ... || Arrays.asList(Wizardry.settings.summonedCreatureTargetsWhitelist) - .contains(EntityList.getKey(entity.getClass()).toString().toLowerCase(Locale.ROOT))) + .contains(EntityList.getKey(entity.getClass()))) // ... and isn't in the blacklist ... && !Arrays.asList(Wizardry.settings.summonedCreatureTargetsBlacklist) - .contains(EntityList.getKey(entity.getClass()).toString().toLowerCase(Locale.ROOT))){ + .contains(EntityList.getKey(entity.getClass()))){ // ... it can be attacked. return true; } diff --git a/src/main/java/electroblob/wizardry/entity/living/ISummonedCreature.java b/src/main/java/electroblob/wizardry/entity/living/ISummonedCreature.java index 092a7dd5..30c852ab 100644 --- a/src/main/java/electroblob/wizardry/entity/living/ISummonedCreature.java +++ b/src/main/java/electroblob/wizardry/entity/living/ISummonedCreature.java @@ -2,7 +2,6 @@ package electroblob.wizardry.entity.living; import java.lang.ref.WeakReference; import java.util.Arrays; -import java.util.Locale; import java.util.UUID; import javax.annotation.Nullable; @@ -190,10 +189,10 @@ public interface ISummonedCreature extends IEntityAdditionalSpawnData { || (entity instanceof EntityWizard && !(getCaster() instanceof EntityWizard)) // ... or in the whitelist ... || Arrays.asList(Wizardry.settings.summonedCreatureTargetsWhitelist) - .contains(EntityList.getKey(entity.getClass()).toString().toLowerCase(Locale.ROOT))) + .contains(EntityList.getKey(entity.getClass()))) // ... and isn't in the blacklist ... && !Arrays.asList(Wizardry.settings.summonedCreatureTargetsBlacklist) - .contains(EntityList.getKey(entity.getClass()).toString().toLowerCase(Locale.ROOT))){ + .contains(EntityList.getKey(entity.getClass()))){ // ... it can be attacked. return true; } diff --git a/src/main/java/electroblob/wizardry/spell/MindControl.java b/src/main/java/electroblob/wizardry/spell/MindControl.java index 2b7f5e59..e061d180 100644 --- a/src/main/java/electroblob/wizardry/spell/MindControl.java +++ b/src/main/java/electroblob/wizardry/spell/MindControl.java @@ -2,7 +2,6 @@ package electroblob.wizardry.spell; import java.util.Arrays; import java.util.List; -import java.util.Locale; import electroblob.wizardry.Wizardry; import electroblob.wizardry.constants.Element; @@ -146,8 +145,8 @@ public class MindControl extends Spell { /** Returns true if the given entity can be mind controlled (i.e. is not a player, npc, evil wizard or boss). */ public static boolean canControl(EntityLivingBase target){ return target instanceof EntityLiving && target.isNonBoss() && !(target instanceof INpc) - && !(target instanceof EntityEvilWizard) && !Arrays.asList(Wizardry.settings.summonedCreatureTargetsBlacklist) - .contains(EntityList.getKey(entity.getClass()).toString().toLowerCase(Locale.ROOT)); + && !(target instanceof EntityEvilWizard) && !Arrays.asList(Wizardry.settings.mindControlTargetsBlacklist) + .contains(EntityList.getKey(target.getClass())); } /**