See extended description
Changed module architecture again Added rounded corners / borders to gui Moved all packages into /net/
This commit is contained in:
parent
b9ecec9b43
commit
e2904f860e
40 changed files with 0 additions and 6574 deletions
|
@ -1,86 +0,0 @@
|
|||
package machinemuse.general.geometry;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* A class representing an RGBA colour and various helper functions. Mainly to
|
||||
* improve readability elsewhere.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*/
|
||||
public class Colour {
|
||||
/**
|
||||
* The RGBA values are stored as floats from 0.0F (nothing) to 1.0F (full
|
||||
* saturation/opacity)
|
||||
*/
|
||||
public float r, g, b, a;
|
||||
|
||||
/**
|
||||
* Constructor. Just sets the RGBA values to the parameters.
|
||||
*/
|
||||
public Colour(float r, float g, float b, float a) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Secondary constructor. Sets RGB accordingly and sets alpha to 1.0F (full
|
||||
* opacity)
|
||||
*/
|
||||
public Colour(float r, float g, float b) {
|
||||
this(r, g, b, 1.0F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes colours in the integer format that Minecraft uses, and converts.
|
||||
*/
|
||||
public Colour(int c) {
|
||||
this.a = (c >> 24 & 255) / 255.0F;
|
||||
this.r = (c >> 16 & 255) / 255.0F;
|
||||
this.g = (c >> 8 & 255) / 255.0F;
|
||||
this.b = (c & 255) / 255.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this colour as an int in Minecraft's format (I think)
|
||||
*
|
||||
* @return int value of this colour
|
||||
*/
|
||||
public int getInt() {
|
||||
int val = 0;
|
||||
val = val | ((int) (a * 255) << 24);
|
||||
val = val | ((int) (r * 255) << 16);
|
||||
val = val | ((int) (g * 255) << 8);
|
||||
val = val | ((int) (b * 255));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a colour with RGB set to the same value ie. a shade of grey.
|
||||
*/
|
||||
|
||||
public static Colour getGreyscale(float value, float alpha) {
|
||||
return new Colour(value, value, value, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a colour at interval interval along a linear gradient from this
|
||||
* to target
|
||||
*/
|
||||
|
||||
public Colour interpolate(Colour target, float interval) {
|
||||
float complement = 1 - interval;
|
||||
return new Colour(
|
||||
this.r * complement + target.r * interval,
|
||||
this.g * complement + target.g * interval,
|
||||
this.b * complement + target.b * interval,
|
||||
this.a * complement + target.a * interval);
|
||||
}
|
||||
|
||||
public void doGL() {
|
||||
GL11.glColor4f(r, g, b, a);
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package machinemuse.general.geometry;
|
||||
|
||||
public class FlyFromMiddlePoint2D extends Point2D {
|
||||
protected long spawnTime;
|
||||
protected float timeTo;
|
||||
|
||||
public FlyFromMiddlePoint2D(float x, float y, float timeTo) {
|
||||
super(x, y);
|
||||
spawnTime = System.currentTimeMillis();
|
||||
this.timeTo = timeTo;
|
||||
}
|
||||
|
||||
public FlyFromMiddlePoint2D(Point2D target, float timeTo) {
|
||||
this(target.x(), target.y(), timeTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float x() {
|
||||
return doRatio(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float y() {
|
||||
return doRatio(y);
|
||||
}
|
||||
|
||||
public float doRatio(float val) {
|
||||
long elapsed = System.currentTimeMillis() - spawnTime;
|
||||
float ratio = elapsed / timeTo;
|
||||
if (ratio > 1.0F) {
|
||||
return val;
|
||||
} else {
|
||||
return val * ratio;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,576 +0,0 @@
|
|||
package machinemuse.general.geometry;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Contains a bunch of random OpenGL-related functions, accessed statically.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public abstract class MuseRenderer {
|
||||
|
||||
/**
|
||||
* Mostly for placeholder graphics, this function draws a 3x3 grid of swirly
|
||||
* circles over a 16x16 square.
|
||||
*/
|
||||
public static void draw3x3placeholder(boolean a, boolean b, boolean c,
|
||||
boolean d,
|
||||
boolean e, boolean f, boolean g, boolean h, boolean i) {
|
||||
if (a)
|
||||
drawCircleAround(3, 3, 2);
|
||||
if (b)
|
||||
drawCircleAround(8, 3, 2);
|
||||
if (c)
|
||||
drawCircleAround(13, 3, 2);
|
||||
|
||||
if (d)
|
||||
drawCircleAround(3, 8, 2);
|
||||
if (e)
|
||||
drawCircleAround(8, 8, 2);
|
||||
if (f)
|
||||
drawCircleAround(13, 8, 2);
|
||||
|
||||
if (g)
|
||||
drawCircleAround(3, 13, 2);
|
||||
if (h)
|
||||
drawCircleAround(8, 13, 2);
|
||||
if (i)
|
||||
drawCircleAround(13, 13, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a swirly green circle at the specified coordinates in the current
|
||||
* reference frame.
|
||||
*
|
||||
* @param xoffset
|
||||
* @param yoffset
|
||||
* @param radius
|
||||
*/
|
||||
public static void drawCircleAround(float xoffset, float yoffset,
|
||||
float radius) {
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
// GL11.glDepthFunc(GL11.GL_GREATER);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
|
||||
int numSegments = 360;
|
||||
double theta = (2 * Math.PI) / numSegments;
|
||||
|
||||
int start = (int) (System.currentTimeMillis() / 4 % numSegments);
|
||||
double x = radius * Math.sin(theta * start);
|
||||
double y = radius * Math.cos(theta * start);
|
||||
double tf = Math.tan(theta);
|
||||
double rf = Math.cos(theta);
|
||||
double tx;
|
||||
double ty;
|
||||
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++) {
|
||||
GL11.glColor4f(c.r, c.g, c.b, c.a);
|
||||
GL11.glVertex2d(x + xoffset, y + yoffset);
|
||||
tx = y;
|
||||
ty = -x;
|
||||
x += tx * tf;
|
||||
y += ty * tf;
|
||||
x *= rf;
|
||||
y *= rf;
|
||||
c.r += theta / 7;
|
||||
c.b += theta / 7;
|
||||
c.a += theta / 2;
|
||||
}
|
||||
GL11.glEnd();
|
||||
|
||||
texturelessOff();
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
// GL11.glDepthFunc(GL11.GL_LEQUAL);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a swirly green circle at the specified coordinates in the current
|
||||
* reference frame.
|
||||
*
|
||||
* @param xoffset
|
||||
* @param yoffset
|
||||
* @param radius
|
||||
*/
|
||||
public static void drawTriangles2D(float[] v, float[] c,
|
||||
int[] i) {
|
||||
arraysOnC();
|
||||
texturelessOn();
|
||||
smoothingOn();
|
||||
on2D();
|
||||
|
||||
// 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 colours = BufferUtils.createFloatBuffer(c.length);
|
||||
colours.put(c);
|
||||
colours.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.glColorPointer(4, 0, colours);
|
||||
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, indices);
|
||||
|
||||
// GL11.glTranslatef(0, radius / subdivisions, 0);
|
||||
// }
|
||||
// GL11.glTranslatef(radius / subdivisions, -radius * 2, 0);
|
||||
// }
|
||||
// GL11.glPopMatrix();
|
||||
|
||||
off2D();
|
||||
texturelessOff();
|
||||
arraysOff();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the given vertex arrays (textureless)
|
||||
*
|
||||
*/
|
||||
public static void drawTriangles3DR(float[] v, float[] c,
|
||||
int[] i) {
|
||||
arraysOnC();
|
||||
texturelessOn();
|
||||
smoothingOn();
|
||||
|
||||
// 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 colours = BufferUtils.createFloatBuffer(c.length);
|
||||
colours.put(c);
|
||||
colours.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.glColorPointer(4, 0, colours);
|
||||
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, indices);
|
||||
|
||||
// GL11.glTranslatef(0, radius / subdivisions, 0);
|
||||
// }
|
||||
// GL11.glTranslatef(radius / subdivisions, -radius * 2, 0);
|
||||
// }
|
||||
// GL11.glPopMatrix();
|
||||
|
||||
texturelessOff();
|
||||
arraysOff();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 2D rendering mode on/off
|
||||
*/
|
||||
|
||||
public static void on2D() {
|
||||
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
// GL11.glDisable(GL11.GL_CULL_FACE);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
|
||||
// attempt at fake antialiasing
|
||||
// GL11.glBlendFunc(GL11.GL_SRC_ALPHA_SATURATE, GL11.GL_ONE);
|
||||
// GL11.glColorMask(false, false, false, true);
|
||||
// GL11.glClearColor(0, 0, 0, 0);
|
||||
// GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
|
||||
// GL11.glColorMask(true, true, true, true);
|
||||
|
||||
// GL11.glHint(GL11.GL_POINT_SMOOTH, GL11.GL_NICEST);
|
||||
// GL11.glHint(GL11.GL_LINE_SMOOTH, GL11.GL_NICEST);
|
||||
// GL11.glHint(GL11.GL_POLYGON_SMOOTH, GL11.GL_NICEST);
|
||||
// GL11.glDepthFunc(GL11.GL_GREATER);
|
||||
}
|
||||
|
||||
public static void off2D() {
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Arrays on/off
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Call before doing any pure geometry (ie. with colours rather than
|
||||
* textures).
|
||||
*/
|
||||
public static void texturelessOn() {
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Call after doing pure geometry (ie. with colours) to go back to the
|
||||
* texture mode (default).
|
||||
*/
|
||||
public static void texturelessOff() {
|
||||
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.
|
||||
*/
|
||||
public static void drawGradientRect(float left, float top, float right,
|
||||
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;
|
||||
|
||||
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 drawItemAt(int x, int y, MuseGui gui, ItemStack item) {
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
// GL11.glDepthFunc(GL11.GL_GREATER);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
|
||||
gui.getRenderItem().zLevel = 100.0F;
|
||||
gui.getRenderItem().renderItemAndEffectIntoGUI(
|
||||
gui.getFontRenderer(), gui.getRenderEngine(), item, x, y);
|
||||
gui.getRenderItem().renderItemOverlayIntoGUI(gui.getFontRenderer(),
|
||||
gui.getRenderEngine(), item, x, y);
|
||||
gui.getRenderItem().zLevel = 0.0F;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void relativeCoords(MuseGui gui) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(gui.width / 2, gui.height / 2, 0);
|
||||
GL11.glScalef(gui.getxSize(), gui.getySize(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void popMatrix() {
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a rectangular prism (cube or otherwise orthogonal)
|
||||
*/
|
||||
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)
|
||||
};
|
||||
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)
|
||||
|
||||
};
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package machinemuse.general.geometry;
|
||||
|
||||
/**
|
||||
* Base class for Points. The main reason for this is to have a
|
||||
* pass-by-reference coordinate with getter/setter functions so that points with
|
||||
* more elaborate behaviour can be implemented - such as for open/close
|
||||
* animations.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class Point2D {
|
||||
protected float x;
|
||||
protected float y;
|
||||
|
||||
public Point2D(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Point2D(Point2D p) {
|
||||
this(p.x, p.y);
|
||||
}
|
||||
|
||||
public float x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Point2D plus(Point2D b) {
|
||||
return new Point2D(x + b.x, y + b.y);
|
||||
}
|
||||
|
||||
public Point2D minus(Point2D b) {
|
||||
return new Point2D(x - b.x, y - b.y);
|
||||
}
|
||||
|
||||
public Point2D times(float f) {
|
||||
return new Point2D(x * f, y * f);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package machinemuse.powersuits.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class TileEntityTinkerTable extends TileEntity {
|
||||
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package machinemuse.powersuits.client;
|
||||
|
||||
import machinemuse.powersuits.block.TileEntityTinkerTable;
|
||||
import machinemuse.powersuits.common.CommonProxy;
|
||||
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.ClientRegistry;
|
||||
import cpw.mods.fml.common.registry.TickRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
/**
|
||||
* The Client Proxy does all the things that should only be done client-side,
|
||||
* like registering client-side handlers and renderers.
|
||||
*
|
||||
* @author Claire
|
||||
*
|
||||
*/
|
||||
public class ClientProxy extends CommonProxy {
|
||||
private static EquipmentRenderer eRenderer = new EquipmentRenderer();
|
||||
|
||||
/**
|
||||
* Register all the custom renderers for this mod.
|
||||
*/
|
||||
@Override
|
||||
public void registerRenderers() {
|
||||
for (Item i : PowersuitsMod.allItems) {
|
||||
MinecraftForgeClient.registerItemRenderer(
|
||||
i.shiftedIndex, eRenderer);
|
||||
}
|
||||
// for (Item i : PowersuitsMod.allBlocks) {
|
||||
// MinecraftForgeClient.registerItemRenderer(
|
||||
// i.shiftedIndex, eRenderer);
|
||||
// }
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(
|
||||
TileEntityTinkerTable.class, new TinkerTableRenderer());
|
||||
MinecraftForgeClient.preloadTexture("/tinkertable.png");
|
||||
MinecraftForgeClient.preloadTexture("/moduleicons.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the tick handler (for on-tick behaviour) and packet handler (for
|
||||
* network synchronization and permission stuff).
|
||||
*/
|
||||
@Override
|
||||
public void registerHandlers() {
|
||||
tickHandler = new PlayerTickHandler();
|
||||
TickRegistry.registerTickHandler(tickHandler, Side.CLIENT);
|
||||
|
||||
packetHandler = new MusePacketHandler().register();
|
||||
}
|
||||
}
|
|
@ -1,184 +0,0 @@
|
|||
package machinemuse.powersuits.client;
|
||||
|
||||
import machinemuse.general.geometry.MuseRenderer;
|
||||
import machinemuse.powersuits.item.IModularItem;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.RenderEngine;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.storage.MapData;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
|
||||
/**
|
||||
* Custom renderer for the power armor and tools. Note - this only renders the
|
||||
* item as held in hand, in an inventory slot, or sitting on the ground. To
|
||||
* render the player's armor is a different interface (not sure yet).
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class EquipmentRenderer implements IItemRenderer {
|
||||
|
||||
/**
|
||||
* Forge checks this to see if our custom renderer will handle a certain
|
||||
* type of rendering.
|
||||
*
|
||||
* type can be:
|
||||
*
|
||||
* ENTITY - When the item is floating in the world, e.g. after being tossed
|
||||
* or dropped by a mob.
|
||||
*
|
||||
* INVENTORY - Drawing it on an inventory slot.
|
||||
*
|
||||
* EQUIPPED - Rendering the item in an entity's hand e.g. endermen.
|
||||
*
|
||||
* FIRST_PERSON_MAP - Drawing it in the viewing player's hand
|
||||
*/
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to actually render the item. type is as above, item is the item to
|
||||
* render, and data is some extra data depending on the type.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack itemStack,
|
||||
Object... data) {
|
||||
|
||||
IModularItem item;
|
||||
if (itemStack.getItem() instanceof IModularItem) {
|
||||
item = (IModularItem) (itemStack.getItem());
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case ENTITY:
|
||||
RenderBlocks renderEntity = (RenderBlocks) data[0];
|
||||
EntityItem entityEntity = (EntityItem) data[1];
|
||||
break;
|
||||
case INVENTORY:
|
||||
RenderBlocks renderInventory = (RenderBlocks) data[0];
|
||||
break;
|
||||
case EQUIPPED:
|
||||
RenderBlocks renderEquipped = (RenderBlocks) data[0];
|
||||
EntityLiving entityEquipped = (EntityLiving) data[1];
|
||||
break;
|
||||
case FIRST_PERSON_MAP:
|
||||
EntityPlayer playerFirstPerson = (EntityPlayer) data[0];
|
||||
RenderEngine engineFirstPerson = (RenderEngine) data[1];
|
||||
MapData mapDataFirstPerson = (MapData) data[2];
|
||||
break;
|
||||
default:
|
||||
}
|
||||
switch (item.getItemType()) {
|
||||
case PowerArmorHead:
|
||||
drawHead(itemStack);
|
||||
break;
|
||||
case PowerArmorTorso:
|
||||
drawTorso(itemStack);
|
||||
break;
|
||||
case PowerArmorLegs:
|
||||
drawLegs(itemStack);
|
||||
break;
|
||||
case PowerArmorFeet:
|
||||
drawFeet(itemStack);
|
||||
break;
|
||||
case PowerTool:
|
||||
drawTool(itemStack);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHead(ItemStack itemStack) {
|
||||
MuseRenderer.draw3x3placeholder(
|
||||
true, true, true,
|
||||
true, false, true,
|
||||
false, false, false);
|
||||
}
|
||||
|
||||
public void drawTorso(ItemStack itemStack) {
|
||||
MuseRenderer.draw3x3placeholder(
|
||||
true, false, true,
|
||||
true, true, true,
|
||||
true, true, true);
|
||||
}
|
||||
|
||||
public void drawLegs(ItemStack itemStack) {
|
||||
float z = 1.0F;
|
||||
float a = 1F;
|
||||
|
||||
float[] v = {
|
||||
2, 1, z,
|
||||
14, 1, z,
|
||||
15, 15, z,
|
||||
9, 15, z,
|
||||
8, 5, z,
|
||||
7, 15, z,
|
||||
1, 15, z
|
||||
};
|
||||
|
||||
float[] c = {
|
||||
1.0F, 1.0F, 1.0F, a,
|
||||
0.1F, 0.1F, 0.1F, a,
|
||||
0.1F, 0.1F, 0.1F, a,
|
||||
0.7F, 0.7F, 0.7f, a,
|
||||
0.8F, 0.8F, 0.8F, a,
|
||||
0.9F, 0.9F, 0.9F, a,
|
||||
1.0F, 1.0F, 1.0F, a
|
||||
};
|
||||
int[] i = {
|
||||
0, 6, 5,
|
||||
0, 5, 4,
|
||||
0, 4, 1,
|
||||
1, 3, 2,
|
||||
1, 4, 3
|
||||
};
|
||||
MuseRenderer.drawTriangles2D(v, c, i);
|
||||
}
|
||||
|
||||
public void drawFeet(ItemStack itemStack) {
|
||||
MuseRenderer.draw3x3placeholder(
|
||||
true, true, true,
|
||||
false, true, false,
|
||||
false, true, false);
|
||||
// MuseRenderer.drawRectPrism(0, 16, 0, 16, 0, 16);
|
||||
}
|
||||
|
||||
public void drawTool(ItemStack itemStack) {
|
||||
MuseRenderer.draw3x3placeholder(
|
||||
true, true, true,
|
||||
false, true, false,
|
||||
false, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not to use the RenderHelper for this item. Helper can be:
|
||||
*
|
||||
* ENTITY_ROTATION - Isometric rotation, for block items
|
||||
*
|
||||
* ENTITY_BOBBING - Up-and-down bobbing effect for EntityItem
|
||||
*
|
||||
* EQUIPPED_BLOCK - Determines if the currently equipped item should be
|
||||
* rendered as a 3D block or as a 2D texture.
|
||||
*
|
||||
* BLOCK_3D - Determines if the item should equate to a block that has
|
||||
* RenderBlocks.renderItemIn3d return true
|
||||
*
|
||||
* INVENTORY_BLOCK - Determines if the item should be rendered in GUI
|
||||
* inventory slots as a 3D block or as a 2D texture.
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,
|
||||
ItemRendererHelper helper) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
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);
|
||||
// }
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package machinemuse.powersuits.common;
|
||||
|
||||
import machinemuse.powersuits.network.MusePacketHandler;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.registry.TickRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
/**
|
||||
* Server side of the CommonProxy/ClientProxy paradigm. Provides functions which
|
||||
* the ClientProxy will override if the behaviour is different for client and
|
||||
* server.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class CommonProxy {
|
||||
public static String ITEMS_PNG = "/tutorial/generic/items.png";
|
||||
public static String BLOCK_PNG = "/tutorial/generic/block.png";
|
||||
|
||||
public static ITickHandler tickHandler;
|
||||
public static MusePacketHandler packetHandler;
|
||||
|
||||
/**
|
||||
* Only the client needs to register renderers.
|
||||
*/
|
||||
public void registerRenderers() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the server-side tickhandler and packethandler.
|
||||
*/
|
||||
public void registerHandlers() {
|
||||
tickHandler = new PlayerTickHandler();
|
||||
TickRegistry.registerTickHandler(tickHandler, Side.SERVER);
|
||||
|
||||
packetHandler = new MusePacketHandler();
|
||||
packetHandler.register();
|
||||
}
|
||||
}
|
|
@ -1,182 +0,0 @@
|
|||
package machinemuse.powersuits.common;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.StepSound;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
|
||||
/**
|
||||
* Initial attempt at storing all tweakable/configurable values in one class.
|
||||
* This got really messy really fast so it's in the process of being reworked.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class Config extends Configuration {
|
||||
private static final int[] assignedItemIDs = new int[Items.values().length];
|
||||
private static final int[] assignedBlockIDs = new int[Blocks.values().length];
|
||||
private static Configuration config;
|
||||
|
||||
/**
|
||||
* Called in the pre-init phase of initialization, informs Forge that we
|
||||
* want the following blockIDs.
|
||||
*
|
||||
* @param config
|
||||
* The Forge configuration object which will handle such
|
||||
* requests.
|
||||
*/
|
||||
public static void init(Configuration config) {
|
||||
Config.config = config;
|
||||
config.load();
|
||||
|
||||
// Request block IDs
|
||||
for (Blocks b : Blocks.values()) {
|
||||
assignedBlockIDs[b.ordinal()] =
|
||||
config.getBlock(b.englishName, 1002).getInt();
|
||||
}
|
||||
|
||||
// Request item IDs
|
||||
for (Items i : Items.values()) {
|
||||
assignedItemIDs[i.ordinal()] =
|
||||
config.getItem(i.englishName, 5000).getInt();
|
||||
}
|
||||
config.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* The packet channel for this mod. We will only listen for and send packets
|
||||
* on this 'channel'. Max of 16 characters.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getNetworkChannelName() {
|
||||
return "mmmPowerSuits";
|
||||
}
|
||||
|
||||
/**
|
||||
* The default creative tab to add all these items to. This behaviour may
|
||||
* change if more items are added, but I doubt it.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static CreativeTabs getCreativeTab() {
|
||||
return CreativeTabs.tabMisc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Once Forge has assigned IDs for all our items, this function will tell us
|
||||
* what was actually assigned.
|
||||
*
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
public static int getAssignedItemID(Items item) {
|
||||
if (assignedItemIDs[item.ordinal()] == 0) {
|
||||
assignedItemIDs[item.ordinal()] = config.getItem(item.englishName,
|
||||
1002).getInt();
|
||||
}
|
||||
return assignedItemIDs[item.ordinal()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Once Forge has assigned IDs for all our blocks, this function will tell
|
||||
* us what was actually assigned.
|
||||
*
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
public static int getAssignedBlockID(Blocks block) {
|
||||
if (assignedBlockIDs[block.ordinal()] == 0) {
|
||||
assignedBlockIDs[block.ordinal()] = config.getBlock(
|
||||
block.englishName, 5000).getInt();
|
||||
}
|
||||
return assignedBlockIDs[block.ordinal()];
|
||||
}
|
||||
|
||||
/**
|
||||
* An enum listing all the blocks that this mod adds. Used for assigning IDs
|
||||
* and various other things.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public static enum Blocks {
|
||||
TinkerTable(1002, 0, "tinkerTable", "Tinker Table",
|
||||
80.0F, Material.iron, Block.soundMetalFootstep,
|
||||
"pickaxe", 1);
|
||||
|
||||
public final int defaultBlockId;
|
||||
public final int textureIndex;
|
||||
public final String idName;
|
||||
public final String englishName;
|
||||
public final float hardness;
|
||||
public final Material material;
|
||||
public final StepSound stepSound;
|
||||
public final String harvestTool;
|
||||
public final int harvestLevel;
|
||||
|
||||
private Blocks(
|
||||
int defaultBlockId, int textureIndex, String idName,
|
||||
String englishName,
|
||||
float hardness, Material material,
|
||||
StepSound stepSound, String harvestTool, int harvestLevel) {
|
||||
this.defaultBlockId = defaultBlockId;
|
||||
this.textureIndex = textureIndex;
|
||||
this.idName = idName;
|
||||
this.englishName = englishName;
|
||||
this.hardness = hardness;
|
||||
this.material = material;
|
||||
this.stepSound = stepSound;
|
||||
this.harvestTool = harvestTool;
|
||||
this.harvestLevel = harvestLevel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An enum listing all the items that this mod adds. Used for assigning IDs
|
||||
* and various other things.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public static enum Items {
|
||||
// Icon index, ID name, English name, Armor Type
|
||||
PowerArmorHead(0, "powerArmorHead", "Power Armor Head"),
|
||||
PowerArmorTorso(1, "powerArmorTorso", "Power Armor Torso"),
|
||||
PowerArmorLegs(2, "powerArmorLegs", "Power Armor Legs"),
|
||||
PowerArmorFeet(3, "powerArmorFeet", "Power Armor Feet"),
|
||||
PowerTool(4, "powerTool", "Power Tool"),
|
||||
|
||||
;
|
||||
|
||||
public final int iconIndex;
|
||||
public final String idName;
|
||||
public final String englishName;
|
||||
|
||||
Items(int iconIndex,
|
||||
String idName, String englishName) {
|
||||
this.iconIndex = iconIndex;
|
||||
this.idName = idName;
|
||||
this.englishName = englishName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An enum to describe the various GUI windows which can appear. IDs are
|
||||
* less important here since this data isn't saved or synced.
|
||||
*
|
||||
* @author Claire
|
||||
*
|
||||
*/
|
||||
public static enum Guis {
|
||||
GuiTinkerTable,
|
||||
GuiSuitManager;
|
||||
}
|
||||
|
||||
public static int getAugMaxID() {
|
||||
return 256;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package machinemuse.powersuits.common;
|
||||
|
||||
import machinemuse.powersuits.gui.GuiTinkerTable;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
|
||||
/**
|
||||
* Gui handler for this mod. Mainly just takes an ID according to what was
|
||||
* passed to player.OpenGUI, and opens the corresponding GUI.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class GuiHandler implements IGuiHandler {
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
|
||||
int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
|
||||
int x, int y, int z) {
|
||||
switch (ID) {
|
||||
case 0:
|
||||
return new GuiTinkerTable((EntityClientPlayerMP) player);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package machinemuse.powersuits.common;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Logger access class. May become more fleshed out in the future.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public abstract class MuseLogger {
|
||||
protected final static String DEBUGPREFIX = "MMMPS - DEBUG - ";
|
||||
|
||||
protected final static String ERRORPREFIX = "MMMPS - ERROR - ";
|
||||
|
||||
public static void logDebug(String string) {
|
||||
Logger.getLogger("STDOUT").info(DEBUGPREFIX + string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string
|
||||
*/
|
||||
public static void logError(String string) {
|
||||
Logger.getLogger("STDERR").info(ERRORPREFIX + string);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package machinemuse.powersuits.common;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Workaround class to access static NBTTagCompound.getTagMap()
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class NBTTagAccessor extends NBTTagCompound {
|
||||
public static Method mTagAccessor;
|
||||
|
||||
/**
|
||||
* Accesses the package-visible
|
||||
*
|
||||
* <pre>
|
||||
* Map NBTTagCompound.getTagMap(NBTTagCompound tag)
|
||||
* </pre>
|
||||
*
|
||||
* Will likely need to be updated every time the obfuscation changes.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Method getTagAccessor() {
|
||||
if (mTagAccessor == null) {
|
||||
try {
|
||||
mTagAccessor = NBTTagCompound.class.getDeclaredMethod(
|
||||
"getTagMap", NBTTagCompound.class);
|
||||
mTagAccessor.setAccessible(true);
|
||||
return mTagAccessor;
|
||||
} catch (NoSuchMethodException e) {
|
||||
MuseLogger.logError("4");
|
||||
try {
|
||||
mTagAccessor = NBTTagCompound.class.getDeclaredMethod(
|
||||
"a", NBTTagCompound.class);
|
||||
mTagAccessor.setAccessible(true);
|
||||
return mTagAccessor;
|
||||
} catch (NoSuchMethodException e1) {
|
||||
MuseLogger.logError("1");
|
||||
e1.printStackTrace();
|
||||
} catch (SecurityException e1) {
|
||||
MuseLogger.logError("2");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
MuseLogger.logError("3");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
MuseLogger.logError("Error 1: Unable to access nbt tag map!");
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map getMap(NBTTagCompound nbt) {
|
||||
try {
|
||||
return (Map) getTagAccessor().invoke(null, nbt);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MuseLogger.logError("Error 2: Unable to access nbt tag map!");
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package machinemuse.powersuits.common;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import machinemuse.powersuits.item.ItemUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
/**
|
||||
* Tick handler for Player ticks. This is where we compute all the updates that
|
||||
* should go every tick.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*/
|
||||
public class PlayerTickHandler implements ITickHandler {
|
||||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData) {
|
||||
EntityPlayer player = toPlayer(tickData[0]);
|
||||
List<NBTTagCompound> playerAugs = ItemUtils
|
||||
.getPlayerAugs(player);
|
||||
float totalEnergy = 0;
|
||||
float totalWeight = 0;
|
||||
Iterator<NBTTagCompound> iter = playerAugs.iterator();
|
||||
|
||||
if (totalWeight > 25) {
|
||||
player.motionX *= 25 / totalWeight;
|
||||
player.motionZ *= 25 / totalWeight;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
|
||||
EntityPlayer player = toPlayer(tickData[0]);
|
||||
List<ItemStack> stacks = ItemUtils
|
||||
.getModularItemsInInventory(player.inventory);
|
||||
|
||||
}
|
||||
|
||||
public static World toWorld(Object data) {
|
||||
World world = null;
|
||||
try {
|
||||
world = (World) data;
|
||||
} catch (ClassCastException e) {
|
||||
MuseLogger.logDebug(
|
||||
"MMMPS: Player tick handler received invalid World object");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
public static EntityPlayer toPlayer(Object data) {
|
||||
EntityPlayer player = null;
|
||||
try {
|
||||
player = (EntityPlayer) data;
|
||||
} catch (ClassCastException e) {
|
||||
MuseLogger
|
||||
.logDebug(
|
||||
"MMMPS: Player tick handler received invalid Player object");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of tick handled by this handler
|
||||
*/
|
||||
@Override
|
||||
public EnumSet<TickType> ticks() {
|
||||
return EnumSet.of(TickType.PLAYER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Profiling label for this handler
|
||||
*/
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "MMMPS PlayerTickHandler";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,165 +0,0 @@
|
|||
package machinemuse.powersuits.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import machinemuse.powersuits.block.BlockTinkerTable;
|
||||
import machinemuse.powersuits.item.ItemPowerArmor;
|
||||
import machinemuse.powersuits.item.ItemPowerArmorFeet;
|
||||
import machinemuse.powersuits.item.ItemPowerArmorHead;
|
||||
import machinemuse.powersuits.item.ItemPowerArmorLegs;
|
||||
import machinemuse.powersuits.item.ItemPowerArmorTorso;
|
||||
import machinemuse.powersuits.item.ItemPowerTool;
|
||||
import machinemuse.powersuits.network.MusePacketHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.Init;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
import cpw.mods.fml.common.Mod.PostInit;
|
||||
import cpw.mods.fml.common.Mod.PreInit;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import cpw.mods.fml.common.network.NetworkMod.SidedPacketHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
/**
|
||||
* Main mod class. This is what Forge loads to get the mod up and running, both
|
||||
* server- and client-side.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
// Informs forge that this is a base mod class, and gives it some info for the
|
||||
// FML mod list. This is also where it looks to see if your client's version
|
||||
// matches the server's.
|
||||
@Mod(modid = "mmmPowersuits", name = "MachineMuse Modular Powersuits", version = "0.0.1")
|
||||
// Informs forge of the requirements:
|
||||
//
|
||||
// clientSideRequired means players can't connect without it. True for things
|
||||
// that add new blocks/items, false for things like bukkit plugins.
|
||||
//
|
||||
// serverSideRequired means clients can't connect to servers that don't have it.
|
||||
// This isn't a strict restriction currently but it can cause problems if the
|
||||
// mod does anything potentially incompatible in its preInit function. True for
|
||||
// things that add new blocks/items, false for things like Rei's Minimap or
|
||||
// Inventory Tweaks.
|
||||
@NetworkMod(clientSideRequired = true, serverSideRequired = true,
|
||||
clientPacketHandlerSpec =
|
||||
@SidedPacketHandler(channels = { "mmPowersuits" }, packetHandler = MusePacketHandler.class),
|
||||
serverPacketHandlerSpec =
|
||||
@SidedPacketHandler(channels = { "mmPowersuits" }, packetHandler = MusePacketHandler.class))
|
||||
public class PowersuitsMod {
|
||||
|
||||
/**
|
||||
* The instance of the mod that Forge will access. Note that it has to be
|
||||
* set by hand in the preInit step.
|
||||
*/
|
||||
@Instance("PowersuitsMod")
|
||||
public static PowersuitsMod instance;
|
||||
|
||||
/**
|
||||
* Tells Forge what classes to load for the client and server proxies. These
|
||||
* execute side-specific code like registering renderers (for the client) or
|
||||
* different tick handlers (for the server).
|
||||
*/
|
||||
@SidedProxy(clientSide = "machinemuse.powersuits.client.ClientProxy", serverSide = "machinemuse.powersuits.common.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
/**
|
||||
* In the preInit step you only want to load configs, reserve block/item
|
||||
* IDs, and inform Forge if your mod has to be loaded after any others. No
|
||||
* heavy loading or registering should occur here, because it happens as
|
||||
* soon as they start Minecraft and there's no guarantee that your mod will
|
||||
* be loaded.
|
||||
*
|
||||
* @param event
|
||||
* An event object with useful data
|
||||
*/
|
||||
@PreInit
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
instance = this;
|
||||
Config.init(new Configuration(
|
||||
event.getSuggestedConfigurationFile()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A static handle for the blocks and items. We only want one instance of
|
||||
* each of them.
|
||||
*/
|
||||
public static List<Block> allBlocks = new ArrayList<Block>();
|
||||
public static List<Item> allItems = new ArrayList<Item>();
|
||||
public static GuiHandler guiHandler = new GuiHandler();
|
||||
|
||||
/**
|
||||
* This is where all the heavy loading and registering of handlers goes.
|
||||
* This occurs when you connect to a server or open a world.
|
||||
*
|
||||
* @param event
|
||||
* An event object with useful data
|
||||
*/
|
||||
@Init
|
||||
public void load(FMLInitializationEvent event) {
|
||||
loadBlocks();
|
||||
|
||||
loadItems();
|
||||
|
||||
proxy.registerHandlers();
|
||||
proxy.registerRenderers();
|
||||
NetworkRegistry.instance().registerGuiHandler(this, guiHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom function to collect all the item-loading in one place.
|
||||
*/
|
||||
public static void loadItems() {
|
||||
ItemPowerArmor item = new ItemPowerArmorHead();
|
||||
allItems.add(item);
|
||||
|
||||
item = new ItemPowerArmorTorso();
|
||||
allItems.add(item);
|
||||
|
||||
item = new ItemPowerArmorLegs();
|
||||
allItems.add(item);
|
||||
|
||||
item = new ItemPowerArmorFeet();
|
||||
allItems.add(item);
|
||||
|
||||
ItemPowerTool tool = new ItemPowerTool();
|
||||
allItems.add(tool);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom function to collect all the block-loading in one place.
|
||||
*/
|
||||
public static void loadBlocks() {
|
||||
Block tinkTable = new BlockTinkerTable();
|
||||
|
||||
ItemStack iron = new ItemStack(Item.ingotIron);
|
||||
ItemStack emerald = new ItemStack(Item.emerald);
|
||||
ItemStack lapis = new ItemStack(Item.dyePowder, 1);
|
||||
GameRegistry.addRecipe(new ItemStack(tinkTable),
|
||||
"ILI",
|
||||
"LEL",
|
||||
"ILI",
|
||||
'I', iron, 'L', lapis, 'E', emerald);
|
||||
allBlocks.add(tinkTable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stuff to do after the player connects. This is for things that need to
|
||||
* wait until the world is completely loaded before initializing.
|
||||
*
|
||||
* @param event
|
||||
* An event object with useful data
|
||||
*/
|
||||
@PostInit
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
package machinemuse.powersuits.common;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
/**
|
||||
* Tick handler for the mod. This is where you put code that should be executed
|
||||
* once every tick.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class WorldTickHandler implements ITickHandler {
|
||||
/**
|
||||
* Called at the "start" phase of a tick
|
||||
*
|
||||
* Multiple tick types may fire simultaneously- you will only be called once
|
||||
* with all the firing ticks
|
||||
*/
|
||||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData) {
|
||||
World world;
|
||||
EntityPlayer player;
|
||||
// if (type.contains(TickType.WORLD)) {
|
||||
// world = (World) tickData[0];
|
||||
// }
|
||||
// TODO: Find a better way to handle this^
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at the "end" phase of a tick
|
||||
*
|
||||
* Multiple ticks may fire simultaneously- you will only be called once with
|
||||
* all the firing ticks
|
||||
*/
|
||||
@Override
|
||||
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of ticks this tick handler is interested in receiving at
|
||||
* the minute
|
||||
*/
|
||||
@Override
|
||||
public EnumSet<TickType> ticks() {
|
||||
return EnumSet.of(
|
||||
TickType.WORLD,
|
||||
TickType.PLAYER);
|
||||
// return EnumSet.of(TickType.WORLD);
|
||||
}
|
||||
|
||||
/**
|
||||
* A profiling label for this tick handler
|
||||
*/
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "MachineMuse Powersuits";
|
||||
}
|
||||
|
||||
/**
|
||||
* Tick types:
|
||||
*
|
||||
* WORLD - server and client side - Fired during the world evaluation loop
|
||||
*
|
||||
* arg 0 : world object of the world that is ticking
|
||||
*
|
||||
*
|
||||
* RENDER - client side Fired during the render processing phase
|
||||
*
|
||||
* arg 0 : float "partial render time"
|
||||
*
|
||||
* GUI - client side Fired during the render processing phase if a GUI is
|
||||
* open
|
||||
*
|
||||
* arg 0 : float "partial render time"
|
||||
*
|
||||
* arg 1 : the open gui or null if no gui is open
|
||||
*
|
||||
*
|
||||
* CLIENTGUI - client side - Fired during the client evaluation loop arg 0 :
|
||||
* The open gui or null if no gui is open
|
||||
*
|
||||
* WORLDLOAD - server side - Fired once as the world loads from disk
|
||||
*
|
||||
* CLIENT - client side - Fired once per client tick loop.
|
||||
*
|
||||
* PLAYER - client and server side. - Fired whenever the player's update
|
||||
* loop runs.
|
||||
*
|
||||
* arg 0 : the player
|
||||
*
|
||||
* arg 1 : the world the player is in
|
||||
*
|
||||
*
|
||||
* SERVER - server side - This is the server game tick. Fired once per tick
|
||||
* loop on the server.
|
||||
*/
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package machinemuse.powersuits.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import machinemuse.general.geometry.Point2D;
|
||||
import net.minecraft.client.renderer.RenderEngine;
|
||||
|
||||
/**
|
||||
* Defines a generic clickable item for a MuseGui.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*/
|
||||
public abstract class Clickable {
|
||||
protected Point2D position;
|
||||
|
||||
public Clickable() {
|
||||
position = new Point2D(0, 0);
|
||||
}
|
||||
|
||||
public Clickable(Point2D point) {
|
||||
position = point;
|
||||
}
|
||||
|
||||
public Point2D getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Point2D position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public abstract void draw(RenderEngine engine, MuseGui gui);
|
||||
|
||||
public abstract boolean hitBox(int x, int y, MuseGui gui);
|
||||
|
||||
public abstract List<String> getToolTip();
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package machinemuse.powersuits.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import machinemuse.general.geometry.Colour;
|
||||
import machinemuse.general.geometry.MuseRenderer;
|
||||
import machinemuse.general.geometry.Point2D;
|
||||
import net.minecraft.client.renderer.RenderEngine;
|
||||
|
||||
/**
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class ClickableButton extends Clickable {
|
||||
protected String label;
|
||||
protected Point2D radius;
|
||||
protected boolean enabled;
|
||||
|
||||
public ClickableButton(String label, Point2D position, Point2D radius,
|
||||
boolean enabled) {
|
||||
this.label = label;
|
||||
this.position = position;
|
||||
this.radius = radius;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* machinemuse.powersuits.gui.Clickable#draw(net.minecraft.client.renderer
|
||||
* .RenderEngine, machinemuse.powersuits.gui.MuseGui)
|
||||
*/
|
||||
@Override
|
||||
public void draw(RenderEngine engine, MuseGui gui) {
|
||||
Colour topcolour;
|
||||
Colour bottomcolour;
|
||||
if (enabled) {
|
||||
topcolour = new Colour(0.5F, 0.6F, 0.8F, 1);
|
||||
bottomcolour = new Colour(0.3F, 0.3F, 0.3F, 1);
|
||||
} else {
|
||||
topcolour = new Colour(0.3F, 0.3F, 0.3F, 1);
|
||||
bottomcolour = new Colour(0.5F, 0.6F, 0.8F, 1);
|
||||
}
|
||||
MuseRenderer.drawGradientRect(
|
||||
gui.absX(position.x() - radius.x()),
|
||||
gui.absY(position.y() - radius.y()),
|
||||
gui.absX(position.x() + radius.x()),
|
||||
gui.absY(position.y() + radius.y()),
|
||||
topcolour,
|
||||
bottomcolour,
|
||||
0.0F);
|
||||
gui.drawCenteredString(gui.getFontRenderer(),
|
||||
this.label,
|
||||
gui.absX(position.x()),
|
||||
gui.absY(position.y()) - 4,
|
||||
Colour.getGreyscale(1.0F, 1.0F).getInt());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see machinemuse.powersuits.gui.Clickable#hitBox(int, int,
|
||||
* machinemuse.powersuits.gui.MuseGui)
|
||||
*/
|
||||
@Override
|
||||
public boolean hitBox(int x, int y, MuseGui gui) {
|
||||
boolean hitx = Math.abs(x - gui.absX(getPosition().x())) < gui.xSize
|
||||
* radius.x();
|
||||
boolean hity = Math.abs(y - gui.absY(getPosition().y())) < gui.ySize
|
||||
* radius.y();
|
||||
return hitx && hity;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see machinemuse.powersuits.gui.Clickable#getToolTip()
|
||||
*/
|
||||
@Override
|
||||
public List<String> getToolTip() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package machinemuse.powersuits.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import machinemuse.general.geometry.MuseRenderer;
|
||||
import machinemuse.general.geometry.Point2D;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderEngine;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Extends the Clickable class to add a clickable ItemStack - note that this
|
||||
* will be a button that looks like the item, not a container slot.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*/
|
||||
public class ClickableItem extends Clickable {
|
||||
public static final int offsetx = 8;
|
||||
public static final int offsety = 8;
|
||||
public static RenderItem itemRenderer;
|
||||
public int inventorySlot;
|
||||
protected ItemStack item;
|
||||
|
||||
public ClickableItem(ItemStack item, Point2D pos, int inventorySlot) {
|
||||
super(pos);
|
||||
this.inventorySlot = inventorySlot;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitBox(int x, int y, MuseGui gui) {
|
||||
boolean hitx = Math.abs(x - gui.absX(getPosition().x())) < offsetx;
|
||||
boolean hity = Math.abs(y - gui.absY(getPosition().y())) < offsety;
|
||||
return hitx && hity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getToolTip() {
|
||||
return item.getTooltip(Minecraft.getMinecraft().thePlayer, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the specified itemstack at the *relative* coordinates x,y. Used
|
||||
* mainly in clickables.
|
||||
*/
|
||||
@Override
|
||||
public void draw(RenderEngine engine, MuseGui gui) {
|
||||
MuseRenderer.drawItemAt(
|
||||
gui.absX(getPosition().x()) - offsetx,
|
||||
gui.absY(getPosition().y()) - offsety,
|
||||
gui, item);
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package machinemuse.powersuits.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import machinemuse.general.geometry.Colour;
|
||||
import machinemuse.general.geometry.MuseRenderer;
|
||||
import machinemuse.general.geometry.Point2D;
|
||||
import machinemuse.powersuits.powermodule.PowerModule;
|
||||
import net.minecraft.client.renderer.RenderEngine;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Extends the Clickable class to make a clickable Augmentation; note that this
|
||||
* will not be an actual item.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*/
|
||||
public class ClickablePowerModule extends Clickable {
|
||||
protected PowerModule module;
|
||||
protected NBTTagCompound moduleTag;
|
||||
|
||||
/**
|
||||
* @param vaug
|
||||
*/
|
||||
public ClickablePowerModule(PowerModule module, Point2D position) {
|
||||
super(position);
|
||||
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 module.getTooltip(
|
||||
null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(RenderEngine engine, MuseGui gui) {
|
||||
int x = gui.absX(getPosition().x());
|
||||
int y = gui.absY(getPosition().y());
|
||||
|
||||
Colour c1 = new Colour(1.0F, 0.2F, 0.6F, 1.0F);
|
||||
Colour c2 = new Colour(0.6F, 0.2F, 1.0F, 1.0F);
|
||||
|
||||
MuseRenderer.drawModuleAt(x - 8, y - 8, gui, module, moduleTag, null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitBox(int x, int y, MuseGui gui) {
|
||||
boolean hitx = Math.abs(x - gui.absX(getPosition().x())) < 8;
|
||||
boolean hity = Math.abs(y - gui.absY(getPosition().y())) < 8;
|
||||
return hitx && hity;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,309 +0,0 @@
|
|||
package machinemuse.powersuits.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import machinemuse.general.geometry.Colour;
|
||||
import machinemuse.general.geometry.FlyFromMiddlePoint2D;
|
||||
import machinemuse.general.geometry.MuseRenderer;
|
||||
import machinemuse.general.geometry.Point2D;
|
||||
import machinemuse.powersuits.item.ItemUtils;
|
||||
import machinemuse.powersuits.network.MusePacketUpgradeRequest;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
/**
|
||||
* The gui class for the TinkerTable block.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class GuiTinkerTable extends MuseGui {
|
||||
protected EntityClientPlayerMP player;
|
||||
protected List<ClickableItem> itemButtons;
|
||||
protected int selectedItemStack = -1;
|
||||
protected List<ClickablePowerModule> augButtons;
|
||||
protected int selectedAugClickable = -1;
|
||||
protected List<ItemStack> workingUpgradeCost;
|
||||
protected List<ItemStack> workingDowngradeRefund;
|
||||
protected ClickableButton upgradeButton;
|
||||
protected ClickableButton downgradeButton;
|
||||
|
||||
/**
|
||||
* Constructor. Takes a player as an argument.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public GuiTinkerTable(EntityClientPlayerMP player) {
|
||||
this.player = player;
|
||||
this.loadItems();
|
||||
|
||||
this.xSize = 256;
|
||||
this.ySize = 226;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the buttons (and other controls) to the screen.
|
||||
*/
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the clickables for the modular items available
|
||||
*
|
||||
*/
|
||||
public void loadItems() {
|
||||
itemButtons = new ArrayList<ClickableItem>();
|
||||
List<Integer> slots = ItemUtils
|
||||
.getModularItemSlotsInInventory(player.inventory);
|
||||
|
||||
List<Point2D> points = this.pointsInLine(slots.size(),
|
||||
new Point2D(-0.9F, -0.9F),
|
||||
new Point2D(-0.9F, 0.9F));
|
||||
|
||||
Iterator<Integer> slotiterator = slots.iterator();
|
||||
Iterator<Point2D> pointiterator = points.iterator();
|
||||
|
||||
for (int slot : slots) {
|
||||
ClickableItem clickie = new ClickableItem(
|
||||
player.inventory.getStackInSlot(slot),
|
||||
// Fly from middle over 200 ms
|
||||
new FlyFromMiddlePoint2D(pointiterator.next(), 200), slot);
|
||||
itemButtons.add(clickie);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void loadAugList(ClickableItem itemClicked) {
|
||||
augButtons = new ArrayList<ClickablePowerModule>();
|
||||
List<NBTTagCompound> workingAugs = ItemUtils
|
||||
.getItemModulesWithPadding(itemClicked
|
||||
.getItem());
|
||||
List<Point2D> points = this.pointsInLine(workingAugs.size(),
|
||||
new Point2D(-0.7F, -0.9F),
|
||||
new Point2D(-0.7F, 0.9F));
|
||||
Iterator<Point2D> pointiter = points.iterator();
|
||||
for (NBTTagCompound aug : workingAugs) {
|
||||
augButtons.add(new ClickablePowerModule(aug, pointiter.next()));
|
||||
}
|
||||
}
|
||||
|
||||
// public void drawNthItem(ItemStack stack, int n) {
|
||||
// // TBI
|
||||
// // draw item
|
||||
// // draw a button if it's moddable
|
||||
// }
|
||||
//
|
||||
|
||||
public void drawSelection() {
|
||||
if (selectedItemStack != -1) {
|
||||
MuseRenderer.drawCircleAround(
|
||||
absX(itemButtons.get(selectedItemStack).getPosition().x()),
|
||||
absY(itemButtons.get(selectedItemStack).getPosition().y()),
|
||||
10);
|
||||
}
|
||||
|
||||
if (selectedAugClickable != -1) {
|
||||
MuseRenderer
|
||||
.drawCircleAround(
|
||||
absX(augButtons.get(selectedAugClickable)
|
||||
.getPosition().x()),
|
||||
absY(augButtons.get(selectedAugClickable)
|
||||
.getPosition().y()),
|
||||
10);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// public void drawLayout(AugLayout layout) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
|
||||
/**
|
||||
* Draws the background layer for the GUI.
|
||||
*/
|
||||
public void drawBackground() {
|
||||
this.drawDefaultBackground(); // Shading on the world view
|
||||
this.drawRectangularBackground(); // The window rectangle
|
||||
}
|
||||
|
||||
/**
|
||||
* Called every frame, draws the screen!
|
||||
*/
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float z) {
|
||||
super.drawScreen(x, y, z);
|
||||
drawBackground();
|
||||
drawClickables(this.itemButtons);
|
||||
drawSelection();
|
||||
drawClickables(this.augButtons);
|
||||
drawUpgradeDowngrade();
|
||||
drawToolTip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the upgrade/downgrade cost, buttons, and labels.
|
||||
*/
|
||||
public void drawUpgradeDowngrade() {
|
||||
if (workingUpgradeCost != null && workingUpgradeCost.size() > 0) {
|
||||
this.drawString(fontRenderer, "Cost:", absX(0.4F),
|
||||
absY(-0.7F),
|
||||
new Colour(0.5F, 1.0F, 0.5F, 1.0F).getInt());
|
||||
List<Point2D> points = this.pointsInLine(workingUpgradeCost.size(),
|
||||
new Point2D(0.4F, -0.5F),
|
||||
new Point2D(0.9F, -0.5F));
|
||||
Iterator<Point2D> pointiter = points.iterator();
|
||||
for (ItemStack item : workingUpgradeCost) {
|
||||
Point2D next = pointiter.next();
|
||||
MuseRenderer.drawItemAt(absX(next.x()), absY(next.y()), this,
|
||||
item);
|
||||
}
|
||||
upgradeButton.draw(this.getRenderEngine(), this);
|
||||
}
|
||||
if (workingDowngradeRefund != null && workingDowngradeRefund.size() > 0) {
|
||||
MuseRenderer.on2D();
|
||||
this.drawString(fontRenderer, "Refund:", absX(0.4F),
|
||||
absY(0.3F),
|
||||
new Colour(1.0F, 0.6F, 0.2F, 1.0F).getInt());
|
||||
MuseRenderer.off2D();
|
||||
List<Point2D> points = this.pointsInLine(
|
||||
workingDowngradeRefund.size(),
|
||||
new Point2D(0.4F, 0.5F),
|
||||
new Point2D(0.9F, 0.5F));
|
||||
Iterator<Point2D> pointiter = points.iterator();
|
||||
for (ItemStack item : workingDowngradeRefund) {
|
||||
Point2D next = pointiter.next();
|
||||
MuseRenderer.drawItemAt(absX(next.x()), absY(next.y()), this,
|
||||
item);
|
||||
}
|
||||
downgradeButton.draw(this.getRenderEngine(), this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all the UI stuff that's there.
|
||||
*/
|
||||
protected void clearSelections() {
|
||||
this.selectedAugClickable = -1;
|
||||
this.workingUpgradeCost = null;
|
||||
this.workingDowngradeRefund = null;
|
||||
this.upgradeButton = null;
|
||||
this.downgradeButton = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the mouse is clicked.
|
||||
*/
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button)
|
||||
{
|
||||
if (button == 0) // Left Mouse Button
|
||||
{
|
||||
int itemClicked = hitboxClickables(x, y, this.itemButtons);
|
||||
int augClicked = hitboxClickables(x, y, this.augButtons);
|
||||
if (itemClicked != -1) {
|
||||
clearSelections();
|
||||
this.selectedItemStack = itemClicked;
|
||||
loadAugList(itemButtons.get(itemClicked));
|
||||
} else if (augClicked != -1) {
|
||||
this.selectedAugClickable = augClicked;
|
||||
refreshUpgrades();
|
||||
} else if (upgradeButton != null
|
||||
&& upgradeButton.enabled
|
||||
&& upgradeButton.hitBox(x, y, this)) {
|
||||
doUpgrade();
|
||||
} else if (downgradeButton != null
|
||||
&& downgradeButton.enabled
|
||||
&& downgradeButton.hitBox(x, y, this)) {
|
||||
doDowngrade();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void doDowngrade() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs all the functions associated with the upgrade button. This
|
||||
* requires communicating with the server.
|
||||
*/
|
||||
private void doUpgrade() {
|
||||
if (ItemUtils.hasInInventory(workingUpgradeCost, player.inventory)) {
|
||||
// ItemUtils.deleteFromInventory(workingUpgradeCost,
|
||||
// player.inventory);
|
||||
// workingAugmentation.upgrade();
|
||||
player.sendQueue
|
||||
.addToSendQueue(
|
||||
new MusePacketUpgradeRequest(
|
||||
(Player) player,
|
||||
itemButtons.get(selectedItemStack).inventorySlot,
|
||||
augButtons.get(selectedAugClickable).module
|
||||
.getName()
|
||||
).getPacket()
|
||||
);
|
||||
// player.sendQueue.sendPacket();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the upgrade/downgrade buttons. May someday also include repairs.
|
||||
*/
|
||||
private void refreshUpgrades() {
|
||||
if (selectedAugClickable != -1) {
|
||||
this.workingUpgradeCost =
|
||||
augButtons.get(selectedAugClickable).module.getCost(player,
|
||||
augButtons.get(selectedAugClickable).moduleTag);
|
||||
if (workingUpgradeCost != null) {
|
||||
this.upgradeButton = new ClickableButton("Upgrade",
|
||||
new Point2D(0.6F, -0.2F),
|
||||
new Point2D(0.25F, 0.05F), true);
|
||||
if (ItemUtils.hasInInventory(workingUpgradeCost,
|
||||
player.inventory)) {
|
||||
upgradeButton.enabled = true;
|
||||
} else {
|
||||
upgradeButton.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected List<String> getToolTip(int x, int y) {
|
||||
List<String> hitTip = null;
|
||||
int itemHover = hitboxClickables(x, y, this.itemButtons);
|
||||
if (itemHover > -1) {
|
||||
hitTip = itemButtons.get(itemHover).getToolTip();
|
||||
}
|
||||
int augHover = hitboxClickables(x, y, this.augButtons);
|
||||
if (augHover > -1) {
|
||||
hitTip = augButtons.get(augHover).getToolTip();
|
||||
}
|
||||
return hitTip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
loadItems();
|
||||
if (selectedItemStack != -1 && selectedItemStack < itemButtons.size()) {
|
||||
loadAugList(itemButtons.get(selectedItemStack));
|
||||
}
|
||||
refreshUpgrades();
|
||||
}
|
||||
}
|
|
@ -1,292 +0,0 @@
|
|||
package machinemuse.powersuits.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import machinemuse.general.geometry.Colour;
|
||||
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;
|
||||
|
||||
/**
|
||||
* I got fed up with Minecraft's gui system so I wrote my own (to some extent.
|
||||
* Still based on GuiScreen). This class contains a variety of helper functions
|
||||
* to draw geometry and various other prettifications. Note that MuseGui is
|
||||
* heavily geometry-based as opposed to texture-based.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class MuseGui extends GuiScreen {
|
||||
protected static RenderItem renderItem;
|
||||
protected final boolean usePretty = true;
|
||||
protected static final Tessellator tesselator = Tessellator.instance;
|
||||
protected Point2D ul, br;
|
||||
protected long creationTime;
|
||||
protected int xSize;
|
||||
protected int ySize;
|
||||
|
||||
public MuseGui() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the buttons (and other controls) to the screen in question.
|
||||
*/
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
this.controlList.clear();
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
creationTime = System.currentTimeMillis();
|
||||
|
||||
int xpadding = (width - getxSize()) / 2;
|
||||
int ypadding = (height - ySize) / 2;
|
||||
ul = new FlyFromMiddlePoint2D(-1, -1, 150);
|
||||
br = new FlyFromMiddlePoint2D(1, 1, 150);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the gradient-rectangle background you see in the TinkerTable gui.
|
||||
*/
|
||||
public void drawRectangularBackground() {
|
||||
MuseRenderer.drawGradientRect(
|
||||
absX(ul.x()), absY(ul.y()),
|
||||
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),
|
||||
this.zLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws all clickables in a list!
|
||||
*/
|
||||
public void drawClickables(List<? extends Clickable> list) {
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
Iterator<? extends Clickable> iter = list.iterator();
|
||||
Clickable clickie;
|
||||
while (iter.hasNext())
|
||||
{
|
||||
clickie = iter.next();
|
||||
clickie.draw(Minecraft.getMinecraft().renderEngine, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first ID in the list that is hit by a click
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int hitboxClickables(int x, int y,
|
||||
List<? extends Clickable> list) {
|
||||
if (list == null) {
|
||||
return -1;
|
||||
}
|
||||
Clickable clickie;
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
{
|
||||
clickie = list.get(i);
|
||||
if (clickie.hitBox(x, y, this)) {
|
||||
// MuseLogger.logDebug("Hit!");
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list of points linearly interpolated between points a and b
|
||||
* noninclusive.
|
||||
*
|
||||
* @return A list of num points
|
||||
*/
|
||||
public List<Point2D> pointsInLine(int num, Point2D a, Point2D b) {
|
||||
List<Point2D> points = new ArrayList<Point2D>();
|
||||
if (num < 1) {
|
||||
return null;
|
||||
} else if (num < 2) {
|
||||
points.add(b.minus(a).times(0.5F).plus(a));
|
||||
} else {
|
||||
Point2D step = b.minus(a).times(1.0F / (num + 1));
|
||||
for (int i = 1; i < num + 2; i++) {
|
||||
points.add(a.plus(step.times(i)));
|
||||
}
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this gui pauses the game in single player.
|
||||
*/
|
||||
@Override
|
||||
public boolean doesGuiPauseGame()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton pattern for the RenderItem
|
||||
*
|
||||
* @return the static renderItem instance
|
||||
*/
|
||||
public static RenderItem getRenderItem() {
|
||||
if (renderItem == null) {
|
||||
renderItem = new RenderItem();
|
||||
}
|
||||
return renderItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton pattern for FontRenderer
|
||||
*/
|
||||
public static FontRenderer getFontRenderer() {
|
||||
return Minecraft.getMinecraft().fontRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton pattern for RenderEngine
|
||||
*/
|
||||
public static RenderEngine getRenderEngine() {
|
||||
return Minecraft.getMinecraft().renderEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns absolute screen coordinates (int 0 to width) from a relative
|
||||
* coordinate (float -1.0F to +1.0F)
|
||||
*
|
||||
* @param relx
|
||||
* Relative X coordinate
|
||||
* @return Absolute X coordinate
|
||||
*/
|
||||
public int absX(float relx) {
|
||||
int absx = (int) ((relx + 1) * getxSize() / 2);
|
||||
int xpadding = (width - getxSize()) / 2;
|
||||
return absx + xpadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relative coordinate (float -1.0F to +1.0F) from absolute
|
||||
* coordinates (int 0 to width)
|
||||
*
|
||||
*/
|
||||
public int relX(float absx) {
|
||||
int padding = (width - getxSize()) / 2;
|
||||
int relx = (int) ((absx - padding) * 2 / getxSize() - 1);
|
||||
return relx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns absolute screen coordinates (int 0 to width) from a relative
|
||||
* coordinate (float -1.0F to +1.0F)
|
||||
*
|
||||
* @param relx
|
||||
* Relative Y coordinate
|
||||
* @return Absolute Y coordinate
|
||||
*/
|
||||
public int absY(float rely) {
|
||||
int absy = (int) ((rely + 1) * ySize / 2);
|
||||
int ypadding = (height - ySize) / 2;
|
||||
return absy + ypadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relative coordinate (float -1.0F to +1.0F) from absolute
|
||||
* coordinates (int 0 to width)
|
||||
*
|
||||
*/
|
||||
public int relY(float absy) {
|
||||
int padding = (height - ySize) / 2;
|
||||
int rely = (int) ((absy - padding) * 2 / ySize - 1);
|
||||
return rely;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the xSize
|
||||
*/
|
||||
public int getxSize() {
|
||||
return xSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param xSize
|
||||
* the xSize to set
|
||||
*/
|
||||
public void setxSize(int xSize) {
|
||||
this.xSize = xSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ySize
|
||||
*/
|
||||
public int getySize() {
|
||||
return ySize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ySize
|
||||
* the ySize to set
|
||||
*/
|
||||
public void setySize(int ySize) {
|
||||
this.ySize = ySize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
protected void drawToolTip() {
|
||||
int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
||||
int y = this.height - Mouse.getEventY() * this.height
|
||||
/ this.mc.displayHeight - 1;
|
||||
List<String> tooltip = getToolTip(x, y);
|
||||
if (tooltip != null) {
|
||||
int strwidth = 0;
|
||||
for (String s : tooltip) {
|
||||
int currstrwidth = getFontRenderer().getStringWidth(s);
|
||||
if (currstrwidth > strwidth) {
|
||||
strwidth = currstrwidth;
|
||||
}
|
||||
}
|
||||
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),
|
||||
x + 5,
|
||||
y - 10 * (tooltip.size() - i), fontcolour.getInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected List<String> getToolTip(int x, int y) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void refresh() {
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package machinemuse.powersuits.item;
|
||||
|
||||
import machinemuse.powersuits.common.Config;
|
||||
|
||||
/**
|
||||
* Interface for ItemPowerArmor and ItemPowerTool to share.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*/
|
||||
public interface IModularItem {
|
||||
|
||||
public Config.Items getItemType();
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
package machinemuse.powersuits.item;
|
||||
|
||||
import machinemuse.powersuits.common.Config;
|
||||
import machinemuse.powersuits.common.Config.Items;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumArmorMaterial;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraftforge.common.ISpecialArmor;
|
||||
|
||||
/**
|
||||
* Describes the 4 different modular armor pieces - head, torso, legs, feet.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*/
|
||||
public abstract class ItemPowerArmor extends ItemArmor
|
||||
implements ISpecialArmor, IModularItem {
|
||||
Config.Items itemType;
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param material
|
||||
* @param renderIndex
|
||||
* @param armorType
|
||||
* 0 = head; 1 = torso; 2 = legs; 3 = feet
|
||||
*/
|
||||
public ItemPowerArmor(int id, EnumArmorMaterial material,
|
||||
int renderIndex, int armorType) {
|
||||
super(id, material, renderIndex, armorType);
|
||||
setMaxStackSize(1);
|
||||
setCreativeTab(Config.getCreativeTab());
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherited from ISpecialArmor, allows significant customization of damage
|
||||
* calculations.
|
||||
*/
|
||||
@Override
|
||||
public ArmorProperties getProperties(EntityLiving player, ItemStack armor,
|
||||
DamageSource source, double damage, int slot) {
|
||||
// Order in which this armor is assessed for damage. Higher(?) priority
|
||||
// items take damage first, and if none spills over, the other items
|
||||
// take no damage.
|
||||
int priority = 1;
|
||||
|
||||
// How much of incoming damage is absorbed by this armor piece.
|
||||
// 1.0 = absorbs all damage
|
||||
// 0.5 = 50% damage to item, 50% damage carried over
|
||||
double absorbRatio = 0.2;
|
||||
|
||||
// Maximum damage absorbed by this piece. Actual damage to this item
|
||||
// will be clamped between (damage * absorbRatio) and (absorbMax). Note
|
||||
// that a player has 20 hp (1hp = 1 half-heart)
|
||||
int absorbMax = 4;
|
||||
|
||||
return new ArmorProperties(priority, absorbRatio,
|
||||
absorbMax);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherited from ISpecialArmor, allows us to customize the calculations for
|
||||
* how much armor will display on the player's HUD.
|
||||
*/
|
||||
@Override
|
||||
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherited from ISpecialArmor, allows us to customize how the armor
|
||||
* handles being damaged.
|
||||
*/
|
||||
@Override
|
||||
public void damageArmor(EntityLiving entity, ItemStack stack,
|
||||
DamageSource source, int damage, int slot) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Items getItemType() {
|
||||
return itemType;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package machinemuse.powersuits.item;
|
||||
|
||||
import machinemuse.powersuits.common.Config;
|
||||
import net.minecraft.item.EnumArmorMaterial;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
/**
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class ItemPowerArmorFeet extends ItemPowerArmor {
|
||||
/**
|
||||
* @param item
|
||||
*/
|
||||
public ItemPowerArmorFeet() {
|
||||
super(Config.getAssignedItemID(Config.Items.PowerArmorFeet), // itemID
|
||||
EnumArmorMaterial.IRON, // Material
|
||||
0, // Texture index
|
||||
3); // armor type. 0=head, 1=torso, 2=legs, 3=feet
|
||||
itemType = Config.Items.PowerArmorFeet;
|
||||
setItemName(itemType.idName);
|
||||
|
||||
LanguageRegistry.addName(this, itemType.englishName);
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package machinemuse.powersuits.item;
|
||||
|
||||
import machinemuse.powersuits.common.Config;
|
||||
import net.minecraft.item.EnumArmorMaterial;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
public class ItemPowerArmorHead extends ItemPowerArmor {
|
||||
public ItemPowerArmorHead() {
|
||||
super(Config.getAssignedItemID(Config.Items.PowerArmorHead), // itemID
|
||||
EnumArmorMaterial.IRON, // Material
|
||||
0, // Texture index
|
||||
0); // armor type. 0=head, 1=torso, 2=legs, 3=feet
|
||||
itemType = Config.Items.PowerArmorHead;
|
||||
setItemName(itemType.idName);
|
||||
LanguageRegistry.addName(this, itemType.englishName);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package machinemuse.powersuits.item;
|
||||
|
||||
import machinemuse.powersuits.common.Config;
|
||||
import net.minecraft.item.EnumArmorMaterial;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
public class ItemPowerArmorLegs extends ItemPowerArmor {
|
||||
public ItemPowerArmorLegs() {
|
||||
super(Config.getAssignedItemID(Config.Items.PowerArmorLegs), // itemID
|
||||
EnumArmorMaterial.IRON, // Material
|
||||
0, // Texture index
|
||||
2); // armor type. 0=head, 1=torso, 2=legs, 3=feet
|
||||
itemType = Config.Items.PowerArmorLegs;
|
||||
setItemName(itemType.idName);
|
||||
|
||||
LanguageRegistry.addName(this, itemType.englishName);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package machinemuse.powersuits.item;
|
||||
|
||||
import machinemuse.powersuits.common.Config;
|
||||
import net.minecraft.item.EnumArmorMaterial;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
|
||||
public class ItemPowerArmorTorso extends ItemPowerArmor {
|
||||
public ItemPowerArmorTorso() {
|
||||
super(Config.getAssignedItemID(Config.Items.PowerArmorTorso), // itemID
|
||||
EnumArmorMaterial.IRON, // Material
|
||||
0, // Texture index
|
||||
1); // armor type.
|
||||
itemType = Config.Items.PowerArmorTorso;
|
||||
setItemName(itemType.idName);
|
||||
|
||||
LanguageRegistry.addName(this, itemType.englishName);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
package machinemuse.powersuits.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import machinemuse.powersuits.common.Config;
|
||||
import machinemuse.powersuits.common.Config.Items;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.item.EnumToolMaterial;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Describes the modular power tool.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*/
|
||||
public class ItemPowerTool extends ItemTool implements IModularItem {
|
||||
protected List<String> validAugTypes;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public ItemPowerTool() {
|
||||
super( // ID
|
||||
Config.getAssignedItemID(Config.Items.PowerTool),
|
||||
// Damage bonus, added to the material's damage
|
||||
0,
|
||||
// Tool material, can be changed if necessary
|
||||
EnumToolMaterial.EMERALD,
|
||||
// not important since it's private and we will override the
|
||||
// getter
|
||||
new Block[0] // Block[] BlocksEffectiveAgainst
|
||||
);
|
||||
setMaxStackSize(1);
|
||||
setMaxDamage(0);
|
||||
this.damageVsEntity = 1;
|
||||
setCreativeTab(Config.getCreativeTab());
|
||||
setIconIndex(Config.Items.PowerTool.iconIndex);
|
||||
setItemName(Config.Items.PowerTool.idName);
|
||||
LanguageRegistry.addName(this, Config.Items.PowerTool.englishName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Items getItemType() {
|
||||
return Config.Items.PowerTool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the strength of the stack against a given block. 1.0F base,
|
||||
* (Quality+1)*2 if correct blocktype, 1.5F if sword
|
||||
*/
|
||||
@Override
|
||||
public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) {
|
||||
// for (int var3 = 0; var3 < this.blocksEffectiveAgainst.length; ++var3)
|
||||
// {
|
||||
// if (this.blocksEffectiveAgainst[var3] == par2Block) {
|
||||
// return this.efficiencyOnProperMaterial;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
return 1.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current implementations of this method in child classes do not use the
|
||||
* entry argument beside stack. They just raise the damage on the stack.
|
||||
*/
|
||||
@Override
|
||||
public boolean hitEntity(ItemStack stack,
|
||||
EntityLiving entityDoingHitting, EntityLiving entityBeingHit) {
|
||||
// stack.damageItem(2, entityBeingHit);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is destroyed using this tool.
|
||||
*/
|
||||
@Override
|
||||
public boolean onBlockDestroyed(ItemStack stack, World world,
|
||||
int blockID, int x, int y, int z,
|
||||
EntityLiving par7EntityLiving) {
|
||||
if (Block.blocksList[blockID]
|
||||
.getBlockHardness(world, x, y, z) != 0.0D) {
|
||||
stack.damageItem(1, par7EntityLiving);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the damage against a given entity.
|
||||
*/
|
||||
@Override
|
||||
public int getDamageVsEntity(Entity par1Entity) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
/**
|
||||
* Returns True is the item is renderer in full 3D when hold.
|
||||
*/
|
||||
public boolean isFull3D() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item. In this case, 0. Might add
|
||||
* an enchantability module later :P
|
||||
*/
|
||||
@Override
|
||||
public int getItemEnchantability() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name for this tool's material.
|
||||
*/
|
||||
@Override
|
||||
public String getToolMaterialName() {
|
||||
return this.toolMaterial.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this item is repairable in an anvil.
|
||||
*/
|
||||
@Override
|
||||
public boolean getIsRepairable(ItemStack par1ItemStack,
|
||||
ItemStack par2ItemStack) {
|
||||
return this.toolMaterial.getToolCraftingMaterial() == par2ItemStack.itemID ? true
|
||||
: super.getIsRepairable(par1ItemStack, par2ItemStack);
|
||||
}
|
||||
|
||||
/** FORGE: Overridden to allow custom tool effectiveness */
|
||||
@Override
|
||||
public float getStrVsBlock(ItemStack stack, Block block, int meta) {
|
||||
if (ForgeHooks.isToolEffective(stack, block, meta)) {
|
||||
return efficiencyOnProperMaterial;
|
||||
}
|
||||
return getStrVsBlock(stack, block);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,186 +0,0 @@
|
|||
package machinemuse.powersuits.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import machinemuse.powersuits.powermodule.PowerModule;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ItemUtils {
|
||||
/**
|
||||
* Scans a specified inventory for modular items.
|
||||
*
|
||||
* @param inv
|
||||
* IInventory to scan.
|
||||
* @return A List of ItemStacks in the inventory which implement
|
||||
* IModularItem
|
||||
*/
|
||||
public static List<ItemStack> getModularItemsInInventory(IInventory inv) {
|
||||
ArrayList<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
if (stack != null && stack.getItem() instanceof IModularItem) {
|
||||
stacks.add(stack);
|
||||
}
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans a specified inventory for modular items.
|
||||
*
|
||||
* @param inv
|
||||
* IInventory to scan.
|
||||
* @return A List of inventory slots containing an IModularItem
|
||||
*/
|
||||
public static List<Integer> getModularItemSlotsInInventory(IInventory inv) {
|
||||
ArrayList<Integer> slots = new ArrayList<Integer>();
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
if (stack != null && stack.getItem() instanceof IModularItem) {
|
||||
slots.add(i);
|
||||
}
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to cast an item to IModularItem, returns null if fails
|
||||
*/
|
||||
public static IModularItem getAsModular(Item item) {
|
||||
if (item instanceof IModularItem) {
|
||||
return (IModularItem) item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public static List<NBTTagCompound> getPlayerAugs(EntityPlayer player) {
|
||||
List<NBTTagCompound> augs = new ArrayList<NBTTagCompound>();
|
||||
List<ItemStack> items = getModularItemsInInventory(player.inventory);
|
||||
Iterator<ItemStack> iter = items.iterator();
|
||||
while (iter.hasNext()) {
|
||||
NBTTagCompound itemAugs = PowerModule.getItemModules(iter.next());
|
||||
for (Object ob : itemAugs.getTags()) {
|
||||
if (ob instanceof NBTTagCompound) {
|
||||
augs.add((NBTTagCompound) ob);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return augs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param next
|
||||
* @return
|
||||
*/
|
||||
public static List<NBTTagCompound> getItemModulesWithPadding(ItemStack stack) {
|
||||
List<PowerModule> validModules = 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 {
|
||||
NBTTagCompound newModule = validModule.newModuleTag();
|
||||
modulesList.add(newModule);
|
||||
itemModule.setCompoundTag(validModule.getName(), newModule);
|
||||
}
|
||||
}
|
||||
return modulesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player has a copy of all of the items in
|
||||
* workingUpgradeCost.
|
||||
*
|
||||
* @param workingUpgradeCost
|
||||
* @param inventory
|
||||
* @return
|
||||
*/
|
||||
public static boolean hasInInventory(List<ItemStack> workingUpgradeCost,
|
||||
InventoryPlayer inventory) {
|
||||
for (int j = 0; j < workingUpgradeCost.size(); j++) {
|
||||
ItemStack stackInCost = workingUpgradeCost.get(j);
|
||||
int found = 0;
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
ItemStack stackInInventory = inventory.getStackInSlot(i);
|
||||
if (stackInInventory != null) {
|
||||
if (stackInInventory.itemID == stackInCost.itemID) {
|
||||
found += stackInInventory.stackSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found < stackInCost.stackSize) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param workingUpgradeCost
|
||||
* @param inventory
|
||||
*/
|
||||
public static List<Integer> deleteFromInventory(List<ItemStack> cost,
|
||||
InventoryPlayer inventory) {
|
||||
List<Integer> slots = new LinkedList<Integer>();
|
||||
for (int j = 0; j < cost.size(); j++) {
|
||||
ItemStack stackInCost = cost.get(j);
|
||||
int remaining = stackInCost.stackSize;
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
ItemStack stackInInventory = inventory.getStackInSlot(i);
|
||||
if (stackInInventory != null) {
|
||||
if (stackInInventory.itemID == stackInCost.itemID) {
|
||||
if (stackInInventory.stackSize > remaining) {
|
||||
stackInInventory.stackSize -= remaining;
|
||||
remaining = 0;
|
||||
slots.add(i);
|
||||
break;
|
||||
} else {
|
||||
remaining -= stackInInventory.stackSize;
|
||||
inventory.setInventorySlotContents(i, null);
|
||||
}
|
||||
slots.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums the weights of augmentations in the list.
|
||||
*
|
||||
* @param playerAugs
|
||||
* @return
|
||||
*/
|
||||
public static float getTotalWeight(EntityPlayer player,
|
||||
List<NBTTagCompound> playerAugs) {
|
||||
float weight = 0;
|
||||
for (NBTTagCompound aug : playerAugs) {
|
||||
weight += PowerModule.getModuleFromNBT(aug).getWeight(player, aug);
|
||||
}
|
||||
return weight;
|
||||
}
|
||||
}
|
|
@ -1,248 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package machinemuse.powersuits.network;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
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;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
/**
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public abstract class MusePacket {
|
||||
|
||||
protected static final int READ_ERROR = -150;
|
||||
|
||||
protected Player player;
|
||||
|
||||
protected ByteArrayOutputStream bytes;
|
||||
|
||||
protected Packet250CustomPayload packet;
|
||||
protected DataOutputStream dataout;
|
||||
protected DataInputStream datain;
|
||||
protected int id;
|
||||
|
||||
protected MusePacket(Player player) {
|
||||
this.player = player;
|
||||
this.bytes = new ByteArrayOutputStream();
|
||||
this.dataout = new DataOutputStream(bytes);
|
||||
int id = MusePacketHandler.getTypeID(this);
|
||||
writeInt(id);
|
||||
}
|
||||
|
||||
private String listBytes(byte[] bytes) {
|
||||
String s = "";
|
||||
for (byte b : bytes) {
|
||||
s = s + Byte.toString(b) + " ~ ";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
protected MusePacket(Player player, DataInputStream data) {
|
||||
this.player = player;
|
||||
this.datain = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the MC packet associated with this MusePacket
|
||||
*
|
||||
* @return Packet250CustomPayload
|
||||
*/
|
||||
public Packet250CustomPayload getPacket() {
|
||||
byte[] output = bytes.toByteArray();
|
||||
return new Packet250CustomPayload(Config.getNetworkChannelName(),
|
||||
bytes.toByteArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the network manager since it does all the packet mapping
|
||||
*
|
||||
* @param player2
|
||||
*/
|
||||
public abstract void handleClient(EntityClientPlayerMP player);
|
||||
|
||||
public abstract void handleServer(EntityPlayerMP player);
|
||||
|
||||
public int readInt() {
|
||||
try {
|
||||
int read = datain.readInt();
|
||||
return read;
|
||||
} catch (IOException e) {
|
||||
MuseLogger.logError("PROBLEM WRITING INT TO PACKET D:");
|
||||
e.printStackTrace();
|
||||
return READ_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeInt(int i) {
|
||||
try {
|
||||
dataout.writeInt(i);
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a ItemStack from the InputStream
|
||||
*/
|
||||
public ItemStack readItemStack()
|
||||
{
|
||||
ItemStack stack = null;
|
||||
try {
|
||||
short itemID = datain.readShort();
|
||||
|
||||
if (itemID >= 0)
|
||||
{
|
||||
byte stackSize = datain.readByte();
|
||||
short damageAmount = datain.readShort();
|
||||
stack = new ItemStack(itemID, stackSize, damageAmount);
|
||||
stack.stackTagCompound = readNBTTagCompound();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
MuseLogger.logError("Problem reading itemstack D:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the ItemStack's ID (short), then size (byte), then damage. (short)
|
||||
*/
|
||||
public void writeItemStack(ItemStack stack)
|
||||
{
|
||||
try {
|
||||
if (stack == null)
|
||||
{
|
||||
dataout.writeShort(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataout.writeShort(stack.itemID);
|
||||
dataout.writeByte(stack.stackSize);
|
||||
dataout.writeShort(stack.getItemDamage());
|
||||
NBTTagCompound nbt = null;
|
||||
|
||||
if (stack.getItem().isDamageable()
|
||||
|| stack.getItem().getShareTag())
|
||||
{
|
||||
nbt = stack.stackTagCompound;
|
||||
}
|
||||
|
||||
writeNBTTagCompound(nbt);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
MuseLogger.logError("Problem writing itemstack D:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a compressed NBTTagCompound from the InputStream
|
||||
*/
|
||||
public NBTTagCompound readNBTTagCompound() throws IOException
|
||||
{
|
||||
short length = datain.readShort();
|
||||
|
||||
if (length < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] fullData = new byte[length];
|
||||
datain.readFully(fullData);
|
||||
return CompressedStreamTools.decompress(fullData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a compressed NBTTagCompound to the OutputStream
|
||||
*/
|
||||
protected void writeNBTTagCompound(
|
||||
NBTTagCompound nbt) throws IOException
|
||||
{
|
||||
if (nbt == null)
|
||||
{
|
||||
dataout.writeShort(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] compressednbt = CompressedStreamTools.compress(nbt);
|
||||
dataout.writeShort((short) compressednbt.length);
|
||||
dataout.write(compressednbt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a String to the DataOutputStream
|
||||
*/
|
||||
public void writeString(String string)
|
||||
{
|
||||
try {
|
||||
if (string.length() > 32767)
|
||||
{
|
||||
throw new IOException("String too big");
|
||||
}
|
||||
else
|
||||
{
|
||||
dataout.writeShort(string.length());
|
||||
dataout.writeChars(string);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
MuseLogger.logError("String too big D:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a string from a packet
|
||||
*/
|
||||
public String readString(int maxlength)
|
||||
{
|
||||
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)
|
||||
{
|
||||
builder.append(datain.readChar());
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package machinemuse.powersuits.network;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
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();
|
||||
|
||||
@Override
|
||||
public void onPacketData(INetworkManager manager,
|
||||
Packet250CustomPayload payload, Player player) {
|
||||
if (payload.channel.equals(Config.getNetworkChannelName())) {
|
||||
MusePacket repackaged = repackage(payload, player);
|
||||
if (repackaged != null) {
|
||||
Side side = FMLCommonHandler.instance().getEffectiveSide();
|
||||
if (side == Side.CLIENT) {
|
||||
repackaged.handleClient((EntityClientPlayerMP) player);
|
||||
} else if (side == Side.SERVER) {
|
||||
repackaged.handleServer((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static MusePacket repackage(Packet250CustomPayload payload,
|
||||
Player player) {
|
||||
MusePacket repackaged = null;
|
||||
DataInputStream data = new DataInputStream(new ByteArrayInputStream(
|
||||
payload.data));
|
||||
EntityPlayer target = (EntityPlayer) player;
|
||||
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;
|
||||
}
|
||||
|
||||
return repackaged;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public static int getTypeID(MusePacket packet) {
|
||||
try {
|
||||
return packetConstructors.inverse().get(
|
||||
getConstructor(packet.getClass()));
|
||||
} catch (NoSuchMethodException e) {
|
||||
MuseLogger.logError("INVALID PACKET CONSTRUCTOR D:");
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
MuseLogger.logError("PACKET SECURITY PROBLEM D:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -150;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the constructor of the given object. Keep in sync with
|
||||
* useConstructor.
|
||||
*
|
||||
* @param packetType
|
||||
* @return
|
||||
* @throws NoSuchMethodException
|
||||
* @throws SecurityException
|
||||
*/
|
||||
protected static Constructor<? extends MusePacket> getConstructor(
|
||||
Class<? extends MusePacket> packetType)
|
||||
throws NoSuchMethodException, SecurityException {
|
||||
return packetType.getConstructor(DataInputStream.class, Player.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance of the object, created via the constructor in
|
||||
* question. Keep in sync with getConstructor.
|
||||
*
|
||||
* @param constructor
|
||||
* @return
|
||||
*/
|
||||
protected static MusePacket useConstructor(
|
||||
Constructor<? extends MusePacket> constructor,
|
||||
DataInputStream data, Player player) {
|
||||
try {
|
||||
return constructor.newInstance(data, player);
|
||||
} catch (InstantiationException e) {
|
||||
MuseLogger.logError("PROBLEM INSTATIATING PACKET D:");
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
MuseLogger.logError("PROBLEM ACCESSING PACKET D:");
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
MuseLogger.logError("INVALID PACKET CONSTRUCTOR D:");
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
MuseLogger.logError("PROBLEM INVOKING PACKET CONSTRUCTOR D:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean addPacketType(int id,
|
||||
Class<? extends MusePacket> packetType) {
|
||||
try {
|
||||
// Add constructor to the list
|
||||
packetConstructors.put(id, getConstructor(packetType));
|
||||
return true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
MuseLogger.logError("UNABLE TO REGISTER PACKET TYPE: "
|
||||
+ packetType + ": INVALID CONSTRUCTOR");
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
MuseLogger.logError("UNABLE TO REGISTER PACKET TYPE: "
|
||||
+ packetType + ": SECURITY PROBLEM");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package machinemuse.powersuits.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
|
||||
import machinemuse.powersuits.common.MuseLogger;
|
||||
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.network.Player;
|
||||
|
||||
/**
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class MusePacketInventoryRefresh extends MusePacket {
|
||||
protected ItemStack stack;
|
||||
protected int slot;
|
||||
|
||||
/**
|
||||
* @param player
|
||||
*/
|
||||
public MusePacketInventoryRefresh(Player player, int slot,
|
||||
ItemStack stack) {
|
||||
super(player);
|
||||
writeInt(slot);
|
||||
writeItemStack(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param data
|
||||
*/
|
||||
public MusePacketInventoryRefresh(DataInputStream datain, Player player) {
|
||||
super(player, datain);
|
||||
slot = readInt();
|
||||
stack = readItemStack();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see machinemuse.powersuits.network.MusePacket#handleSelf()
|
||||
*/
|
||||
@Override
|
||||
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) {
|
||||
}
|
||||
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package machinemuse.powersuits.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
/**
|
||||
* Packet for requesting to purchase an upgrade. Player-to-server. Server
|
||||
* decides whether it is a valid upgrade or not and replies with an associated
|
||||
* inventoryrefresh packet.
|
||||
*
|
||||
* @author MachineMuse
|
||||
*
|
||||
*/
|
||||
public class MusePacketUpgradeRequest extends MusePacket {
|
||||
protected ItemStack stack;
|
||||
protected int slot;
|
||||
protected String moduleName;
|
||||
|
||||
/**
|
||||
* Constructor for sending this packet.
|
||||
*
|
||||
* @param player
|
||||
* Player making the request
|
||||
* @param slotToUpgrade
|
||||
* Slot containing the item for which the upgrade is requested
|
||||
* @param augToUpgrade
|
||||
*/
|
||||
public MusePacketUpgradeRequest(Player player, int slotToUpgrade,
|
||||
String augToUpgrade) {
|
||||
super(player);
|
||||
writeInt(slotToUpgrade);
|
||||
writeString(augToUpgrade);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for receiving this packet.
|
||||
*
|
||||
* @param player
|
||||
* @param data
|
||||
* @throws IOException
|
||||
*
|
||||
*/
|
||||
public MusePacketUpgradeRequest(DataInputStream data, Player player) {
|
||||
super(player, data);
|
||||
slot = readInt();
|
||||
moduleName = readString(64);
|
||||
Side side = FMLCommonHandler.instance().getEffectiveSide();
|
||||
if (side == Side.SERVER) {
|
||||
EntityPlayerMP srvplayer = (EntityPlayerMP) player;
|
||||
stack = srvplayer.inventory.getStackInSlot(slot);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,309 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
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");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue