Reworked Module property calculator

This commit is contained in:
MachineMuse 2013-01-09 17:09:31 -07:00
parent 786080d18b
commit 88e19fd427
20 changed files with 285 additions and 380 deletions

View file

@ -7,7 +7,7 @@ import net.machinemuse.general.MuseStringUtils;
import net.machinemuse.general.geometry.Colour;
import net.machinemuse.general.geometry.MuseRenderer;
import net.machinemuse.general.geometry.Point2D;
import net.machinemuse.powersuits.powermodule.GenericModule;
import net.machinemuse.powersuits.powermodule.PowerModule;
/**
* Extends the Clickable class to make a clickable Augmentation; note that this
@ -16,12 +16,12 @@ import net.machinemuse.powersuits.powermodule.GenericModule;
* @author MachineMuse
*/
public class ClickableModule extends Clickable {
private GenericModule module;
private PowerModule module;
/**
* @param vaug
*/
public ClickableModule(GenericModule module, Point2D position) {
public ClickableModule(PowerModule module, Point2D position) {
super(position);
this.setModule(module);
}
@ -54,11 +54,11 @@ public class ClickableModule extends Clickable {
return hitx && hity;
}
public GenericModule getModule() {
public PowerModule getModule() {
return module;
}
public ClickableModule setModule(GenericModule module) {
public ClickableModule setModule(PowerModule module) {
this.module = module;
return this;
}

View file

@ -12,7 +12,7 @@ import net.machinemuse.powersuits.item.ItemUtils;
import net.machinemuse.powersuits.network.MusePacket;
import net.machinemuse.powersuits.network.MusePacketInstallModuleRequest;
import net.machinemuse.powersuits.network.MusePacketSalvageModuleRequest;
import net.machinemuse.powersuits.powermodule.GenericModule;
import net.machinemuse.powersuits.powermodule.PowerModule;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.network.Player;
@ -66,7 +66,7 @@ public class InstallSalvageFrame extends ScrollableFrame {
private void drawItems() {
ItemStack stack = targetItem.getSelectedItem().getItem();
GenericModule module = targetModule.getSelectedModule().getModule();
PowerModule module = targetModule.getSelectedModule().getModule();
List<ItemStack> itemsToDraw = targetModule.getSelectedModule()
.getModule().getInstallCost();
double yoffset;
@ -88,7 +88,7 @@ public class InstallSalvageFrame extends ScrollableFrame {
private void drawButtons() {
ItemStack stack = targetItem.getSelectedItem().getItem();
GenericModule module = targetModule.getSelectedModule().getModule();
PowerModule module = targetModule.getSelectedModule().getModule();
if (!ItemUtils.itemHasModule(stack, module.getName())) {
installButton.setEnabled(ItemUtils.hasInInventory(
@ -104,7 +104,7 @@ public class InstallSalvageFrame extends ScrollableFrame {
ClickableModule selModule = targetModule.getSelectedModule();
if (selItem != null && selModule != null) {
ItemStack stack = selItem.getItem();
GenericModule module = selModule.getModule();
PowerModule module = selModule.getModule();
if (!ItemUtils.itemHasModule(stack, module.getName())) {
if (installButton.hitBox(x, y)) {
@ -119,7 +119,7 @@ public class InstallSalvageFrame extends ScrollableFrame {
}
private void doSalvage() {
GenericModule module = targetModule.getSelectedModule().getModule();
PowerModule module = targetModule.getSelectedModule().getModule();
MusePacket newpacket = new MusePacketSalvageModuleRequest(
(Player) player,
targetItem.getSelectedItem().inventorySlot,
@ -133,7 +133,7 @@ public class InstallSalvageFrame extends ScrollableFrame {
*/
private void doInstall() {
ItemStack stack = targetItem.getSelectedItem().getItem();
GenericModule module = targetModule.getSelectedModule().getModule();
PowerModule module = targetModule.getSelectedModule().getModule();
if (ItemUtils.hasInInventory(module.getInstallCost(), player.inventory)) {
// Doing it client-side first in case of lag
ItemUtils.deleteFromInventory(module.getInstallCost(),

View file

@ -8,7 +8,7 @@ import net.machinemuse.general.geometry.Point2D;
import net.machinemuse.general.gui.clickable.ClickableItem;
import net.machinemuse.general.gui.clickable.ClickableModule;
import net.machinemuse.powersuits.item.ItemUtils;
import net.machinemuse.powersuits.powermodule.GenericModule;
import net.machinemuse.powersuits.powermodule.PowerModule;
public class ModuleSelectionFrame extends ScrollableFrame {
protected ItemSelectionFrame target;
@ -79,7 +79,7 @@ public class ModuleSelectionFrame extends ScrollableFrame {
moduleButtons = new ArrayList();
categories = new HashMap();
List<GenericModule> workingModules = ItemUtils
List<PowerModule> workingModules = ItemUtils
.getValidModulesForItem(null,
clickie.getItem());
if (workingModules.size() > 0) {
@ -88,7 +88,7 @@ public class ModuleSelectionFrame extends ScrollableFrame {
new Point2D(centerx, topleft.y()),
new Point2D(centerx, bottomright.y()));
Iterator<Point2D> pointiter = points.iterator();
for (GenericModule module : workingModules) {
for (PowerModule module : workingModules) {
ModuleSelectionSubFrame frame = getOrCreateCategory(module
.getCategory());
moduleButtons.add(frame.addModule(module));

View file

@ -6,7 +6,7 @@ import java.util.List;
import net.machinemuse.general.geometry.MuseRenderer;
import net.machinemuse.general.geometry.Point2D;
import net.machinemuse.general.gui.clickable.ClickableModule;
import net.machinemuse.powersuits.powermodule.GenericModule;
import net.machinemuse.powersuits.powermodule.PowerModule;
public class ModuleSelectionSubFrame {
protected List<ClickableModule> moduleButtons;
@ -29,7 +29,7 @@ public class ModuleSelectionSubFrame {
}
}
public ClickableModule addModule(GenericModule module) {
public ClickableModule addModule(PowerModule module) {
double x = topleft.x() + 8 + 16 * moduleButtons.size();
double y = topleft.y() + 16;
ClickableModule clickie = new ClickableModule(module, new Point2D(x, y));

View file

@ -2,6 +2,7 @@ package net.machinemuse.general.gui.frame;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -16,8 +17,9 @@ import net.machinemuse.general.gui.clickable.ClickableSlider;
import net.machinemuse.powersuits.item.ItemUtils;
import net.machinemuse.powersuits.network.MusePacket;
import net.machinemuse.powersuits.network.MusePacketTweakRequest;
import net.machinemuse.powersuits.powermodule.GenericModule;
import net.machinemuse.powersuits.powermodule.IModuleProperty;
import net.machinemuse.powersuits.powermodule.PowerModule;
import net.machinemuse.powersuits.powermodule.property.IPropertyModifier;
import net.machinemuse.powersuits.powermodule.property.PropertyModifierLinearAdditive;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -46,12 +48,13 @@ public class ModuleTweakFrame extends ScrollableFrame {
this.player = player;
}
@Override public void update(double mousex, double mousey) {
@Override
public void update(double mousex, double mousey) {
mousex /= SCALERATIO;
mousey /= SCALERATIO;
if (itemTarget.getSelectedItem() != null && moduleTarget.getSelectedModule() != null) {
ItemStack stack = itemTarget.getSelectedItem().getItem();
GenericModule module = moduleTarget.getSelectedModule().getModule();
PowerModule module = moduleTarget.getSelectedModule().getModule();
if (ItemUtils.itemHasModule(itemTarget.getSelectedItem().getItem(), moduleTarget.getSelectedModule().getModule().getName())) {
loadTweaks(stack, module);
} else {
@ -68,7 +71,8 @@ public class ModuleTweakFrame extends ScrollableFrame {
}
@Override public void draw() {
@Override
public void draw() {
if (sliders != null) {
MuseRenderer.drawFrameRect(topleft.times(SCALERATIO), bottomright.times(SCALERATIO), borderColour, insideColour, 0, 2);
MuseRenderer.drawCenteredString("Tinker", (topleft.x() + bottomright.x()) / 4, topleft.y() / 2 + 2);
@ -88,23 +92,26 @@ public class ModuleTweakFrame extends ScrollableFrame {
}
}
private void loadTweaks(ItemStack stack, GenericModule module) {
private void loadTweaks(ItemStack stack, PowerModule module) {
NBTTagCompound itemTag = ItemUtils.getMuseItemTag(stack);
NBTTagCompound moduleTag = itemTag.getCompoundTag(module.getName());
propertyStrings = new HashMap();
Set<String> tweaks = new HashSet<String>();
Set<IModuleProperty> propertyCalcs = module.getPropertyComputers();
for (IModuleProperty property : propertyCalcs) {
Map<String, List<IPropertyModifier>> propertyModifiers = module.getPropertyModifiers();
for (Map.Entry<String, List<IPropertyModifier>> property : propertyModifiers.entrySet()) {
double currValue = 0;
if (propertyStrings.containsKey(property.getName())) {
currValue = propertyStrings.get(property.getName());
for (IPropertyModifier modifier : property.getValue()) {
currValue = modifier.applyModifier(moduleTag, currValue);
if (modifier instanceof PropertyModifierLinearAdditive) {
tweaks.add(((PropertyModifierLinearAdditive) modifier).getTradeoffName());
}
}
currValue += property.computeProperty(moduleTag);
propertyStrings.put(property.getName(), currValue);
propertyStrings.put(property.getKey(), currValue);
}
Set<String> tweaks = module.getTweaks();
sliders = new LinkedList();
int y = 0;
for (String tweak : tweaks) {
@ -117,7 +124,8 @@ public class ModuleTweakFrame extends ScrollableFrame {
}
}
@Override public void onMouseDown(double x, double y, int button) {
@Override
public void onMouseDown(double x, double y, int button) {
x /= SCALERATIO;
y /= SCALERATIO;
if (button == 0) {
@ -131,10 +139,11 @@ public class ModuleTweakFrame extends ScrollableFrame {
}
}
@Override public void onMouseUp(double x, double y, int button) {
@Override
public void onMouseUp(double x, double y, int button) {
if (selectedSlider != null && itemTarget.getSelectedItem() != null && moduleTarget.getSelectedModule() != null) {
ClickableItem item = itemTarget.getSelectedItem();
GenericModule module = moduleTarget.getSelectedModule().getModule();
PowerModule module = moduleTarget.getSelectedModule().getModule();
MusePacket tweakRequest = new MusePacketTweakRequest((Player) player, item.inventorySlot, module.getName(), selectedSlider.getName(),
selectedSlider.getValue());
player.sendQueue.addToSendQueue(tweakRequest.getPacket250());

View file

@ -2,7 +2,7 @@ package net.machinemuse.powersuits.common;
import net.machinemuse.general.gui.MuseIcon;
import net.machinemuse.powersuits.item.ModularCommon;
import net.machinemuse.powersuits.powermodule.GenericModule;
import net.machinemuse.powersuits.powermodule.PowerModule;
import net.machinemuse.powersuits.powermodule.ModuleManager;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
@ -127,45 +127,39 @@ public class Config extends Configuration {
boolean[] FEETONLY = { false, false, false, true, false };
boolean[] TOOLONLY = { false, false, false, false, true };
boolean[] ALLITEMS = { true, true, true, true, true };
GenericModule module;
PowerModule module;
module = new GenericModule(ModularCommon.MODULE_IRON_PLATING, ARMORONLY, MuseIcon.ORB_1_GREEN, ModularCommon.CATEGORY_ARMOR)
module = new PowerModule(ModularCommon.MODULE_IRON_PLATING, ARMORONLY, MuseIcon.ORB_1_GREEN, ModularCommon.CATEGORY_ARMOR)
.setDescription("Iron plating is heavy but protective.")
.addInstallCost(new ItemStack(Item.ingotIron, 5));
ModuleManager.addSimpleTradeoff(
module, "Plating Thickness",
ModularCommon.ARMOR_VALUE_PHYSICAL, "", 0, 5,
ModularCommon.WEIGHT, "g", 0, 10000);
.addInstallCost(new ItemStack(Item.ingotIron, 5))
.addTradeoffProperty(ModularCommon.ARMOR_VALUE_PHYSICAL, 5, "Plating Thickness")
.addTradeoffProperty(ModularCommon.WEIGHT, 10000, "Plating Thickness");
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_DIAMOND_PLATING, ARMORONLY, MuseIcon.ORB_1_BLUE, ModularCommon.CATEGORY_ARMOR)
module = new PowerModule(ModularCommon.MODULE_DIAMOND_PLATING, ARMORONLY, MuseIcon.ORB_1_BLUE, ModularCommon.CATEGORY_ARMOR)
.setDescription("Diamonds are lighter, harder, and more protective than Iron but much harder to find.")
.addInstallCost(new ItemStack(Item.diamond, 5));
ModuleManager.addSimpleTradeoff(
module, "Plating Thickness",
ModularCommon.ARMOR_VALUE_PHYSICAL, "", 0, 6,
ModularCommon.WEIGHT, "g", 0, 6000);
.addInstallCost(new ItemStack(Item.diamond, 5))
.addTradeoffProperty(ModularCommon.ARMOR_VALUE_PHYSICAL, 6, "Plating Thickness")
.addTradeoffProperty(ModularCommon.WEIGHT, 6000, "Plating Thickness");
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_ENERGY_SHIELD, ARMORONLY, MuseIcon.ENERGY_SHIELD, ModularCommon.CATEGORY_ARMOR)
module = new PowerModule(ModularCommon.MODULE_ENERGY_SHIELD, ARMORONLY, MuseIcon.ENERGY_SHIELD, ModularCommon.CATEGORY_ARMOR)
.setDescription("Energy shields are much lighter than plating, but consume energy.")
.addInstallCost(new ItemStack(BasicComponents.itemCircuit, 3, 1));
ModuleManager.addSimpleTradeoff(
module, "Field Strength",
ModularCommon.ARMOR_ENERGY_CONSUMPTION, "J", 0, 500,
ModularCommon.ARMOR_VALUE_ENERGY, "", 0, 6);
.addInstallCost(new ItemStack(BasicComponents.itemCircuit, 3, 1))
.addTradeoffProperty(ModularCommon.ARMOR_VALUE_ENERGY, 6, "Field Strength")
.addTradeoffProperty(ModularCommon.ARMOR_ENERGY_CONSUMPTION, 500, "Field Strength");
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_SHOVEL, TOOLONLY, MuseIcon.TOOL_SHOVEL, ModularCommon.CATEGORY_TOOL)
module = new PowerModule(ModularCommon.MODULE_SHOVEL, TOOLONLY, MuseIcon.TOOL_SHOVEL, ModularCommon.CATEGORY_TOOL)
.setDescription("Shovels are good for soft materials like dirt and sand.")
.addInstallCost(new ItemStack(Item.ingotIron, 3));
ModuleManager.addSimpleTradeoff(
module, "Overclock",
ModularCommon.SHOVEL_ENERGY_CONSUMPTION, "J", 10, 990,
ModularCommon.SHOVEL_HARVEST_SPEED, "", 2, 18);
.addInstallCost(new ItemStack(Item.ingotIron, 3))
.addBaseProperty(ModularCommon.SHOVEL_ENERGY_CONSUMPTION, 10)
.addBaseProperty(ModularCommon.SHOVEL_HARVEST_SPEED, 2)
.addTradeoffProperty(ModularCommon.SHOVEL_ENERGY_CONSUMPTION, 990, "Overclock")
.addTradeoffProperty(ModularCommon.SHOVEL_HARVEST_SPEED, 18, "Overclock");
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_AXE, TOOLONLY, MuseIcon.TOOL_AXE, ModularCommon.CATEGORY_TOOL)
module = new PowerModule(ModularCommon.MODULE_AXE, TOOLONLY, MuseIcon.TOOL_AXE, ModularCommon.CATEGORY_TOOL)
.setDescription("Axes are mostly for chopping trees.")
.addInstallCost(new ItemStack(Item.ingotIron, 3));
ModuleManager.addSimpleTradeoff(
@ -174,7 +168,7 @@ public class Config extends Configuration {
ModularCommon.AXE_HARVEST_SPEED, "", 2, 18);
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_PICKAXE, TOOLONLY, MuseIcon.TOOL_PICK, ModularCommon.CATEGORY_TOOL)
module = new PowerModule(ModularCommon.MODULE_PICKAXE, TOOLONLY, MuseIcon.TOOL_PICK, ModularCommon.CATEGORY_TOOL)
.setDescription("Picks are good for harder materials like stone and ore.")
.addInstallCost(new ItemStack(Item.ingotIron, 3));
ModuleManager.addSimpleTradeoff(
@ -183,7 +177,7 @@ public class Config extends Configuration {
ModularCommon.PICKAXE_HARVEST_SPEED, "", 2, 18);
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_BATTERY_BASIC, ALLITEMS, MuseIcon.NEXUS_1_GREEN, ModularCommon.CATEGORY_ENERGY)
module = new PowerModule(ModularCommon.MODULE_BATTERY_BASIC, ALLITEMS, MuseIcon.NEXUS_1_GREEN, ModularCommon.CATEGORY_ENERGY)
.setDescription("Integrate a battery to allow the item to store energy.")
.addInstallCost(new ItemStack(BasicComponents.itemBattery, 1));
ModuleManager.addSimpleTradeoff(
@ -192,17 +186,17 @@ public class Config extends Configuration {
ModularCommon.WEIGHT, "g", 2000, 8000);
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_DIAMOND_PICK_UPGRADE, TOOLONLY, MuseIcon.INDICATOR_1_BLUE, ModularCommon.CATEGORY_TOOL)
module = new PowerModule(ModularCommon.MODULE_DIAMOND_PICK_UPGRADE, TOOLONLY, MuseIcon.INDICATOR_1_BLUE, ModularCommon.CATEGORY_TOOL)
.setDescription("Add diamonds to allow your pickaxe module to mine Obsidian.")
.addInstallCost(new ItemStack(Item.diamond, 3));
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_TRANSPARENT_ARMOR, ARMORONLY, MuseIcon.PLATE_2_GREEN, ModularCommon.CATEGORY_COSMETIC)
module = new PowerModule(ModularCommon.MODULE_TRANSPARENT_ARMOR, ARMORONLY, MuseIcon.PLATE_2_GREEN, ModularCommon.CATEGORY_COSMETIC)
.setDescription("Show some skin.")
.addInstallCost(new ItemStack(Block.glass, 3));
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_SPRINT_ASSIST, LEGSONLY, MuseIcon.SPRINT_ASSIST, ModularCommon.CATEGORY_MOVEMENT)
module = new PowerModule(ModularCommon.MODULE_SPRINT_ASSIST, LEGSONLY, MuseIcon.SPRINT_ASSIST, ModularCommon.CATEGORY_MOVEMENT)
.setDescription("A set of servo motors to help you sprint (double-tap forward) faster.")
.addInstallCost(new ItemStack(BasicComponents.itemMotor, 4));
ModuleManager.addSimpleTradeoff(
@ -215,7 +209,7 @@ public class Config extends Configuration {
ModularCommon.SPRINT_FOOD_COMPENSATION, "x", 0, 1);
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_JUMP_ASSIST, LEGSONLY, MuseIcon.JUMP_ASSIST, ModularCommon.CATEGORY_MOVEMENT)
module = new PowerModule(ModularCommon.MODULE_JUMP_ASSIST, LEGSONLY, MuseIcon.JUMP_ASSIST, ModularCommon.CATEGORY_MOVEMENT)
.setDescription("Another set of servo motors to help you jump higher.")
.addInstallCost(new ItemStack(BasicComponents.itemMotor, 4));
ModuleManager.addSimpleTradeoff(
@ -224,7 +218,7 @@ public class Config extends Configuration {
ModularCommon.JUMP_MULTIPLIER, "x", 1, 2);
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_SHOCK_ABSORBER, FEETONLY, MuseIcon.PLATE_1_RED, ModularCommon.CATEGORY_MOVEMENT)
module = new PowerModule(ModularCommon.MODULE_SHOCK_ABSORBER, FEETONLY, MuseIcon.PLATE_1_RED, ModularCommon.CATEGORY_MOVEMENT)
.setDescription("With some servos, springs, and padding, you should be able to negate a portion of fall damage.")
.addInstallCost(new ItemStack(BasicComponents.itemMotor, 2))
.addInstallCost(new ItemStack(Block.cloth, 2));
@ -234,7 +228,7 @@ public class Config extends Configuration {
ModularCommon.SHOCK_ABSORB_MULTIPLIER, "x", 0, 1);
ModuleManager.addModule(module);
module = new GenericModule(ModularCommon.MODULE_GLIDER, TORSOONLY, MuseIcon.GLIDER, ModularCommon.CATEGORY_MOVEMENT)
module = new PowerModule(ModularCommon.MODULE_GLIDER, TORSOONLY, MuseIcon.GLIDER, ModularCommon.CATEGORY_MOVEMENT)
.setDescription("Tack on some wings so you can slow your fall and maybe fly a bit if you jump from a decent height.")
.addInstallCost(new ItemStack(BasicComponents.itemSteelPlate, 2));
ModuleManager.addModule(module);

View file

@ -7,7 +7,7 @@ import java.util.List;
import java.util.Set;
import net.machinemuse.general.MuseMathUtils;
import net.machinemuse.powersuits.powermodule.GenericModule;
import net.machinemuse.powersuits.powermodule.PowerModule;
import net.machinemuse.powersuits.powermodule.ModuleManager;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayer;
@ -21,10 +21,10 @@ import net.minecraft.nbt.NBTTagCompound;
public class ItemUtils {
public static final String NBTPREFIX = "mmmpsmod";
public static List<GenericModule> getValidModulesForItem(
public static List<PowerModule> getValidModulesForItem(
EntityPlayer player, ItemStack stack) {
List<GenericModule> validModules = new ArrayList();
for (GenericModule module : ModuleManager.getAllModules().values()) {
List<PowerModule> validModules = new ArrayList();
for (PowerModule module : ModuleManager.getAllModules().values()) {
if (module.isValidForSlot(getAsModular(stack.getItem())
.getItemType().ordinal())) {
validModules.add(module);
@ -45,11 +45,11 @@ public class ItemUtils {
return tagHasModule(getMuseItemTag(stack), moduleName);
}
public static void tagAddModule(NBTTagCompound tag, GenericModule module) {
public static void tagAddModule(NBTTagCompound tag, PowerModule module) {
tag.setCompoundTag(module.getName(), module.getNewTag());
}
public static void itemAddModule(ItemStack stack, GenericModule module) {
public static void itemAddModule(ItemStack stack, PowerModule module) {
tagAddModule(getMuseItemTag(stack), module);
}

View file

@ -8,7 +8,7 @@ import java.io.IOException;
import java.util.List;
import net.machinemuse.powersuits.item.ItemUtils;
import net.machinemuse.powersuits.powermodule.GenericModule;
import net.machinemuse.powersuits.powermodule.PowerModule;
import net.machinemuse.powersuits.powermodule.ModuleManager;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayerMP;
@ -72,7 +72,7 @@ public class MusePacketInstallModuleRequest extends MusePacket {
if (moduleName != null) {
InventoryPlayer inventory = playerEntity.inventory;
int entityId = playerEntity.entityId;
GenericModule moduleType = ModuleManager.getModule(moduleName);
PowerModule moduleType = ModuleManager.getModule(moduleName);
List<ItemStack> cost = moduleType.getInstallCost();
if (ItemUtils.hasInInventory(cost, playerEntity.inventory)) {

View file

@ -11,7 +11,7 @@ import java.util.Set;
import net.machinemuse.powersuits.common.Config;
import net.machinemuse.powersuits.item.ItemUtils;
import net.machinemuse.powersuits.powermodule.GenericModule;
import net.machinemuse.powersuits.powermodule.PowerModule;
import net.machinemuse.powersuits.powermodule.ModuleManager;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayerMP;
@ -75,7 +75,7 @@ public class MusePacketSalvageModuleRequest extends MusePacket {
if (moduleName != null) {
InventoryPlayer inventory = playerEntity.inventory;
int entityId = playerEntity.entityId;
GenericModule moduleType = ModuleManager.getModule(moduleName);
PowerModule moduleType = ModuleManager.getModule(moduleName);
List<ItemStack> refund = moduleType.getInstallCost();
if (ItemUtils.itemHasModule(stack, moduleName)) {

View file

@ -1,107 +0,0 @@
package net.machinemuse.powersuits.powermodule;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.machinemuse.general.gui.MuseIcon;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class GenericModule {
protected String name;
protected String description;
protected String category;
protected MuseIcon icon;
protected boolean[] validSlots;
protected Set<String> tweaks;
protected Set<IModuleProperty> propertyComputers;
protected List<ItemStack> installCost;
protected NBTTagCompound defaultTag;
public GenericModule(String name, boolean[] validSlots, MuseIcon icon, String category) {
this.name = name;
this.validSlots = validSlots;
this.icon = icon;
this.category = category;
this.tweaks = new HashSet();
this.propertyComputers = new HashSet();
this.installCost = new ArrayList();
this.defaultTag = new NBTTagCompound();
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getCategory() {
return category;
}
public MuseIcon getIcon() {
return icon;
}
public NBTTagCompound getNewTag() {
return (NBTTagCompound) defaultTag.copy();
}
public boolean isValidForSlot(int i) {
return validSlots[i];
}
public Set<String> getTweaks() {
return tweaks;
}
public List<ItemStack> getInstallCost() {
return installCost;
}
public Set<IModuleProperty> getPropertyComputers() {
return propertyComputers;
}
public GenericModule setDescription(String description) {
this.description = description;
return this;
}
public GenericModule setCategory(String category) {
this.category = category;
return this;
}
public GenericModule setIcon(MuseIcon icon) {
this.icon = icon;
return this;
}
public GenericModule setDefaultString(String key, String value) {
this.defaultTag.setString(key, value);
return this;
}
public GenericModule setDefaultDouble(String key, double value) {
this.defaultTag.setDouble(key, value);
return this;
}
public GenericModule addInstallCost(ItemStack stack) {
this.installCost.add(stack);
return this;
}
public GenericModule addProperty(IModuleProperty prop) {
this.propertyComputers.add(prop);
return this;
}
public GenericModule addTweak(String tweak) {
this.tweaks.add(tweak);
return this;
}
}

View file

@ -1,7 +0,0 @@
package net.machinemuse.powersuits.powermodule;
import net.minecraft.item.ItemStack;
public interface IModularProperty {
public double computeProperty(ItemStack stack);
}

View file

@ -1,11 +0,0 @@
package net.machinemuse.powersuits.powermodule;
import net.minecraft.nbt.NBTTagCompound;
public interface IModuleProperty {
public double computeProperty(NBTTagCompound moduleTag);
public String getName();
public String getUnits();
}

View file

@ -1,57 +0,0 @@
package net.machinemuse.powersuits.powermodule;
import java.util.*;
import java.util.Map.Entry;
import net.machinemuse.powersuits.item.ItemUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class ModularProperty implements IModularProperty {
protected Map<String, List<IModuleProperty>> modulesWithProperty;
protected String name;
protected double baseValue;
public ModularProperty(String name, double baseValue) {
this.name = name;
this.baseValue = baseValue;
this.modulesWithProperty = new HashMap();
}
@Override public double computeProperty(ItemStack stack) {
double value = baseValue;
NBTTagCompound itemTag = ItemUtils.getMuseItemTag(stack);
for (Entry<String, List<IModuleProperty>> entry : modulesWithProperty.entrySet()) {
if (itemTag.hasKey(entry.getKey())) {
for (IModuleProperty property : entry.getValue()) {
NBTTagCompound moduleTag = itemTag.getCompoundTag(entry.getKey());
value += property.computeProperty(moduleTag);
}
}
}
return value;
}
public void addModuleWithProperty(String moduleName, IModuleProperty property) {
if (!modulesWithProperty.containsKey(moduleName)) {
modulesWithProperty.put(moduleName, new LinkedList());
}
List<IModuleProperty> moduleProperties = modulesWithProperty.get(moduleName);
moduleProperties.add(property);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBaseValue() {
return baseValue;
}
public void setBaseValue(double baseValue) {
this.baseValue = baseValue;
}
}

View file

@ -3,63 +3,43 @@ package net.machinemuse.powersuits.powermodule;
import java.util.HashMap;
import java.util.Map;
import net.machinemuse.powersuits.item.ItemUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class ModuleManager {
private static final Map<String, GenericModule> allModules = new HashMap();
private static final Map<String, ModularProperty> allModularProperties = new HashMap();
protected static final Map<String, PowerModule> allModules = new HashMap();
public static Map<String, ModularProperty> getAllModularProperties() {
return allModularProperties;
}
public static IModularProperty getModularProperty(String key) {
return allModularProperties.get(key);
}
public static Map<String, GenericModule> getAllModules() {
public static Map<String, PowerModule> getAllModules() {
return allModules;
}
public static GenericModule getModule(String key) {
public static PowerModule getModule(String key) {
return allModules.get(key);
}
public static void addModule(GenericModule module) {
public static void addModule(PowerModule module) {
allModules.put(module.getName(), module);
}
public static ModularProperty loadModularProperty(String name, double defaultValue) {
if (allModularProperties.containsKey(name)) {
return allModularProperties.get(name);
} else {
ModularProperty newprop = new ModularProperty(name, defaultValue);
allModularProperties.put(name, newprop);
return newprop;
}
}
public static double computeModularProperty(ItemStack stack, String propertyName) {
ModularProperty propertyComputer = loadModularProperty(propertyName, 0);
return propertyComputer.computeProperty(stack);
double propertyValue = 0;
NBTTagCompound itemTag = ItemUtils.getMuseItemTag(stack);
for (PowerModule module : allModules.values()) {
propertyValue = module.applyPropertyModifiers(itemTag, propertyName, propertyValue);
}
return propertyValue;
}
public static void addSimpleTradeoff(
GenericModule module, String tradeoffName,
PowerModule module, String tradeoffName,
String firstPropertyName, String firstUnits, double firstPropertyBase, double firstPropertyMultiplier,
String secondPropertyName, String secondUnits, double secondPropertyBase, double secondPropertyMultiplier) {
IModuleProperty first = new ModulePropertySimple(firstPropertyName, firstUnits, firstPropertyBase, tradeoffName, firstPropertyMultiplier);
ModularProperty firstFull = loadModularProperty(firstPropertyName, 0);
firstFull.addModuleWithProperty(module.getName(), first);
IModuleProperty second = new ModulePropertySimple(secondPropertyName, secondUnits, secondPropertyBase, tradeoffName, secondPropertyMultiplier);
ModularProperty secondFull = loadModularProperty(secondPropertyName, 0);
secondFull.addModuleWithProperty(module.getName(), second);
module.addTweak(tradeoffName);
module.addProperty(first);
module.addProperty(second);
module.addBaseProperty(firstPropertyName, firstPropertyBase);
module.addTradeoffProperty(firstPropertyName, firstPropertyMultiplier, tradeoffName);
module.addBaseProperty(secondPropertyName, secondPropertyBase);
module.addTradeoffProperty(secondPropertyName, secondPropertyMultiplier, tradeoffName);
}
}

View file

@ -1,45 +0,0 @@
package net.machinemuse.powersuits.powermodule;
import java.util.Map;
import net.minecraft.nbt.NBTTagCompound;
public class ModulePropertyComplex implements IModuleProperty {
public String name;
public String units;
public double base;
public Map<String, Double> multipliers;
public ModulePropertyComplex(String name, String units, double base) {
this.name = name;
this.units = units;
this.base = base;
}
public void addTweak(String ratioName, double multiplier) {
multipliers.put(ratioName, multiplier);
}
@Override public double computeProperty(NBTTagCompound moduleTag) {
double property = base;
for (Map.Entry<String, Double> multiplier : multipliers.entrySet()) {
double ratio = 0;
String key = multiplier.getKey();
if (moduleTag.hasKey(key)) {
ratio = moduleTag.getDouble(key);
} else {
moduleTag.setDouble(key, ratio);
}
property += ratio * multiplier.getValue();
}
return property;
}
@Override public String getName() {
return name;
}
@Override public String getUnits() {
return units;
}
}

View file

@ -1,39 +0,0 @@
package net.machinemuse.powersuits.powermodule;
import net.minecraft.nbt.NBTTagCompound;
public class ModulePropertySimple implements IModuleProperty {
public double base;
public String ratioName;
public double multiplier;
public String name;
public String units;
public ModulePropertySimple(String name, String units, double base, String ratioName, double multiplier) {
this.name = name;
this.units = units;
this.base = base;
this.ratioName = ratioName;
this.multiplier = multiplier;
}
@Override public double computeProperty(NBTTagCompound moduleTag) {
double property = base;
double ratio = 0;
if (moduleTag.hasKey(ratioName)) {
ratio = moduleTag.getDouble(ratioName);
} else {
moduleTag.setDouble(ratioName, ratio);
}
property += ratio * multiplier;
return property;
}
@Override public String getName() {
return name;
}
@Override public String getUnits() {
return units;
}
}

View file

@ -0,0 +1,140 @@
package net.machinemuse.powersuits.powermodule;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.machinemuse.general.gui.MuseIcon;
import net.machinemuse.powersuits.powermodule.property.IPropertyModifier;
import net.machinemuse.powersuits.powermodule.property.PropertyModifierFlatAdditive;
import net.machinemuse.powersuits.powermodule.property.PropertyModifierLinearAdditive;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class PowerModule {
protected String name;
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;
public PowerModule(String name, boolean[] validSlots, MuseIcon icon, String category) {
this.name = name;
this.validSlots = validSlots;
this.icon = icon;
this.category = category;
this.tweaks = new HashSet();
this.propertyModifiers = new HashMap();
this.installCost = new ArrayList();
this.defaultTag = new NBTTagCompound();
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getCategory() {
return category;
}
public MuseIcon getIcon() {
return icon;
}
public PowerModule addTradeoffProperty(String propertyName, double multiplier, String tradeoffName) {
return addPropertyModifier(propertyName, new PropertyModifierLinearAdditive(tradeoffName, multiplier));
}
public PowerModule addBaseProperty(String propertyName, double baseVal) {
return addPropertyModifier(propertyName, new PropertyModifierFlatAdditive(baseVal));
}
public PowerModule addPropertyModifier(String propertyName, IPropertyModifier modifier) {
List<IPropertyModifier> modifiers;
if (propertyModifiers.containsKey(propertyName)) {
modifiers = propertyModifiers.get(propertyName);
} else {
modifiers = new LinkedList();
propertyModifiers.put(propertyName, modifiers);
}
modifiers.add(modifier);
return this;
}
public Map<String, List<IPropertyModifier>> getPropertyModifiers() {
return propertyModifiers;
}
public double applyPropertyModifiers(NBTTagCompound itemTag, String propertyName, double propertyValue) {
if (propertyModifiers.containsKey(propertyName) && itemTag.hasKey(this.name)) {
NBTTagCompound moduleTag = itemTag.getCompoundTag(this.name);
for (IPropertyModifier modifier : propertyModifiers.get(propertyName)) {
propertyValue = modifier.applyModifier(moduleTag, propertyValue);
}
}
return propertyValue;
}
public NBTTagCompound getNewTag() {
return (NBTTagCompound) defaultTag.copy();
}
public boolean isValidForSlot(int i) {
return validSlots[i];
}
public Set<String> getTweaks() {
return tweaks;
}
public List<ItemStack> getInstallCost() {
return installCost;
}
public PowerModule setDescription(String description) {
this.description = description;
return this;
}
public PowerModule setCategory(String category) {
this.category = category;
return this;
}
public PowerModule setIcon(MuseIcon icon) {
this.icon = icon;
return this;
}
public PowerModule setDefaultString(String key, String value) {
this.defaultTag.setString(key, value);
return this;
}
public PowerModule setDefaultDouble(String key, double value) {
this.defaultTag.setDouble(key, value);
return this;
}
public PowerModule addInstallCost(ItemStack stack) {
this.installCost.add(stack);
return this;
}
public PowerModule addTweak(String tweak) {
this.tweaks.add(tweak);
return this;
}
}

View file

@ -0,0 +1,7 @@
package net.machinemuse.powersuits.powermodule.property;
import net.minecraft.nbt.NBTTagCompound;
public interface IPropertyModifier {
public double applyModifier(NBTTagCompound moduleTag, double value);
}

View file

@ -0,0 +1,17 @@
package net.machinemuse.powersuits.powermodule.property;
import net.minecraft.nbt.NBTTagCompound;
public class PropertyModifierFlatAdditive implements IPropertyModifier {
protected double valueAdded;
public PropertyModifierFlatAdditive(double valueAdded) {
this.valueAdded = valueAdded;
}
@Override
public double applyModifier(NBTTagCompound moduleTag, double value) {
return value + this.valueAdded;
}
}

View file

@ -0,0 +1,24 @@
package net.machinemuse.powersuits.powermodule.property;
import net.machinemuse.powersuits.item.ItemUtils;
import net.minecraft.nbt.NBTTagCompound;
public class PropertyModifierLinearAdditive implements IPropertyModifier {
protected double multiplier;
protected String tradeoffName;
public PropertyModifierLinearAdditive(String tradeoffName, double multiplier) {
this.multiplier = multiplier;
this.tradeoffName = tradeoffName;
}
@Override
public double applyModifier(NBTTagCompound moduleTag, double value) {
return value + multiplier * ItemUtils.getDoubleOrZero(moduleTag, tradeoffName);
}
public String getTradeoffName() {
return tradeoffName;
}
}