Move wand and armour map retrieval methods to WizardryItems, encapsulating the underlying maps
This commit is contained in:
@@ -188,8 +188,8 @@ public final class WizardryItems {
|
||||
|
||||
public static final Item identification_scroll = new ItemIdentificationScroll();
|
||||
|
||||
public static final Map<Pair<Tier, Element>, Item> WAND_MAP = new HashMap<>();
|
||||
public static final Map<Pair<EntityEquipmentSlot, Element>, Item> ARMOUR_MAP = new HashMap<>();
|
||||
private static final Map<Pair<Tier, Element>, Item> WAND_MAP = new HashMap<>();
|
||||
private static final Map<Pair<EntityEquipmentSlot, Element>, Item> ARMOUR_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
|
||||
@@ -260,6 +260,46 @@ public final class WizardryItems {
|
||||
ARMOUR_MAP.put(ImmutablePair.of(EntityEquipmentSlot.FEET, Element.HEALING), wizard_boots_healing);
|
||||
}
|
||||
|
||||
// TODO: These methods need a rethink. What are we trying to achieve with them? Should each use case look in the
|
||||
// same pool of items? For example, might we (or someone else) want to have a wand which can generate in chests, but
|
||||
// is not used by wizards?
|
||||
|
||||
// I reckon this should be strictly for cases where we only ever want the standard wand set, i.e. wizards' gear,
|
||||
// etc.
|
||||
|
||||
/**
|
||||
* Helper method to return the appropriate wand based on tier and element. As of Wizardry 2.1, this uses the
|
||||
* immutable map stored in {@link WizardryItems#WAND_MAP}. Currently used for upgrading wands, for chest generation
|
||||
* and to iterate through wands for charging recipes.
|
||||
*
|
||||
* @param tier The tier of the wand required.
|
||||
* @param element The element of the wand required. Null will be converted to {@link Element#MAGIC}.
|
||||
* @return The wand item which corresponds to the given element and slot, or null if no such item exists.
|
||||
* @throws NullPointerException if the given tier is null.
|
||||
*/
|
||||
public static Item getWand(Tier tier, Element element){
|
||||
if(tier == null) throw new NullPointerException("The given tier cannot be null.");
|
||||
if(element == null) element = Element.MAGIC;
|
||||
return WAND_MAP.get(ImmutablePair.of(tier, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to return the appropriate armour item based on element and slot. As of Wizardry 2.1, this uses the
|
||||
* immutable map stored in {@link WizardryItems#ARMOUR_MAP}. Currently used to iterate through armour for
|
||||
* registering charging recipes and for chest generation.
|
||||
*
|
||||
* @param element The EnumElement of the armour required. Null will be converted to {@link Element#MAGIC}.
|
||||
* @param slot EntityEquipmentSlot of the armour piece required
|
||||
* @return The armour item which corresponds to the given element and slot, or null if no such item exists.
|
||||
* @throws IllegalArgumentException if the given slot is not an armour slot.
|
||||
*/
|
||||
public static Item getArmour(Element element, EntityEquipmentSlot slot){
|
||||
if(slot == null || slot.getSlotType() != Type.ARMOR)
|
||||
throw new IllegalArgumentException("Must be a valid armour slot");
|
||||
if(element == null) element = Element.MAGIC;
|
||||
return ARMOUR_MAP.get(ImmutablePair.of(slot, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets both the registry and unlocalised names of the given item, then registers it with the given registry. Use
|
||||
* this instead of {@link Item#setRegistryName(String)} and {@link Item#setUnlocalizedName(String)} during
|
||||
|
||||
@@ -1056,43 +1056,4 @@ public final class WizardryUtilities {
|
||||
return spells.get(random.nextInt(spells.size())).id();
|
||||
}
|
||||
|
||||
// TODO: These methods need a rethink. What are we trying to achieve with them? Should each use case look in the
|
||||
// same pool of items? For example, might we (or someone else) want to have a wand which can generate in chests, but
|
||||
// is not used by wizards?
|
||||
|
||||
// I reckon this should be strictly for cases where we only ever want the standard wand set, i.e. wizards' gear,
|
||||
// etc.
|
||||
|
||||
/**
|
||||
* Helper method to return the appropriate armour item based on element and slot. As of Wizardry 2.1, this uses the
|
||||
* immutable map stored in {@link WizardryItems#ARMOUR_MAP}. Currently used to iterate through armour for
|
||||
* registering charging recipes and for chest generation.
|
||||
*
|
||||
* @param element The EnumElement of the armour required. Null will be converted to {@link Element#MAGIC}.
|
||||
* @param slot EntityEquipmentSlot of the armour piece required
|
||||
* @return The armour item which corresponds to the given element and slot, or null if no such item exists.
|
||||
* @throws IllegalArgumentException if the given slot is not an armour slot.
|
||||
*/
|
||||
public static Item getArmour(Element element, EntityEquipmentSlot slot){
|
||||
if(slot == null || slot.getSlotType() != Type.ARMOR)
|
||||
throw new IllegalArgumentException("Must be a valid armour slot");
|
||||
if(element == null) element = Element.MAGIC;
|
||||
return WizardryItems.ARMOUR_MAP.get(ImmutablePair.of(slot, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to return the appropriate wand based on tier and element.As of Wizardry 2.1, this uses the
|
||||
* immutable map stored in {@link WizardryItems#WAND_MAP}. Currently used in the packet handler for upgrading wands,
|
||||
* for chest generation and to iterate through wands for charging recipes.
|
||||
*
|
||||
* @param tier The tier of the wand required.
|
||||
* @param element The element of the wand required. Null will be converted to {@link Element#MAGIC}.
|
||||
* @return The wand item which corresponds to the given element and slot, or null if no such item exists.
|
||||
* @throws NullPointerException if the given tier is null.
|
||||
*/
|
||||
public static Item getWand(Tier tier, Element element){
|
||||
if(tier == null) throw new NullPointerException("The given tier cannot be null.");
|
||||
if(element == null) element = Element.MAGIC;
|
||||
return WizardryItems.WAND_MAP.get(ImmutablePair.of(tier, element));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user