More GUI work, extended 'tinker' system
This commit is contained in:
parent
4fef905a94
commit
5ad9e2eaf0
26 changed files with 578 additions and 241 deletions
BIN
icons.png
Normal file
BIN
icons.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
|
@ -5,13 +5,12 @@ import java.nio.FloatBuffer;
|
|||
import java.nio.IntBuffer;
|
||||
|
||||
import net.machinemuse.powersuits.gui.MuseGui;
|
||||
import net.machinemuse.powersuits.trash.PowerModule;
|
||||
import net.machinemuse.powersuits.gui.MuseIcon;
|
||||
import net.minecraft.client.model.PositionTextureVertex;
|
||||
import net.minecraft.client.model.TexturedQuad;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
|
||||
|
@ -453,14 +452,16 @@ public abstract class MuseRenderer {
|
|||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
public static void drawModuleAt(int x, int y, MuseGui gui,
|
||||
PowerModule module, NBTTagCompound moduleTag, Colour colour) {
|
||||
public static void drawIconAt(int x, int y, MuseGui gui,
|
||||
MuseIcon icon, Colour colour) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glDisable(GL11.GL_CULL_FACE);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
texturelessOff();
|
||||
smoothingOn();
|
||||
|
||||
ForgeHooksClient.bindTexture(module.getIconFile(), 0);
|
||||
ForgeHooksClient.bindTexture(icon.getTexturefile(), 0);
|
||||
|
||||
if (colour != null)
|
||||
{
|
||||
|
@ -470,8 +471,8 @@ public abstract class MuseRenderer {
|
|||
Tessellator tess = Tessellator.instance;
|
||||
tess.startDrawingQuads();
|
||||
float r = 0.0625f;
|
||||
float u = (module.getIconIndex() % 16) * r;
|
||||
float v = (module.getIconIndex() / 16) * r;
|
||||
float u = (icon.getIconIndex() % 16) * r;
|
||||
float v = (icon.getIconIndex() / 16) * r;
|
||||
tess.addVertexWithUV(
|
||||
x, y, 0,
|
||||
u, v);
|
||||
|
@ -490,6 +491,7 @@ public abstract class MuseRenderer {
|
|||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
// GL11.glDepthFunc(GL11.GL_LEQUAL);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,7 @@ package net.machinemuse.powersuits.client;
|
|||
import net.machinemuse.powersuits.block.TileEntityTinkerTable;
|
||||
import net.machinemuse.powersuits.common.CommonProxy;
|
||||
import net.machinemuse.powersuits.common.PlayerTickHandler;
|
||||
import net.machinemuse.powersuits.common.PowersuitsMod;
|
||||
import net.machinemuse.powersuits.network.MusePacketHandler;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.registry.TickRegistry;
|
||||
|
@ -26,11 +24,7 @@ public class ClientProxy extends CommonProxy {
|
|||
*/
|
||||
@Override
|
||||
public void registerRenderers() {
|
||||
for (Item i : PowersuitsMod.allItems) {
|
||||
MinecraftForgeClient.registerItemRenderer(
|
||||
i.shiftedIndex, eRenderer);
|
||||
}
|
||||
// for (Item i : PowersuitsMod.allBlocks) {
|
||||
// for (Item i : PowersuitsMod.allItems) {
|
||||
// MinecraftForgeClient.registerItemRenderer(
|
||||
// i.shiftedIndex, eRenderer);
|
||||
// }
|
||||
|
|
|
@ -3,11 +3,14 @@ package net.machinemuse.powersuits.common;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.machinemuse.powersuits.item.TinkerAction;
|
||||
import net.machinemuse.powersuits.gui.MuseIcon;
|
||||
import net.machinemuse.powersuits.item.*;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.StepSound;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
|
||||
/**
|
||||
|
@ -21,6 +24,11 @@ public class Config extends Configuration {
|
|||
private static final int[] assignedItemIDs = new int[Items.values().length];
|
||||
private static final int[] assignedBlockIDs = new int[Blocks.values().length];
|
||||
private static final Map<String, TinkerAction> tinkerings = new HashMap();
|
||||
|
||||
public static Map<String, TinkerAction> getTinkerings() {
|
||||
return tinkerings;
|
||||
}
|
||||
|
||||
private static Configuration config;
|
||||
|
||||
/**
|
||||
|
@ -100,10 +108,78 @@ public class Config extends Configuration {
|
|||
return assignedBlockIDs[block.ordinal()];
|
||||
}
|
||||
|
||||
public static void addTinkerAction(TinkerAction action) {
|
||||
tinkerings.put(action.getName(), action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all the tinkerings in the config file into memory.
|
||||
* Load all the tinkerings in the config file into memory. Eventually. For
|
||||
* now, they are hardcoded.
|
||||
*/
|
||||
public void loadTinkerings() {
|
||||
public static void loadTinkerings() {
|
||||
boolean[] ARMORONLY = { true, true, true, true, false };
|
||||
boolean[] TOOLONLY = { false, false, false, false, true };
|
||||
boolean[] ALLITEMS = { true, true, true, true, true };
|
||||
addTinkerAction(new TinkerAction("Add armor plating", ARMORONLY)
|
||||
.addCost(new ItemStack(Item.ingotIron))
|
||||
.addEffect(
|
||||
new TinkerEffectAdditive(
|
||||
IModularItem.ARMOR_VALUE, 1.0, 2.0))
|
||||
.addEffect(
|
||||
new TinkerEffectAdditive(
|
||||
IModularItem.ARMOR_DURABILITY, 1.0, 2.0))
|
||||
.addEffect(
|
||||
new TinkerEffectAdditive(
|
||||
IModularItem.ARMOR_WEIGHT, 1.0, 2.0))
|
||||
.setDescription(
|
||||
"By adding some iron plating, you might be able to make this armor more protective.")
|
||||
.setIcon(new MuseIcon("/icons.png", 1)));
|
||||
addTinkerAction(new TinkerAction("Lighten armor plating", ARMORONLY)
|
||||
.addCost(new ItemStack(Item.lightStoneDust))
|
||||
.addEffect(
|
||||
new TinkerEffectMultiplicative(
|
||||
IModularItem.ARMOR_VALUE, .95, 1))
|
||||
.addEffect(
|
||||
new TinkerEffectMultiplicative(
|
||||
IModularItem.ARMOR_DURABILITY, .95, 1))
|
||||
.addEffect(
|
||||
new TinkerEffectMultiplicative(
|
||||
IModularItem.ARMOR_WEIGHT, .9, .95))
|
||||
.addRequirement(
|
||||
new TinkerRequirement(IModularItem.ARMOR_VALUE, '>', 2))
|
||||
.addRequirement(
|
||||
new TinkerRequirement(IModularItem.ARMOR_WEIGHT, '>', 2))
|
||||
.setDescription(
|
||||
"Using the lightening effects of glowstone, you might be able to reduce the weight of this armor.")
|
||||
.setIcon(new MuseIcon("/icons.png", 4)));
|
||||
addTinkerAction(new TinkerAction("Install a battery", ALLITEMS)
|
||||
.addCost(new ItemStack(Item.redstone))
|
||||
.addEffect(
|
||||
new TinkerEffectAdditive(
|
||||
IModularItem.MAXIMUM_ENERGY, 10000.0, 20000.0))
|
||||
.addEffect(
|
||||
new TinkerEffectAdditive(
|
||||
IModularItem.ARMOR_WEIGHT, 0.5, 1))
|
||||
.addRequirement(
|
||||
new TinkerRequirement(
|
||||
IModularItem.MAXIMUM_ENERGY, '=', 0))
|
||||
.setDescription(
|
||||
"By adding a battery, you might be able to have a source of energy on hand at all times.")
|
||||
.setIcon(new MuseIcon("/icons.png", 5)));
|
||||
addTinkerAction(new TinkerAction("Lighten the battery", ALLITEMS)
|
||||
.addCost(new ItemStack(Item.redstone))
|
||||
.addEffect(
|
||||
new TinkerEffectMultiplicative(
|
||||
IModularItem.MAXIMUM_ENERGY, .95, 1))
|
||||
.addEffect(
|
||||
new TinkerEffectMultiplicative(
|
||||
IModularItem.ARMOR_WEIGHT, .9, .95))
|
||||
.addRequirement(
|
||||
new TinkerRequirement(
|
||||
IModularItem.MAXIMUM_ENERGY, '>', 10000))
|
||||
.setDescription(
|
||||
"Using lapis instead of redstone might allow you to store the same amount of energy in a smaller frame.")
|
||||
.setIcon(new MuseIcon("/icons.png", 9)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
package net.machinemuse.powersuits.common;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -28,8 +27,11 @@ public class NBTTagAccessor extends NBTTagCompound {
|
|||
* Will likely need to be updated every time the obfuscation changes.
|
||||
*
|
||||
* @return
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchMethodException
|
||||
*/
|
||||
public static Method getTagAccessor() {
|
||||
public static Method getTagAccessor() throws NoSuchMethodException,
|
||||
SecurityException {
|
||||
if (mTagAccessor == null) {
|
||||
try {
|
||||
mTagAccessor = NBTTagCompound.class.getDeclaredMethod(
|
||||
|
@ -37,40 +39,23 @@ public class NBTTagAccessor extends NBTTagCompound {
|
|||
mTagAccessor.setAccessible(true);
|
||||
return mTagAccessor;
|
||||
} catch (NoSuchMethodException e) {
|
||||
MuseLogger.logError("4");
|
||||
try {
|
||||
mTagAccessor = NBTTagCompound.class.getDeclaredMethod(
|
||||
"a", NBTTagCompound.class);
|
||||
mTagAccessor.setAccessible(true);
|
||||
return mTagAccessor;
|
||||
} catch (NoSuchMethodException e1) {
|
||||
MuseLogger.logError("1");
|
||||
e1.printStackTrace();
|
||||
} catch (SecurityException e1) {
|
||||
MuseLogger.logError("2");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
MuseLogger.logError("3");
|
||||
e.printStackTrace();
|
||||
} else {
|
||||
return mTagAccessor;
|
||||
}
|
||||
|
||||
}
|
||||
MuseLogger.logError("Error 1: Unable to access nbt tag map!");
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map getMap(NBTTagCompound nbt) {
|
||||
try {
|
||||
return (Map) getTagAccessor().invoke(null, nbt);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
return (Map) getTagAccessor().invoke(nbt, nbt);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MuseLogger.logError("Error 2: Unable to access nbt tag map!");
|
||||
MuseLogger.logError("Unable to access nbt tag map!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@ public class PowersuitsMod {
|
|||
event.getSuggestedConfigurationFile()));
|
||||
}
|
||||
|
||||
public static Config config;
|
||||
/**
|
||||
* A static handle for the blocks and items. We only want one instance of
|
||||
* each of them.
|
||||
|
@ -127,6 +128,9 @@ public class PowersuitsMod {
|
|||
|
||||
ItemPowerTool tool = new ItemPowerTool();
|
||||
allItems.add(tool);
|
||||
|
||||
Config.loadTinkerings();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package net.machinemuse.powersuits.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.machinemuse.general.geometry.Colour;
|
||||
import net.machinemuse.general.geometry.MuseRenderer;
|
||||
import net.machinemuse.general.geometry.Point2D;
|
||||
import net.machinemuse.powersuits.trash.ModuleUtils;
|
||||
import net.machinemuse.powersuits.trash.PowerModule;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.machinemuse.powersuits.item.TinkerAction;
|
||||
import net.machinemuse.powersuits.item.TinkerEffect;
|
||||
import net.minecraft.client.renderer.RenderEngine;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Extends the Clickable class to make a clickable Augmentation; note that this
|
||||
|
@ -18,31 +17,46 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
* @author MachineMuse
|
||||
*/
|
||||
public class ClickableTinkerAction extends Clickable {
|
||||
protected PowerModule module;
|
||||
protected NBTTagCompound moduleTag;
|
||||
protected TinkerAction action;
|
||||
|
||||
/**
|
||||
* @param vaug
|
||||
*/
|
||||
public ClickableTinkerAction(PowerModule module, Point2D position) {
|
||||
public ClickableTinkerAction(TinkerAction action, Point2D position) {
|
||||
super(position);
|
||||
this.module = module;
|
||||
this.moduleTag = module.newModuleTag();
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param vaug
|
||||
*/
|
||||
public ClickableTinkerAction(NBTTagCompound moduleTag, Point2D position) {
|
||||
super(position);
|
||||
this.moduleTag = moduleTag;
|
||||
this.module = ModuleUtils.getModuleFromNBT(moduleTag);
|
||||
public List<String> wrapString(String str, int length) {
|
||||
List<String> strlist = new ArrayList();
|
||||
|
||||
int i = 0;
|
||||
while (i + length < str.length()) {
|
||||
int j = str.lastIndexOf(" ", i + length);
|
||||
if (j == -1) {
|
||||
j = str.indexOf(" ", i + length);
|
||||
}
|
||||
if (j == -1) {
|
||||
break;
|
||||
}
|
||||
strlist.add(str.substring(i, j));
|
||||
i = j;
|
||||
}
|
||||
strlist.add(str.substring(i));
|
||||
|
||||
return strlist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getToolTip() {
|
||||
return module.getTooltip(
|
||||
Minecraft.getMinecraft().thePlayer, moduleTag);
|
||||
List<String> toolTipText = new ArrayList();
|
||||
toolTipText.add(action.name);
|
||||
toolTipText.addAll(wrapString(action.description, 30));
|
||||
for (TinkerEffect effect : action.getEffects()) {
|
||||
toolTipText.add(effect.toString());
|
||||
}
|
||||
|
||||
return toolTipText;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,7 +67,8 @@ public class ClickableTinkerAction extends Clickable {
|
|||
Colour c1 = new Colour(1.0F, 0.2F, 0.6F, 1.0F);
|
||||
Colour c2 = new Colour(0.6F, 0.2F, 1.0F, 1.0F);
|
||||
|
||||
MuseRenderer.drawModuleAt(x - 8, y - 8, gui, module, moduleTag, null);
|
||||
Colour.getGreyscale(1.0f, 1.0f).doGL();
|
||||
MuseRenderer.drawIconAt(x - 8, y - 8, gui, action.getIcon(), null);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.machinemuse.general.geometry.FlyFromMiddlePoint2D;
|
|||
import net.machinemuse.general.geometry.MuseRenderer;
|
||||
import net.machinemuse.general.geometry.Point2D;
|
||||
import net.machinemuse.powersuits.item.ItemUtils;
|
||||
import net.machinemuse.powersuits.item.TinkerAction;
|
||||
import net.machinemuse.powersuits.network.MusePacketTinkerRequest;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -24,12 +25,11 @@ public class GuiTinkerTable extends MuseGui {
|
|||
protected EntityClientPlayerMP player;
|
||||
protected List<ClickableItem> itemButtons;
|
||||
protected int selectedItemStack = -1;
|
||||
protected List<ClickableTinkerAction> augButtons;
|
||||
protected int selectedAugClickable = -1;
|
||||
protected List<ClickableTinkerAction> tinkeringButtons;
|
||||
protected int selectedTinkerAction = -1;
|
||||
protected List<ItemStack> workingUpgradeCost;
|
||||
protected List<ItemStack> workingDowngradeRefund;
|
||||
protected ClickableButton upgradeButton;
|
||||
protected ClickableButton downgradeButton;
|
||||
protected ClickableButton applyTinkerButton;
|
||||
protected StatsFrame statsFrame;
|
||||
|
||||
/**
|
||||
|
@ -64,8 +64,8 @@ public class GuiTinkerTable extends MuseGui {
|
|||
.getModularItemSlotsInInventory(player.inventory);
|
||||
|
||||
List<Point2D> points = this.pointsInLine(slots.size(),
|
||||
new Point2D(-0.9F, -0.9F),
|
||||
new Point2D(-0.9F, 0.9F));
|
||||
new Point2D(-0.9F, 0.9F),
|
||||
new Point2D(-0.9F, -0.9F));
|
||||
|
||||
Iterator<Integer> slotiterator = slots.iterator();
|
||||
Iterator<Point2D> pointiterator = points.iterator();
|
||||
|
@ -80,24 +80,28 @@ public class GuiTinkerTable extends MuseGui {
|
|||
|
||||
}
|
||||
|
||||
protected void loadAugList(ClickableItem itemClicked) {
|
||||
protected void loadTinkersList(ClickableItem itemClicked) {
|
||||
statsFrame = new StatsFrame(
|
||||
absX(-0.7f), absY(-0.9f),
|
||||
absX(0.3f), absY(0.9f),
|
||||
absX(0f), absY(-0.9f),
|
||||
absX(0.9f), absY(0.9f),
|
||||
Colour.LIGHTBLUE.withAlpha(0.8),
|
||||
Colour.DARKBLUE.withAlpha(0.8),
|
||||
itemClicked.getItem());
|
||||
// augButtons = new ArrayList<ClickableTinkering>();
|
||||
// List<NBTTagCompound> workingAugs = ItemUtils
|
||||
// .getItemModulesWithPadding(itemClicked
|
||||
// .getItem());
|
||||
// List<Point2D> points = this.pointsInLine(workingAugs.size(),
|
||||
// new Point2D(-0.7F, -0.9F),
|
||||
// new Point2D(-0.7F, 0.9F));
|
||||
// Iterator<Point2D> pointiter = points.iterator();
|
||||
// for (NBTTagCompound aug : workingAugs) {
|
||||
// augButtons.add(new ClickableTinkering(aug, pointiter.next()));
|
||||
// }
|
||||
tinkeringButtons = new ArrayList();
|
||||
List<TinkerAction> workingTinkers = ItemUtils
|
||||
.getValidTinkersForItem(player, itemClicked
|
||||
.getItem());
|
||||
if (workingTinkers.size() > 0) {
|
||||
List<Point2D> points = this.pointsInLine(workingTinkers.size(),
|
||||
new Point2D(-0.7F, -0.9F),
|
||||
new Point2D(-0.7F, 0.9F));
|
||||
Iterator<Point2D> pointiter = points.iterator();
|
||||
for (TinkerAction tinker : workingTinkers) {
|
||||
tinkeringButtons.add(new ClickableTinkerAction(tinker,
|
||||
pointiter
|
||||
.next()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public void drawNthItem(ItemStack stack, int n) {
|
||||
|
@ -115,12 +119,12 @@ public class GuiTinkerTable extends MuseGui {
|
|||
10);
|
||||
}
|
||||
|
||||
if (selectedAugClickable != -1) {
|
||||
if (selectedTinkerAction != -1) {
|
||||
MuseRenderer
|
||||
.drawCircleAround(
|
||||
absX(augButtons.get(selectedAugClickable)
|
||||
absX(tinkeringButtons.get(selectedTinkerAction)
|
||||
.getPosition().x()),
|
||||
absY(augButtons.get(selectedAugClickable)
|
||||
absY(tinkeringButtons.get(selectedTinkerAction)
|
||||
.getPosition().y()),
|
||||
10);
|
||||
|
||||
|
@ -153,47 +157,29 @@ public class GuiTinkerTable extends MuseGui {
|
|||
if (statsFrame != null) {
|
||||
statsFrame.draw();
|
||||
}
|
||||
// drawClickables(this.augButtons);
|
||||
// drawUpgradeDowngrade();
|
||||
drawClickables(this.tinkeringButtons);
|
||||
drawApplyTinkerFrame();
|
||||
drawToolTip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the upgrade/downgrade cost, buttons, and labels.
|
||||
*/
|
||||
public void drawUpgradeDowngrade() {
|
||||
public void drawApplyTinkerFrame() {
|
||||
if (workingUpgradeCost != null && workingUpgradeCost.size() > 0) {
|
||||
this.drawString(fontRenderer, "Cost:", absX(0.4F),
|
||||
absY(-0.7F),
|
||||
new Colour(0.5F, 1.0F, 0.5F, 1.0F).getInt());
|
||||
MuseRenderer.drawString("Cost:", absX(-0.6F),
|
||||
absY(0.5F),
|
||||
new Colour(0.5F, 1.0F, 0.5F, 1.0F));
|
||||
List<Point2D> points = this.pointsInLine(workingUpgradeCost.size(),
|
||||
new Point2D(0.4F, -0.5F),
|
||||
new Point2D(0.9F, -0.5F));
|
||||
new Point2D(-0.4F, 0.7F),
|
||||
new Point2D(-0.8F, 0.7F));
|
||||
Iterator<Point2D> pointiter = points.iterator();
|
||||
for (ItemStack item : workingUpgradeCost) {
|
||||
Point2D next = pointiter.next();
|
||||
MuseRenderer.drawItemAt(absX(next.x()), absY(next.y()), this,
|
||||
item);
|
||||
}
|
||||
upgradeButton.draw(this.getRenderEngine(), this);
|
||||
}
|
||||
if (workingDowngradeRefund != null && workingDowngradeRefund.size() > 0) {
|
||||
MuseRenderer.on2D();
|
||||
this.drawString(fontRenderer, "Refund:", absX(0.4F),
|
||||
absY(0.3F),
|
||||
new Colour(1.0F, 0.6F, 0.2F, 1.0F).getInt());
|
||||
MuseRenderer.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();
|
||||
MuseRenderer.drawItemAt(absX(next.x()), absY(next.y()), this,
|
||||
item);
|
||||
}
|
||||
downgradeButton.draw(this.getRenderEngine(), this);
|
||||
applyTinkerButton.draw(this.getRenderEngine(), this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -202,11 +188,10 @@ public class GuiTinkerTable extends MuseGui {
|
|||
* Clear all the UI stuff that's there.
|
||||
*/
|
||||
protected void clearSelections() {
|
||||
this.selectedAugClickable = -1;
|
||||
this.selectedTinkerAction = -1;
|
||||
this.workingUpgradeCost = null;
|
||||
this.workingDowngradeRefund = null;
|
||||
this.upgradeButton = null;
|
||||
this.downgradeButton = null;
|
||||
this.applyTinkerButton = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,22 +203,18 @@ public class GuiTinkerTable extends MuseGui {
|
|||
if (button == 0) // Left Mouse Button
|
||||
{
|
||||
int itemClicked = hitboxClickables(x, y, this.itemButtons);
|
||||
int augClicked = hitboxClickables(x, y, this.augButtons);
|
||||
int augClicked = hitboxClickables(x, y, this.tinkeringButtons);
|
||||
if (itemClicked != -1) {
|
||||
clearSelections();
|
||||
this.selectedItemStack = itemClicked;
|
||||
loadAugList(itemButtons.get(itemClicked));
|
||||
loadTinkersList(itemButtons.get(itemClicked));
|
||||
} else if (augClicked != -1) {
|
||||
this.selectedAugClickable = augClicked;
|
||||
this.selectedTinkerAction = augClicked;
|
||||
refreshUpgrades();
|
||||
} else if (upgradeButton != null
|
||||
&& upgradeButton.enabled
|
||||
&& upgradeButton.hitBox(x, y, this)) {
|
||||
doUpgrade();
|
||||
} else if (downgradeButton != null
|
||||
&& downgradeButton.enabled
|
||||
&& downgradeButton.hitBox(x, y, this)) {
|
||||
doDowngrade();
|
||||
} else if (applyTinkerButton != null
|
||||
&& applyTinkerButton.enabled
|
||||
&& applyTinkerButton.hitBox(x, y, this)) {
|
||||
doTinker();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -250,7 +231,7 @@ public class GuiTinkerTable extends MuseGui {
|
|||
* Performs all the functions associated with the upgrade button. This
|
||||
* requires communicating with the server.
|
||||
*/
|
||||
private void doUpgrade() {
|
||||
private void doTinker() {
|
||||
if (ItemUtils.hasInInventory(workingUpgradeCost, player.inventory)) {
|
||||
// ItemUtils.deleteFromInventory(workingUpgradeCost,
|
||||
// player.inventory);
|
||||
|
@ -260,7 +241,7 @@ public class GuiTinkerTable extends MuseGui {
|
|||
new MusePacketTinkerRequest(
|
||||
(Player) player,
|
||||
itemButtons.get(selectedItemStack).inventorySlot,
|
||||
augButtons.get(selectedAugClickable).module
|
||||
tinkeringButtons.get(selectedTinkerAction).action
|
||||
.getName()
|
||||
).getPacket()
|
||||
);
|
||||
|
@ -268,23 +249,26 @@ public class GuiTinkerTable extends MuseGui {
|
|||
}
|
||||
}
|
||||
|
||||
static boolean refreshing = false;
|
||||
|
||||
/**
|
||||
* Updates the upgrade/downgrade buttons. May someday also include repairs.
|
||||
*/
|
||||
private void refreshUpgrades() {
|
||||
if (selectedAugClickable != -1) {
|
||||
if (selectedTinkerAction != -1
|
||||
&& tinkeringButtons.size() > selectedTinkerAction) {
|
||||
this.workingUpgradeCost =
|
||||
augButtons.get(selectedAugClickable).module.getCost(player,
|
||||
augButtons.get(selectedAugClickable).moduleTag);
|
||||
tinkeringButtons.get(selectedTinkerAction).action
|
||||
.getCosts();
|
||||
if (workingUpgradeCost != null) {
|
||||
this.upgradeButton = new ClickableButton("Upgrade",
|
||||
new Point2D(0.6F, -0.2F),
|
||||
new Point2D(0.25F, 0.05F), true);
|
||||
this.applyTinkerButton = new ClickableButton("Apply",
|
||||
new Point2D(-.25F, 0.8F),
|
||||
new Point2D(0.20F, 0.05F), true);
|
||||
if (ItemUtils.hasInInventory(workingUpgradeCost,
|
||||
player.inventory)) {
|
||||
upgradeButton.enabled = true;
|
||||
applyTinkerButton.enabled = true;
|
||||
} else {
|
||||
upgradeButton.enabled = false;
|
||||
applyTinkerButton.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -300,9 +284,9 @@ public class GuiTinkerTable extends MuseGui {
|
|||
if (itemHover > -1) {
|
||||
hitTip = itemButtons.get(itemHover).getToolTip();
|
||||
}
|
||||
int augHover = hitboxClickables(x, y, this.augButtons);
|
||||
int augHover = hitboxClickables(x, y, this.tinkeringButtons);
|
||||
if (augHover > -1) {
|
||||
hitTip = augButtons.get(augHover).getToolTip();
|
||||
hitTip = tinkeringButtons.get(augHover).getToolTip();
|
||||
}
|
||||
return hitTip;
|
||||
}
|
||||
|
@ -311,7 +295,7 @@ public class GuiTinkerTable extends MuseGui {
|
|||
public void refresh() {
|
||||
loadItems();
|
||||
if (selectedItemStack != -1 && selectedItemStack < itemButtons.size()) {
|
||||
loadAugList(itemButtons.get(selectedItemStack));
|
||||
loadTinkersList(itemButtons.get(selectedItemStack));
|
||||
}
|
||||
refreshUpgrades();
|
||||
}
|
||||
|
|
53
net/machinemuse/powersuits/gui/ItemInfoFrame.java
Normal file
53
net/machinemuse/powersuits/gui/ItemInfoFrame.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package net.machinemuse.powersuits.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.machinemuse.general.geometry.Colour;
|
||||
import net.machinemuse.general.geometry.MuseRenderer;
|
||||
import net.machinemuse.powersuits.item.IModularItem;
|
||||
import net.machinemuse.powersuits.item.ItemUtils;
|
||||
import net.machinemuse.powersuits.item.TinkerAction;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class ItemInfoFrame extends GuiFrame {
|
||||
protected ItemStack stack;
|
||||
protected TinkerAction previewAction;
|
||||
|
||||
public ItemInfoFrame(int left, int top, int right, int bottom,
|
||||
Colour borderColour, Colour insideColour, ItemStack itemStack) {
|
||||
super(left, top, right, bottom, borderColour, insideColour);
|
||||
this.stack = itemStack;
|
||||
this.left *= 2.0;
|
||||
this.right *= 2.0;
|
||||
this.top *= 2.0;
|
||||
this.bottom *= 2.0;
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScaled(0.50, 0.50, 0.50);
|
||||
drawBackground();
|
||||
int xoffset = 8;
|
||||
int yoffset = 8;
|
||||
int i = 0;
|
||||
List<String> info = ((IModularItem) stack.getItem()).getLongInfo();
|
||||
for (String propName : propertiesToList) {
|
||||
double propValue = ItemUtils.getDoubleOrZero(
|
||||
ItemUtils.getItemModularProperties(stack), propName);
|
||||
String propValueString = String.format("%.2f", propValue);
|
||||
int strlen = MuseGui.getFontRenderer().getStringWidth(
|
||||
propValueString);
|
||||
MuseRenderer.drawString(propName, left + xoffset,
|
||||
top + yoffset + i * 10, borderColour);
|
||||
MuseRenderer.drawString(propValueString, right - xoffset
|
||||
- strlen - 40,
|
||||
top + yoffset + i * 10, borderColour);
|
||||
i++;
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,29 @@
|
|||
package net.machinemuse.powersuits.gui;
|
||||
|
||||
public class MuseIcon {
|
||||
String texturefile;
|
||||
int index;
|
||||
|
||||
public MuseIcon() {
|
||||
// TODO Auto-generated constructor stub
|
||||
public MuseIcon(String texturefile, int index) {
|
||||
super();
|
||||
this.texturefile = texturefile;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String getTexturefile() {
|
||||
return texturefile;
|
||||
}
|
||||
|
||||
public void setTexturefile(String texturefile) {
|
||||
this.texturefile = texturefile;
|
||||
}
|
||||
|
||||
public int getIconIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIconIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,33 +1,43 @@
|
|||
package net.machinemuse.powersuits.gui;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.machinemuse.general.geometry.Colour;
|
||||
import net.machinemuse.general.geometry.MuseRenderer;
|
||||
import net.machinemuse.powersuits.common.NBTTagAccessor;
|
||||
import net.machinemuse.powersuits.item.ItemUtils;
|
||||
import net.machinemuse.powersuits.item.TinkerAction;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class StatsFrame extends GuiFrame {
|
||||
protected NBTTagCompound properties;
|
||||
protected ItemStack stack;
|
||||
protected List<String> propertiesToList;
|
||||
protected Set<String> propertiesToList;
|
||||
protected TinkerAction previewAction;
|
||||
|
||||
public StatsFrame(int left, int top, int right, int bottom,
|
||||
Colour borderColour, Colour insideColour, ItemStack itemStack) {
|
||||
super(left, top, right, bottom, borderColour, insideColour);
|
||||
this.stack = itemStack;
|
||||
this.properties = ItemUtils.getItemModularProperties(stack);
|
||||
this.propertiesToList = ItemUtils.getAsModular(stack.getItem())
|
||||
.getValidProperties();
|
||||
this.propertiesToList = NBTTagAccessor.getMap(properties).keySet();
|
||||
this.left *= 2.0;
|
||||
this.right *= 2.0;
|
||||
this.top *= 2.0;
|
||||
this.bottom *= 2.0;
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScaled(0.50, 0.50, 0.50);
|
||||
drawBackground();
|
||||
int xoffset = 8;
|
||||
int yoffset = 8;
|
||||
for (int i = 0; i < propertiesToList.size(); i++) {
|
||||
String propName = propertiesToList.get(i);
|
||||
int i = 0;
|
||||
for (String propName : propertiesToList) {
|
||||
double propValue = ItemUtils.getDoubleOrZero(properties, propName);
|
||||
String propValueString = String.format("%.2f", propValue);
|
||||
int strlen = MuseGui.getFontRenderer().getStringWidth(
|
||||
|
@ -35,10 +45,11 @@ public class StatsFrame extends GuiFrame {
|
|||
MuseRenderer.drawString(propName, left + xoffset,
|
||||
top + yoffset + i * 10, borderColour);
|
||||
MuseRenderer.drawString(propValueString, right - xoffset
|
||||
- strlen,
|
||||
- strlen - 40,
|
||||
top + yoffset + i * 10, borderColour);
|
||||
|
||||
i++;
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.List;
|
|||
|
||||
import net.machinemuse.powersuits.common.Config;
|
||||
|
||||
|
||||
/**
|
||||
* Interface for ItemPowerArmor and ItemPowerTool to share.
|
||||
*
|
||||
|
@ -12,6 +11,14 @@ import net.machinemuse.powersuits.common.Config;
|
|||
*/
|
||||
public interface IModularItem {
|
||||
|
||||
public static final String MAXIMUM_ENERGY = "Maximum Energy";
|
||||
public static final String CURRENT_ENERGY = "Current Energy";
|
||||
public static final String BATTERY_WEIGHT = "Battery Weight";
|
||||
public static final String ARMOR_WEIGHT = "Armor Weight";
|
||||
public static final String ARMOR_DURABILITY = "Armor Durability";
|
||||
public static final String ARMOR_VALUE = "Armor Value";
|
||||
public static final String PASSIVE_SHIELDING = "Passive Shielding";
|
||||
|
||||
public Config.Items getItemType();
|
||||
|
||||
public List<String> getValidProperties();
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraftforge.common.ISpecialArmor;
|
||||
import universalelectricity.core.electricity.ElectricInfo;
|
||||
import universalelectricity.core.implement.IItemElectric;
|
||||
|
||||
/**
|
||||
|
@ -37,6 +38,7 @@ public abstract class ItemPowerArmor extends ItemArmor
|
|||
public ItemPowerArmor(int id, EnumArmorMaterial material,
|
||||
int renderIndex, int armorType) {
|
||||
super(id, material, renderIndex, armorType);
|
||||
setTextureFile("/icons.png");
|
||||
setMaxStackSize(1);
|
||||
setCreativeTab(Config.getCreativeTab());
|
||||
}
|
||||
|
@ -73,7 +75,26 @@ public abstract class ItemPowerArmor extends ItemArmor
|
|||
*/
|
||||
@Override
|
||||
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
|
||||
return 4;
|
||||
double totalarmor = 0;
|
||||
NBTTagCompound props = ItemUtils.getItemModularProperties(armor);
|
||||
|
||||
double physArmor = ItemUtils.getDoubleOrZero(props,
|
||||
IModularItem.ARMOR_VALUE);
|
||||
double armorDura = ItemUtils.getDoubleOrZero(props,
|
||||
IModularItem.ARMOR_DURABILITY);
|
||||
if (armorDura > 0) {
|
||||
totalarmor += physArmor;
|
||||
}
|
||||
|
||||
double elecArmor = ItemUtils.getDoubleOrZero(props,
|
||||
IModularItem.PASSIVE_SHIELDING);
|
||||
double energy = ItemUtils.getDoubleOrZero(props,
|
||||
IModularItem.CURRENT_ENERGY);
|
||||
if (energy > 0) {
|
||||
totalarmor += elecArmor;
|
||||
}
|
||||
|
||||
return (int) totalarmor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,10 +132,11 @@ public abstract class ItemPowerArmor extends ItemArmor
|
|||
@Override
|
||||
public double onReceive(double amps, double voltage, ItemStack itemStack) {
|
||||
double stored = getJoules(itemStack);
|
||||
double received = Math.min(amps * voltage, stored
|
||||
- getMaxJoules(itemStack));
|
||||
double receivable = ElectricInfo.getJoules(amps, voltage, 1);
|
||||
double received = Math.min(receivable,
|
||||
getMaxJoules(itemStack) - stored);
|
||||
setJoules(stored + received, itemStack);
|
||||
return received;
|
||||
return receivable - received;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -143,20 +165,23 @@ public abstract class ItemPowerArmor extends ItemArmor
|
|||
public double getJoules(Object... data) {
|
||||
NBTTagCompound itemProperties = ItemUtils
|
||||
.getItemModularProperties(getStackFromData(data));
|
||||
return ItemUtils.getDoubleOrZero(itemProperties, "Current energy");
|
||||
return ItemUtils.getDoubleOrZero(itemProperties,
|
||||
IModularItem.CURRENT_ENERGY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJoules(double joules, Object... data) {
|
||||
NBTTagCompound itemProperties = ItemUtils
|
||||
.getItemModularProperties(getStackFromData(data));
|
||||
itemProperties.setDouble("Current energy", joules);
|
||||
itemProperties.setDouble(IModularItem.CURRENT_ENERGY, joules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxJoules(Object... data) {
|
||||
|
||||
return 0;
|
||||
NBTTagCompound itemProperties = ItemUtils
|
||||
.getItemModularProperties(getStackFromData(data));
|
||||
return ItemUtils.getDoubleOrZero(itemProperties,
|
||||
IModularItem.MAXIMUM_ENERGY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -165,7 +190,7 @@ public abstract class ItemPowerArmor extends ItemArmor
|
|||
}
|
||||
|
||||
/**
|
||||
* Helper function to deal with varargs
|
||||
* Helper function to deal with UE's use of varargs
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
|
|
|
@ -22,8 +22,7 @@ public class ItemPowerArmorFeet extends ItemPowerArmor {
|
|||
3); // armor type. 0=head, 1=torso, 2=legs, 3=feet
|
||||
itemType = Config.Items.PowerArmorFeet;
|
||||
setItemName(itemType.idName);
|
||||
|
||||
setIconIndex(63);
|
||||
LanguageRegistry.addName(this, itemType.englishName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ public class ItemPowerArmorHead extends ItemPowerArmor {
|
|||
0); // armor type. 0=head, 1=torso, 2=legs, 3=feet
|
||||
itemType = Config.Items.PowerArmorHead;
|
||||
setItemName(itemType.idName);
|
||||
setIconIndex(15);
|
||||
LanguageRegistry.addName(this, itemType.englishName);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ public class ItemPowerArmorLegs extends ItemPowerArmor {
|
|||
2); // armor type. 0=head, 1=torso, 2=legs, 3=feet
|
||||
itemType = Config.Items.PowerArmorLegs;
|
||||
setItemName(itemType.idName);
|
||||
|
||||
setIconIndex(47);
|
||||
LanguageRegistry.addName(this, itemType.englishName);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ public class ItemPowerArmorTorso extends ItemPowerArmor {
|
|||
1); // armor type.
|
||||
itemType = Config.Items.PowerArmorTorso;
|
||||
setItemName(itemType.idName);
|
||||
|
||||
setIconIndex(31);
|
||||
LanguageRegistry.addName(this, itemType.englishName);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import net.minecraft.item.ItemTool;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import universalelectricity.core.electricity.ElectricInfo;
|
||||
import universalelectricity.core.implement.IItemElectric;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
@ -29,19 +30,6 @@ public class ItemPowerTool extends ItemTool
|
|||
IModularItem,
|
||||
IItemElectric {
|
||||
|
||||
/**
|
||||
* Copied the comment for reference
|
||||
*/
|
||||
// /** Array of blocks the tool has extra effect against. */
|
||||
// private Block[] blocksEffectiveAgainst;
|
||||
// public float efficiencyOnProperMaterial = 4.0F;
|
||||
//
|
||||
// /** Damage versus entities. */
|
||||
// public int damageVsEntity;
|
||||
//
|
||||
// /** The material this tool is made from. */
|
||||
// protected EnumToolMaterial toolMaterial;
|
||||
|
||||
/**
|
||||
* Constructor. Takes information from the Config.Items enum.
|
||||
*/
|
||||
|
@ -60,7 +48,8 @@ public class ItemPowerTool extends ItemTool
|
|||
setMaxDamage(0);
|
||||
this.damageVsEntity = 1;
|
||||
setCreativeTab(Config.getCreativeTab());
|
||||
setIconIndex(Config.Items.PowerTool.iconIndex);
|
||||
setIconIndex(9);
|
||||
setTextureFile("/icons.png");
|
||||
setItemName(Config.Items.PowerTool.idName);
|
||||
LanguageRegistry.addName(this, Config.Items.PowerTool.englishName);
|
||||
}
|
||||
|
@ -178,8 +167,8 @@ public class ItemPowerTool extends ItemTool
|
|||
@Override
|
||||
public List<String> getValidProperties() {
|
||||
return Arrays.asList(
|
||||
"Max Energy",
|
||||
"Current Energy",
|
||||
IModularItem.CURRENT_ENERGY,
|
||||
IModularItem.MAXIMUM_ENERGY,
|
||||
"Shovel Level",
|
||||
"Axe Level",
|
||||
"Pick level");
|
||||
|
@ -188,10 +177,11 @@ public class ItemPowerTool extends ItemTool
|
|||
@Override
|
||||
public double onReceive(double amps, double voltage, ItemStack itemStack) {
|
||||
double stored = getJoules(itemStack);
|
||||
double received = Math.min(amps * voltage, stored
|
||||
- getMaxJoules(itemStack));
|
||||
double receivable = ElectricInfo.getJoules(amps, voltage, 1);
|
||||
double received = Math.min(receivable,
|
||||
getMaxJoules(itemStack) - stored);
|
||||
setJoules(stored + received, itemStack);
|
||||
return received;
|
||||
return receivable - received;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -220,20 +210,23 @@ public class ItemPowerTool extends ItemTool
|
|||
public double getJoules(Object... data) {
|
||||
NBTTagCompound itemProperties = ItemUtils
|
||||
.getItemModularProperties(getStackFromData(data));
|
||||
return ItemUtils.getDoubleOrZero(itemProperties, "Current energy");
|
||||
return ItemUtils.getDoubleOrZero(itemProperties,
|
||||
IModularItem.CURRENT_ENERGY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJoules(double joules, Object... data) {
|
||||
NBTTagCompound itemProperties = ItemUtils
|
||||
.getItemModularProperties(getStackFromData(data));
|
||||
itemProperties.setDouble("Current energy", joules);
|
||||
itemProperties.setDouble(IModularItem.CURRENT_ENERGY, joules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxJoules(Object... data) {
|
||||
|
||||
return 0;
|
||||
NBTTagCompound itemProperties = ItemUtils
|
||||
.getItemModularProperties(getStackFromData(data));
|
||||
return ItemUtils.getDoubleOrZero(itemProperties,
|
||||
IModularItem.MAXIMUM_ENERGY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.Iterator;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.machinemuse.powersuits.common.Config;
|
||||
import net.machinemuse.powersuits.trash.IPowerModuleWeight;
|
||||
import net.machinemuse.powersuits.trash.ModuleUtils;
|
||||
import net.machinemuse.powersuits.trash.PowerModule;
|
||||
|
@ -16,6 +17,18 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ItemUtils {
|
||||
|
||||
public static List<TinkerAction> getValidTinkersForItem(
|
||||
EntityPlayer player, ItemStack stack) {
|
||||
List<TinkerAction> validActions = new ArrayList();
|
||||
for (TinkerAction action : Config.getTinkerings().values()) {
|
||||
if (action.validate(player, stack)) {
|
||||
validActions.add(action);
|
||||
}
|
||||
}
|
||||
return validActions;
|
||||
}
|
||||
|
||||
public static NBTTagCompound getItemModularProperties(ItemStack stack) {
|
||||
NBTTagCompound properties = null;
|
||||
if (stack.hasTagCompound()) {
|
||||
|
|
|
@ -4,7 +4,11 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import net.machinemuse.powersuits.gui.MuseIcon;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class TinkerAction {
|
||||
public String name;
|
||||
|
@ -13,12 +17,55 @@ public class TinkerAction {
|
|||
public List<ItemStack> costs;
|
||||
public MuseIcon icon;
|
||||
public String description;
|
||||
public boolean[] validSlots;
|
||||
|
||||
public TinkerAction(String name) {
|
||||
public TinkerAction(String name, boolean[] validSlots) {
|
||||
this.name = name;
|
||||
requirements = new ArrayList();
|
||||
effects = new ArrayList();
|
||||
costs = new ArrayList();
|
||||
this.validSlots = validSlots;
|
||||
}
|
||||
|
||||
public boolean validate(EntityPlayer player, ItemStack stack) {
|
||||
boolean slot = validForItemType(stack.getItem());
|
||||
boolean req = validateRequirements(ItemUtils
|
||||
.getItemModularProperties(stack));
|
||||
boolean cost = validateCost(player.inventory);
|
||||
|
||||
return slot && req && cost;
|
||||
}
|
||||
|
||||
public boolean validForItemType(Item item) {
|
||||
if (item instanceof ItemPowerArmorHead) {
|
||||
return validSlots[0];
|
||||
}
|
||||
if (item instanceof ItemPowerArmorTorso) {
|
||||
return validSlots[1];
|
||||
}
|
||||
if (item instanceof ItemPowerArmorLegs) {
|
||||
return validSlots[2];
|
||||
}
|
||||
if (item instanceof ItemPowerArmorFeet) {
|
||||
return validSlots[3];
|
||||
}
|
||||
if (item instanceof ItemPowerTool) {
|
||||
return validSlots[4];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean validateRequirements(NBTTagCompound nbt) {
|
||||
for (TinkerRequirement requirement : requirements) {
|
||||
if (!requirement.test(nbt)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean validateCost(InventoryPlayer inventory) {
|
||||
return ItemUtils.hasInInventory(costs, inventory);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -29,40 +76,52 @@ public class TinkerAction {
|
|||
return requirements;
|
||||
}
|
||||
|
||||
public void addRequirement(TinkerRequirement requirement) {
|
||||
public TinkerAction addRequirement(TinkerRequirement requirement) {
|
||||
this.requirements.add(requirement);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<TinkerEffect> getEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
||||
public void addEffect(TinkerEffect effect) {
|
||||
public TinkerAction addEffect(TinkerEffect effect) {
|
||||
this.effects.add(effect);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<ItemStack> getCosts() {
|
||||
return costs;
|
||||
}
|
||||
|
||||
public void addCosts(ItemStack cost) {
|
||||
public TinkerAction addCost(ItemStack cost) {
|
||||
this.costs.add(cost);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MuseIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(MuseIcon icon) {
|
||||
public TinkerAction setIcon(MuseIcon icon) {
|
||||
this.icon = icon;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
public TinkerAction setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void apply(ItemStack stack) {
|
||||
NBTTagCompound tag = ItemUtils.getItemModularProperties(stack);
|
||||
for (TinkerEffect effect : this.effects) {
|
||||
effect.applyEffect(tag);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,27 +1,14 @@
|
|||
package net.machinemuse.powersuits.item;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class TinkerEffect {
|
||||
public static Random random = new Random();
|
||||
public String propertyAffected;
|
||||
public double minimumEffect;
|
||||
public double maximumEffect;
|
||||
public abstract class TinkerEffect {
|
||||
public abstract void applyEffect(NBTTagCompound properties);
|
||||
|
||||
public TinkerEffect(String propertyAffected, double minimumEffect,
|
||||
double maximumEffect) {
|
||||
super();
|
||||
this.propertyAffected = propertyAffected;
|
||||
this.minimumEffect = minimumEffect;
|
||||
this.maximumEffect = maximumEffect;
|
||||
}
|
||||
public abstract double simEffectMin(NBTTagCompound properties);
|
||||
|
||||
public void applyEffect(NBTTagCompound properties) {
|
||||
double prev = ItemUtils.getDoubleOrZero(properties, propertyAffected);
|
||||
double effect = (maximumEffect - minimumEffect) * random.nextDouble()
|
||||
+ minimumEffect;
|
||||
properties.setDouble(propertyAffected, Math.max(0, prev + effect));
|
||||
}
|
||||
public abstract double simEffectMax(NBTTagCompound properties);
|
||||
|
||||
@Override
|
||||
public abstract String toString();
|
||||
}
|
||||
|
|
54
net/machinemuse/powersuits/item/TinkerEffectAdditive.java
Normal file
54
net/machinemuse/powersuits/item/TinkerEffectAdditive.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package net.machinemuse.powersuits.item;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class TinkerEffectAdditive extends TinkerEffect {
|
||||
public static Random random = new Random();
|
||||
public String propertyAffected;
|
||||
public double minimumEffect;
|
||||
public double maximumEffect;
|
||||
|
||||
public TinkerEffectAdditive(String propertyAffected, double minimumEffect,
|
||||
double maximumEffect) {
|
||||
super();
|
||||
this.propertyAffected = propertyAffected;
|
||||
this.minimumEffect = minimumEffect;
|
||||
this.maximumEffect = maximumEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEffect(NBTTagCompound properties) {
|
||||
double prev = ItemUtils.getDoubleOrZero(properties, propertyAffected);
|
||||
double effect = (maximumEffect - minimumEffect) * random.nextDouble()
|
||||
+ minimumEffect;
|
||||
if (prev + effect <= 0) {
|
||||
properties.removeTag(propertyAffected);
|
||||
} else {
|
||||
properties.setDouble(propertyAffected, prev + effect);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
|
||||
format.setPositivePrefix("+");
|
||||
format.setMaximumFractionDigits(2);
|
||||
return this.propertyAffected + " " + format.format(minimumEffect)
|
||||
+ "~" + format.format(maximumEffect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double simEffectMin(NBTTagCompound properties) {
|
||||
return ItemUtils.getDoubleOrZero(properties, propertyAffected)
|
||||
+ minimumEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double simEffectMax(NBTTagCompound properties) {
|
||||
return ItemUtils.getDoubleOrZero(properties, propertyAffected)
|
||||
+ maximumEffect;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package net.machinemuse.powersuits.item;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class TinkerEffectMultiplicative extends TinkerEffect {
|
||||
public static Random random = new Random();
|
||||
public String propertyAffected;
|
||||
public double minimumEffect;
|
||||
public double maximumEffect;
|
||||
|
||||
public TinkerEffectMultiplicative(String propertyAffected,
|
||||
double minimumEffect,
|
||||
double maximumEffect) {
|
||||
super();
|
||||
this.propertyAffected = propertyAffected;
|
||||
this.minimumEffect = minimumEffect;
|
||||
this.maximumEffect = maximumEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEffect(NBTTagCompound properties) {
|
||||
double prev = ItemUtils.getDoubleOrZero(properties, propertyAffected);
|
||||
double effect = (maximumEffect - minimumEffect) * random.nextDouble()
|
||||
+ minimumEffect;
|
||||
if (prev == 0) {
|
||||
properties.removeTag(propertyAffected);
|
||||
} else {
|
||||
properties.setDouble(propertyAffected, prev * effect);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
|
||||
format.setPositivePrefix("+");
|
||||
format.setMaximumFractionDigits(2);
|
||||
return this.propertyAffected + " "
|
||||
+ format.format((minimumEffect - 1) * 100)
|
||||
+ "-" + format.format((maximumEffect - 1) * 100) + "%%";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double simEffectMin(NBTTagCompound properties) {
|
||||
return ItemUtils.getDoubleOrZero(properties, propertyAffected)
|
||||
* minimumEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double simEffectMax(NBTTagCompound properties) {
|
||||
return ItemUtils.getDoubleOrZero(properties, propertyAffected)
|
||||
* maximumEffect;
|
||||
}
|
||||
}
|
|
@ -25,9 +25,11 @@ public class TinkerRequirement {
|
|||
return testvalue < value;
|
||||
case '>':
|
||||
return testvalue > value;
|
||||
case '=':
|
||||
return testvalue == value;
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid operator; must be one of < or >");
|
||||
"Invalid operator; must be one of <, =, or >");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ package net.machinemuse.powersuits.network;
|
|||
|
||||
import java.io.DataInputStream;
|
||||
|
||||
import net.machinemuse.powersuits.common.MuseLogger;
|
||||
import net.machinemuse.powersuits.gui.MuseGui;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
|
@ -52,7 +51,6 @@ public class MusePacketInventoryRefresh extends MusePacket {
|
|||
public void handleClient(EntityClientPlayerMP player) {
|
||||
IInventory inventory = player.inventory;
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
MuseLogger.logDebug("Received slot " + slot);
|
||||
GuiScreen playerscreen = Minecraft.getMinecraft().currentScreen;
|
||||
if (playerscreen != null && playerscreen instanceof MuseGui) {
|
||||
((MuseGui) playerscreen).refresh();
|
||||
|
|
|
@ -7,9 +7,9 @@ import java.io.DataInputStream;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.machinemuse.powersuits.common.Config;
|
||||
import net.machinemuse.powersuits.item.ItemUtils;
|
||||
import net.machinemuse.powersuits.trash.ModuleUtils;
|
||||
import net.machinemuse.powersuits.trash.PowerModule;
|
||||
import net.machinemuse.powersuits.item.TinkerAction;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
@ -30,23 +30,23 @@ import cpw.mods.fml.relauncher.Side;
|
|||
*/
|
||||
public class MusePacketTinkerRequest extends MusePacket {
|
||||
protected ItemStack stack;
|
||||
protected int slot;
|
||||
protected String moduleName;
|
||||
protected int itemSlot;
|
||||
protected String tinkerName;
|
||||
|
||||
/**
|
||||
* Constructor for sending this packet.
|
||||
*
|
||||
* @param player
|
||||
* Player making the request
|
||||
* @param slotToUpgrade
|
||||
* @param itemSlot
|
||||
* Slot containing the item for which the upgrade is requested
|
||||
* @param augToUpgrade
|
||||
* @param tinkerName
|
||||
*/
|
||||
public MusePacketTinkerRequest(Player player, int slotToUpgrade,
|
||||
String augToUpgrade) {
|
||||
public MusePacketTinkerRequest(Player player, int itemSlot,
|
||||
String tinkerName) {
|
||||
super(player);
|
||||
writeInt(slotToUpgrade);
|
||||
writeString(augToUpgrade);
|
||||
writeInt(itemSlot);
|
||||
writeString(tinkerName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,31 +59,30 @@ public class MusePacketTinkerRequest extends MusePacket {
|
|||
*/
|
||||
public MusePacketTinkerRequest(DataInputStream data, Player player) {
|
||||
super(player, data);
|
||||
slot = readInt();
|
||||
moduleName = readString(64);
|
||||
itemSlot = readInt();
|
||||
tinkerName = readString(64);
|
||||
Side side = FMLCommonHandler.instance().getEffectiveSide();
|
||||
if (side == Side.SERVER) {
|
||||
EntityPlayerMP srvplayer = (EntityPlayerMP) player;
|
||||
stack = srvplayer.inventory.getStackInSlot(slot);
|
||||
stack = srvplayer.inventory.getStackInSlot(itemSlot);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServer(EntityPlayerMP playerEntity) {
|
||||
if (moduleName != null) {
|
||||
if (tinkerName != null) {
|
||||
InventoryPlayer inventory = playerEntity.inventory;
|
||||
int entityId = playerEntity.entityId;
|
||||
PowerModule moduleType = ModuleUtils.getModuleByID(moduleName);
|
||||
NBTTagCompound moduleTag = ModuleUtils.getItemModules(stack)
|
||||
TinkerAction tinkerType = Config.getTinkerings().get(tinkerName);
|
||||
NBTTagCompound itemTag = ItemUtils
|
||||
.getItemModularProperties(stack)
|
||||
.getCompoundTag(
|
||||
moduleName);
|
||||
List<ItemStack> cost = moduleType.getCost(playerEntity,
|
||||
moduleTag);
|
||||
if (ItemUtils.hasInInventory(cost, inventory)) {
|
||||
tinkerName);
|
||||
if (tinkerType.validate(playerEntity, stack)) {
|
||||
List<Integer> slots = ItemUtils.deleteFromInventory(
|
||||
cost, inventory);
|
||||
moduleType.onUpgrade(playerEntity, moduleTag);
|
||||
slots.add(this.slot);
|
||||
tinkerType.getCosts(), inventory);
|
||||
tinkerType.apply(stack);
|
||||
slots.add(this.itemSlot);
|
||||
for (Integer slotiter : slots) {
|
||||
MusePacket reply = new MusePacketInventoryRefresh(
|
||||
player,
|
||||
|
|
Loading…
Reference in a new issue