diff --git a/src/main/java/electroblob/wizardry/CommonProxy.java b/src/main/java/electroblob/wizardry/CommonProxy.java index 63cf5ede..947a6e93 100644 --- a/src/main/java/electroblob/wizardry/CommonProxy.java +++ b/src/main/java/electroblob/wizardry/CommonProxy.java @@ -19,6 +19,7 @@ import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; import net.minecraftforge.common.config.Property; +import javax.annotation.Nullable; import java.util.List; import java.util.Set; @@ -74,7 +75,7 @@ public class CommonProxy { // SECTION Items // =============================================================================================================== - public boolean shouldDisplayDiscovered(Spell spell, ItemStack stack){ + public boolean shouldDisplayDiscovered(Spell spell, @Nullable ItemStack stack){ return false; } diff --git a/src/main/java/electroblob/wizardry/client/ClientProxy.java b/src/main/java/electroblob/wizardry/client/ClientProxy.java index 7b4f2e6e..b81987be 100644 --- a/src/main/java/electroblob/wizardry/client/ClientProxy.java +++ b/src/main/java/electroblob/wizardry/client/ClientProxy.java @@ -79,6 +79,7 @@ import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.client.registry.RenderingRegistry; import org.lwjgl.input.Keyboard; +import javax.annotation.Nullable; import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.List; @@ -208,7 +209,7 @@ public class ClientProxy extends CommonProxy { // =============================================================================================================== @Override - public boolean shouldDisplayDiscovered(Spell spell, ItemStack stack){ + public boolean shouldDisplayDiscovered(Spell spell, @Nullable ItemStack stack){ EntityPlayerSP player = Minecraft.getMinecraft().player; diff --git a/src/main/java/electroblob/wizardry/inventory/ContainerArcaneWorkbench.java b/src/main/java/electroblob/wizardry/inventory/ContainerArcaneWorkbench.java index 43c4a0de..a3dc3704 100644 --- a/src/main/java/electroblob/wizardry/inventory/ContainerArcaneWorkbench.java +++ b/src/main/java/electroblob/wizardry/inventory/ContainerArcaneWorkbench.java @@ -288,7 +288,6 @@ public class ContainerArcaneWorkbench extends Container { * or null if no slots are appropriate. Note that this does mean the stack will fit, only that it is valid * for all of the slots in the given range, and will fit if there is space for it. * @param stack The stack to find a slot for - * @param excludeBookshelves Whether to exclude the bookshelf slots (useful when transferring from them) * @return A 2-element int array of the minimum and maximum slot IDs respectively */ @Nullable diff --git a/src/main/java/electroblob/wizardry/spell/Spell.java b/src/main/java/electroblob/wizardry/spell/Spell.java index e817980f..8db0c753 100644 --- a/src/main/java/electroblob/wizardry/spell/Spell.java +++ b/src/main/java/electroblob/wizardry/spell/Spell.java @@ -118,9 +118,15 @@ public abstract class Spell extends IForgeRegistryEntry.Impl implements C public static final String SPLASH_EFFECT_STRENGTH = "splash_effect_strength"; // TODO: Translations for these? - public static final String TIER_MATCH_PREFIX = "tier="; - public static final String ELEMENT_MATCH_PREFIX = "element="; - public static final String TYPE_MATCH_PREFIX = "type="; + public static final String TIER_MATCH_PREFIX = "tier"; + public static final String ELEMENT_MATCH_PREFIX = "element"; + public static final String TYPE_MATCH_PREFIX = "type"; + public static final String DISCOVERED_MATCH_PREFIX = "discovered"; + public static final String MODID_MATCH_PREFIX = "modid"; + + public static final String MATCH_CONDITION_SEPARATOR = ";"; + public static final String MATCH_KEY_VALUE_SEPARATOR = "="; + public static final String MATCH_VALUE_SEPARATOR = ","; /** Forge registry-based replacement for the internal spells list. */ public static IForgeRegistry registry; @@ -682,26 +688,68 @@ public abstract class Spell extends IForgeRegistryEntry.Impl implements C /** * Returns whether this spell matches the given string. Client-side only! A spell matches a particular string - * if any of the following conditions are true:

+ * if any of the following conditions are true: + *

* - The spell's localised name contains the given string
* - The string starts with "tier:", and the localised name of the spell's tier contains the given string
* - The string starts with "element:", and the localised name of the spell's element contains the given string
- * - The string starts with "type:", and the localised name of the spell's type contains the given string

+ * - The string starts with "type:", and the localised name of the spell's type contains the given string + *

* Matches are not case-sensitive. * @param text The string to tested * @return True if this spell matches the given string, false otherwise. */ public boolean matches(@Nonnull String text){ - if(text.startsWith(TIER_MATCH_PREFIX)){ - return getTier().getDisplayName().toLowerCase(Locale.ROOT).contains(text.substring(TIER_MATCH_PREFIX.length())); - }else if(text.startsWith(ELEMENT_MATCH_PREFIX)){ - return getElement().getDisplayName().toLowerCase(Locale.ROOT).contains(text.substring(ELEMENT_MATCH_PREFIX.length())); - }else if(text.startsWith(TYPE_MATCH_PREFIX)){ - return getType().getDisplayName().toLowerCase(Locale.ROOT).contains(text.substring(TYPE_MATCH_PREFIX.length())); - }else{ - return getDisplayName().toLowerCase(Locale.ROOT).contains(text); + if(text.isEmpty()) return true; + + boolean discovered = Wizardry.proxy.shouldDisplayDiscovered(this, null); + + String[] conditions = text.split(MATCH_CONDITION_SEPARATOR); + + for(String condition : conditions){ + + String[] args = condition.split(MATCH_KEY_VALUE_SEPARATOR, 2); + + // Invalid condition, treat the whole lot as a spell name instead + if(args.length < 2) return discovered && getDisplayName().toLowerCase(Locale.ROOT).contains(text); + + String key = args[0]; + String[] values = args[1].split(MATCH_VALUE_SEPARATOR); + + String target; + + switch(key){ + case TIER_MATCH_PREFIX: + // Tier IS known for undiscovered spells so we can match it + target = getTier().getDisplayName().toLowerCase(Locale.ROOT); + break; + case ELEMENT_MATCH_PREFIX: + if(!discovered) return false; // Element is unknown so doesn't match + target = getElement().getDisplayName().toLowerCase(Locale.ROOT); + break; + case TYPE_MATCH_PREFIX: + if(!discovered) return false; // Type is unknown so doesn't match + target = getType().getDisplayName().toLowerCase(Locale.ROOT); + break; + case MODID_MATCH_PREFIX: + if(!discovered) return false; // Mod ID is unknown so doesn't match + target = getRegistryName().getNamespace().toLowerCase(Locale.ROOT); + break; + case DISCOVERED_MATCH_PREFIX: + target = Boolean.toString(discovered); + break; + default: + // Invalid condition, treat the whole lot as a spell name instead + return discovered && getDisplayName().toLowerCase(Locale.ROOT).contains(text); + } + + if(Arrays.stream(values).noneMatch(target::contains)) return false; // Didn't match + } + + return true; // Matched all the conditions, yay! + } // ============================================ Sound methods ==============================================