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