Initial 1.11.2 update

This commit is contained in:
Electroblob
2018-02-07 21:15:50 +00:00
parent 67f6be0671
commit 3df5597dcc
368 changed files with 17234 additions and 15082 deletions
@@ -11,29 +11,32 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/** Much like {@link net.minecraft.enchantment.EnchantmentHelper EnchantmentHelper}, this class has some static methods
/**
* Much like {@link net.minecraft.enchantment.EnchantmentHelper EnchantmentHelper}, this class has some static methods
* which allow cleaner and more concise interaction with the wand NBT data, which is quite a complex structure. Such
* interaction previously resulted in rather verbose and repetitive code which was hard to read and even harder to debug!
* For example, this class allowed {@link electroblob.wizardry.item.ItemWand ItemWand} to be shortened by about 80 lines.
* In addition, by having all the various null checks and array size checks in one place, the chance of accidental errors
* due to forgetting to check these things is greatly reduced.
* interaction previously resulted in rather verbose and repetitive code which was hard to read and even harder to
* debug! For example, this class allowed {@link electroblob.wizardry.item.ItemWand ItemWand} to be shortened by about
* 80 lines. In addition, by having all the various null checks and array size checks in one place, the chance of
* accidental errors due to forgetting to check these things is greatly reduced.
* <p>
* Note that these methods contain no game logic at all; they are purely for interacting with the NBT data. Conversely,
* you should never need to access the wand's NBT data directly when using this class, but the keys are public in the
* unlikely case that this is necessary.
* <p>
* Also note that none of the methods in this class actually check that the given ItemStack contains an ItemWand; you
* can, for example, pass in a stack of snowballs without causing problems, but that is of course pointless! However,
* if you have your own spell casting item (which doesn't extend ItemWand), this setup means you can still use this class
* can, for example, pass in a stack of snowballs without causing problems, but that is of course pointless! However, if
* you have your own spell casting item (which doesn't extend ItemWand), this setup means you can still use this class
* to manage its NBT structure.
* <p>
* All <b>get</b> methods in this class return some kind of default if the passed-in wand stack has no nbt data.
* See individual method descriptions for more details.<br>
* All <b>set</b> methods in this class create a new nbt data for the passed-in wand if it has none, before doing
* All <b>get</b> methods in this class return some kind of default if the passed-in wand stack has no nbt data. See
* individual method descriptions for more details.<br>
* All <b>set</b> methods in this class create a new nbt data for the passed-in wand if it has none, before doing
* whatever else they do.
*
* @see electroblob.wizardry.item.ItemWand ItemWand
* @see electroblob.wizardry.packet.PacketControlInput PacketControlInput
* @since Wizardry 1.1 */
* @since Wizardry 1.1
*/
public final class WandHelper {
// NBT tag keys
@@ -44,7 +47,7 @@ public final class WandHelper {
private static final HashMap<Item, String> upgradeMap = new HashMap<Item, String>();
static {
static{
upgradeMap.put(WizardryItems.condenser_upgrade, "condenser");
upgradeMap.put(WizardryItems.storage_upgrade, "storage");
upgradeMap.put(WizardryItems.siphon_upgrade, "siphon");
@@ -55,9 +58,11 @@ public final class WandHelper {
upgradeMap.put(WizardryItems.attunement_upgrade, "attunement");
}
/** Returns an array containing the spells currently bound to the given wand. As of Wizardry 1.1, this array is not
/**
* Returns an array containing the spells currently bound to the given wand. As of Wizardry 1.1, this array is not
* always the same size; it can be anywhere between 5 and 8 (inclusive) in length. If the wand has no spell data,
* returns an array of length 0. */
* returns an array of length 0.
*/
public static Spell[] getSpells(ItemStack wand){
Spell[] spells = new Spell[0];
@@ -68,7 +73,7 @@ public final class WandHelper {
spells = new Spell[spellIDs.length];
for(int i=0; i<spellIDs.length; i++){
for(int i = 0; i < spellIDs.length; i++){
spells[i] = Spell.get(spellIDs[i]);
}
}
@@ -76,14 +81,17 @@ public final class WandHelper {
return spells;
}
/** Binds the given array of spells to the given wand. The array can be anywhere between 5 and 8 (inclusive) in length. */
/**
* Binds the given array of spells to the given wand. The array can be anywhere between 5 and 8 (inclusive) in
* length.
*/
public static void setSpells(ItemStack wand, Spell[] spells){
if(wand.getTagCompound() == null) wand.setTagCompound((new NBTTagCompound()));
int[] spellIDs = new int[spells.length];
for(int i=0; i<spells.length; i++){
for(int i = 0; i < spells.length; i++){
spellIDs[i] = spells[i] != null ? spells[i].id() : Spells.none.id();
}
@@ -111,12 +119,12 @@ public final class WandHelper {
public static void selectNextSpell(ItemStack wand){
// 5 here because if the spell array doesn't exist, the wand can't possibly have attunement upgrades
if(getSpells(wand).length < 0) setSpells(wand, new Spell[5]);
if(wand.getTagCompound() != null){
int numberOfSpells = getSpells(wand).length;
int selectedSpell = wand.getTagCompound().getInteger(SELECTED_SPELL_KEY);
// Greater than or equal to so that if attunement upgrades are somehow removed by NBT modification it just
// resets.
if(selectedSpell >= numberOfSpells - 1){
@@ -124,36 +132,38 @@ public final class WandHelper {
}else{
selectedSpell++;
}
wand.getTagCompound().setInteger(SELECTED_SPELL_KEY, selectedSpell);
}
}
/** Selects the previous spell in this wand's list of spells. */
public static void selectPreviousSpell(ItemStack wand){
// 5 here because if the spell array doesn't exist, the wand can't possibly have attunement upgrades
if(getSpells(wand).length < 0) setSpells(wand, new Spell[5]);
// This cannot possibly be null here, and yet I am getting an NPE...
if(wand.getTagCompound() != null){
int numberOfSpells = getSpells(wand).length;
int selectedSpell = wand.getTagCompound().getInteger(SELECTED_SPELL_KEY);
if(selectedSpell <= 0){
selectedSpell = numberOfSpells - 1;
}else{
selectedSpell--;
}
wand.getTagCompound().setInteger(SELECTED_SPELL_KEY, selectedSpell);
}
}
/** Returns an array of the cooldowns for each spell bound to the given wand. As of Wizardry 1.1, this array is not
/**
* Returns an array of the cooldowns for each spell bound to the given wand. As of Wizardry 1.1, this array is not
* always the same size; it can be anywhere between 5 and 8 (inclusive) in length. If the wand has no cooldown data,
* returns an array of length 0. */
* returns an array of length 0.
*/
public static int[] getCooldowns(ItemStack wand){
int[] cooldowns = new int[0];
@@ -182,7 +192,7 @@ public final class WandHelper {
// If there are no cooldowns, it is assumed that they are all zero and therefore nothing needs to be done.
if(cooldowns.length == 0) return;
for(int i=0; i<cooldowns.length; i++){
for(int i = 0; i < cooldowns.length; i++){
if(cooldowns[i] > 0) cooldowns[i]--;
}
@@ -215,8 +225,10 @@ public final class WandHelper {
setCooldowns(wand, cooldowns);
}
/** Returns the number of upgrades of the given type that have been applied to the given wand, or 0 if the wand has
* no upgrade data or the given item is not a valid wand upgrade. */
/**
* Returns the number of upgrades of the given type that have been applied to the given wand, or 0 if the wand has
* no upgrade data or the given item is not a valid wand upgrade.
*/
public static int getUpgradeLevel(ItemStack wand, Item upgrade){
String key = upgradeMap.get(upgrade);
@@ -229,8 +241,10 @@ public final class WandHelper {
}
/** Returns the total number of upgrades that have been applied to the given wand, or 0 if the wand has no upgrade
* data. */
/**
* Returns the total number of upgrades that have been applied to the given wand, or 0 if the wand has no upgrade
* data.
*/
public static int getTotalUpgrades(ItemStack wand){
int totalUpgrades = 0;
@@ -242,13 +256,16 @@ public final class WandHelper {
return totalUpgrades;
}
/** Applies the given upgrade to the given wand, or in other words increases the level for that upgrade by 1. This
* does <b>not</b> account for the individual or total upgrade stack limits. */
/**
* Applies the given upgrade to the given wand, or in other words increases the level for that upgrade by 1. This
* does <b>not</b> account for the individual or total upgrade stack limits.
*/
public static void applyUpgrade(ItemStack wand, Item upgrade){
if(wand.getTagCompound() == null) wand.setTagCompound((new NBTTagCompound()));
if(!wand.getTagCompound().hasKey(UPGRADES_KEY)) wand.getTagCompound().setTag(UPGRADES_KEY, new NBTTagCompound());
if(!wand.getTagCompound().hasKey(UPGRADES_KEY))
wand.getTagCompound().setTag(UPGRADES_KEY, new NBTTagCompound());
NBTTagCompound upgrades = wand.getTagCompound().getCompoundTag(UPGRADES_KEY);
@@ -258,35 +275,42 @@ public final class WandHelper {
wand.getTagCompound().setTag(UPGRADES_KEY, upgrades);
}
/** Returns true if the given item is a valid special wand upgrade. */
public static boolean isWandUpgrade(Item upgrade){
return upgradeMap.containsKey(upgrade);
}
/** Returns an unmodifiable set of all the items which are valid special wand upgrades. */
public static Set<Item> getSpecialUpgrades(){
return Collections.unmodifiableSet(WandHelper.upgradeMap.keySet());
}
/** Package-protected getter for the identifier that corresponds to the given item, used only in the
/**
* Package-protected getter for the identifier that corresponds to the given item, used only in the
* {@link SpellModifiers} class. Internal to Wizardry.
* @throws IllegalArgumentException if the given item is not a registered special wand upgrade.*/
*
* @throws IllegalArgumentException if the given item is not a registered special wand upgrade.
*/
static String getIdentifier(Item upgrade){
if(!isWandUpgrade(upgrade)) throw new IllegalArgumentException("Tried to get a wand upgrade key for an item"
+ "that is not a registered special wand upgrade.");
if(!isWandUpgrade(upgrade)) throw new IllegalArgumentException(
"Tried to get a wand upgrade key for an item" + "that is not a registered special wand upgrade.");
return upgradeMap.get(upgrade);
}
/** Registers a special upgrade with wizardry. Not used in the base mod, but I've put it here to make it easy
* for add-ons to add new wand upgrades.
/**
* Registers a special upgrade with wizardry. Not used in the base mod, but I've put it here to make it easy for
* add-ons to add new wand upgrades.
*
* @param upgrade The wand upgrade item
* @param identifier A unique string, used as a key for wand nbt tags
* @throws IllegalArgumentException if the passed in identifier is already used for another wand upgrade */
* @throws IllegalArgumentException if the passed in identifier is already used for another wand upgrade
*/
public static void registerSpecialUpgrade(Item upgrade, String identifier){
// Throwing an exception is the best thing to do here, since if a duplicate was allowed weird things would
// happen later with wand NBT.
if(upgradeMap.containsValue(identifier)) throw new IllegalArgumentException("Duplicate wand upgrade identifier: " + identifier);
if(upgradeMap.containsValue(identifier))
throw new IllegalArgumentException("Duplicate wand upgrade identifier: " + identifier);
upgradeMap.put(upgrade, identifier);
}
}