emptied trash and cleaned up some old code
This commit is contained in:
parent
c003fc132a
commit
251ffa97d7
|
@ -3,15 +3,6 @@
|
|||
*/
|
||||
package net.machinemuse.powersuits.energy;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.machinemuse.powersuits.trash.IPowerModuleEnergyStorage;
|
||||
import net.machinemuse.powersuits.trash.ModuleUtils;
|
||||
import net.machinemuse.powersuits.trash.PowerModule;
|
||||
import net.machinemuse.powersuits.trash.PowerModuleBattery;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Energy Manager will provide a simplified and scalable interface for keeping
|
||||
|
@ -22,42 +13,42 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
*
|
||||
*/
|
||||
public class EnergyManager {
|
||||
public float getPlayerEnergy(EntityPlayer player) {
|
||||
float energy = 0;
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
||||
ItemStack stack = player.inventory.getStackInSlot(i);
|
||||
if (stack != null) {
|
||||
NBTTagCompound tags = ModuleUtils.getItemModules(stack);
|
||||
for (NBTTagCompound moduleTag : (Collection<NBTTagCompound>) tags
|
||||
.getTags()) {
|
||||
PowerModule module = ModuleUtils
|
||||
.getModuleFromNBT(moduleTag);
|
||||
if (module instanceof IPowerModuleEnergyStorage) {
|
||||
IPowerModuleEnergyStorage psmodule = (IPowerModuleEnergyStorage) module;
|
||||
energy += psmodule.getMaxEnergy(player, moduleTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return energy;
|
||||
}
|
||||
|
||||
public float getPlayerMaxEnergy(EntityPlayer player) {
|
||||
float energy = 0;
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
||||
ItemStack stack = player.inventory.getStackInSlot(i);
|
||||
if (stack != null) {
|
||||
NBTTagCompound tags = ModuleUtils.getItemModules(stack);
|
||||
// TODO: Make this scalable
|
||||
if (tags.hasKey("Electric Battery")) {
|
||||
NBTTagCompound batteryTag = tags
|
||||
.getCompoundTag("Electric Battery");
|
||||
PowerModuleBattery bat = (PowerModuleBattery) ModuleUtils
|
||||
.getModuleFromNBT(batteryTag);
|
||||
energy += bat.getMaxEnergy(player, batteryTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
return energy;
|
||||
}
|
||||
// public float getPlayerEnergy(EntityPlayer player) {
|
||||
// float energy = 0;
|
||||
// for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
||||
// ItemStack stack = player.inventory.getStackInSlot(i);
|
||||
// if (stack != null) {
|
||||
// NBTTagCompound tags = ModuleUtils.getItemModules(stack);
|
||||
// for (NBTTagCompound moduleTag : (Collection<NBTTagCompound>) tags
|
||||
// .getTags()) {
|
||||
// PowerModule module = ModuleUtils
|
||||
// .getModuleFromNBT(moduleTag);
|
||||
// if (module instanceof IPowerModuleEnergyStorage) {
|
||||
// IPowerModuleEnergyStorage psmodule = (IPowerModuleEnergyStorage) module;
|
||||
// energy += psmodule.getMaxEnergy(player, moduleTag);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return energy;
|
||||
// }
|
||||
//
|
||||
// public float getPlayerMaxEnergy(EntityPlayer player) {
|
||||
// float energy = 0;
|
||||
// for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
||||
// ItemStack stack = player.inventory.getStackInSlot(i);
|
||||
// if (stack != null) {
|
||||
// NBTTagCompound tags = ModuleUtils.getItemModules(stack);
|
||||
// // TODO: Make this scalable
|
||||
// if (tags.hasKey("Electric Battery")) {
|
||||
// NBTTagCompound batteryTag = tags
|
||||
// .getCompoundTag("Electric Battery");
|
||||
// PowerModuleBattery bat = (PowerModuleBattery) ModuleUtils
|
||||
// .getModuleFromNBT(batteryTag);
|
||||
// energy += bat.getMaxEnergy(player, batteryTag);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return energy;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public abstract class ItemPowerArmor extends ItemArmor
|
|||
// How much of incoming damage is absorbed by this armor piece.
|
||||
// 1.0 = absorbs all damage
|
||||
// 0.5 = 50% damage to item, 50% damage carried over
|
||||
double absorbRatio = 0.2;
|
||||
double absorbRatio = Math.min(0.04 * getArmorDouble(armor), 0.25);
|
||||
|
||||
// Maximum damage absorbed by this piece. Actual damage to this item
|
||||
// will be clamped between (damage * absorbRatio) and (absorbMax). Note
|
||||
|
@ -96,6 +96,9 @@ public abstract class ItemPowerArmor extends ItemArmor
|
|||
totalarmor += elecArmor;
|
||||
}
|
||||
|
||||
// Make it so each armor piece can only contribute 1/4 of the armor
|
||||
// value
|
||||
totalarmor = Math.min(6.25, totalarmor);
|
||||
return totalarmor;
|
||||
}
|
||||
|
||||
|
|
|
@ -199,9 +199,9 @@ public class ItemPowerTool extends ItemTool
|
|||
advancedToolTips);
|
||||
}
|
||||
|
||||
// //////////////////////////////////////////////
|
||||
// --- UNIVERSAL ELECTRICITY COMPATABILITY ---//
|
||||
// //////////////////////////////////////////////
|
||||
// /////////////////////////////////////////// //
|
||||
// --- UNIVERSAL ELECTRICITY COMPATABILITY --- //
|
||||
// /////////////////////////////////////////// //
|
||||
@Override
|
||||
public double onReceive(double amps, double voltage, ItemStack itemStack) {
|
||||
return ModularItemCommon.onReceive(amps, voltage, itemStack);
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
package net.machinemuse.powersuits.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.machinemuse.powersuits.common.Config;
|
||||
import net.machinemuse.powersuits.tinker.TinkerAction;
|
||||
import net.machinemuse.powersuits.trash.IPowerModuleWeight;
|
||||
import net.machinemuse.powersuits.trash.ModuleUtils;
|
||||
import net.machinemuse.powersuits.trash.PowerModule;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
@ -19,6 +15,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ItemUtils {
|
||||
public static final String nbtPrefix = "mmmpsmod";
|
||||
|
||||
public static List<TinkerAction> getValidTinkersForItem(
|
||||
EntityPlayer player, ItemStack stack) {
|
||||
|
@ -38,19 +35,19 @@ public class ItemUtils {
|
|||
NBTTagCompound properties = null;
|
||||
if (stack.hasTagCompound()) {
|
||||
NBTTagCompound stackTag = stack.getTagCompound();
|
||||
if (stackTag.hasKey(PowerModule.Constants.nbtPrefix)) {
|
||||
if (stackTag.hasKey(nbtPrefix)) {
|
||||
properties = stackTag
|
||||
.getCompoundTag(PowerModule.Constants.nbtPrefix);
|
||||
.getCompoundTag(nbtPrefix);
|
||||
} else {
|
||||
properties = new NBTTagCompound();
|
||||
properties.setCompoundTag(PowerModule.Constants.nbtPrefix,
|
||||
properties.setCompoundTag(nbtPrefix,
|
||||
properties);
|
||||
}
|
||||
} else {
|
||||
NBTTagCompound stackTag = new NBTTagCompound();
|
||||
stack.setTagCompound(stackTag);
|
||||
properties = new NBTTagCompound();
|
||||
stackTag.setCompoundTag(PowerModule.Constants.nbtPrefix, properties);
|
||||
stackTag.setCompoundTag(nbtPrefix, properties);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
@ -105,52 +102,6 @@ public class ItemUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public static List<NBTTagCompound> getPlayerAugs(EntityPlayer player) {
|
||||
List<NBTTagCompound> augs = new ArrayList<NBTTagCompound>();
|
||||
List<ItemStack> items = getModularItemsInInventory(player.inventory);
|
||||
Iterator<ItemStack> iter = items.iterator();
|
||||
while (iter.hasNext()) {
|
||||
NBTTagCompound itemAugs = ModuleUtils.getItemModules(iter.next());
|
||||
for (Object ob : itemAugs.getTags()) {
|
||||
if (ob instanceof NBTTagCompound) {
|
||||
augs.add((NBTTagCompound) ob);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return augs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param next
|
||||
* @return
|
||||
*/
|
||||
public static List<NBTTagCompound> getItemModulesWithPadding(ItemStack stack) {
|
||||
List<PowerModule> validModules = ModuleUtils
|
||||
.getValidModulesForItem(stack.getItem());
|
||||
NBTTagCompound itemModule = ModuleUtils.getItemModules(stack);
|
||||
List<NBTTagCompound> modulesList = new ArrayList<NBTTagCompound>();
|
||||
for (PowerModule validModule : validModules) {
|
||||
if (itemModule.hasKey(validModule.getName())) {
|
||||
NBTTagCompound matchedAug = itemModule
|
||||
.getCompoundTag(validModule
|
||||
.getName());
|
||||
modulesList.add(matchedAug);
|
||||
} else {
|
||||
NBTTagCompound newModule = validModule.newModuleTag();
|
||||
modulesList.add(newModule);
|
||||
itemModule.setCompoundTag(validModule.getName(), newModule);
|
||||
}
|
||||
}
|
||||
return modulesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player has a copy of all of the items in
|
||||
* workingUpgradeCost.
|
||||
|
@ -210,24 +161,6 @@ public class ItemUtils {
|
|||
return slots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums the weights of augmentations in the list.
|
||||
*
|
||||
* @param playerModules
|
||||
* @return
|
||||
*/
|
||||
public static float getTotalWeight(EntityPlayer player,
|
||||
List<NBTTagCompound> playerModules) {
|
||||
float weight = 0;
|
||||
for (NBTTagCompound aug : playerModules) {
|
||||
PowerModule module = ModuleUtils.getModuleFromNBT(aug);
|
||||
if (module instanceof IPowerModuleWeight) {
|
||||
weight += ((IPowerModuleWeight) module).getWeight(player, aug);
|
||||
}
|
||||
}
|
||||
return weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the given NBTTag and returns the value if it exists, otherwise 0.
|
||||
*/
|
||||
|
|
|
@ -43,14 +43,6 @@ public abstract class MusePacket {
|
|||
writeInt(id);
|
||||
}
|
||||
|
||||
private String listBytes(byte[] bytes) {
|
||||
String s = "";
|
||||
for (byte b : bytes) {
|
||||
s = s + Byte.toString(b) + " ~ ";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
protected MusePacket(Player player, DataInputStream data) {
|
||||
this.player = player;
|
||||
this.datain = data;
|
||||
|
@ -194,15 +186,8 @@ public abstract class MusePacket {
|
|||
public void writeString(String string)
|
||||
{
|
||||
try {
|
||||
if (string.length() > 32767)
|
||||
{
|
||||
throw new IOException("String too big");
|
||||
}
|
||||
else
|
||||
{
|
||||
dataout.writeShort(string.length());
|
||||
dataout.writeChars(string);
|
||||
}
|
||||
dataout.writeShort(string.length());
|
||||
dataout.writeChars(string);
|
||||
} catch (IOException e) {
|
||||
MuseLogger.logError("String too big D:");
|
||||
e.printStackTrace();
|
||||
|
@ -214,6 +199,7 @@ public abstract class MusePacket {
|
|||
*/
|
||||
public String readString(int maxlength)
|
||||
{
|
||||
String read = null;
|
||||
try {
|
||||
short length = datain.readShort();
|
||||
|
||||
|
@ -237,12 +223,12 @@ public abstract class MusePacket {
|
|||
builder.append(datain.readChar());
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
read = builder.toString();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return read;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package net.machinemuse.powersuits.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
/**
|
||||
* @author Claire
|
||||
*
|
||||
*/
|
||||
public class MusePacketModeChangeRequest extends MusePacket {
|
||||
|
||||
/**
|
||||
* @param player
|
||||
*/
|
||||
public MusePacketModeChangeRequest(Player player) {
|
||||
super(player);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param data
|
||||
*/
|
||||
public MusePacketModeChangeRequest(Player player, DataInputStream data) {
|
||||
super(player, data);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.machinemuse.powersuits.network.MusePacket#handleClient(net.minecraft.client.entity.EntityClientPlayerMP)
|
||||
*/
|
||||
@Override
|
||||
public void handleClient(EntityClientPlayerMP player) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.machinemuse.powersuits.network.MusePacket#handleServer(net.minecraft.entity.player.EntityPlayerMP)
|
||||
*/
|
||||
@Override
|
||||
public void handleServer(EntityPlayerMP player) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -4,14 +4,12 @@
|
|||
package net.machinemuse.powersuits.tick;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.machinemuse.powersuits.common.MuseLogger;
|
||||
import net.machinemuse.powersuits.item.ItemUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
@ -30,12 +28,8 @@ public class PlayerTickHandler implements ITickHandler {
|
|||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData) {
|
||||
EntityPlayer player = toPlayer(tickData[0]);
|
||||
List<NBTTagCompound> playerAugs = ItemUtils
|
||||
.getPlayerAugs(player);
|
||||
float totalEnergy = 0;
|
||||
float totalWeight = 0;
|
||||
Iterator<NBTTagCompound> iter = playerAugs.iterator();
|
||||
|
||||
if (totalWeight > 25) {
|
||||
player.motionX *= 25 / totalWeight;
|
||||
player.motionZ *= 25 / totalWeight;
|
||||
|
|
|
@ -12,7 +12,7 @@ import cpw.mods.fml.common.TickType;
|
|||
|
||||
/**
|
||||
* Called before and after the 3D world is rendered (tickEnd is called BEFORE
|
||||
* the 2D gui is drawn).
|
||||
* the 2D gui is drawn... I think?).
|
||||
*
|
||||
* @param float tickData[0] the amount of time (0.0f-1.0f) since the last tick.
|
||||
*
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package net.machinemuse.powersuits.trash;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface IPowerModuleArmor {
|
||||
/**
|
||||
* Returns the current armor value provided by the module.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract float getArmorValue(
|
||||
EntityPlayer player, NBTTagCompound moduleTag);
|
||||
|
||||
/**
|
||||
* Perform the appropriate calculations for when a player with the module is
|
||||
* dealt damage - either reduce durability, or drain the energy net, or
|
||||
* something else perhaps.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public float damageArmor(EntityPlayer player, NBTTagCompound tag,
|
||||
float damageAmount);
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package net.machinemuse.powersuits.trash;
|
||||
|
||||
public interface IPowerModuleEnergyGenerator {
|
||||
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package net.machinemuse.powersuits.trash;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface IPowerModuleEnergyStorage {
|
||||
public static final String MAXENERGY = "Maximum Energy";
|
||||
public static final String CURRENERGY = "Current Energy";
|
||||
|
||||
public float getStoredEnergy(EntityPlayer player, NBTTagCompound batteryTag);
|
||||
|
||||
public float getMaxEnergy(EntityPlayer player, NBTTagCompound batteryTag);
|
||||
|
||||
public float changeEnergy(EntityPlayer player, NBTTagCompound batteryTag,
|
||||
float amount);
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package net.machinemuse.powersuits.trash;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IPowerModuleTool {
|
||||
public static final String DURABILITY = "Durability";
|
||||
|
||||
public abstract float getStrVsBlock(ItemStack stack, Block block, int meta);
|
||||
|
||||
public abstract boolean onBlockDestroyed(ItemStack stack, World world,
|
||||
int blockID, int x, int y, int z,
|
||||
EntityLiving destroyerEntity);
|
||||
// if (Block.blocksList[blockID]
|
||||
// .getBlockHardness(world, x, y, z) != 0.0D) {
|
||||
// stack.damageItem(1, par7EntityLiving);
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package net.machinemuse.powersuits.trash;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Modules that implement this interface will limit the player by slowing them
|
||||
* down if they have too much total weight.
|
||||
*
|
||||
*/
|
||||
public interface IPowerModuleWeight {
|
||||
/**
|
||||
* Returns the weight of the module in kg. More than 25kg of equipment will
|
||||
* start to slow a player down.
|
||||
*
|
||||
* @return Module's weight in kg
|
||||
*/
|
||||
public abstract float getWeight(
|
||||
EntityPlayer player, NBTTagCompound moduleTag);
|
||||
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
package net.machinemuse.powersuits.trash;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.machinemuse.powersuits.common.MuseLogger;
|
||||
import net.machinemuse.powersuits.item.ItemPowerArmor;
|
||||
import net.machinemuse.powersuits.item.ItemPowerTool;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
public abstract class ModuleUtils {
|
||||
|
||||
protected static boolean initialized = false;
|
||||
static {
|
||||
if (!initialized) {
|
||||
init();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Module List
|
||||
*/
|
||||
public static BiMap<String, PowerModule> allModules;
|
||||
/**
|
||||
* Module validity mappings. Slot 0-3 = armor, 4 = tool
|
||||
*/
|
||||
public static List<PowerModule>[] validModulesForSlot;
|
||||
|
||||
public static final String DURABILITY = "Durability";
|
||||
|
||||
/**
|
||||
* Reduces durability of the passed module tag by the specified amount, to a
|
||||
* minimum of 0. Returns 0 unless there is some remainder.
|
||||
*
|
||||
* @param compound
|
||||
* @return
|
||||
*/
|
||||
public static float reduceDurability(NBTTagCompound moduleTag,
|
||||
float damageAmount) {
|
||||
float durability = 0;
|
||||
float absorbed = 0;
|
||||
if (moduleTag.hasKey(DURABILITY)) {
|
||||
durability = moduleTag.getFloat(DURABILITY);
|
||||
if (durability > damageAmount) {
|
||||
absorbed = damageAmount;
|
||||
} else {
|
||||
absorbed = durability;
|
||||
}
|
||||
moduleTag.setFloat(DURABILITY, durability - absorbed);
|
||||
}
|
||||
return (int) damageAmount - absorbed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization for the module list
|
||||
*/
|
||||
protected static void init() {
|
||||
|
||||
allModules = HashBiMap.create();
|
||||
validModulesForSlot = new ArrayList[5];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
validModulesForSlot[i] = new ArrayList();
|
||||
}
|
||||
new PowerModuleIronPlating();
|
||||
new PowerModuleBattery();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
public static void addModule(String id, PowerModule p) {
|
||||
if (allModules.containsKey(id)) {
|
||||
MuseLogger.logError("Warning: module " + p.getName()
|
||||
+ " already bound!");
|
||||
}
|
||||
allModules.put(id, p);
|
||||
}
|
||||
|
||||
public static PowerModule getModuleByID(String i) {
|
||||
if (allModules.containsKey(i)) {
|
||||
return allModules.get(i);
|
||||
} else {
|
||||
MuseLogger.logError("Module " + i + " not assigned!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static PowerModule getModuleFromNBT(NBTTagCompound moduleTag) {
|
||||
return getModuleByID(moduleTag.getString("Name"));
|
||||
}
|
||||
|
||||
public static String getModuleID(PowerModule module) {
|
||||
if (allModules.inverse().containsKey(module)) {
|
||||
return allModules.inverse().get(module);
|
||||
} else {
|
||||
MuseLogger.logError("Module " + module.getName()
|
||||
+ " not initialized!");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static List<PowerModule> getValidModulesForItem(Item item) {
|
||||
if (item instanceof ItemPowerArmor) {
|
||||
ItemPowerArmor itema = (ItemPowerArmor) item;
|
||||
return validModulesForSlot[itema.armorType];
|
||||
} else if (item instanceof ItemPowerTool) {
|
||||
return validModulesForSlot[4];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param next
|
||||
* @return
|
||||
*/
|
||||
public static NBTTagCompound getItemModules(ItemStack stack) {
|
||||
NBTTagCompound modules = null;
|
||||
if (stack.hasTagCompound()) {
|
||||
NBTTagCompound stackTag = stack.getTagCompound();
|
||||
if (stackTag.hasKey(PowerModule.Constants.nbtPrefix)) {
|
||||
modules = stackTag
|
||||
.getCompoundTag(PowerModule.Constants.nbtPrefix);
|
||||
} else {
|
||||
modules = new NBTTagCompound();
|
||||
stackTag.setCompoundTag(PowerModule.Constants.nbtPrefix,
|
||||
modules);
|
||||
}
|
||||
} else {
|
||||
NBTTagCompound stackTag = new NBTTagCompound();
|
||||
stack.setTagCompound(stackTag);
|
||||
modules = new NBTTagCompound();
|
||||
stackTag.setCompoundTag(PowerModule.Constants.nbtPrefix, modules);
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
}
|
|
@ -1,195 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package net.machinemuse.powersuits.trash;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* PowerModule is the base class for the modules which can be installed in
|
||||
* various power armor items.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public abstract class PowerModule {
|
||||
/**
|
||||
* Contains constant strings. Mainly for consistency.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*/
|
||||
public static final class Constants {
|
||||
public static final String NAME = "Name";
|
||||
public static final String LEVEL = "Level";
|
||||
public static final String nbtPrefix = "mmmpsmod";
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor adds the module to the appropriate lists.
|
||||
*/
|
||||
public PowerModule() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (getValidSlots()[i]) {
|
||||
ModuleUtils.validModulesForSlot[i].add(this);
|
||||
}
|
||||
}
|
||||
ModuleUtils.addModule(getName(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Since modules themselves should be singletons, this is our instance
|
||||
* pattern.
|
||||
*
|
||||
* @return A new NBTTagCompound describing a new instance of this module
|
||||
* (pre-upgrade)
|
||||
*/
|
||||
public abstract NBTTagCompound newModuleTag();
|
||||
|
||||
/**
|
||||
* Returns the name of the module. Should be unique. Used for both tooltips
|
||||
* and for ID mapping.
|
||||
*
|
||||
* @return A string
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Returns the current upgrade level of the module based on the nbttag.
|
||||
* Level 0 modules should do nothing.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getLevel(
|
||||
EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
return moduleTag.getInteger(Constants.LEVEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum level of the upgrade. If the upgrade's level is equal
|
||||
* or greater, further upgrades will not be allowed.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getMaxLevel(
|
||||
EntityPlayer player, NBTTagCompound moduleTag);
|
||||
|
||||
/**
|
||||
* Returns the lines of text to appear in the module's tooltip in the
|
||||
* tinkertable UI.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract List<String> getTooltip(
|
||||
EntityPlayer player, NBTTagCompound moduleTag);
|
||||
|
||||
/**
|
||||
* Returns the list of itemstacks a player should receive if they uninstall
|
||||
* this module.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract List<ItemStack> getRefund(
|
||||
EntityPlayer player, NBTTagCompound moduleTag);
|
||||
|
||||
/**
|
||||
* Returns the list of itemstacks required to upgrade this module.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract List<ItemStack> getCost(
|
||||
EntityPlayer player, NBTTagCompound moduleTag);
|
||||
|
||||
/**
|
||||
* Returns the a list of modules which must be purchased before this one
|
||||
* will be available. Can be different depending on level.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract List<PowerModule> getPrerequisites(
|
||||
EntityPlayer player, NBTTagCompound moduleTag);
|
||||
|
||||
/**
|
||||
* Returns an array of booleans, one for each possible itemslot, describing
|
||||
* whether or not the module can be slotted in that item.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean[] getValidSlots();
|
||||
|
||||
/**
|
||||
* Returns a category name for the module. Modules with the same category
|
||||
* will be grouped together in the UI.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getCategory();
|
||||
|
||||
/**
|
||||
* Event trigger in the player tick.
|
||||
*/
|
||||
public abstract void onPlayerTick(
|
||||
EntityPlayer player, NBTTagCompound moduleTag);
|
||||
|
||||
/**
|
||||
* Event trigger when the item is assigned durability damage.
|
||||
*
|
||||
* @param player
|
||||
* @param moduleTag
|
||||
* @param damageAmount
|
||||
*/
|
||||
public abstract void onDamageItem(
|
||||
EntityPlayer player, NBTTagCompound moduleTag, float damageAmount);
|
||||
|
||||
/**
|
||||
* Event trigger for when the item is upgraded. Should include leveling up.
|
||||
*
|
||||
* @param player
|
||||
* @param moduleTag
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean onUpgrade(
|
||||
EntityPlayer player, NBTTagCompound moduleTag);
|
||||
|
||||
/**
|
||||
* Texture file for the module in GUI.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getIconFile() {
|
||||
return "/moduleicons.png";
|
||||
}
|
||||
|
||||
/**
|
||||
* Texture file for the module when slotted in an item.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getItemOverlayFile() {
|
||||
return "/moduleoverlays.png";
|
||||
}
|
||||
|
||||
/**
|
||||
* Index in the 256p*256p icon file. Indices go like this:
|
||||
*
|
||||
* <pre>
|
||||
* 0 1 2 3 ...
|
||||
* 16 18 19 20 ...
|
||||
* 32 33 34 35 ...
|
||||
* </pre>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getIconIndex();
|
||||
|
||||
/**
|
||||
* Index in the item overlay file, same convention as icon index
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getItemOverlayIndex();
|
||||
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
package net.machinemuse.powersuits.trash;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class PowerModuleBattery extends PowerModule
|
||||
implements
|
||||
IPowerModuleEnergyStorage,
|
||||
IPowerModuleWeight {
|
||||
@Override
|
||||
public NBTTagCompound newModuleTag() {
|
||||
NBTTagCompound newtag = new NBTTagCompound();
|
||||
newtag.setString("Name", getName());
|
||||
newtag.setFloat("Maximum Energy", 0);
|
||||
newtag.setFloat("Current Energy", 0);
|
||||
newtag.setInteger("Level", 0);
|
||||
return newtag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Electric Battery";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWeight(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
return getLevel(player, moduleTag) * 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
return moduleTag.getInteger("Level");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTooltip(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
String[] strings = { getName(), "Battery" };
|
||||
return Arrays.asList(strings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getRefund(EntityPlayer player,
|
||||
NBTTagCompound moduleTag) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
stacks.add(new ItemStack(Item.redstone,
|
||||
(getLevel(player, moduleTag) + 1) * 4));
|
||||
return stacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getCost(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
stacks.add(new ItemStack(Item.redstone,
|
||||
(getLevel(player, moduleTag) + 1) * 4));
|
||||
return stacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PowerModule> getPrerequisites(EntityPlayer player,
|
||||
NBTTagCompound moduleTag) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean[] getValidSlots() {
|
||||
boolean[] slots = { true, true, true, true, true };
|
||||
return slots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return "Energy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTick(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
/** Do nothing **/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDamageItem(EntityPlayer player, NBTTagCompound moduleTag,
|
||||
float damageAmount) {
|
||||
/** Do nothing **/
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpgrade(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
int level = moduleTag.getInteger("Level");
|
||||
if (level < getMaxLevel(player, moduleTag)) {
|
||||
moduleTag.setInteger("Level", level + 1);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemOverlayIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getStoredEnergy(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
return moduleTag.getFloat(CURRENERGY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergy(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
return moduleTag.getFloat(MAXENERGY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float changeEnergy(EntityPlayer player, NBTTagCompound moduleTag,
|
||||
float amount) {
|
||||
return amount;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
package net.machinemuse.powersuits.trash;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class PowerModuleIronPlating extends PowerModule
|
||||
implements
|
||||
IPowerModuleArmor,
|
||||
IPowerModuleWeight {
|
||||
|
||||
@Override
|
||||
public NBTTagCompound newModuleTag() {
|
||||
NBTTagCompound newtag = new NBTTagCompound();
|
||||
newtag.setString("Name", getName());
|
||||
newtag.setFloat("Durability", 100f);
|
||||
newtag.setInteger("Level", 0);
|
||||
return newtag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Iron Armor Plating";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWeight(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
return getLevel(player, moduleTag) * 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
return moduleTag.getInteger("Level");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getArmorValue(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
return getLevel(player, moduleTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTooltip(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
String[] strings = { "Hi", "Module" };
|
||||
return Arrays.asList(strings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getRefund(EntityPlayer player,
|
||||
NBTTagCompound moduleTag) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
stacks.add(new ItemStack(Item.redstone,
|
||||
(getLevel(player, moduleTag) + 1) * 3));
|
||||
return stacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getCost(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
stacks.add(new ItemStack(Item.redstone,
|
||||
(getLevel(player, moduleTag) + 1) * 4));
|
||||
return stacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PowerModule> getPrerequisites(EntityPlayer player,
|
||||
NBTTagCompound moduleTag) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean[] getValidSlots() {
|
||||
boolean[] slots = { true, true, true, true, false };
|
||||
return slots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return "Defense";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTick(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
/** Do nothing **/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDamageItem(EntityPlayer player, NBTTagCompound moduleTag,
|
||||
float damageAmount) {
|
||||
float durability = moduleTag.getFloat("Durability");
|
||||
moduleTag.setFloat("Durability", durability - damageAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpgrade(EntityPlayer player, NBTTagCompound moduleTag) {
|
||||
int level = moduleTag.getInteger("Level");
|
||||
if (level < getMaxLevel(player, moduleTag)) {
|
||||
moduleTag.setInteger("Level", level + 1);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemOverlayIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float damageArmor(EntityPlayer player, NBTTagCompound moduleTag,
|
||||
float damageAmount) {
|
||||
return ModuleUtils.reduceDurability(moduleTag, damageAmount);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue