Changed valid items to use contains() instead of an array of booleans

This commit is contained in:
MachineMuse 2013-02-01 02:38:39 -07:00
parent ba6e5e216f
commit d13c655721
7 changed files with 44 additions and 17 deletions

View file

@ -2,6 +2,12 @@ package net.machinemuse.general.gui;
import net.machinemuse.powersuits.common.Config;
/**
* MuseIcon is just a helper class to make it more convenient to have multiple
* sprite sheets and to keep all the icon indices in one place.
*
* @author MachineMuse
*/
public class MuseIcon {
public static final String SEBK_ICON_PATH = Config.SEBK_ICON_PATH;
public static final String WC_ICON_PATH = Config.WC_ICON_PATH;

View file

@ -1,7 +1,11 @@
package net.machinemuse.powersuits.common;
import java.util.Arrays;
import java.util.List;
import net.machinemuse.general.MuseStringUtils;
import net.machinemuse.general.gui.MuseIcon;
import net.machinemuse.powersuits.item.IModularItem;
import net.machinemuse.powersuits.item.ItemComponent;
import net.machinemuse.powersuits.item.ModularCommon;
import net.machinemuse.powersuits.powermodule.ModuleManager;
@ -154,13 +158,24 @@ public class Config {
*/
public static void loadPowerModules() {
// loadModularProperties();
boolean[] ARMORONLY = { true, true, true, true, false };
boolean[] HEADONLY = { true, false, false, false, false };
boolean[] TORSOONLY = { false, true, false, false, false };
boolean[] LEGSONLY = { false, false, true, false, false };
boolean[] FEETONLY = { false, false, false, true, false };
boolean[] TOOLONLY = { false, false, false, false, true };
boolean[] ALLITEMS = { true, true, true, true, true };
List<IModularItem> ARMORONLY = Arrays.asList((IModularItem)
ModularPowersuits.powerArmorHead, ModularPowersuits.powerArmorTorso,
ModularPowersuits.powerArmorLegs, ModularPowersuits.powerArmorFeet);
List<IModularItem> HEADONLY = Arrays.asList((IModularItem)
ModularPowersuits.powerArmorHead);
List<IModularItem> TORSOONLY = Arrays.asList((IModularItem)
ModularPowersuits.powerArmorTorso);
List<IModularItem> LEGSONLY = Arrays.asList((IModularItem)
ModularPowersuits.powerArmorLegs);
List<IModularItem> FEETONLY = Arrays.asList((IModularItem)
ModularPowersuits.powerArmorFeet);
List<IModularItem> TOOLONLY = Arrays.asList((IModularItem)
ModularPowersuits.powerTool);
List<IModularItem> ALLITEMS = Arrays.asList((IModularItem)
ModularPowersuits.powerArmorHead, ModularPowersuits.powerArmorTorso,
ModularPowersuits.powerArmorLegs, ModularPowersuits.powerArmorFeet,
ModularPowersuits.powerTool);
PowerModule module;
module = new PowerModule(ModularCommon.MODULE_NIGHT_VISION, HEADONLY, MuseIcon.SCANNER, ModularCommon.CATEGORY_VISION)

View file

@ -1,8 +1,10 @@
package net.machinemuse.powersuits.common;
import java.lang.reflect.Field;
import java.util.Arrays;
import net.machinemuse.general.gui.MuseIcon;
import net.machinemuse.powersuits.item.IModularItem;
import net.machinemuse.powersuits.item.ItemComponent;
import net.machinemuse.powersuits.item.ModularCommon;
import net.machinemuse.powersuits.powermodule.ModuleManager;
@ -95,7 +97,7 @@ public class ModCompatability {
Field itemGoggles = tcItems.getField("itemGoggles");
Item goggles = (Item) itemGoggles.get(itemGoggles);
gogglesStack = new ItemStack(goggles);
PowerModule module = new PowerModule("Aurameter", new boolean[] { true, false, false, false, false }, new MuseIcon(
PowerModule module = new PowerModule("Aurameter", Arrays.asList((IModularItem) ModularPowersuits.powerArmorHead), new MuseIcon(
"/thaumcraft/resources/ss_core.png", 144), ModularCommon.CATEGORY_VISION)
.setDescription(
"Connect up some Thaumic goggles to show the nearby aura values. (Does not reveal aura nodes, only shows the HUD)")

View file

@ -25,8 +25,7 @@ public class ItemUtils {
EntityPlayer player, ItemStack stack) {
List<IPowerModule> validModules = new ArrayList();
for (IPowerModule module : ModuleManager.getAllModules()) {
if (module.isValidForSlot(getAsModular(stack.getItem())
.getItemType().ordinal())) {
if (module.isValidForItem(stack)) {
validModules.add(module);
}
}

View file

@ -15,7 +15,7 @@ public interface IPowerModule {
public abstract String getCategory();
public abstract boolean isValidForSlot(int slotnumber);
public abstract boolean isValidForItem(ItemStack stack);
public abstract String getName();

View file

@ -9,6 +9,7 @@ import java.util.Map;
import java.util.Set;
import net.machinemuse.general.gui.MuseIcon;
import net.machinemuse.powersuits.item.IModularItem;
import net.machinemuse.powersuits.item.ItemUtils;
import net.machinemuse.powersuits.powermodule.property.IPropertyModifier;
import net.machinemuse.powersuits.powermodule.property.PropertyModifierFlatAdditive;
@ -21,17 +22,17 @@ public class PowerModule implements IPowerModule {
protected String description;
protected String category;
protected MuseIcon icon;
protected boolean[] validSlots;
protected Set<String> tweaks;
protected List<ItemStack> installCost;
protected NBTTagCompound defaultTag;
protected Map<String, List<IPropertyModifier>> propertyModifiers;
protected static Map<String, String> units = new HashMap();
protected boolean toggleable = false;
protected List<IModularItem> validItems;
public PowerModule(String name, boolean[] validSlots, MuseIcon icon, String category) {
public PowerModule(String name, List<IModularItem> validItems, MuseIcon icon, String category) {
this.name = name;
this.validSlots = validSlots;
this.validItems = validItems;
this.icon = icon;
this.category = category;
this.tweaks = new HashSet();
@ -123,8 +124,12 @@ public class PowerModule implements IPowerModule {
return (NBTTagCompound) defaultTag.copy();
}
public boolean isValidForSlot(int i) {
return validSlots[i];
public boolean isValidForItem(ItemStack stack) {
if (this.validItems.contains(stack.getItem())) {
return true;
} else {
return false;
}
}
public Set<String> getTweaks() {

View file

@ -9,7 +9,7 @@ import cpw.mods.fml.common.TickType;
/**
* World tick handler for the mod. This is where you put code that should be
* executed once every world tick.
* executed once every world tick. ~Not yet used~
*
* @author MachineMuse
*