See extended description

Added glow-in-dark effect to tinker table
Included sprites from SebK and adjusted gui to use them
Changed module architecture (again) to be more scaleable in the future
and more closely resemble existing energynet designs (mostly UE)
A few packet handling tweaks
This commit is contained in:
MachineMuse 2012-12-26 11:55:54 -07:00
parent 7e9c970731
commit b9ecec9b43
31 changed files with 1345 additions and 622 deletions

View file

@ -1,5 +1,7 @@
package machinemuse.general.geometry;
import org.lwjgl.opengl.GL11;
/**
* A class representing an RGBA colour and various helper functions. Mainly to
* improve readability elsewhere.
@ -77,4 +79,8 @@ public class Colour {
this.b * complement + target.b * interval,
this.a * complement + target.a * interval);
}
public void doGL() {
GL11.glColor4f(r, g, b, a);
}
}

View file

@ -4,8 +4,14 @@ import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import machinemuse.powersuits.gui.MuseGui;
import machinemuse.powersuits.powermodule.PowerModule;
import net.minecraft.client.model.PositionTextureVertex;
import net.minecraft.client.model.TexturedQuad;
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;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
@ -74,6 +80,7 @@ public abstract class MuseRenderer {
Colour c = new Colour(0.0f, 1.0f, 0.0f, 0.0f);
texturelessOn();
smoothingOn();
GL11.glBegin(GL11.GL_LINE_LOOP);
for (int i = 0; i < numSegments; i++) {
@ -108,8 +115,9 @@ public abstract class MuseRenderer {
*/
public static void drawTriangles2D(float[] v, float[] c,
int[] i) {
arraysOn();
arraysOnC();
texturelessOn();
smoothingOn();
on2D();
// float subdivisions = 5f;
@ -156,8 +164,9 @@ public abstract class MuseRenderer {
*/
public static void drawTriangles3DR(float[] v, float[] c,
int[] i) {
arraysOn();
arraysOnC();
texturelessOn();
smoothingOn();
// float subdivisions = 5f;
// float radius = 0.5f;
@ -202,8 +211,8 @@ public abstract class MuseRenderer {
public static void on2D() {
GL11.glDisable(GL11.GL_DEPTH_TEST);
// GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
// attempt at fake antialiasing
@ -220,8 +229,7 @@ public abstract class MuseRenderer {
}
public static void off2D() {
GL11.glDisable(GL11.GL_DEPTH_TEST);
// GL11.glDepthFunc(GL11.GL_GREATER);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_LIGHTING);
}
@ -229,15 +237,22 @@ public abstract class MuseRenderer {
* Arrays on/off
*/
public static void arraysOn() {
public static void arraysOnC() {
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
// GL11.glEnableClientState(GL11.GL_INDEX_ARRAY);
}
public static void arraysOnT() {
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
// GL11.glEnableClientState(GL11.GL_INDEX_ARRAY);
}
public static void arraysOff() {
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
// GL11.glDisableClientState(GL11.GL_INDEX_ARRAY);
}
@ -248,13 +263,7 @@ public abstract class MuseRenderer {
*/
public static void texturelessOn() {
GL11.glDisable(GL11.GL_TEXTURE_2D);
// GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
/**
@ -262,12 +271,25 @@ public abstract class MuseRenderer {
* texture mode (default).
*/
public static void texturelessOff() {
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
public static void smoothingOn() {
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
public static void smoothingOff() {
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glDisable(GL11.GL_LINE_SMOOTH);
GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
GL11.glDisable(GL11.GL_BLEND);
// GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
/**
* Draws a rectangle with a vertical gradient between the specified colors.
*/
@ -275,6 +297,60 @@ public abstract class MuseRenderer {
float bottom, Colour c1, Colour c2, double zLevel)
{
texturelessOn();
smoothingOn();
on2D();
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(c1.r, c1.g, c1.b, c1.a);
tessellator.addVertex(right, top,
zLevel);
tessellator
.addVertex(left, top, zLevel);
tessellator.setColorRGBA_F(c2.r, c2.g, c2.b, c2.a);
tessellator.addVertex(left, bottom,
zLevel);
tessellator.addVertex(right, bottom,
zLevel);
tessellator.draw();
off2D();
texturelessOff();
}
public static void drawGradientRect3D(Vec3 origin, Vec3 size, Colour c1,
Colour c2)
{
Tessellator tessellator = Tessellator.instance;
tessellator.setBrightness(256);
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(c1.r, c1.g, c1.b, c1.a);
tessellator.addVertex(origin.xCoord, origin.yCoord,
origin.zCoord);
tessellator.addVertex(origin.xCoord + size.xCoord, origin.yCoord,
origin.zCoord);
tessellator.setColorRGBA_F(c2.r, c2.g, c2.b, c2.a);
tessellator.addVertex(origin.xCoord + size.xCoord, origin.yCoord
+ size.yCoord,
origin.zCoord + size.zCoord);
tessellator.addVertex(origin.xCoord, origin.yCoord + size.yCoord,
origin.zCoord + size.zCoord);
tessellator.draw();
}
/**
* Draws a rectangle with the specified texture coords.
*/
public static void drawTexRect(float left, float top, float right,
float bottom, Colour c1, Colour c2, double zLevel)
{
texturelessOff();
smoothingOn();
on2D();
Tessellator tessellator = Tessellator.instance;
@ -312,7 +388,46 @@ public abstract class MuseRenderer {
GL11.glDisable(GL11.GL_DEPTH_TEST);
// GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glEnable(GL11.GL_LIGHTING);
}
public static void drawModuleAt(int x, int y, MuseGui gui,
PowerModule module, NBTTagCompound moduleTag, Colour colour) {
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_CULL_FACE);
smoothingOn();
ForgeHooksClient.bindTexture(module.getIconFile(), 0);
if (colour != null)
{
colour.doGL();
}
Tessellator tess = Tessellator.instance;
tess.startDrawingQuads();
float r = 0.0625f;
float u = (module.getIconIndex() % 16) * r;
float v = (module.getIconIndex() / 16) * r;
tess.addVertexWithUV(
x, y, 0,
u, v);
tess.addVertexWithUV(
x, y + 16, 0,
u, v + r);
tess.addVertexWithUV(
x + 16, y + 16, 0,
u + r, v + r);
tess.addVertexWithUV(
x + 16, y, 0,
u + r, v);
tess.draw();
MuseRenderer.smoothingOff();
GL11.glEnable(GL11.GL_CULL_FACE);
// GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
/**
@ -334,45 +449,128 @@ public abstract class MuseRenderer {
/**
* Draws a rectangular prism (cube or otherwise orthogonal)
*/
public static void drawRectPrism(float bottom, float top, float left,
float right, float front, float back) {
float[] points = {
bottom, left, front,
top, left, front,
bottom, right, front,
top, right, front,
bottom, left, back,
top, left, back,
bottom, right, back,
top, right, back
public static void drawRectPrism(double x, double d, double e,
double f, double z, double g,
float texturex, float texturey,
float texturex2, float texturey2) {
arraysOnT();
texturelessOff();
Vec3[] points = {
Vec3.createVectorHelper(x, e, z),
Vec3.createVectorHelper(d, e, z),
Vec3.createVectorHelper(x, f, z),
Vec3.createVectorHelper(d, f, z),
Vec3.createVectorHelper(x, e, g),
Vec3.createVectorHelper(d, e, g),
Vec3.createVectorHelper(x, f, g),
Vec3.createVectorHelper(d, f, g)
};
float r = 0.3f;
float g = 0.8f;
float b = 0.5f;
float a = 0.9f;
float[] colours = {
r, g, b, a,
r, g, b, a,
r, g, b, a,
r, g, b, a,
r, g, b, a,
r, g, b, a,
r, g, b, a,
r, g, b, a
PositionTextureVertex[] va1 = {
new PositionTextureVertex(points[0], texturex, texturey2),
new PositionTextureVertex(points[2], texturex2, texturey2),
new PositionTextureVertex(points[3], texturex2, texturey),
new PositionTextureVertex(points[1], texturex, texturey)
};
int[] indices = {
0, 3, 1,
0, 2, 3,
2, 6, 7,
2, 7, 3,
6, 4, 5,
6, 5, 7,
4, 0, 1,
4, 1, 5,
1, 3, 7,
1, 7, 5,
0, 6, 2,
0, 4, 6
new TexturedQuad(va1).draw(Tessellator.instance, 1.0F);
PositionTextureVertex[] va2 = {
new PositionTextureVertex(points[2], texturex, texturey2),
new PositionTextureVertex(points[6], texturex2, texturey2),
new PositionTextureVertex(points[7], texturex2, texturey),
new PositionTextureVertex(points[3], texturex, texturey)
};
new TexturedQuad(va2).draw(Tessellator.instance, 1.0F);
PositionTextureVertex[] va3 = {
new PositionTextureVertex(points[6], texturex, texturey2),
new PositionTextureVertex(points[4], texturex2, texturey2),
new PositionTextureVertex(points[5], texturex2, texturey),
new PositionTextureVertex(points[7], texturex, texturey)
};
new TexturedQuad(va3).draw(Tessellator.instance, 1.0F);
PositionTextureVertex[] va4 = {
new PositionTextureVertex(points[4], texturex, texturey2),
new PositionTextureVertex(points[0], texturex2, texturey2),
new PositionTextureVertex(points[1], texturex2, texturey),
new PositionTextureVertex(points[5], texturex, texturey)
};
new TexturedQuad(va4).draw(Tessellator.instance, 1.0F);
PositionTextureVertex[] va5 = {
new PositionTextureVertex(points[1], texturex, texturey2),
new PositionTextureVertex(points[3], texturex2, texturey2),
new PositionTextureVertex(points[7], texturex2, texturey),
new PositionTextureVertex(points[5], texturex, texturey)
};
new TexturedQuad(va5).draw(Tessellator.instance, 1.0F);
PositionTextureVertex[] va6 = {
new PositionTextureVertex(points[0], texturex, texturey2),
new PositionTextureVertex(points[4], texturex2, texturey2),
new PositionTextureVertex(points[6], texturex2, texturey),
new PositionTextureVertex(points[2], texturex, texturey)
};
new TexturedQuad(va6).draw(Tessellator.instance, 1.0F);
// int[] indices = {
// 0, 3, 1,
// 0, 2, 3,
// 2, 6, 7,
// 2, 7, 3,
// 6, 4, 5,
// 6, 5, 7,
// 4, 0, 1,
// 4, 1, 5,
// 1, 3, 7,
// 1, 7, 5,
// 0, 6, 2,
// 0, 4, 6
// };
// drawTriangles3DT(points, textures, indices);
texturelessOff();
arraysOff();
}
private static void drawTriangles3DT(float[] v, float[] textures2,
int[] i) {
arraysOnT();
texturelessOff();
// float subdivisions = 5f;
// float radius = 0.5f;
// GL11.glPushMatrix();
// GL11.glTranslatef(-radius, -radius, 0);
// for (int i1 = 0; i1 <= subdivisions * 2; i1++) {
// for (int i2 = 0; i2 <= subdivisions * 2; i2++) {
FloatBuffer vertices = BufferUtils.createFloatBuffer(v.length);
vertices.put(v);
vertices.flip();
FloatBuffer textures = BufferUtils.createFloatBuffer(textures2.length);
textures.put(textures2);
textures.flip();
IntBuffer indices = BufferUtils.createIntBuffer(i.length);
indices.put(i);
indices.flip();
// GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
GL11.glVertexPointer(3, 0, vertices);
GL11.glTexCoordPointer(2, 0, textures);
GL11.glDrawElements(GL11.GL_TRIANGLES, indices);
// GL11.glTranslatef(0, radius / subdivisions, 0);
// }
// GL11.glTranslatef(radius / subdivisions, -radius * 2, 0);
// }
// GL11.glPopMatrix();
texturelessOff();
arraysOff();
}
}

View file

@ -1,179 +0,0 @@
package machinemuse.powersuits.augmentation;
import java.util.ArrayList;
import java.util.List;
import machinemuse.powersuits.common.MuseLogger;
import machinemuse.powersuits.item.ItemPowerArmor;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/**
* An Augmentation is a module that can be slotted into the power armor or tool.
*
* @author MachineMuse
*
*/
public abstract class AugManager {
/**
* Default compound for all NBTtag keys on itemstacks. Needed in case some
* other mod adds NBT data to these items.
*
* @return
*/
public static final String nbtPrefix = "mmmpsmod";
/**
* Names of augs
*/
public static final String STONEARMORPLATING = "Stone Armor Plating";
public static final String IRONARMORPLATING = "Iron Armor Plating";
public static final String DIAMONDARMORPLATING = "Diamond Armor Plating";
public static final String NICADBATTERY = "Nickel-Cadmium Battery";
public static final String LIIONBATTERY = "Lithium-Ion Battery";
public static final String CARBONTUBEBATTERY = "Carbon Nanotube Battery";
/**
* Names of aug properties
*/
public static final String LEVEL = "Level";
public static final String WEIGHT = "Weight";
public static final String NAME = "Name";
public static final String DURABILITY = "Durability";
public static int getLevel(NBTTagCompound aug) {
if (aug.hasKey(LEVEL)) {
return aug.getInteger(LEVEL);
} else {
return 0;
}
}
public static void setLevel(NBTTagCompound aug, int level) {
aug.setInteger(LEVEL, level);
}
public static String getName(NBTTagCompound aug) {
return aug.getString(NAME);
}
/**
* The amount that the Aug contributes to the weight factor. Mostly used in
* determining speed penalty for now.
*
* @return
*/
public static float getWeight(NBTTagCompound aug) {
String augname = aug.getString(NAME);
if (augname.equals(STONEARMORPLATING)
|| augname.equals(IRONARMORPLATING)
|| augname.equals(DIAMONDARMORPLATING)) {
return 10.0F * getLevel(aug);
}
return 0;
}
/**
* Returns a list of material requirements to upgrade the augmentation to
* the next level.
*
* @param level
* the level you would be upgrading to
* @return a list of ItemStacks describing the cost.
*/
public static List<ItemStack> getInstallCost(String augType) {
List<ItemStack> cost = new ArrayList<ItemStack>();
cost.add(new ItemStack(Item.redstone, 3));
if (augType.equals(STONEARMORPLATING)) {
cost.add(new ItemStack(Block.cobblestone, 10));
}
return cost;
}
/**
* Returns a list of materials that would be refunded from downgrading or
* removing this augmentation.
*
* @param level
* the level you would be downgrading to
* @return a list of ItemStacks describing the cost.
*/
public static List<ItemStack> getDowngradeRefund(String augType) {
List<ItemStack> refund = new ArrayList<ItemStack>();
refund.add(new ItemStack(Item.redstone, 3));
return refund;
}
/**
* @param validAug
* @return
*/
public static NBTTagCompound newAugOfType(String validAug) {
NBTTagCompound newAug = new NBTTagCompound();
if (validAug.equals(STONEARMORPLATING)) {
newAug.setString(NAME, STONEARMORPLATING);
newAug.setInteger(DURABILITY, 100);
} else if (validAug.equals(IRONARMORPLATING)) {
newAug.setString(NAME, IRONARMORPLATING);
newAug.setInteger(DURABILITY, 100);
} else if (validAug.equals(DIAMONDARMORPLATING)) {
newAug.setString(NAME, DIAMONDARMORPLATING);
newAug.setInteger(DURABILITY, 100);
} else if (validAug.equals(NICADBATTERY)) {
newAug.setString(NAME, NICADBATTERY);
} else if (validAug.equals(LIIONBATTERY)) {
newAug.setString(NAME, LIIONBATTERY);
} else if (validAug.equals(CARBONTUBEBATTERY)) {
newAug.setString(NAME, CARBONTUBEBATTERY);
}
return newAug;
}
/**
* @param item
* @return
*/
public static List<String> getValidAugsForItem(Item item) {
List<String> validAugs = new ArrayList<String>();
if (item instanceof ItemPowerArmor) {
validAugs.add(STONEARMORPLATING);
validAugs.add(IRONARMORPLATING);
validAugs.add(DIAMONDARMORPLATING);
}
validAugs.add(NICADBATTERY);
validAugs.add(LIIONBATTERY);
validAugs.add(CARBONTUBEBATTERY);
return validAugs;
}
/**
* @param itemAugs
* @param aug
*/
public static void upgrade(NBTTagCompound itemAugs, String aug) {
MuseLogger.logDebug("Upgrading " + aug);
if (itemAugs.hasKey(aug)) {
NBTTagCompound augTag = itemAugs.getCompoundTag(aug);
setLevel(augTag, getLevel(augTag) + 1);
} else {
NBTTagCompound augTag = newAugOfType(aug);
itemAugs.setCompoundTag(aug, augTag);
setLevel(augTag, getLevel(augTag) + 1);
}
}
/**
* @param aug
* @return
*/
public static List<String> getTooltipFor(NBTTagCompound aug) {
List<String> tooltiplines = new ArrayList<String>();
tooltiplines.add("Augmentation: ");
tooltiplines.add(aug.getString(NAME));
tooltiplines.add("Level: " + aug.getInteger(LEVEL));
return tooltiplines;
}
}

View file

@ -1,14 +1,13 @@
package machinemuse.powersuits.block;
import machinemuse.powersuits.common.CommonProxy;
import machinemuse.powersuits.common.Config;
import machinemuse.powersuits.common.PowersuitsMod;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@ -33,10 +32,11 @@ public class BlockTinkerTable extends Block {
setResistance(80.0F);
setStepSound(Config.Blocks.TinkerTable.stepSound);
setBlockName(Config.Blocks.TinkerTable.idName);
setLightOpacity(1); // How much light is stopped by this block
setLightOpacity(0); // How much light is stopped by this block
setCreativeTab(Config.getCreativeTab());
setLightValue(0.25F); // Light level / 15
setTickRandomly(false); // Whether to receive random ticks e.g. plants
setLightValue(0.4f); // Light level, 0-1. Gets multiplied by 15.
setTickRandomly(false); // Whether to receive random ticks e.g.
// plants
LanguageRegistry.addName(this, Config.Blocks.TinkerTable.englishName);
MinecraftForge.setBlockHarvestLevel(this,
@ -44,15 +44,13 @@ public class BlockTinkerTable extends Block {
Config.Blocks.TinkerTable.harvestLevel);
ItemStack recipeResult = new ItemStack(this);
GameRegistry.registerTileEntity(TileEntityTinkerTable.class,
Config.Blocks.TinkerTable.idName);
GameRegistry.registerBlock(this);
}
@Override
public String getTextureFile() {
return CommonProxy.BLOCK_PNG;
}
/**
* Called upon block activation (right click on the block.)
*/
@ -77,7 +75,7 @@ public class BlockTinkerTable extends Block {
*/
@Override
public int getRenderType() {
return -1;
return Config.getAssignedBlockID(Config.Blocks.TinkerTable);
}
/**
@ -1308,28 +1306,29 @@ public class BlockTinkerTable extends Block {
// return blockMaterial.isOpaque() && renderAsNormalBlock();
// }
//
/**
* Checks if the block is a solid face on the given side, used by placement
* logic.
*
* @param world
* The current world
* @param x
* X Position
* @param y
* Y position
* @param z
* Z position
* @param side
* The side to check
* @return True if the block is solid on the specified side.
*/
@Override
public boolean isBlockSolidOnSide(World world, int x, int y, int z,
ForgeDirection side)
{
return false;
}
// /**
// * Checks if the block is a solid face on the given side, used by
// placement
// * logic.
// *
// * @param world
// * The current world
// * @param x
// * X Position
// * @param y
// * Y position
// * @param z
// * Z position
// * @param side
// * The side to check
// * @return True if the block is solid on the specified side.
// */
// @Override
// public boolean isBlockSolidOnSide(World world, int x, int y, int z,
// ForgeDirection side)
// {
// return true;
// }
// /**
// * Determines if a new block can be replace the space occupied by this
@ -1532,45 +1531,42 @@ public class BlockTinkerTable extends Block {
// blockFireSpreadSpeed[id] = encouragement;
// blockFlammability[id] = flammability;
// }
//
// /**
// * Called throughout the code as a replacement for block instanceof
// BlockContainer
// * Moving this to the Block base class allows for mods that wish to extend
// vinella
// * blocks, and also want to have a tile entity on that block, may.
// *
// * Return true from this function to specify this block has a tile entity.
// *
// * @param metadata Metadata of the current block
// * @return True if block has a tile entity, false otherwise
// */
// @Override
// public boolean hasTileEntity(int metadata)
// {
// return isBlockContainer;
// }
//
// /**
// * Called throughout the code as a replacement for
// BlockContainer.getBlockEntity
// * Return the same thing you would from that function.
// * This will fall back to BlockContainer.getBlockEntity if this block is a
// BlockContainer.
// *
// * @param metadata The Metadata of the current block
// * @return A instance of a class extending TileEntity
// */
// @Override
// public TileEntity createTileEntity(World world, int metadata)
// {
// if (this instanceof BlockContainer)
// {
// return ((BlockContainer)this).createNewTileEntity(world, metadata);
// }
// return null;
// }
//
/**
* Called throughout the code as a replacement for block instanceof
* BlockContainer Moving this to the Block base class allows for mods that
* wish to extend vinella blocks, and also want to have a tile entity on
* that block, may.
*
* Return true from this function to specify this block has a tile entity.
*
* @param metadata
* Metadata of the current block
* @return True if block has a tile entity, false otherwise
*/
@Override
public boolean hasTileEntity(int metadata)
{
return true;
}
/**
* Called throughout the code as a replacement for
* BlockContainer.getBlockEntity Return the same thing you would from that
* function. This will fall back to BlockContainer.getBlockEntity if this
* block is a BlockContainer.
*
* @param metadata
* The Metadata of the current block
* @return A instance of a class extending TileEntity
*/
@Override
public TileEntity createTileEntity(World world, int metadata)
{
return new TileEntityTinkerTable();
}
// /**
// * Metadata and fortune sensitive version, this replaces the old (int
// meta, Random rand)

View file

@ -0,0 +1,14 @@
/**
*
*/
package machinemuse.powersuits.block;
import net.minecraft.tileentity.TileEntity;
/**
* @author MachineMuse
*
*/
public class TileEntityTinkerTable extends TileEntity {
}

View file

@ -1,79 +0,0 @@
/**
*
*/
package machinemuse.powersuits.client;
import machinemuse.general.geometry.MuseRenderer;
import machinemuse.powersuits.common.Config;
import machinemuse.powersuits.common.Config.Blocks;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
/**
* @author Claire
*
*/
public class BlockRenderer implements ISimpleBlockRenderingHandler {
/**
*
*/
public BlockRenderer() {
// TODO Auto-generated constructor stub
}
/*
* (non-Javadoc)
*
* @see cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler#
* renderInventoryBlock(net.minecraft.block.Block, int, int,
* net.minecraft.client.renderer.RenderBlocks)
*/
@Override
public void renderInventoryBlock(Block block, int metadata, int modelID,
RenderBlocks renderer) {
MuseRenderer.drawRectPrism(0, 1, 0, 1, 0, 1);
}
/*
* (non-Javadoc)
*
* @see
* cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler#renderWorldBlock
* (net.minecraft.world.IBlockAccess, int, int, int,
* net.minecraft.block.Block, int,
* net.minecraft.client.renderer.RenderBlocks)
*/
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z,
Block block, int modelId, RenderBlocks renderer) {
MuseRenderer.drawRectPrism(0, 1, 0, 1, 0, 1);
return true;
}
/*
* (non-Javadoc)
*
* @see cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler#
* shouldRender3DInInventory()
*/
@Override
public boolean shouldRender3DInInventory() {
return true;
}
/*
* (non-Javadoc)
*
* @see
* cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler#getRenderId()
*/
@Override
public int getRenderId() {
return Config.getAssignedBlockID(Blocks.TinkerTable);
}
}

View file

@ -1,13 +1,13 @@
package machinemuse.powersuits.client;
import machinemuse.powersuits.block.TileEntityTinkerTable;
import machinemuse.powersuits.common.CommonProxy;
import machinemuse.powersuits.common.MuseLogger;
import machinemuse.powersuits.common.PlayerTickHandler;
import machinemuse.powersuits.common.PowersuitsMod;
import machinemuse.powersuits.network.MusePacketHandler;
import net.minecraft.item.Item;
import net.minecraftforge.client.MinecraftForgeClient;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;
@ -34,9 +34,10 @@ public class ClientProxy extends CommonProxy {
// MinecraftForgeClient.registerItemRenderer(
// i.shiftedIndex, eRenderer);
// }
MuseLogger.logDebug("Registering TinkerTable renderer");
RenderingRegistry.registerBlockHandler(new BlockRenderer());
// MinecraftForgeClient.preloadTexture("/gui/tinktablegui.png");
ClientRegistry.bindTileEntitySpecialRenderer(
TileEntityTinkerTable.class, new TinkerTableRenderer());
MinecraftForgeClient.preloadTexture("/tinkertable.png");
MinecraftForgeClient.preloadTexture("/moduleicons.png");
}
/**
@ -48,7 +49,6 @@ public class ClientProxy extends CommonProxy {
tickHandler = new PlayerTickHandler();
TickRegistry.registerTickHandler(tickHandler, Side.CLIENT);
packetHandler = new MusePacketHandler();
packetHandler.register();
packetHandler = new MusePacketHandler().register();
}
}

View file

@ -146,9 +146,10 @@ public class EquipmentRenderer implements IItemRenderer {
public void drawFeet(ItemStack itemStack) {
MuseRenderer.draw3x3placeholder(
false, false, false,
true, false, true,
true, false, true);
true, true, true,
false, true, false,
false, true, false);
// MuseRenderer.drawRectPrism(0, 16, 0, 16, 0, 16);
}
public void drawTool(ItemStack itemStack) {

View file

@ -0,0 +1,143 @@
package machinemuse.powersuits.client;
import java.util.Random;
import machinemuse.general.geometry.Colour;
import machinemuse.general.geometry.MuseRenderer;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.Vec3;
import org.lwjgl.opengl.GL11;
public class TinkerTableModel extends Render {
// public float onGround;
// public boolean isRiding = false;
protected ModelBase model = new ModelBase() {
};
private static final Random random = new Random();
/**
* This is a list of all the boxes (ModelRenderer.class) in the current
* model.
*/
// public List boxList = new ArrayList();
// public boolean isChild = true;
/** A mapping for all texture offsets */
// private Map modelTextureMap = new HashMap();
// public int textureWidth = 64;
// public int textureHeight = 32;
protected ModelRenderer slab;
protected ModelRenderer legs;
protected ModelRenderer cube;
/**
*
*/
public TinkerTableModel() {
model.textureWidth = 64;
model.textureHeight = 40;
slab = new ModelRenderer(model, 0, 0);
slab.mirror = true;
slab.addBox(
0, 12, 0, // xyz offset of the model
16, 4, 16); // xyz size
// renderer.setRotationPoint(0,0,0);
legs = new ModelRenderer(model, 32, 20);
legs.mirror = true;
legs.addBox(
1, 0, 1,
4, 12, 4);
legs.addBox(
1, 0, 11,
4, 12, 4);
legs.addBox(
11, 0, 1,
4, 12, 4);
legs.addBox(
11, 0, 11,
4, 12, 4);
cube = new ModelRenderer(model, 0, 20);
cube.mirror = true;
cube.addBox(-4, -4, -4, 8, 8, 8);
}
@Override
public void doRender(Entity entity, double x, double y, double z, float f,
float f1) {
int timestep = (int) ((System.currentTimeMillis()) % 10000);
double angle = timestep * Math.PI / 5000.0;
slab.render(0.0625f);
legs.render(0.0625f);
GL11.glPushMatrix();
MuseRenderer.smoothingOn();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,
240.0F, 240.0F);
RenderHelper.disableStandardItemLighting();
GL11.glPushMatrix();
GL11.glTranslated(0.5f, 1.05f, 0.5f);
GL11.glTranslated(0, 0.02f * Math.sin(angle * 3), 0);
// GLRotate uses degrees instead of radians for some reason grr
GL11.glRotatef((float) (angle * 57.2957795131), 0.0f, 1.0f, 0.0f);
GL11.glRotatef(45f, 1.0f, 0.0f, 0.0f);
// arctangent of 0.5.
GL11.glRotatef(35.2643897f, 0, 1, 1);
// cube.render(0.0625f);
cube.render(0.015625f);
// cube.render(0.016000f);
GL11.glPopMatrix();
for (int i = 0; i < 2; i++) {
drawScanLine(angle);
}
GL11.glDisable(GL11.GL_CULL_FACE);
MuseRenderer.drawGradientRect3D(
Vec3.createVectorHelper(0, 1.2, 0),
Vec3.createVectorHelper(1, 0, 1),
new Colour(0.3f, 1.0f, 0.3f, 0.8f),
new Colour(0.3f, 1.0f, 0.3f, 0.8f));
GL11.glEnable(GL11.GL_CULL_FACE);
// MuseRenderer.off2D();
RenderHelper.enableStandardItemLighting();
MuseRenderer.smoothingOff();
GL11.glPopMatrix();
}
private void drawScanLine(double angle) {
float xtarg = random.nextFloat();
float ytarg = random.nextFloat();
GL11.glLineWidth(2);
GL11.glBegin(GL11.GL_LINES);
GL11.glColor4d(0.0, 1.0, 0.2, 1.0);
GL11.glVertex3d(0.5, 1.05 + 0.02f * Math.sin(angle * 3), 0.5);
GL11.glVertex3d(xtarg, 1.2f, ytarg);
GL11.glEnd();
}
/**
* Sets the models various rotation angles then renders the model.
*/
public void render(Entity par1Entity, float par2, float par3, float par4,
float par5, float par6, float par7) {
model.render(par1Entity, par2, par3, par4, par5, par6, par7);
}
// @Override
// protected void setTextureOffset(String par1Str, int par2, int par3)
// {
// this.modelTextureMap.put(par1Str, new TextureOffset(par2, par3));
// }
//
// @Override
// public TextureOffset getTextureOffset(String par1Str)
// {
// return (TextureOffset) this.modelTextureMap.get(par1Str);
// }
}

View file

@ -0,0 +1,43 @@
/**
*
*/
package machinemuse.powersuits.client;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.ForgeHooksClient;
import org.lwjgl.opengl.GL11;
/**
* @author Claire
*
*/
public class TinkerTableRenderer extends TileEntitySpecialRenderer {
protected TinkerTableModel model;
public TinkerTableRenderer() {
model = new TinkerTableModel();
}
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y,
double z, float partialTickTime) {
ForgeHooksClient.bindTexture("/tinkertable.png", 0);
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
model.doRender(null, x, y, z, partialTickTime, partialTickTime);
// float texturex = 80 / 256.0f;
// float texturey = 32 / 256.0f;
// float texturex2 = 96 / 256.0f;
// float texturey2 = 48 / 256.0f;
// MuseRenderer.drawRectPrism(
// x, x + 1,
// y + 0.5f, y + 1,
// z, z + 1,
// texturex, texturey, texturex2, texturey2);
GL11.glPopMatrix();
}
}

View file

@ -175,4 +175,8 @@ public class Config extends Configuration {
GuiTinkerTable,
GuiSuitManager;
}
public static int getAugMaxID() {
return 256;
}
}

View file

@ -28,18 +28,9 @@ public class PlayerTickHandler implements ITickHandler {
List<NBTTagCompound> playerAugs = ItemUtils
.getPlayerAugs(player);
float totalEnergy = 0;
float totalWeight = ItemUtils
.getTotalWeight(playerAugs);
float totalWeight = 0;
Iterator<NBTTagCompound> iter = playerAugs.iterator();
while (iter.hasNext()) {
NBTTagCompound aug = iter.next();
if (aug.hasKey("Available Energy")) {
totalEnergy += aug.getFloat("Available Energy");
}
totalWeight += aug.getCompoundTag("Armor").getInteger("Level");
}
if (totalWeight > 25) {
player.motionX *= 25 / totalWeight;
player.motionZ *= 25 / totalWeight;

View file

@ -0,0 +1,58 @@
/**
*
*/
package machinemuse.powersuits.energy;
import machinemuse.powersuits.powermodule.PowerModule;
import machinemuse.powersuits.powermodule.PowerModuleBattery;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/**
* Energy Manager will provide a simplified and scalable interface for keeping
* track of all the individual modules in an item which might store, consume, or
* produce power.
*
* @author MachineMuse
*
*/
public class EnergyManager {
public float getStoredEnergy(EntityPlayer player) {
float energy = 0;
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stack = player.inventory.getStackInSlot(i);
if (stack != null) {
NBTTagCompound tags = PowerModule.getItemModules(stack);
// TODO: Make this scalable
if (tags.hasKey("Electric Battery")) {
NBTTagCompound batteryTag = tags
.getCompoundTag("Electric Battery");
PowerModuleBattery bat = (PowerModuleBattery) PowerModule
.getModuleFromNBT(batteryTag);
energy += bat.getStoredEnergy(player, batteryTag);
}
}
}
return energy;
}
public float getMaxEnergy(EntityPlayer player) {
float energy = 0;
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stack = player.inventory.getStackInSlot(i);
if (stack != null) {
NBTTagCompound tags = PowerModule.getItemModules(stack);
// TODO: Make this scalable
if (tags.hasKey("Electric Battery")) {
NBTTagCompound batteryTag = tags
.getCompoundTag("Electric Battery");
PowerModuleBattery bat = (PowerModuleBattery) PowerModule
.getModuleFromNBT(batteryTag);
energy += bat.getMaxEnergy(player, batteryTag);
}
}
}
return energy;
}
}

View file

@ -50,10 +50,9 @@ public class ClickableItem extends Clickable {
*/
@Override
public void draw(RenderEngine engine, MuseGui gui) {
MuseRenderer.drawItemAt(
(int) gui.absX(getPosition().x()) - offsetx,
(int) gui.absY(getPosition().y()) - offsety,
gui.absX(getPosition().x()) - offsetx,
gui.absY(getPosition().y()) - offsety,
gui, item);
}
}

View file

@ -5,7 +5,7 @@ import java.util.List;
import machinemuse.general.geometry.Colour;
import machinemuse.general.geometry.MuseRenderer;
import machinemuse.general.geometry.Point2D;
import machinemuse.powersuits.augmentation.AugManager;
import machinemuse.powersuits.powermodule.PowerModule;
import net.minecraft.client.renderer.RenderEngine;
import net.minecraft.nbt.NBTTagCompound;
@ -15,21 +15,32 @@ import net.minecraft.nbt.NBTTagCompound;
*
* @author MachineMuse
*/
public class ClickableAugmentation extends Clickable {
protected NBTTagCompound aug;
public class ClickablePowerModule extends Clickable {
protected PowerModule module;
protected NBTTagCompound moduleTag;
/**
* @param vaug
*/
public ClickableAugmentation(NBTTagCompound aug, Point2D position) {
public ClickablePowerModule(PowerModule module, Point2D position) {
super(position);
this.aug = aug;
this.module = module;
this.moduleTag = module.newModuleTag();
}
/**
* @param vaug
*/
public ClickablePowerModule(NBTTagCompound moduleTag, Point2D position) {
super(position);
this.moduleTag = moduleTag;
this.module = PowerModule.getModuleFromNBT(moduleTag);
}
@Override
public List<String> getToolTip() {
return AugManager.getTooltipFor(aug);
return module.getTooltip(
null, null);
}
@Override
@ -40,7 +51,7 @@ public class ClickableAugmentation 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.drawGradientRect(x - 8, y - 8, x + 8, y + 8, c1, c2, 100.0f);
MuseRenderer.drawModuleAt(x - 8, y - 8, gui, module, moduleTag, null);
}

View file

@ -5,10 +5,9 @@ import java.util.Iterator;
import java.util.List;
import machinemuse.general.geometry.Colour;
import machinemuse.general.geometry.MuseRenderer;
import machinemuse.general.geometry.FlyFromMiddlePoint2D;
import machinemuse.general.geometry.MuseRenderer;
import machinemuse.general.geometry.Point2D;
import machinemuse.powersuits.augmentation.AugManager;
import machinemuse.powersuits.item.ItemUtils;
import machinemuse.powersuits.network.MusePacketUpgradeRequest;
import net.minecraft.client.entity.EntityClientPlayerMP;
@ -26,7 +25,7 @@ public class GuiTinkerTable extends MuseGui {
protected EntityClientPlayerMP player;
protected List<ClickableItem> itemButtons;
protected int selectedItemStack = -1;
protected List<ClickableAugmentation> augButtons;
protected List<ClickablePowerModule> augButtons;
protected int selectedAugClickable = -1;
protected List<ItemStack> workingUpgradeCost;
protected List<ItemStack> workingDowngradeRefund;
@ -49,6 +48,7 @@ public class GuiTinkerTable extends MuseGui {
/**
* Add the buttons (and other controls) to the screen.
*/
@Override
public void initGui()
{
super.initGui();
@ -81,16 +81,16 @@ public class GuiTinkerTable extends MuseGui {
}
protected void loadAugList(ClickableItem itemClicked) {
augButtons = new ArrayList<ClickableAugmentation>();
augButtons = new ArrayList<ClickablePowerModule>();
List<NBTTagCompound> workingAugs = ItemUtils
.getItemAugsWithPadding(itemClicked
.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 ClickableAugmentation(aug, pointiter.next()));
augButtons.add(new ClickablePowerModule(aug, pointiter.next()));
}
}
@ -110,10 +110,13 @@ public class GuiTinkerTable extends MuseGui {
}
if (selectedAugClickable != -1) {
MuseRenderer.drawCircleAround(
absX(augButtons.get(selectedAugClickable).getPosition().x()),
absY(augButtons.get(selectedAugClickable).getPosition().y()),
10);
MuseRenderer
.drawCircleAround(
absX(augButtons.get(selectedAugClickable)
.getPosition().x()),
absY(augButtons.get(selectedAugClickable)
.getPosition().y()),
10);
}
@ -160,7 +163,8 @@ public class GuiTinkerTable extends MuseGui {
Iterator<Point2D> pointiter = points.iterator();
for (ItemStack item : workingUpgradeCost) {
Point2D next = pointiter.next();
MuseRenderer.drawItemAt(absX(next.x()), absY(next.y()), this, item);
MuseRenderer.drawItemAt(absX(next.x()), absY(next.y()), this,
item);
}
upgradeButton.draw(this.getRenderEngine(), this);
}
@ -177,7 +181,8 @@ public class GuiTinkerTable extends MuseGui {
Iterator<Point2D> pointiter = points.iterator();
for (ItemStack item : workingDowngradeRefund) {
Point2D next = pointiter.next();
MuseRenderer.drawItemAt(absX(next.x()), absY(next.y()), this, item);
MuseRenderer.drawItemAt(absX(next.x()), absY(next.y()), this,
item);
}
downgradeButton.draw(this.getRenderEngine(), this);
}
@ -198,6 +203,7 @@ public class GuiTinkerTable extends MuseGui {
/**
* Called when the mouse is clicked.
*/
@Override
protected void mouseClicked(int x, int y, int button)
{
if (button == 0) // Left Mouse Button
@ -240,12 +246,15 @@ public class GuiTinkerTable extends MuseGui {
// ItemUtils.deleteFromInventory(workingUpgradeCost,
// player.inventory);
// workingAugmentation.upgrade();
player.sendQueue.addToSendQueue(new MusePacketUpgradeRequest(
(Player) player,
itemButtons.get(selectedItemStack).inventorySlot,
augButtons
.get(this.selectedAugClickable).aug
.getString(AugManager.NAME)).getPacket());
player.sendQueue
.addToSendQueue(
new MusePacketUpgradeRequest(
(Player) player,
itemButtons.get(selectedItemStack).inventorySlot,
augButtons.get(selectedAugClickable).module
.getName()
).getPacket()
);
// player.sendQueue.sendPacket();
}
}
@ -256,9 +265,8 @@ public class GuiTinkerTable extends MuseGui {
private void refreshUpgrades() {
if (selectedAugClickable != -1) {
this.workingUpgradeCost =
AugManager.getInstallCost(augButtons
.get(selectedAugClickable).aug
.getString(AugManager.NAME));
augButtons.get(selectedAugClickable).module.getCost(player,
augButtons.get(selectedAugClickable).moduleTag);
if (workingUpgradeCost != null) {
this.upgradeButton = new ClickableButton("Upgrade",
new Point2D(0.6F, -0.2F),
@ -270,15 +278,6 @@ public class GuiTinkerTable extends MuseGui {
upgradeButton.enabled = false;
}
}
this.workingDowngradeRefund =
AugManager.getDowngradeRefund(augButtons
.get(selectedAugClickable).aug
.getString(AugManager.NAME));
if (workingDowngradeRefund != null) {
this.downgradeButton = new ClickableButton("Downgrade",
new Point2D(0.6F, 0.8F),
new Point2D(0.25F, 0.05F), true);
}
}
}

View file

@ -5,19 +5,19 @@ import java.util.Iterator;
import java.util.List;
import machinemuse.general.geometry.Colour;
import machinemuse.general.geometry.MuseRenderer;
import machinemuse.general.geometry.FlyFromMiddlePoint2D;
import machinemuse.general.geometry.MuseRenderer;
import machinemuse.general.geometry.Point2D;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.RenderEngine;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderItem;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
/**
* I got fed up with Minecraft's gui system so I wrote my own (to some extent.
@ -66,7 +66,7 @@ public class MuseGui extends GuiScreen {
absX(br.x()), absY(br.y()),
new Colour(0.1F, 0.9F, 0.1F, 0.8F),
new Colour(0.0F, 0.2F, 0.0F, 0.8F),
(double) this.zLevel);
this.zLevel);
}
/**
@ -109,7 +109,7 @@ public class MuseGui extends GuiScreen {
/**
* Creates a list of points linearly interpolated between points a and b
* inclusive.
* noninclusive.
*
* @return A list of num points
*/
@ -261,13 +261,13 @@ public class MuseGui extends GuiScreen {
strwidth = currstrwidth;
}
}
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
MuseRenderer.drawGradientRect(
x, y - 10 * tooltip.size() - 5,
x + 10 + strwidth, y + 5,
new Colour(0.2F, 0.6F, 0.9F, 0.7F),
new Colour(0.1F, 0.3F, 0.4F, 0.7F),
0.0F);
RenderHelper.disableStandardItemLighting();
Colour fontcolour = new Colour(0.9F, 0.6F, 0.2F, 1.0F);
for (int i = 0; i < tooltip.size(); i++) {
this.getFontRenderer().drawStringWithShadow(tooltip.get(i),

View file

@ -1,7 +1,5 @@
package machinemuse.powersuits.item;
import java.util.List;
import machinemuse.powersuits.common.Config;
import machinemuse.powersuits.common.Config.Items;
import net.minecraft.entity.EntityLiving;
@ -19,19 +17,18 @@ import net.minecraftforge.common.ISpecialArmor;
*/
public abstract class ItemPowerArmor extends ItemArmor
implements ISpecialArmor, IModularItem {
protected List<String> validAugTypes;
Config.Items itemType;
/**
* @param par1
* @param par2EnumArmorMaterial
* @param par3
* @param par4
* @param id
* @param material
* @param renderIndex
* @param armorType
* 0 = head; 1 = torso; 2 = legs; 3 = feet
*/
public ItemPowerArmor(int par1, EnumArmorMaterial par2EnumArmorMaterial,
int par3, int par4) {
super(par1, par2EnumArmorMaterial, par3, par4);
public ItemPowerArmor(int id, EnumArmorMaterial material,
int renderIndex, int armorType) {
super(id, material, renderIndex, armorType);
setMaxStackSize(1);
setCreativeTab(Config.getCreativeTab());
}

View file

@ -1,7 +1,5 @@
package machinemuse.powersuits.item;
import java.util.ArrayList;
import machinemuse.powersuits.common.Config;
import net.minecraft.item.EnumArmorMaterial;
import cpw.mods.fml.common.registry.LanguageRegistry;
@ -14,19 +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);
setValidAugTypes();
LanguageRegistry.addName(this, itemType.englishName);
}
/**
* For IModularItem's aug-list functionality.
*
* @param types
*/
public void setValidAugTypes() {
validAugTypes = new ArrayList<String>();
validAugTypes.add("Battery");
validAugTypes.add("Armor Plating");
}
}

View file

@ -1,7 +1,5 @@
package machinemuse.powersuits.item;
import java.util.ArrayList;
import machinemuse.powersuits.common.Config;
import net.minecraft.item.EnumArmorMaterial;
import cpw.mods.fml.common.registry.LanguageRegistry;
@ -14,20 +12,8 @@ public class ItemPowerArmorLegs extends ItemPowerArmor {
2); // armor type. 0=head, 1=torso, 2=legs, 3=feet
itemType = Config.Items.PowerArmorLegs;
setItemName(itemType.idName);
setValidAugTypes();
LanguageRegistry.addName(this, itemType.englishName);
}
/**
* For IModularItem's aug-list functionality.
*
* @param types
*/
public void setValidAugTypes() {
validAugTypes = new ArrayList<String>();
validAugTypes.add("Battery");
validAugTypes.add("Armor Plating");
}
}

View file

@ -1,7 +1,5 @@
package machinemuse.powersuits.item;
import java.util.ArrayList;
import machinemuse.powersuits.common.Config;
import net.minecraft.item.EnumArmorMaterial;
import cpw.mods.fml.common.registry.LanguageRegistry;
@ -14,19 +12,8 @@ public class ItemPowerArmorTorso extends ItemPowerArmor {
1); // armor type.
itemType = Config.Items.PowerArmorTorso;
setItemName(itemType.idName);
setValidAugTypes();
LanguageRegistry.addName(this, itemType.englishName);
}
/**
* For IModularItem's aug-list functionality.
*
* @param types
*/
public void setValidAugTypes() {
validAugTypes = new ArrayList<String>();
validAugTypes.add("Battery");
validAugTypes.add("Armor Plating");
}
}

View file

@ -5,7 +5,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import machinemuse.powersuits.augmentation.AugManager;
import machinemuse.powersuits.powermodule.PowerModule;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
@ -75,7 +75,7 @@ public class ItemUtils {
List<ItemStack> items = getModularItemsInInventory(player.inventory);
Iterator<ItemStack> iter = items.iterator();
while (iter.hasNext()) {
NBTTagCompound itemAugs = getItemAugs(iter.next());
NBTTagCompound itemAugs = PowerModule.getItemModules(iter.next());
for (Object ob : itemAugs.getTags()) {
if (ob instanceof NBTTagCompound) {
augs.add((NBTTagCompound) ob);
@ -87,51 +87,27 @@ public class ItemUtils {
}
/**
*
*
* @param next
* @return
*/
public static NBTTagCompound getItemAugs(ItemStack stack) {
NBTTagCompound augs = null;
if (stack.hasTagCompound()) {
NBTTagCompound stackTag = stack.getTagCompound();
if (stackTag.hasKey(AugManager.nbtPrefix)) {
augs = stackTag.getCompoundTag(AugManager.nbtPrefix);
public static List<NBTTagCompound> getItemModulesWithPadding(ItemStack stack) {
List<PowerModule> validModules = PowerModule
.getValidModulesForItem(stack.getItem());
NBTTagCompound itemModule = PowerModule.getItemModules(stack);
List<NBTTagCompound> modulesList = new ArrayList<NBTTagCompound>();
for (PowerModule validModule : validModules) {
if (itemModule.hasKey(validModule.getName())) {
NBTTagCompound matchedAug = itemModule
.getCompoundTag(validModule
.getName());
modulesList.add(matchedAug);
} else {
augs = new NBTTagCompound();
stackTag.setCompoundTag(AugManager.nbtPrefix, augs);
}
} else {
NBTTagCompound stackTag = new NBTTagCompound();
stack.setTagCompound(stackTag);
augs = new NBTTagCompound();
stackTag.setCompoundTag(AugManager.nbtPrefix, augs);
}
return augs;
}
/**
* @param next
* @return
*/
public static List<NBTTagCompound> getItemAugsWithPadding(ItemStack stack) {
List<String> validAugs = AugManager
.getValidAugsForItem(stack.getItem());
NBTTagCompound itemAugs = getItemAugs(stack);
List<NBTTagCompound> augsList = new ArrayList<NBTTagCompound>();
for (String validAug : validAugs) {
if (itemAugs.hasKey(validAug)) {
NBTTagCompound matchedAug = itemAugs.getCompoundTag(validAug);
augsList.add(matchedAug);
} else {
NBTTagCompound newAug = AugManager.newAugOfType(validAug);
augsList.add(newAug);
itemAugs.setCompoundTag(validAug, newAug);
NBTTagCompound newModule = validModule.newModuleTag();
modulesList.add(newModule);
itemModule.setCompoundTag(validModule.getName(), newModule);
}
}
return augsList;
return modulesList;
}
/**
@ -199,10 +175,11 @@ public class ItemUtils {
* @param playerAugs
* @return
*/
public static float getTotalWeight(List<NBTTagCompound> playerAugs) {
public static float getTotalWeight(EntityPlayer player,
List<NBTTagCompound> playerAugs) {
float weight = 0;
for (NBTTagCompound aug : playerAugs) {
weight += AugManager.getWeight(aug);
weight += PowerModule.getModuleFromNBT(aug).getWeight(player, aug);
}
return weight;
}

View file

@ -10,6 +10,8 @@ import java.io.IOException;
import machinemuse.powersuits.common.Config;
import machinemuse.powersuits.common.MuseLogger;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
@ -21,6 +23,7 @@ import cpw.mods.fml.common.network.Player;
*
*/
public abstract class MusePacket {
protected static final int READ_ERROR = -150;
protected Player player;
@ -66,8 +69,12 @@ public abstract class MusePacket {
/**
* Called by the network manager since it does all the packet mapping
*
* @param player2
*/
public abstract void handleSelf();
public abstract void handleClient(EntityClientPlayerMP player);
public abstract void handleServer(EntityPlayerMP player);
public int readInt() {
try {
@ -206,32 +213,36 @@ public abstract class MusePacket {
* Reads a string from a packet
*/
public String readString(int maxlength)
throws IOException
{
short length = datain.readShort();
try {
short length = datain.readShort();
if (length > maxlength)
{
throw new IOException(
"Received string length longer than maximum allowed ("
+ length + " > " + maxlength + ")");
}
else if (length < 0)
{
throw new IOException(
"Received string length is less than zero! Weird string!");
}
else
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; ++i)
if (length > maxlength)
{
builder.append(datain.readChar());
throw new IOException(
"Received string length longer than maximum allowed ("
+ length + " > " + maxlength + ")");
}
else if (length < 0)
{
throw new IOException(
"Received string length is less than zero! Weird string!");
}
else
{
StringBuilder builder = new StringBuilder();
return builder.toString();
for (int i = 0; i < length; ++i)
{
builder.append(datain.readChar());
}
return builder.toString();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View file

@ -11,22 +11,35 @@ import java.lang.reflect.InvocationTargetException;
import machinemuse.powersuits.common.Config;
import machinemuse.powersuits.common.MuseLogger;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.relauncher.Side;
/**
* @author MachineMuse
*
*/
public class MusePacketHandler implements IPacketHandler {
public MusePacketHandler register() {
addPacketType(1, MusePacketUpgradeRequest.class);
addPacketType(2, MusePacketInventoryRefresh.class);
NetworkRegistry.instance().registerChannel(this,
Config.getNetworkChannelName());
return this;
}
public static BiMap<Integer, Constructor<? extends MusePacket>> packetConstructors = HashBiMap
.create();
@ -36,7 +49,12 @@ public class MusePacketHandler implements IPacketHandler {
if (payload.channel.equals(Config.getNetworkChannelName())) {
MusePacket repackaged = repackage(payload, player);
if (repackaged != null) {
repackaged.handleSelf();
Side side = FMLCommonHandler.instance().getEffectiveSide();
if (side == Side.CLIENT) {
repackaged.handleClient((EntityClientPlayerMP) player);
} else if (side == Side.SERVER) {
repackaged.handleServer((EntityPlayerMP) player);
}
}
}
}
@ -50,13 +68,13 @@ public class MusePacketHandler implements IPacketHandler {
int packetType;
try {
packetType = data.readInt();
repackaged = useConstructor(packetConstructors.get(packetType),
data, player);
} catch (IOException e) {
MuseLogger.logError("PROBLEM READING PACKET TYPE D:");
e.printStackTrace();
return null;
}
repackaged = useConstructor(packetConstructors.get(packetType), data,
player);
return repackaged;
}
@ -140,15 +158,4 @@ public class MusePacketHandler implements IPacketHandler {
return false;
}
public void register() {
addPacketType(1, MusePacketUpgradeRequest.class);
addPacketType(2, MusePacketInventory.class);
NetworkRegistry.instance().registerChannel(this,
Config.getNetworkChannelName());
}
// UpgradeRequest,
// DowngradeRequest,
// AugData,
// InventoryRefresh;
}

View file

@ -10,24 +10,24 @@ import machinemuse.powersuits.gui.MuseGui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.relauncher.Side;
/**
* @author MachineMuse
*
*/
public class MusePacketInventory extends MusePacket {
public class MusePacketInventoryRefresh extends MusePacket {
protected ItemStack stack;
protected int slot;
/**
* @param player
*/
public MusePacketInventory(Player player, int slot, ItemStack stack) {
public MusePacketInventoryRefresh(Player player, int slot,
ItemStack stack) {
super(player);
writeInt(slot);
writeItemStack(stack);
@ -37,7 +37,7 @@ public class MusePacketInventory extends MusePacket {
* @param player
* @param data
*/
public MusePacketInventory(DataInputStream datain, Player player) {
public MusePacketInventoryRefresh(DataInputStream datain, Player player) {
super(player, datain);
slot = readInt();
stack = readItemStack();
@ -49,19 +49,19 @@ public class MusePacketInventory extends MusePacket {
* @see machinemuse.powersuits.network.MusePacket#handleSelf()
*/
@Override
public void handleSelf() {
Side side = FMLCommonHandler.instance().getEffectiveSide();
if (side == Side.CLIENT) {
EntityClientPlayerMP mpplayer = (EntityClientPlayerMP) player;
IInventory inventory = mpplayer.inventory;
inventory.setInventorySlotContents(slot, stack);
MuseLogger.logDebug("Received slot " + slot);
GuiScreen playerscreen = Minecraft.getMinecraft().currentScreen;
if (playerscreen != null && playerscreen instanceof MuseGui) {
((MuseGui) playerscreen).refresh();
}
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();
}
}
@Override
public void handleServer(EntityPlayerMP player) {
}
}

View file

@ -7,11 +7,13 @@ import java.io.DataInputStream;
import java.io.IOException;
import java.util.List;
import machinemuse.powersuits.augmentation.AugManager;
import machinemuse.powersuits.item.ItemUtils;
import machinemuse.powersuits.powermodule.PowerModule;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
@ -28,7 +30,7 @@ import cpw.mods.fml.relauncher.Side;
public class MusePacketUpgradeRequest extends MusePacket {
protected ItemStack stack;
protected int slot;
protected String aug;
protected String moduleName;
/**
* Constructor for sending this packet.
@ -51,17 +53,13 @@ public class MusePacketUpgradeRequest extends MusePacket {
*
* @param player
* @param data
* @throws IOException
*
*/
public MusePacketUpgradeRequest(DataInputStream data, Player player) {
super(player, data);
slot = readInt();
try {
aug = readString(64);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
moduleName = readString(64);
Side side = FMLCommonHandler.instance().getEffectiveSide();
if (side == Side.SERVER) {
EntityPlayerMP srvplayer = (EntityPlayerMP) player;
@ -70,27 +68,36 @@ public class MusePacketUpgradeRequest extends MusePacket {
}
@Override
public void handleSelf() {
Side side = FMLCommonHandler.instance().getEffectiveSide();
if (side == Side.SERVER) {
if (aug != null) {
InventoryPlayer inventory = ((EntityPlayerMP) player).inventory;
int entityId = ((EntityPlayerMP) player).entityId;
List<ItemStack> cost = AugManager.getInstallCost(aug);
if (ItemUtils.hasInInventory(cost, inventory)) {
List<Integer> slots = ItemUtils.deleteFromInventory(
AugManager.getInstallCost(aug), inventory);
AugManager.upgrade(ItemUtils.getItemAugs(inventory
.getStackInSlot(slot)), aug);
slots.add(this.slot);
for (Integer slotiter : slots) {
MusePacket reply = new MusePacketInventory(player,
slotiter, inventory.getStackInSlot(slotiter));
PacketDispatcher.sendPacketToPlayer(reply.getPacket(),
player);
}
public void handleServer(EntityPlayerMP playerEntity) {
if (moduleName != null) {
InventoryPlayer inventory = playerEntity.inventory;
int entityId = playerEntity.entityId;
PowerModule moduleType = PowerModule.getModuleByID(moduleName);
NBTTagCompound moduleTag = PowerModule.getItemModules(stack)
.getCompoundTag(
moduleName);
List<ItemStack> cost = moduleType.getCost(playerEntity,
moduleTag);
if (ItemUtils.hasInInventory(cost, inventory)) {
List<Integer> slots = ItemUtils.deleteFromInventory(
cost, inventory);
moduleType.onUpgrade(playerEntity, moduleTag);
slots.add(this.slot);
for (Integer slotiter : slots) {
MusePacket reply = new MusePacketInventoryRefresh(
player,
slotiter, inventory.getStackInSlot(slotiter));
PacketDispatcher.sendPacketToPlayer(reply.getPacket(),
player);
}
}
}
}
@Override
public void handleClient(EntityClientPlayerMP player) {
// TODO Auto-generated method stub
}
}

View file

@ -0,0 +1,309 @@
/**
*
*/
package machinemuse.powersuits.powermodule;
import java.util.ArrayList;
import java.util.List;
import machinemuse.powersuits.common.MuseLogger;
import machinemuse.powersuits.item.ItemPowerArmor;
import machinemuse.powersuits.item.ItemPowerTool;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
/**
* PowerModule is the base class for the modules which can be installed in
* various power armor items.
*
* @author MachineMuse
*
*/
public abstract class PowerModule {
/**
* Contains constant strings. Mainly for consistency.
*
* @author MachineMuse
*/
public static final class Constants {
public static final String NAME = "Name";
public static final String MAXENERGY = "Maximum Energy";
public static final String CURRENERGY = "Current Energy";
public static final String LEVEL = "Level";
public static final String DURABILITY = "Durability";
public static final String nbtPrefix = "mmmpsmod";
}
/**
* Initialization for the module list
*/
static {
new PowerModuleIronPlating();
new PowerModuleBattery();
}
/**
* Module List
*/
public static BiMap<String, PowerModule> allModules = HashBiMap.create();
/**
* Module validity mappings. Slot 0-3 = armor, 4 = tool
*/
public static List<PowerModule>[] validModulesForSlot = new ArrayList[5];
/**
* Constructor adds the module to the appropriate lists.
*/
public PowerModule() {
for (int i = 0; i < 5; i++) {
if (validModulesForSlot[i] == null) {
validModulesForSlot[i] = new ArrayList();
}
if (getValidSlots()[i]) {
validModulesForSlot[i].add(this);
}
}
allModules.put(getName(), this);
}
/**
* Since modules themselves should be singletons, this is our instance
* pattern.
*
* @return A new NBTTagCompound describing a new instance of this module
* (pre-upgrade)
*/
public abstract NBTTagCompound newModuleTag();
/**
* Returns the name of the module. Should be unique. Used for both tooltips
* and for ID mapping.
*
* @return A string
*/
public abstract String getName();
/**
* Returns the weight of the module in kg. More than 25kg of equipment will
* start to slow a player down.
*
* @return Module's weight in kg
*/
public abstract float getWeight(
EntityPlayer player, NBTTagCompound moduleTag);
/**
* Returns the current upgrade level of the module based on the nbttag.
* Level 0 modules should do nothing.
*
* @return Module's weight in kg
*/
public int getLevel(
EntityPlayer player, NBTTagCompound moduleTag) {
return moduleTag.getInteger(Constants.LEVEL);
}
/**
* Returns the maximum level of the upgrade. If the upgrade's level is equal
* or greater, further upgrades will not be allowed.
*
* @return
*/
public abstract int getMaxLevel(
EntityPlayer player, NBTTagCompound moduleTag);
/**
* Returns the current armor value provided by the module.
*
* @return
*/
public abstract int getArmorValue(
EntityPlayer player, NBTTagCompound moduleTag);
/**
* Returns the lines of text to appear in the module's tooltip in the
* tinkertable UI.
*
* @return
*/
public abstract List<String> getTooltip(
EntityPlayer player, NBTTagCompound moduleTag);
/**
* Returns the list of itemstacks a player should receive if they uninstall
* this module.
*
* @return
*/
public abstract List<ItemStack> getRefund(
EntityPlayer player, NBTTagCompound moduleTag);
/**
* Returns the list of itemstacks required to upgrade this module.
*
* @return
*/
public abstract List<ItemStack> getCost(
EntityPlayer player, NBTTagCompound moduleTag);
/**
* Returns the a list of modules which must be purchased before this one
* will be available. Can be different depending on level.
*
* @return
*/
public abstract List<PowerModule> getPrerequisites(
EntityPlayer player, NBTTagCompound moduleTag);
/**
* Returns an array of booleans, one for each possible itemslot, describing
* whether or not the module can be slotted in that item.
*
* @return
*/
public abstract boolean[] getValidSlots();
/**
* Returns a category name for the module. Modules with the same category
* will be grouped together in the UI.
*
* @return
*/
public abstract String getCategory();
/**
* Event trigger in the player tick.
*/
public abstract void onPlayerTick(
EntityPlayer player, NBTTagCompound moduleTag);
/**
* Event trigger when the item is assigned durability damage.
*
* @param player
* @param moduleTag
* @param damageAmount
*/
public abstract void onDamageItem(
EntityPlayer player, NBTTagCompound moduleTag, float damageAmount);
/**
* Event trigger for when the item is upgraded. Should include leveling up.
*
* @param player
* @param moduleTag
* @return
*/
public abstract boolean onUpgrade(
EntityPlayer player, NBTTagCompound moduleTag);
/**
* Texture file for the module in GUI.
*
* @return
*/
public String getIconFile() {
return "/moduleicons.png";
}
/**
* Texture file for the module when slotted in an item.
*
* @return
*/
public String getItemOverlayFile() {
return "/moduleoverlays.png";
}
/**
* Index in the 256p*256p icon file. Indices go like this:
*
* <pre>
* 0 1 2 3 ...
* 16 18 19 20 ...
* 32 33 34 35 ...
* </pre>
*
* @return
*/
public abstract int getIconIndex();
/**
* Index in the item overlay file, same convention as icon index
*
* @return
*/
public abstract int getItemOverlayIndex();
/**
*
*
* @param next
* @return
*/
public static NBTTagCompound getItemModules(ItemStack stack) {
NBTTagCompound augs = null;
if (stack.hasTagCompound()) {
NBTTagCompound stackTag = stack.getTagCompound();
if (stackTag.hasKey(Constants.nbtPrefix)) {
augs = stackTag.getCompoundTag(Constants.nbtPrefix);
} else {
augs = new NBTTagCompound();
stackTag.setCompoundTag(Constants.nbtPrefix, augs);
}
} else {
NBTTagCompound stackTag = new NBTTagCompound();
stack.setTagCompound(stackTag);
augs = new NBTTagCompound();
stackTag.setCompoundTag(Constants.nbtPrefix, augs);
}
return augs;
}
public static void addModule(String id, PowerModule p) {
if (allModules.containsKey(id)) {
MuseLogger.logError("Warning: module " + p.getName()
+ " already bound!");
}
allModules.put(id, p);
}
public static PowerModule getModuleByID(String i) {
if (allModules.containsKey(i)) {
return allModules.get(i);
} else {
MuseLogger.logError("Module " + i + " not assigned!");
return null;
}
}
public static PowerModule getModuleFromNBT(NBTTagCompound moduleTag) {
return getModuleByID(moduleTag.getString("Name"));
}
public static String getModuleID(PowerModule module) {
if (allModules.inverse().containsKey(module)) {
return allModules.inverse().get(module);
} else {
MuseLogger.logError("Module " + module.getName()
+ " not initialized!");
return "";
}
}
public static List<PowerModule> getValidModulesForItem(Item item) {
if (item instanceof ItemPowerArmor) {
ItemPowerArmor itema = (ItemPowerArmor) item;
return validModulesForSlot[itema.armorType];
} else if (item instanceof ItemPowerTool) {
return validModulesForSlot[4];
} else {
return null;
}
}
}

View file

@ -0,0 +1,129 @@
package machinemuse.powersuits.powermodule;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class PowerModuleBattery extends PowerModule {
@Override
public NBTTagCompound newModuleTag() {
NBTTagCompound newtag = new NBTTagCompound();
newtag.setString("Name", getName());
newtag.setFloat("Maximum Energy", 100f);
newtag.setFloat("Current Energy", 100f);
newtag.setInteger("Level", 0);
return newtag;
}
@Override
public String getName() {
return "Electric Battery";
}
@Override
public float getWeight(EntityPlayer player, NBTTagCompound moduleTag) {
return 10;
}
@Override
public int getLevel(EntityPlayer player, NBTTagCompound moduleTag) {
return moduleTag.getInteger("Level");
}
@Override
public int getMaxLevel(EntityPlayer player, NBTTagCompound moduleTag) {
return 4;
}
@Override
public int getArmorValue(EntityPlayer player, NBTTagCompound moduleTag) {
return getLevel(player, moduleTag);
}
@Override
public List<String> getTooltip(EntityPlayer player, NBTTagCompound moduleTag) {
String[] strings = { getName(), "Battery" };
return Arrays.asList(strings);
}
@Override
public List<ItemStack> getRefund(EntityPlayer player,
NBTTagCompound moduleTag) {
List<ItemStack> stacks = new ArrayList<ItemStack>();
stacks.add(new ItemStack(Item.redstone,
(getLevel(player, moduleTag) + 1) * 4));
return stacks;
}
@Override
public List<ItemStack> getCost(EntityPlayer player, NBTTagCompound moduleTag) {
List<ItemStack> stacks = new ArrayList<ItemStack>();
stacks.add(new ItemStack(Item.redstone,
(getLevel(player, moduleTag) + 1) * 4));
return stacks;
}
@Override
public List<PowerModule> getPrerequisites(EntityPlayer player,
NBTTagCompound moduleTag) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean[] getValidSlots() {
boolean[] slots = { true, true, true, true, true };
return slots;
}
@Override
public String getCategory() {
return "Energy";
}
@Override
public void onPlayerTick(EntityPlayer player, NBTTagCompound moduleTag) {
/** Do nothing **/
}
@Override
public void onDamageItem(EntityPlayer player, NBTTagCompound moduleTag,
float damageAmount) {
/** Do nothing **/
}
@Override
public boolean onUpgrade(EntityPlayer player, NBTTagCompound moduleTag) {
int level = moduleTag.getInteger("Level");
if (level < getMaxLevel(player, moduleTag)) {
moduleTag.setInteger("Level", level + 1);
return true;
} else {
return false;
}
}
@Override
public int getIconIndex() {
return 0;
}
@Override
public int getItemOverlayIndex() {
return 0;
}
public float getStoredEnergy(EntityPlayer player, NBTTagCompound batteryTag) {
return batteryTag.getFloat("Current Energy");
}
public float getMaxEnergy(EntityPlayer player, NBTTagCompound batteryTag) {
return batteryTag.getFloat("Maximum Energy");
}
}

View file

@ -0,0 +1,122 @@
package machinemuse.powersuits.powermodule;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class PowerModuleIronPlating extends PowerModule {
@Override
public NBTTagCompound newModuleTag() {
NBTTagCompound newtag = new NBTTagCompound();
newtag.setString("Name", getName());
newtag.setFloat("Durability", 100f);
newtag.setInteger("Level", 0);
return newtag;
}
@Override
public String getName() {
return "Iron Armor Plating";
}
@Override
public float getWeight(EntityPlayer player, NBTTagCompound moduleTag) {
return 10;
}
@Override
public int getLevel(EntityPlayer player, NBTTagCompound moduleTag) {
return moduleTag.getInteger("Level");
}
@Override
public int getMaxLevel(EntityPlayer player, NBTTagCompound moduleTag) {
return 4;
}
@Override
public int getArmorValue(EntityPlayer player, NBTTagCompound moduleTag) {
return getLevel(player, moduleTag);
}
@Override
public List<String> getTooltip(EntityPlayer player, NBTTagCompound moduleTag) {
String[] strings = { "Hi", "Module" };
return Arrays.asList(strings);
}
@Override
public List<ItemStack> getRefund(EntityPlayer player,
NBTTagCompound moduleTag) {
List<ItemStack> stacks = new ArrayList<ItemStack>();
stacks.add(new ItemStack(Item.redstone,
(getLevel(player, moduleTag) + 1) * 4));
return stacks;
}
@Override
public List<ItemStack> getCost(EntityPlayer player, NBTTagCompound moduleTag) {
List<ItemStack> stacks = new ArrayList<ItemStack>();
stacks.add(new ItemStack(Item.redstone,
(getLevel(player, moduleTag) + 1) * 4));
return stacks;
}
@Override
public List<PowerModule> getPrerequisites(EntityPlayer player,
NBTTagCompound moduleTag) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean[] getValidSlots() {
boolean[] slots = { true, true, true, true, false };
return slots;
}
@Override
public String getCategory() {
return "Defense";
}
@Override
public void onPlayerTick(EntityPlayer player, NBTTagCompound moduleTag) {
/** Do nothing **/
}
@Override
public void onDamageItem(EntityPlayer player, NBTTagCompound moduleTag,
float damageAmount) {
float durability = moduleTag.getFloat("Durability");
moduleTag.setFloat("Durability", durability - damageAmount);
}
@Override
public boolean onUpgrade(EntityPlayer player, NBTTagCompound moduleTag) {
int level = moduleTag.getInteger("Level");
if (level < getMaxLevel(player, moduleTag)) {
moduleTag.setInteger("Level", level + 1);
return true;
} else {
return false;
}
}
@Override
public int getIconIndex() {
return 0;
}
@Override
public int getItemOverlayIndex() {
return 0;
}
}

BIN
moduleicons.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
tinkertable.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB