From aa73eb6c298b17e26609f55f47e975f73756536b Mon Sep 17 00:00:00 2001 From: Lizbeth Rika Date: Fri, 17 Apr 2015 19:45:08 +0100 Subject: [PATCH] Added more wildcards to the corporea system. --- .../botania/api/corporea/CorporeaHelper.java | 24 +++++++++++++------ .../resources/assets/botania/lang/en_US.lang | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/vazkii/botania/api/corporea/CorporeaHelper.java b/src/main/java/vazkii/botania/api/corporea/CorporeaHelper.java index ae869b2a0..82823e492 100644 --- a/src/main/java/vazkii/botania/api/corporea/CorporeaHelper.java +++ b/src/main/java/vazkii/botania/api/corporea/CorporeaHelper.java @@ -29,6 +29,10 @@ public final class CorporeaHelper { private static final List empty = Collections.unmodifiableList(new ArrayList()); private static final WeakHashMap, List> cachedNetworks = new WeakHashMap(); + private static final String[] WILDCARD_STRINGS = new String[] { + "...", "~", "+", "?" + }; + /** * How many items were matched in the last request. If java had "out" params like C# this wouldn't be needed :V */ @@ -248,14 +252,20 @@ public final class CorporeaHelper { return false; boolean contains = false; - if(s.endsWith("...")) { - contains = true; - s = s.substring(0, s.length() - 3); - } - if(s.startsWith("...")) { - contains = true; - s = s.substring(3); + for(String wc : WILDCARD_STRINGS) { + if(s.endsWith(wc)) { + contains = true; + s = s.substring(0, s.length() - wc.length()); + } + else if(s.startsWith(wc)) { + contains = true; + s = s.substring(wc.length()); + } + + if(contains) + break; } + String name = stack.getDisplayName().toLowerCase().trim(); return equalOrContain(name, s, contains) || equalOrContain(name + "s", s, contains) || equalOrContain(name + "es", s, contains) || name.endsWith("y") && equalOrContain(name.substring(0, name.length() - 1) + "ies", s, contains); diff --git a/src/main/resources/assets/botania/lang/en_US.lang b/src/main/resources/assets/botania/lang/en_US.lang index 82d2a3d46..49d20f5d1 100644 --- a/src/main/resources/assets/botania/lang/en_US.lang +++ b/src/main/resources/assets/botania/lang/en_US.lang @@ -2294,7 +2294,7 @@ botania.page.corporea8=And &1Master Corporea Sparks&0 botania.entry.corporeaIndex=Corporea Index botania.page.corporeaIndex0=The biggest ability of a &4Corporea Network&0 is the ability to vocally request items from it by name. The &1Corporea Index&0 is an ender-crystal like block that can interface with a given &4Corporea Network&0 by having a &1Corporea Spark&0 placed on top of it.
While in the world, approaching it will cause it to activate and show the radius in which it will stay activated. botania.page.corporeaIndex1=While activated, the index will intercept any &4Chat Messages&0 sent by nearby players, taking them in as &4requests&0 and preventing them to be broadcasted to chat. From this, it'll request, from the network, items whose name matches the request. For example, writing "iron ingot" will have the index look through the network for a single &1Iron Ingot&0 and transport it towards itself, materializing it in the world. -botania.page.corporeaIndex2=Writing "iron..." will have it search for any items whose name contains "iron", such as &1Iron Ingot&0, &1Iron Pickaxe&0, and so on. Writing "this" will search for items whose name equals the name of the item in the player's hand.
Requests can be more complex than just a single item. For example "10 apples" will request, as described, 10 &1Apples&0. +botania.page.corporeaIndex2=Requests can be more complex than just a single item. For example "10 apples" will request, as described, 10 &1Apples&0. Writing "this" will search for items whose name equals the name of the item in the player's hand. Prepending or appending to a query "...", "~", "+" or "?" will turn it into a "contains" rather than "equals" query. So writing "iron..." will find all items that have "iron" in their name, for example. botania.page.corporeaIndex3=The plural form of an item's name may only be used case it's a regular noun when it comes to the plural (suffixed by "-s", "-es" or "-ies"), the singular version works just as well for requests of multiple items, such as "10 apple".
"10 of this" requests 10 items whose name equals the item in the player's hand, as expected. botania.page.corporeaIndex4=Examples of complex requests include "10 apples", "a stack of apples", "2 stacks of apples", "2 stacks and 20 apples", "half a stack of apples", "a dozen apples", and so on.
The index will also recognise more or less verbose forms of request, so "2x stacks and 20x of apples" is equal to "2 stack 2 apple" or "2 stacks + 2 apples". botania.page.corporeaIndex5=Requesting with "all" or "every" will deliver every single item in the network that matches the criteria, so "all apples" will deliver all the apples in the network.
On the other side, requesting "count", "show", "display" or "tell" won't request any, but will tell the requester how many exist in the network.