Improved tick handler and gui

This commit is contained in:
MachineMuse 2012-12-22 01:36:32 -07:00
parent eaa79d8b5c
commit 7ead7c3854
22 changed files with 424 additions and 155 deletions

View file

@ -49,9 +49,9 @@ public class Colour {
public int getInt() { public int getInt() {
int val = 0; int val = 0;
val = val | ((int) (a * 255) << 24); val = val | ((int) (a * 255) << 24);
val = val | ((int) (b * 255) << 16); val = val | ((int) (r * 255) << 16);
val = val | ((int) (g * 255) << 8); val = val | ((int) (g * 255) << 8);
val = val | ((int) (r * 255)); val = val | ((int) (b * 255));
return val; return val;
} }

View file

@ -259,6 +259,8 @@ public abstract class Doodler {
gui.getRenderItem().zLevel = 100.0F; gui.getRenderItem().zLevel = 100.0F;
gui.getRenderItem().renderItemAndEffectIntoGUI( gui.getRenderItem().renderItemAndEffectIntoGUI(
gui.getFontRenderer(), gui.getRenderEngine(), item, x, y); gui.getFontRenderer(), gui.getRenderEngine(), item, x, y);
gui.getRenderItem().renderItemOverlayIntoGUI(gui.getFontRenderer(),
gui.getRenderEngine(), item, x, y);
gui.getRenderItem().zLevel = 0.0F; gui.getRenderItem().zLevel = 0.0F;
GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_DEPTH_TEST);

View file

@ -12,6 +12,8 @@ import net.minecraft.nbt.NBTTagCompound;
* *
*/ */
public abstract class Augmentation { public abstract class Augmentation {
protected NBTTagCompound nbtTag;
/** /**
* Default compound for all NBTtag keys on itemstacks. Needed in case some * Default compound for all NBTtag keys on itemstacks. Needed in case some
* other mod adds NBT data to these items. * other mod adds NBT data to these items.
@ -20,17 +22,31 @@ public abstract class Augmentation {
*/ */
public static String nbtPrefix = "mmmpsmod"; public static String nbtPrefix = "mmmpsmod";
public static Augmentation fromNBTTag(NBTTagCompound tag) { protected int level;
int id = tag.getInteger("AugID");
switch (id) { public int getLevel() {
case 1: return level;
return new AugmentationArmorPlating(tag); }
default:
return null; public void upgrade() {
level += 1;
if (nbtTag != null) {
nbtTag.setInteger("level", level);
} }
} }
public void downgrade() {
level -= 1;
}
/**
* Allows the items to create Augmentation instances.
*
* @param tag
* @return
*/
public abstract Augmentation fromNBTTag(NBTTagCompound tag);
/** /**
* Returns the name of this Augmentation. * Returns the name of this Augmentation.
* *
@ -54,7 +70,7 @@ public abstract class Augmentation {
* the level you would be upgrading to * the level you would be upgrading to
* @return a list of ItemStacks describing the cost. * @return a list of ItemStacks describing the cost.
*/ */
public abstract List<ItemStack> getUpgradeCost(int level); public abstract List<ItemStack> getUpgradeCost();
/** /**
* Returns a list of materials that would be refunded from downgrading or * Returns a list of materials that would be refunded from downgrading or
@ -64,9 +80,11 @@ public abstract class Augmentation {
* the level you would be downgrading to * the level you would be downgrading to
* @return a list of ItemStacks describing the cost. * @return a list of ItemStacks describing the cost.
*/ */
public abstract List<ItemStack> getDowngradeRefund(int level); public abstract List<ItemStack> getDowngradeRefund();
public abstract NBTTagCompound getNBTTag(); public NBTTagCompound getNBTTag() {
return nbtTag;
}
public abstract Augmentation newAug(); public abstract Augmentation newAug();
} }

View file

@ -1,18 +1,21 @@
package machinemuse.powersuits.augmentation; package machinemuse.powersuits.augmentation;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
public class AugmentationArmorPlating extends Augmentation { public class AugmentationArmorPlating extends Augmentation {
protected int durability;
public AugmentationArmorPlating() { public AugmentationArmorPlating() {
level = 0;
} }
public AugmentationArmorPlating(NBTTagCompound tag) { public AugmentationArmorPlating(NBTTagCompound tag) {
// TODO Auto-generated constructor stub this.nbtTag = tag;
} }
@Override @Override
@ -26,21 +29,17 @@ public class AugmentationArmorPlating extends Augmentation {
} }
@Override @Override
public List<ItemStack> getUpgradeCost(int level) { public List<ItemStack> getUpgradeCost() {
// TODO Auto-generated method stub List<ItemStack> list = new ArrayList<ItemStack>();
return null; list.add(new ItemStack(Item.redstone, 4));
return list;
} }
@Override @Override
public List<ItemStack> getDowngradeRefund(int level) { public List<ItemStack> getDowngradeRefund() {
// TODO Auto-generated method stub List<ItemStack> list = new ArrayList<ItemStack>();
return null; list.add(new ItemStack(Item.redstone, 3));
} return list;
@Override
public NBTTagCompound getNBTTag() {
// TODO Auto-generated method stub
return null;
} }
@Override @Override
@ -49,4 +48,19 @@ public class AugmentationArmorPlating extends Augmentation {
return new AugmentationArmorPlating(); return new AugmentationArmorPlating();
} }
@Override
public Augmentation fromNBTTag(NBTTagCompound tag) {
AugmentationArmorPlating aug = new AugmentationArmorPlating();
if (tag.hasKey("level")) {
aug.level = tag.getInteger("Level");
} else {
aug.level = new Integer(0);
}
if (tag.hasKey("durability")) {
aug.durability = tag.getInteger("Durability");
} else {
aug.durability = new Integer(0);
}
return aug;
}
} }

View file

@ -3,67 +3,67 @@
*/ */
package machinemuse.powersuits.augmentation; package machinemuse.powersuits.augmentation;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
/** /**
* @author MachineMuse * @author MachineMuse
* *
*/ */
public class AugmentationBattery extends Augmentation { public class AugmentationBattery extends Augmentation {
float energy;
public AugmentationBattery() {
}
/* (non-Javadoc)
* @see machinemuse.powersuits.augmentation.Augmentation#getName()
*/
@Override @Override
public String getName() { public String getName() {
// TODO Auto-generated method stub return "Electric Battery";
return null;
} }
/* (non-Javadoc)
* @see machinemuse.powersuits.augmentation.Augmentation#getWeight()
*/
@Override @Override
public float getWeight() { public float getWeight() {
// TODO Auto-generated method stub return 1;
return 0; }
public float getAvailableEnergy() {
return energy;
}
public float getMaxEnergy() {
return 5000 * 12 ^ level;
}
public float setAvailableEnergy() {
return energy;
} }
/* (non-Javadoc)
* @see machinemuse.powersuits.augmentation.Augmentation#getUpgradeCost(int)
*/
@Override @Override
public List<ItemStack> getUpgradeCost(int level) { public List<ItemStack> getUpgradeCost() {
// TODO Auto-generated method stub List<ItemStack> list = new ArrayList<ItemStack>();
return null; list.add(new ItemStack(Item.redstone, 4));
return list;
} }
/* (non-Javadoc)
* @see machinemuse.powersuits.augmentation.Augmentation#getDowngradeRefund(int)
*/
@Override @Override
public List<ItemStack> getDowngradeRefund(int level) { public List<ItemStack> getDowngradeRefund() {
// TODO Auto-generated method stub List<ItemStack> list = new ArrayList<ItemStack>();
return null; list.add(new ItemStack(Item.redstone, 3));
return list;
} }
/* (non-Javadoc)
* @see machinemuse.powersuits.augmentation.Augmentation#getNBTTag()
*/
@Override
public NBTTagCompound getNBTTag() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see machinemuse.powersuits.augmentation.Augmentation#newAug()
*/
@Override @Override
public Augmentation newAug() { public Augmentation newAug() {
return new AugmentationBattery();
}
@Override
public Augmentation fromNBTTag(NBTTagCompound tag) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View file

@ -1,12 +1,14 @@
package machinemuse.powersuits.augmentation; package machinemuse.powersuits.augmentation;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import machinemuse.powersuits.item.IModularItem; import machinemuse.powersuits.item.IModularItem;
import machinemuse.powersuits.item.ItemUtil; import machinemuse.powersuits.item.ItemUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
/** /**
@ -27,20 +29,21 @@ public class AugmentationList {
* @param itemStack * @param itemStack
*/ */
public AugmentationList(ItemStack itemStack) { public AugmentationList(ItemStack itemStack) {
IModularItem item = ItemUtil.getAsModular(itemStack.getItem()); IModularItem item = ItemUtils.getAsModular(itemStack.getItem());
CraftingManager.getInstance().getRecipeList();
if (item != null) { if (item != null) {
augCache = new HashMap<Augmentation, Augmentation>();
if (itemStack.hasTagCompound()) { if (itemStack.hasTagCompound()) {
this.tag = itemStack.getTagCompound().getCompoundTag( this.tag = itemStack.getTagCompound().getCompoundTag(
Augmentation.nbtPrefix); Augmentation.nbtPrefix);
validAugs = item.getValidAugs(); validAugs = item.getValidAugs();
augCache = new HashMap<Augmentation, Augmentation>();
} else { } else {
NBTTagCompound nbt = new NBTTagCompound(); NBTTagCompound nbt = new NBTTagCompound();
nbt.setCompoundTag(Augmentation.nbtPrefix, nbt.setCompoundTag(Augmentation.nbtPrefix,
new NBTTagCompound()); new NBTTagCompound());
itemStack.setTagCompound(nbt); itemStack.setTagCompound(nbt);
this.tag = nbt;
} }
} }
} }
@ -73,4 +76,16 @@ public class AugmentationList {
return 0; return 0;
} }
/**
* @return
*/
public List<Augmentation> getAllAugData() {
List<Augmentation> augData = new ArrayList<Augmentation>();
Iterator<Augmentation> iter = validAugs.iterator();
while (iter.hasNext()) {
augData.add(getAugData(iter.next()));
}
return augData;
}
} }

View file

@ -3,7 +3,7 @@ package machinemuse.powersuits.client;
import machinemuse.powersuits.common.CommonProxy; import machinemuse.powersuits.common.CommonProxy;
import machinemuse.powersuits.common.Config; import machinemuse.powersuits.common.Config;
import machinemuse.powersuits.common.PowersuitsMod; import machinemuse.powersuits.common.PowersuitsMod;
import machinemuse.powersuits.common.TickHandler; import machinemuse.powersuits.common.WorldTickHandler;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.client.MinecraftForgeClient;
import cpw.mods.fml.common.Side; import cpw.mods.fml.common.Side;
@ -43,7 +43,7 @@ public class ClientProxy extends CommonProxy {
*/ */
@Override @Override
public void registerHandlers() { public void registerHandlers() {
tickHandler = new TickHandler(); tickHandler = new WorldTickHandler();
TickRegistry.registerTickHandler(tickHandler, Side.CLIENT); TickRegistry.registerTickHandler(tickHandler, Side.CLIENT);
packetHandler = new ClientPacketHandler(); packetHandler = new ClientPacketHandler();

View file

@ -31,7 +31,7 @@ public class CommonProxy {
* Register the server-side tickhandler and packethandler. * Register the server-side tickhandler and packethandler.
*/ */
public void registerHandlers() { public void registerHandlers() {
tickHandler = new TickHandler(); tickHandler = new WorldTickHandler();
TickRegistry.registerTickHandler(tickHandler, Side.SERVER); TickRegistry.registerTickHandler(tickHandler, Side.SERVER);
packetHandler = new ServerPacketHandler(); packetHandler = new ServerPacketHandler();

View file

@ -0,0 +1,100 @@
/**
*
*/
package machinemuse.powersuits.common;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import machinemuse.powersuits.augmentation.Augmentation;
import machinemuse.powersuits.augmentation.AugmentationBattery;
import machinemuse.powersuits.item.ItemUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
/**
* Tick handler for Player ticks. This is where we compute all the updates that
* should go every tick.
*
* @author MachineMuse
*/
public class PlayerTickHandler implements ITickHandler {
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
World world = toWorld(tickData[0]);
EntityPlayer player = toPlayer(tickData[1]);
List<Augmentation> playerAugs = ItemUtils
.getPlayerAugs(player);
float totalEnergy = 0;
float totalWeight = 0;
Iterator<Augmentation> iter = playerAugs.iterator();
while (iter.hasNext()) {
Augmentation aug = iter.next();
if (aug instanceof AugmentationBattery) {
totalEnergy += ((AugmentationBattery) aug).getAvailableEnergy();
}
totalWeight += aug.getWeight();
}
if (totalWeight > 25) {
player.motionX *= 25 / totalWeight;
player.motionZ *= 25 / totalWeight;
}
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
World world = toWorld(tickData[0]);
EntityPlayer player = toPlayer(tickData[1]);
List<ItemStack> stacks = ItemUtils
.getModularItemsInInventory(player.inventory);
}
public static World toWorld(Object data) {
World world = null;
try {
world = (World) data;
} catch (ClassCastException e) {
MuseLogger.logDebug(
"MMMPS: Player tick handler received invalid World object");
e.printStackTrace();
}
return world;
}
public static EntityPlayer toPlayer(Object data) {
EntityPlayer player = null;
try {
player = (EntityPlayer) data;
} catch (ClassCastException e) {
MuseLogger
.logDebug(
"MMMPS: Player tick handler received invalid Player object");
e.printStackTrace();
}
return player;
}
/**
* Type of tick handled by this handler
*/
@Override
public EnumSet<TickType> ticks() {
return EnumSet.of(TickType.PLAYER);
}
/**
* Profiling label for this handler
*/
@Override
public String getLabel() {
return "MMMPS PlayerTickHandler";
}
}

View file

@ -14,7 +14,7 @@ import cpw.mods.fml.common.TickType;
* @author MachineMuse * @author MachineMuse
* *
*/ */
public class TickHandler implements ITickHandler { public class WorldTickHandler implements ITickHandler {
/** /**
* Called at the "start" phase of a tick * Called at the "start" phase of a tick
* *
@ -41,7 +41,6 @@ public class TickHandler implements ITickHandler {
@Override @Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) { public void tickEnd(EnumSet<TickType> type, Object... tickData) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/** /**

View file

@ -4,13 +4,14 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import machinemuse.general.geometry.Colour;
import machinemuse.general.geometry.Doodler; import machinemuse.general.geometry.Doodler;
import machinemuse.general.geometry.FlyFromMiddlePoint2D; import machinemuse.general.geometry.FlyFromMiddlePoint2D;
import machinemuse.general.geometry.Point2D; import machinemuse.general.geometry.Point2D;
import machinemuse.powersuits.augmentation.Augmentation; import machinemuse.powersuits.augmentation.Augmentation;
import machinemuse.powersuits.augmentation.AugmentationList; import machinemuse.powersuits.augmentation.AugmentationList;
import machinemuse.powersuits.common.MuseLogger; import machinemuse.powersuits.common.MuseLogger;
import machinemuse.powersuits.item.ItemUtil; import machinemuse.powersuits.item.ItemUtils;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -25,8 +26,11 @@ public class GuiTinkerTable extends MuseGui {
protected List<ClickableItem> itemButtons; protected List<ClickableItem> itemButtons;
protected ClickableItem selectedItemStack; protected ClickableItem selectedItemStack;
protected List<ClickableAugmentation> augButtons; protected List<ClickableAugmentation> augButtons;
protected ClickableAugmentation selectedAugmentation; protected ClickableAugmentation selectedAugClickable;
protected AugmentationList augData; protected AugmentationList augData;
protected Augmentation workingAugmentation;
protected List<ItemStack> workingUpgradeCost;
protected List<ItemStack> workingDowngradeRefund;
/** /**
* Constructor. Takes a player as an argument. * Constructor. Takes a player as an argument.
@ -56,7 +60,7 @@ public class GuiTinkerTable extends MuseGui {
* *
*/ */
public void loadItems() { public void loadItems() {
List<ItemStack> stacks = ItemUtil List<ItemStack> stacks = ItemUtils
.getModularItemsInInventory(player.inventory); .getModularItemsInInventory(player.inventory);
List<Point2D> points = this.pointsInLine(stacks.size(), List<Point2D> points = this.pointsInLine(stacks.size(),
@ -79,7 +83,7 @@ public class GuiTinkerTable extends MuseGui {
protected void loadAugList(ClickableItem itemClicked) { protected void loadAugList(ClickableItem itemClicked) {
augButtons = new ArrayList<ClickableAugmentation>(); augButtons = new ArrayList<ClickableAugmentation>();
augData = new AugmentationList(itemClicked.getItem()); augData = new AugmentationList(itemClicked.getItem());
List<Augmentation> validAugs = ItemUtil.getAsModular(itemClicked List<Augmentation> validAugs = ItemUtils.getAsModular(itemClicked
.getItem().getItem()).getValidAugs(); .getItem().getItem()).getValidAugs();
List<Point2D> points = this.pointsInLine(validAugs.size(), List<Point2D> points = this.pointsInLine(validAugs.size(),
new Point2D(-0.7F, -0.9F), new Point2D(-0.7F, -0.9F),
@ -106,17 +110,13 @@ public class GuiTinkerTable extends MuseGui {
10); 10);
} }
if (selectedAugmentation != null) { if (selectedAugClickable != null) {
Doodler.drawCircleAround( Doodler.drawCircleAround(
absX(selectedAugmentation.getPosition().x()), absX(selectedAugClickable.getPosition().x()),
absY(selectedAugmentation.getPosition().y()), absY(selectedAugClickable.getPosition().y()),
10); 10);
} }
// for (Augmentation a : Augmentation.getAllAugs()) {
// if (a.canGoInSlot(selectedSlot.getType())) {
//
// }
// }
} }
@ -143,13 +143,53 @@ public class GuiTinkerTable extends MuseGui {
drawClickables(this.itemButtons); drawClickables(this.itemButtons);
drawSelection(); drawSelection();
drawClickables(this.augButtons); drawClickables(this.augButtons);
// Colour colour = Colour.getGreyscale(1.0F, 1.0F); drawUpgradeDowngrade();
// if (editingItem != null && editingLayout != null) { }
// drawLayout(editingLayout);
// if (selectedSlot != null) { /**
// drawSelection(); * Draws the upgrade/downgrade cost, buttons, and labels.
// } */
// } public void drawUpgradeDowngrade() {
if (workingUpgradeCost != null) {
this.drawString(fontRenderer, "Cost:", absX(0.4F),
absY(-0.7F),
new Colour(0.5F, 1.0F, 0.5F, 1.0F).getInt());
List<Point2D> points = this.pointsInLine(workingUpgradeCost.size(),
new Point2D(0.4F, -0.5F),
new Point2D(0.9F, -0.5F));
Iterator<Point2D> pointiter = points.iterator();
for (ItemStack item : workingUpgradeCost) {
Point2D next = pointiter.next();
Doodler.drawItemAt(absX(next.x()), absY(next.y()), this, item);
}
}
if (workingDowngradeRefund != null) {
Doodler.on2D();
this.drawString(fontRenderer, "Refund:", absX(0.4F),
absY(0.3F),
new Colour(1.0F, 0.6F, 0.2F, 1.0F).getInt());
Doodler.off2D();
List<Point2D> points = this.pointsInLine(
workingDowngradeRefund.size(),
new Point2D(0.4F, 0.5F),
new Point2D(0.9F, 0.5F));
Iterator<Point2D> pointiter = points.iterator();
for (ItemStack item : workingDowngradeRefund) {
Point2D next = pointiter.next();
Doodler.drawItemAt(absX(next.x()), absY(next.y()), this, item);
}
}
}
/**
* Clear all the UI stuff that's there.
*/
protected void clearSelections() {
this.selectedAugClickable = null;
this.workingAugmentation = null;
this.workingUpgradeCost = null;
this.workingDowngradeRefund = null;
} }
/** /**
@ -165,13 +205,16 @@ public class GuiTinkerTable extends MuseGui {
(ClickableAugmentation) hitboxClickables(x, y, (ClickableAugmentation) hitboxClickables(x, y,
this.augButtons); this.augButtons);
if (itemClicked != null) { if (itemClicked != null) {
clearSelections();
this.selectedItemStack = itemClicked; this.selectedItemStack = itemClicked;
loadAugList(itemClicked); loadAugList(itemClicked);
} else if (augClicked != null) { } else if (augClicked != null) {
this.selectedAugmentation = augClicked; this.selectedAugClickable = augClicked;
// TODO: add ui on the right for stuff this.workingAugmentation = augData.getAugData(augClicked.aug);
this.workingUpgradeCost = workingAugmentation.getUpgradeCost();
this.workingDowngradeRefund = workingAugmentation
.getDowngradeRefund();
} }
} }
} }
} }

View file

@ -61,8 +61,9 @@ public class MuseGui extends GuiScreen {
Doodler.drawGradientRect( Doodler.drawGradientRect(
absX(ul.x()), absY(ul.y()), absX(ul.x()), absY(ul.y()),
absX(br.x()), absY(br.y()), absX(br.x()), absY(br.y()),
Colour.getGreyscale(0.8f, 0.8f), new Colour(0.1F, 0.9F, 0.1F, 0.8F),
Colour.getGreyscale(0.3f, 0.8f), (double) this.zLevel); new Colour(0.0F, 0.2F, 0.0F, 0.8F),
(double) this.zLevel);
} }
/** /**
@ -111,8 +112,8 @@ public class MuseGui extends GuiScreen {
} else if (num < 2) { } else if (num < 2) {
points.add(b.minus(a).times(0.5F).plus(a)); points.add(b.minus(a).times(0.5F).plus(a));
} else { } else {
Point2D step = b.minus(a).times(1.0F / (num - 1)); Point2D step = b.minus(a).times(1.0F / (num + 1));
for (int i = 0; i < num; i++) { for (int i = 1; i < num + 2; i++) {
points.add(a.plus(step.times(i))); points.add(a.plus(step.times(i)));
} }
} }

View file

@ -8,7 +8,7 @@ import machinemuse.powersuits.common.Config;
/** /**
* Interface for ItemPowerArmor and ItemPowerTool to share. * Interface for ItemPowerArmor and ItemPowerTool to share.
* *
* @author Claire * @author MachineMuse
*/ */
public interface IModularItem { public interface IModularItem {
public List<Augmentation> getValidAugs(); public List<Augmentation> getValidAugs();

View file

@ -1,5 +1,8 @@
package machinemuse.powersuits.item; package machinemuse.powersuits.item;
import java.util.List;
import machinemuse.powersuits.augmentation.Augmentation;
import machinemuse.powersuits.common.Config; import machinemuse.powersuits.common.Config;
import machinemuse.powersuits.common.Config.Items; import machinemuse.powersuits.common.Config.Items;
import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLiving;
@ -15,9 +18,12 @@ import net.minecraftforge.common.ISpecialArmor;
* *
* @author MachineMuse * @author MachineMuse
*/ */
public abstract class ItemPowerArmor extends ItemArmor implements public abstract class ItemPowerArmor extends ItemArmor
ISpecialArmor, implements ISpecialArmor, IModularItem {
IModularItem { protected List<Augmentation> validAugTypes;
Config.Items itemType;
/** /**
* @param par1 * @param par1
* @param par2EnumArmorMaterial * @param par2EnumArmorMaterial
@ -31,8 +37,6 @@ public abstract class ItemPowerArmor extends ItemArmor implements
setCreativeTab(Config.getCreativeTab()); setCreativeTab(Config.getCreativeTab());
} }
Config.Items itemType;
/** /**
* Inherited from ISpecialArmor, allows significant customization of damage * Inherited from ISpecialArmor, allows significant customization of damage
* calculations. * calculations.
@ -75,7 +79,7 @@ public abstract class ItemPowerArmor extends ItemArmor implements
@Override @Override
public void damageArmor(EntityLiving entity, ItemStack stack, public void damageArmor(EntityLiving entity, ItemStack stack,
DamageSource source, int damage, int slot) { DamageSource source, int damage, int slot) {
// Damage the armor's durability
} }
@Override @Override
@ -83,4 +87,20 @@ public abstract class ItemPowerArmor extends ItemArmor implements
return itemType; return itemType;
} }
/**
* For IModularItem's aug-list functionality.
*/
public void addValidAugType(Augmentation template) {
validAugTypes.add(template);
}
/**
* Inherited from IModularItem, returns an array of valid augmentations for
* this item.
*/
@Override
public List<Augmentation> getValidAugs() {
return validAugTypes;
}
} }

View file

@ -4,7 +4,6 @@
package machinemuse.powersuits.item; package machinemuse.powersuits.item;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import machinemuse.powersuits.augmentation.Augmentation; import machinemuse.powersuits.augmentation.Augmentation;
import machinemuse.powersuits.augmentation.AugmentationArmorPlating; import machinemuse.powersuits.augmentation.AugmentationArmorPlating;
@ -18,8 +17,6 @@ import cpw.mods.fml.common.registry.LanguageRegistry;
* *
*/ */
public class ItemPowerArmorFeet extends ItemPowerArmor { public class ItemPowerArmorFeet extends ItemPowerArmor {
protected static List<Augmentation> validAugTypes;
/** /**
* @param item * @param item
*/ */
@ -46,13 +43,4 @@ public class ItemPowerArmorFeet extends ItemPowerArmor {
validAugTypes.add(new AugmentationArmorPlating()); validAugTypes.add(new AugmentationArmorPlating());
} }
/**
* Inherited from IModularItem, returns a (potentially sparse) array of
* valid augmentations for this item.
*/
@Override
public List<Augmentation> getValidAugs() {
return validAugTypes;
}
} }

View file

@ -1,7 +1,6 @@
package machinemuse.powersuits.item; package machinemuse.powersuits.item;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import machinemuse.powersuits.augmentation.Augmentation; import machinemuse.powersuits.augmentation.Augmentation;
import machinemuse.powersuits.augmentation.AugmentationArmorPlating; import machinemuse.powersuits.augmentation.AugmentationArmorPlating;
@ -11,8 +10,6 @@ import net.minecraft.item.EnumArmorMaterial;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
public class ItemPowerArmorHead extends ItemPowerArmor { public class ItemPowerArmorHead extends ItemPowerArmor {
protected static List<Augmentation> validAugTypes;
public ItemPowerArmorHead() { public ItemPowerArmorHead() {
super(Config.getAssignedItemID(Config.Items.PowerArmorHead), // itemID super(Config.getAssignedItemID(Config.Items.PowerArmorHead), // itemID
EnumArmorMaterial.IRON, // Material EnumArmorMaterial.IRON, // Material
@ -36,12 +33,4 @@ public class ItemPowerArmorHead extends ItemPowerArmor {
validAugTypes.add(new AugmentationArmorPlating()); validAugTypes.add(new AugmentationArmorPlating());
} }
/**
* Inherited from IModularItem, returns a (potentially sparse) array of
* valid augmentations for this item.
*/
@Override
public List<Augmentation> getValidAugs() {
return validAugTypes;
}
} }

View file

@ -1,7 +1,6 @@
package machinemuse.powersuits.item; package machinemuse.powersuits.item;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import machinemuse.powersuits.augmentation.Augmentation; import machinemuse.powersuits.augmentation.Augmentation;
import machinemuse.powersuits.augmentation.AugmentationArmorPlating; import machinemuse.powersuits.augmentation.AugmentationArmorPlating;
@ -11,8 +10,6 @@ import net.minecraft.item.EnumArmorMaterial;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
public class ItemPowerArmorLegs extends ItemPowerArmor { public class ItemPowerArmorLegs extends ItemPowerArmor {
protected static List<Augmentation> validAugTypes;
public ItemPowerArmorLegs() { public ItemPowerArmorLegs() {
super(Config.getAssignedItemID(Config.Items.PowerArmorLegs), // itemID super(Config.getAssignedItemID(Config.Items.PowerArmorLegs), // itemID
EnumArmorMaterial.IRON, // Material EnumArmorMaterial.IRON, // Material
@ -36,13 +33,4 @@ public class ItemPowerArmorLegs extends ItemPowerArmor {
validAugTypes.add(new AugmentationArmorPlating()); validAugTypes.add(new AugmentationArmorPlating());
} }
/**
* Inherited from IModularItem, returns a (potentially sparse) array of
* valid augmentations for this item.
*/
@Override
public List<Augmentation> getValidAugs() {
return validAugTypes;
}
} }

View file

@ -1,7 +1,6 @@
package machinemuse.powersuits.item; package machinemuse.powersuits.item;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import machinemuse.powersuits.augmentation.Augmentation; import machinemuse.powersuits.augmentation.Augmentation;
import machinemuse.powersuits.augmentation.AugmentationArmorPlating; import machinemuse.powersuits.augmentation.AugmentationArmorPlating;
@ -11,8 +10,6 @@ import net.minecraft.item.EnumArmorMaterial;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
public class ItemPowerArmorTorso extends ItemPowerArmor { public class ItemPowerArmorTorso extends ItemPowerArmor {
protected static List<Augmentation> validAugTypes;
public ItemPowerArmorTorso() { public ItemPowerArmorTorso() {
super(Config.getAssignedItemID(Config.Items.PowerArmorTorso), // itemID super(Config.getAssignedItemID(Config.Items.PowerArmorTorso), // itemID
EnumArmorMaterial.IRON, // Material EnumArmorMaterial.IRON, // Material
@ -35,14 +32,4 @@ public class ItemPowerArmorTorso extends ItemPowerArmor {
validAugTypes.add(new AugmentationBattery()); validAugTypes.add(new AugmentationBattery());
validAugTypes.add(new AugmentationArmorPlating()); validAugTypes.add(new AugmentationArmorPlating());
} }
/**
* Inherited from IModularItem, returns a (potentially sparse) array of
* valid augmentations for this item.
*/
@Override
public List<Augmentation> getValidAugs() {
return validAugTypes;
}
} }

View file

@ -16,7 +16,7 @@ import cpw.mods.fml.common.registry.LanguageRegistry;
* @author MachineMuse * @author MachineMuse
*/ */
public class ItemPowerTool extends Item implements IModularItem { public class ItemPowerTool extends Item implements IModularItem {
private List<Augmentation> validAugTypes; protected List<Augmentation> validAugTypes;
/** /**
* Constructor. Takes information from the Config.Items enum. * Constructor. Takes information from the Config.Items enum.

View file

@ -1,14 +1,17 @@
package machinemuse.powersuits.item; package machinemuse.powersuits.item;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import machinemuse.powersuits.augmentation.Augmentation;
import machinemuse.powersuits.augmentation.AugmentationList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
public abstract class ItemUtil { public class ItemUtils {
/** /**
* Scans a specified inventory for modular items. * Scans a specified inventory for modular items.
* *
@ -29,6 +32,9 @@ public abstract class ItemUtil {
return stacks; return stacks;
} }
/**
* Attempts to cast an item to IModularItem, returns null if fails
*/
public static IModularItem getAsModular(Item item) { public static IModularItem getAsModular(Item item) {
if (item instanceof IModularItem) { if (item instanceof IModularItem) {
return (IModularItem) item; return (IModularItem) item;
@ -36,4 +42,20 @@ public abstract class ItemUtil {
return null; return null;
} }
} }
/**
* @param player
* @return
*/
public static List<Augmentation> getPlayerAugs(EntityPlayer player) {
List<Augmentation> augs = new ArrayList<Augmentation>();
List<ItemStack> items = getModularItemsInInventory(player.inventory);
Iterator<ItemStack> iter = items.iterator();
while (iter.hasNext()) {
AugmentationList itemAugs = new AugmentationList(iter.next());
augs.addAll(itemAugs.getAllAugData());
}
return augs;
}
} }

View file

@ -1,4 +1,4 @@
package machinemuse.powersuits.augmentation; package machinemuse.powersuits.trash;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View file

@ -1,12 +1,18 @@
package machinemuse.powersuits.trash; package machinemuse.powersuits.trash;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import machinemuse.powersuits.item.ItemPowerArmor; import machinemuse.powersuits.item.ItemPowerArmor;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.world.World; import net.minecraft.world.World;
public class ContainerTinkerTable extends Container { public class ContainerTinkerTable extends Container {
@ -172,4 +178,81 @@ public class ContainerTinkerTable extends Container {
return var3; return var3;
} }
/**
* Adds a recipe. See spreadsheet on first page for details.
*/
public void addRecipe(ItemStack outputStack, Object... recipeParameters)
{
String reshapedString = "";
int currentArg = 0;
int var5 = 0;
int var6 = 0;
if (recipeParameters[currentArg] instanceof String[])
{
String[] nextRecipeString = (String[]) ((String[]) recipeParameters[currentArg++]);
for (int i = 0; i < nextRecipeString.length; ++i)
{
String nextChar = nextRecipeString[i];
++var6;
var5 = nextChar.length();
reshapedString = reshapedString + nextChar;
}
}
else
{
while (recipeParameters[currentArg] instanceof String)
{
String var11 = (String) recipeParameters[currentArg++];
++var6;
var5 = var11.length();
reshapedString = reshapedString + var11;
}
}
HashMap var12;
for (var12 = new HashMap(); currentArg < recipeParameters.length; currentArg += 2)
{
Character var13 = (Character) recipeParameters[currentArg];
ItemStack var14 = null;
if (recipeParameters[currentArg + 1] instanceof Item)
{
var14 = new ItemStack((Item) recipeParameters[currentArg + 1]);
}
else if (recipeParameters[currentArg + 1] instanceof Block)
{
var14 = new ItemStack((Block) recipeParameters[currentArg + 1], 1, -1);
}
else if (recipeParameters[currentArg + 1] instanceof ItemStack)
{
var14 = (ItemStack) recipeParameters[currentArg + 1];
}
var12.put(var13, var14);
}
ItemStack[] var15 = new ItemStack[var5 * var6];
for (int var16 = 0; var16 < var5 * var6; ++var16)
{
char var10 = reshapedString.charAt(var16);
if (var12.containsKey(Character.valueOf(var10)))
{
var15[var16] = ((ItemStack) var12.get(Character.valueOf(var10)))
.copy();
}
else
{
var15[var16] = null;
}
}
List<IRecipe> recipes = new ArrayList<IRecipe>();
recipes.add(new ShapedRecipes(var5, var6, var15,
outputStack));
}
} }