From d43a78dcf84fdfc15bfb7dbd44102e24c4ae2023 Mon Sep 17 00:00:00 2001 From: MachineMuse Date: Mon, 17 Dec 2012 21:17:28 -0700 Subject: [PATCH] More changes, reorganization --- machinemuse/general/geometry/Colour.java | 80 +++++++ machinemuse/general/geometry/Point2D.java | 27 +++ .../powersuits/client/EquipmentRenderer.java | 74 +++++- .../powersuits/client/GuiTinkerTable.java | 136 ----------- machinemuse/powersuits/client/MuseGui.java | 147 ------------ machinemuse/powersuits/common/Config.java | 2 +- machinemuse/powersuits/common/GuiHandler.java | 7 +- .../powersuits/common/PowersuitsMod.java | 3 +- .../common/augmentation/Augmentation.java | 9 + .../common/{ => block}/BlockTinkerTable.java | 6 +- .../powersuits/common/item/IModularItem.java | 5 + .../common/{ => item}/ItemPowerArmor.java | 9 +- .../common/{ => item}/ItemPowerTool.java | 4 +- .../common/{ => trash}/AugLayout.java | 3 +- .../common/{ => trash}/AugSlot.java | 3 +- .../{ => trash}/ContainerTinkerTable.java | 3 +- .../{ => trash}/InventoryModularItem.java | 4 +- .../common/{ => trash}/ItemAugmentation.java | 4 +- .../{ => trash}/SlotArmorInTinkerTable.java | 2 +- .../common/{ => trash}/SlotAugmentation.java | 2 +- machinemuse/powersuits/gui/Clickable.java | 29 +++ .../powersuits/gui/ClickableAugmentation.java | 19 ++ machinemuse/powersuits/gui/ClickableItem.java | 29 +++ .../powersuits/gui/GuiTinkerTable.java | 87 +++++++ machinemuse/powersuits/gui/MuseGui.java | 212 ++++++++++++++++++ 25 files changed, 598 insertions(+), 308 deletions(-) create mode 100644 machinemuse/general/geometry/Colour.java create mode 100644 machinemuse/general/geometry/Point2D.java delete mode 100644 machinemuse/powersuits/client/GuiTinkerTable.java delete mode 100644 machinemuse/powersuits/client/MuseGui.java create mode 100644 machinemuse/powersuits/common/augmentation/Augmentation.java rename machinemuse/powersuits/common/{ => block}/BlockTinkerTable.java (85%) create mode 100644 machinemuse/powersuits/common/item/IModularItem.java rename machinemuse/powersuits/common/{ => item}/ItemPowerArmor.java (89%) rename machinemuse/powersuits/common/{ => item}/ItemPowerTool.java (54%) rename machinemuse/powersuits/common/{ => trash}/AugLayout.java (66%) rename machinemuse/powersuits/common/{ => trash}/AugSlot.java (96%) rename machinemuse/powersuits/common/{ => trash}/ContainerTinkerTable.java (97%) rename machinemuse/powersuits/common/{ => trash}/InventoryModularItem.java (96%) rename machinemuse/powersuits/common/{ => trash}/ItemAugmentation.java (92%) rename machinemuse/powersuits/common/{ => trash}/SlotArmorInTinkerTable.java (97%) rename machinemuse/powersuits/common/{ => trash}/SlotAugmentation.java (96%) create mode 100644 machinemuse/powersuits/gui/Clickable.java create mode 100644 machinemuse/powersuits/gui/ClickableAugmentation.java create mode 100644 machinemuse/powersuits/gui/ClickableItem.java create mode 100644 machinemuse/powersuits/gui/GuiTinkerTable.java create mode 100644 machinemuse/powersuits/gui/MuseGui.java diff --git a/machinemuse/general/geometry/Colour.java b/machinemuse/general/geometry/Colour.java new file mode 100644 index 0000000..f1401c4 --- /dev/null +++ b/machinemuse/general/geometry/Colour.java @@ -0,0 +1,80 @@ +package machinemuse.general.geometry; + +/** + * 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) (b * 255) << 16); + val = val | ((int) (g * 255) << 8); + val = val | ((int) (r * 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); + } +} \ No newline at end of file diff --git a/machinemuse/general/geometry/Point2D.java b/machinemuse/general/geometry/Point2D.java new file mode 100644 index 0000000..dd9784e --- /dev/null +++ b/machinemuse/general/geometry/Point2D.java @@ -0,0 +1,27 @@ +package machinemuse.general.geometry; + +public class Point2D { + private float x; + private float y; + + public Point2D(float x, float y) { + this.x = x; + this.y = y; + } + + public float getX() { + return x; + } + + public float getY() { + return y; + } + + public void setX(float x) { + this.x = x; + } + + public void setY(float y) { + this.y = y; + } +} diff --git a/machinemuse/powersuits/client/EquipmentRenderer.java b/machinemuse/powersuits/client/EquipmentRenderer.java index 62fcc3f..dc94ae8 100644 --- a/machinemuse/powersuits/client/EquipmentRenderer.java +++ b/machinemuse/powersuits/client/EquipmentRenderer.java @@ -1,26 +1,88 @@ package machinemuse.powersuits.client; +import machinemuse.powersuits.gui.MuseGui; +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; public class EquipmentRenderer implements IItemRenderer { private static final boolean useRenderHelper = true; + /** + * 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 useRenderHelper; } + /** + * 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 item, Object... data) { + 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: + } + MuseGui muse = new MuseGui(); + muse.drawCircleAround(8, 8, 8); + } + + /** + * 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; } - @Override - public void renderItem(ItemRenderType type, ItemStack item, Object... data) { - MuseGui muse = new MuseGui(); - muse.drawCircleAround(8, 8, 8); - } - } diff --git a/machinemuse/powersuits/client/GuiTinkerTable.java b/machinemuse/powersuits/client/GuiTinkerTable.java deleted file mode 100644 index a29c17c..0000000 --- a/machinemuse/powersuits/client/GuiTinkerTable.java +++ /dev/null @@ -1,136 +0,0 @@ -package machinemuse.powersuits.client; - -import machinemuse.powersuits.common.ContainerTinkerTable; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.inventory.IInventory; - -import org.lwjgl.opengl.GL11; - -public class GuiTinkerTable extends GuiContainer { - public IInventory[] armorInventory; - - public GuiTinkerTable(ContainerTinkerTable container) { - super(container); - this.xSize = 256; - this.ySize = 226; - } - - /** - * Adds the buttons (and other controls) to the screen in question. - */ - public void initGui() - { - super.initGui(); - } - - public void refresh() { - for (int i = 0; i < 4; i++) { - - } - } - - // public void drawNthItem(ItemStack stack, int n) { - // // TBI - // // draw item - // // draw a button if it's moddable - // } - // - // public void drawSelection() { - // // if(selectedSlot != null) { - // // drawCircleAround(selectedSlot.position, renderEngine, selectedSlot); - // // } - // // for (Augmentation a : Augmentation.getAllAugs()) { - // // if (a.canGoInSlot(selectedSlot.getType())) { - // // - // // } - // // } - // - // } - - // public void drawLayout(AugLayout layout) { - // - // } - // - // public void drawBackground() { - // this.drawDefaultBackground(); - // this.drawRectangularBackground(); - // } - // - // public void drawScreen(int par1, int par2, float par3) { - // super.drawScreen(par1, par2, par3); - // drawBackground(); - // drawItemList(); - // if (editingItem != null && editingLayout != null) { - // drawLayout(editingLayout); - // if (selectedSlot != null) { - // drawSelection(); - // } - // } - // } - // - // public void drawItemList() { - // List items = new ArrayList(); - // for (int i = 0; i < 4; i++) { - // ItemStack item = editingPlayer.inventory.armorItemInSlot(i); - // this.drawItemAt(new Point2Df(0, 0), this.mc.renderEngine, item); - // items.add(item); - // } - // for (int i = 0; i < 9; i++) { - // items.add(editingPlayer.inventory.mainInventory[i]); - // } - // this.drawItemsOnVerticalLine(items, new Point2Df(-0.9f, 0), 0.9f, - // this.mc.renderEngine); - // } - - /** - * Draw the foreground layer for the GuiContainer (everything in front of - * the items) - */ - protected void drawGuiContainerForegroundLayer(int par1, int par2) - { - int x = 0; - int y = 0; - int color = 0; - double weight = 0.0; - double capacity = 0.0; - - this.fontRenderer.drawString("Weight: " + weight, 8, 104, - color); - this.fontRenderer.drawString("Capacity: " + capacity, 8, 114, - color); - this.fontRenderer.drawString("Speed: " + capacity, 8, 124, - color); - } - - protected void drawAugmentationContainerBackground(int paddingX, - int paddingY, int j) { - int n = 0; // set N to the number of augs in that item, plus 1 - for (int i = 0; i < n; i++) { - this.drawTexturedModalRect( - paddingX + 35, // where on the screen - paddingY + 8 + 18 * j, - 0, // where in the texture - 227, - 18 * i, // how much - 18); - } - } - - /** - * Draw the background layer for the GuiContainer (everything behind the - * items) - */ - protected void drawGuiContainerBackgroundLayer(float par1, int par2, - int par3) - { - int textureIndex = this.mc.renderEngine - .getTexture("/img/tinktablegui.png"); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.mc.renderEngine.bindTexture(textureIndex); - int paddingX = (this.width - this.xSize) / 2; - int paddingY = (this.height - this.ySize) / 2; - int numrows = 5; - this.drawTexturedModalRect(paddingX, paddingY, 0, 0, this.xSize, - this.ySize); - } -} diff --git a/machinemuse/powersuits/client/MuseGui.java b/machinemuse/powersuits/client/MuseGui.java deleted file mode 100644 index 114d016..0000000 --- a/machinemuse/powersuits/client/MuseGui.java +++ /dev/null @@ -1,147 +0,0 @@ -package machinemuse.powersuits.client; - -import java.util.List; - -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.RenderEngine; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.item.ItemStack; - -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; - -public class MuseGui extends GuiScreen { - protected static RenderItem itemRenderer = new RenderItem(); - private final boolean usePretty = true; - private static final int numSegments = 360; - private static final int xcenter = 8; - private static final int ycenter = 8; - private static final Tessellator tesselator = Tessellator.instance; - - public static final double theta = (2 * Math.PI) / numSegments; - - /** - * Adds the buttons (and other controls) to the screen in question. - */ - public void initGui() { - super.initGui(); - this.controlList.clear(); - Keyboard.enableRepeatEvents(true); - } - - public void drawRectangularBackground() { - GL11.glEnable(GL11.GL_BLEND); - GL11.glEnable(GL11.GL_LINE_SMOOTH); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glBegin(GL11.GL_QUADS); - GL11.glColor4f(0.5f, 0.5f, 0.5f, 0.8f); - GL11.glVertex2d(0, 0); - GL11.glVertex2d(width - 10, 0); - GL11.glVertex2d(width - 10, height - 10); - GL11.glVertex2d(0, height - 10); - GL11.glEnd(); - } - - public void drawItemsOnVerticalLine(List items, Point2Df offset, - float lineheight, RenderEngine engine) { - if (items.size() < 1) { - return; - } else if (items.size() < 2) { - drawItemAt(offset, engine, items.get(0)); - } else { - int top = (int) (offset.getAbsY(height) - height * lineheight / 2); - int bottom = (int) (offset.getAbsY(height) + height * lineheight - / 2); - Point2Df position = new Point2Df(offset.x, top * 2.0f / height - 1); - int step = (top - bottom) / (items.size() - 1); - for (int i = 0; i < items.size(); i++) { - drawItemAt(position, engine, items.get(i)); - position.y += step; - } - } - } - - public void drawItemAt(Point2Df p, RenderEngine engine, - ItemStack item) { - itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, engine, - item, p.getAbsX(width) - xcenter, p.getAbsY(height) - ycenter); - } - - public void drawCircleAround(float xoffset, float yoffset, float radius) { - int start = (int) (System.currentTimeMillis() / 4 % 360); - 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); - GL11.glEnable(GL11.GL_BLEND); - GL11.glEnable(GL11.GL_LINE_SMOOTH); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - 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(); - } - - public static class Colour { - public float r; - public float g; - public float b; - public float a; - - public Colour(float r, float g, float b, float a) { - this.r = r; - this.g = g; - this.b = b; - this.a = a; - } - - public Colour(float r, float g, float b) { - this(r, g, b, 1.0F); - } - - public Colour(int c) { - this.r = (c >> 16 & 255) / 255.0F; - this.g = (c >> 8 & 255) / 255.0F; - this.b = (c & 255) / 255.0F; - this.a = 1.0F; - } - } - - public static class Point2Df { - /* - * point representation where [-1,-1] is the top left corner of the - * screen and [1,1] is the bottom right. - */ - public float x; - public float y; - - public Point2Df(float x, float y) { - this.x = x; - this.y = y; - } - - public int getAbsX(int width) { - return (int) ((x + 1) * width / 2); - } - - public int getAbsY(int height) { - return (int) ((y + 1) * height / 2); - } - - } -} diff --git a/machinemuse/powersuits/common/Config.java b/machinemuse/powersuits/common/Config.java index 921931b..d2cada3 100644 --- a/machinemuse/powersuits/common/Config.java +++ b/machinemuse/powersuits/common/Config.java @@ -1,5 +1,6 @@ package machinemuse.powersuits.common; +import machinemuse.powersuits.common.block.BlockTinkerTable; import net.minecraft.block.Block; import net.minecraft.block.StepSound; import net.minecraft.block.material.Material; @@ -101,7 +102,6 @@ public class Config extends Configuration { PowerArmorLegs(2, "powerArmorLegs", "Power Armor Legs"), PowerArmorFeet(3, "powerArmorFeet", "Power Armor Feet"), PowerTool(4, "powerTool", "Power Tool"), - Augmentation(5, "modularAugmentation", "Modular Augmentation"), ; diff --git a/machinemuse/powersuits/common/GuiHandler.java b/machinemuse/powersuits/common/GuiHandler.java index 946508d..361db8b 100644 --- a/machinemuse/powersuits/common/GuiHandler.java +++ b/machinemuse/powersuits/common/GuiHandler.java @@ -1,6 +1,6 @@ package machinemuse.powersuits.common; -import machinemuse.powersuits.client.GuiTinkerTable; +import machinemuse.powersuits.gui.GuiTinkerTable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; @@ -10,13 +10,12 @@ public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { - return new ContainerTinkerTable(player, world, x, y, z); + return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { - return new GuiTinkerTable(new ContainerTinkerTable(player, world, x, y, - z)); + return new GuiTinkerTable(player); } } diff --git a/machinemuse/powersuits/common/PowersuitsMod.java b/machinemuse/powersuits/common/PowersuitsMod.java index ef1ab91..e8d039c 100644 --- a/machinemuse/powersuits/common/PowersuitsMod.java +++ b/machinemuse/powersuits/common/PowersuitsMod.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.List; import machinemuse.powersuits.client.ClientPacketHandler; +import machinemuse.powersuits.common.block.BlockTinkerTable; +import machinemuse.powersuits.common.item.ItemPowerArmor; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraftforge.common.Configuration; @@ -55,7 +57,6 @@ public class PowersuitsMod { allItems.add(new ItemPowerArmor( Config.Items.values()[i])); } - allItems.add(new ItemAugmentation(Config.Items.Augmentation)); proxy.registerRenderers(); NetworkRegistry.instance().registerGuiHandler(this, guiHandler); diff --git a/machinemuse/powersuits/common/augmentation/Augmentation.java b/machinemuse/powersuits/common/augmentation/Augmentation.java new file mode 100644 index 0000000..c476d1b --- /dev/null +++ b/machinemuse/powersuits/common/augmentation/Augmentation.java @@ -0,0 +1,9 @@ +package machinemuse.powersuits.common.augmentation; + +public abstract class Augmentation { + public abstract String getName(); + + public abstract float getWeight(); + + public abstract boolean isValidForSlot(int slot); +} diff --git a/machinemuse/powersuits/common/BlockTinkerTable.java b/machinemuse/powersuits/common/block/BlockTinkerTable.java similarity index 85% rename from machinemuse/powersuits/common/BlockTinkerTable.java rename to machinemuse/powersuits/common/block/BlockTinkerTable.java index c1506fa..19fa845 100644 --- a/machinemuse/powersuits/common/BlockTinkerTable.java +++ b/machinemuse/powersuits/common/block/BlockTinkerTable.java @@ -1,5 +1,9 @@ -package machinemuse.powersuits.common; +package machinemuse.powersuits.common.block; +import machinemuse.powersuits.common.CommonProxy; +import machinemuse.powersuits.common.Config; +import machinemuse.powersuits.common.PowersuitsMod; +import machinemuse.powersuits.common.Config.Blocks; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; diff --git a/machinemuse/powersuits/common/item/IModularItem.java b/machinemuse/powersuits/common/item/IModularItem.java new file mode 100644 index 0000000..d6a5df2 --- /dev/null +++ b/machinemuse/powersuits/common/item/IModularItem.java @@ -0,0 +1,5 @@ +package machinemuse.powersuits.common.item; + +public interface IModularItem { + +} diff --git a/machinemuse/powersuits/common/ItemPowerArmor.java b/machinemuse/powersuits/common/item/ItemPowerArmor.java similarity index 89% rename from machinemuse/powersuits/common/ItemPowerArmor.java rename to machinemuse/powersuits/common/item/ItemPowerArmor.java index 21f98e7..2d82f84 100644 --- a/machinemuse/powersuits/common/ItemPowerArmor.java +++ b/machinemuse/powersuits/common/item/ItemPowerArmor.java @@ -1,5 +1,7 @@ -package machinemuse.powersuits.common; +package machinemuse.powersuits.common.item; +import machinemuse.powersuits.common.CommonProxy; +import machinemuse.powersuits.common.Config; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumArmorMaterial; @@ -9,8 +11,9 @@ import net.minecraft.util.DamageSource; import net.minecraftforge.common.ISpecialArmor; import cpw.mods.fml.common.registry.LanguageRegistry; -public class ItemPowerArmor extends ItemArmor implements ISpecialArmor { - protected ItemPowerArmor(Config.Items item) { +public class ItemPowerArmor extends ItemArmor implements ISpecialArmor, + IModularItem { + public ItemPowerArmor(Config.Items item) { super(Config.getAssignedItemID(item), // itemID EnumArmorMaterial.IRON, // Material item.iconIndex, // Texture index diff --git a/machinemuse/powersuits/common/ItemPowerTool.java b/machinemuse/powersuits/common/item/ItemPowerTool.java similarity index 54% rename from machinemuse/powersuits/common/ItemPowerTool.java rename to machinemuse/powersuits/common/item/ItemPowerTool.java index 9dc4288..e5f702c 100644 --- a/machinemuse/powersuits/common/ItemPowerTool.java +++ b/machinemuse/powersuits/common/item/ItemPowerTool.java @@ -1,8 +1,8 @@ -package machinemuse.powersuits.common; +package machinemuse.powersuits.common.item; import net.minecraft.item.Item; -public class ItemPowerTool extends Item { +public class ItemPowerTool extends Item implements IModularItem { public ItemPowerTool(int par1) { super(par1); diff --git a/machinemuse/powersuits/common/AugLayout.java b/machinemuse/powersuits/common/trash/AugLayout.java similarity index 66% rename from machinemuse/powersuits/common/AugLayout.java rename to machinemuse/powersuits/common/trash/AugLayout.java index cb861d3..1aa8d02 100644 --- a/machinemuse/powersuits/common/AugLayout.java +++ b/machinemuse/powersuits/common/trash/AugLayout.java @@ -1,7 +1,8 @@ -package machinemuse.powersuits.common; +package machinemuse.powersuits.common.trash; import java.util.List; + public abstract class AugLayout { private List slots; diff --git a/machinemuse/powersuits/common/AugSlot.java b/machinemuse/powersuits/common/trash/AugSlot.java similarity index 96% rename from machinemuse/powersuits/common/AugSlot.java rename to machinemuse/powersuits/common/trash/AugSlot.java index 6b090f7..a6ac2c7 100644 --- a/machinemuse/powersuits/common/AugSlot.java +++ b/machinemuse/powersuits/common/trash/AugSlot.java @@ -1,8 +1,9 @@ -package machinemuse.powersuits.common; +package machinemuse.powersuits.common.trash; import java.util.ArrayList; import java.util.List; + public class AugSlot { private List connectedSlots; private SlotType type; diff --git a/machinemuse/powersuits/common/ContainerTinkerTable.java b/machinemuse/powersuits/common/trash/ContainerTinkerTable.java similarity index 97% rename from machinemuse/powersuits/common/ContainerTinkerTable.java rename to machinemuse/powersuits/common/trash/ContainerTinkerTable.java index 1f048c8..848cb61 100644 --- a/machinemuse/powersuits/common/ContainerTinkerTable.java +++ b/machinemuse/powersuits/common/trash/ContainerTinkerTable.java @@ -1,7 +1,8 @@ -package machinemuse.powersuits.common; +package machinemuse.powersuits.common.trash; import java.util.ArrayList; +import machinemuse.powersuits.common.item.ItemPowerArmor; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; diff --git a/machinemuse/powersuits/common/InventoryModularItem.java b/machinemuse/powersuits/common/trash/InventoryModularItem.java similarity index 96% rename from machinemuse/powersuits/common/InventoryModularItem.java rename to machinemuse/powersuits/common/trash/InventoryModularItem.java index e7e84b0..6f244ef 100644 --- a/machinemuse/powersuits/common/InventoryModularItem.java +++ b/machinemuse/powersuits/common/trash/InventoryModularItem.java @@ -1,7 +1,9 @@ -package machinemuse.powersuits.common; +package machinemuse.powersuits.common.trash; import java.util.ArrayList; +import machinemuse.powersuits.common.item.ItemPowerArmor; +import machinemuse.powersuits.common.item.ItemPowerTool; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; diff --git a/machinemuse/powersuits/common/ItemAugmentation.java b/machinemuse/powersuits/common/trash/ItemAugmentation.java similarity index 92% rename from machinemuse/powersuits/common/ItemAugmentation.java rename to machinemuse/powersuits/common/trash/ItemAugmentation.java index 9f72e21..e4f001f 100644 --- a/machinemuse/powersuits/common/ItemAugmentation.java +++ b/machinemuse/powersuits/common/trash/ItemAugmentation.java @@ -1,8 +1,10 @@ -package machinemuse.powersuits.common; +package machinemuse.powersuits.common.trash; import java.util.ArrayList; import java.util.List; +import machinemuse.powersuits.common.Config; +import machinemuse.powersuits.common.Config.Items; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; diff --git a/machinemuse/powersuits/common/SlotArmorInTinkerTable.java b/machinemuse/powersuits/common/trash/SlotArmorInTinkerTable.java similarity index 97% rename from machinemuse/powersuits/common/SlotArmorInTinkerTable.java rename to machinemuse/powersuits/common/trash/SlotArmorInTinkerTable.java index 01f46ec..22815ed 100644 --- a/machinemuse/powersuits/common/SlotArmorInTinkerTable.java +++ b/machinemuse/powersuits/common/trash/SlotArmorInTinkerTable.java @@ -1,4 +1,4 @@ -package machinemuse.powersuits.common; +package machinemuse.powersuits.common.trash; import net.minecraft.block.Block; import net.minecraft.inventory.IInventory; diff --git a/machinemuse/powersuits/common/SlotAugmentation.java b/machinemuse/powersuits/common/trash/SlotAugmentation.java similarity index 96% rename from machinemuse/powersuits/common/SlotAugmentation.java rename to machinemuse/powersuits/common/trash/SlotAugmentation.java index 46950e3..9d34c4f 100644 --- a/machinemuse/powersuits/common/SlotAugmentation.java +++ b/machinemuse/powersuits/common/trash/SlotAugmentation.java @@ -1,4 +1,4 @@ -package machinemuse.powersuits.common; +package machinemuse.powersuits.common.trash; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; diff --git a/machinemuse/powersuits/gui/Clickable.java b/machinemuse/powersuits/gui/Clickable.java new file mode 100644 index 0000000..365aaa1 --- /dev/null +++ b/machinemuse/powersuits/gui/Clickable.java @@ -0,0 +1,29 @@ +package machinemuse.powersuits.gui; + +import java.util.List; + +import machinemuse.general.geometry.Point2D; + +public abstract class Clickable { + private 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 boolean hitBox(float x, float y); + + public abstract List getToolTip(); +} diff --git a/machinemuse/powersuits/gui/ClickableAugmentation.java b/machinemuse/powersuits/gui/ClickableAugmentation.java new file mode 100644 index 0000000..bdff468 --- /dev/null +++ b/machinemuse/powersuits/gui/ClickableAugmentation.java @@ -0,0 +1,19 @@ +package machinemuse.powersuits.gui; + +import java.util.List; + +public class ClickableAugmentation extends Clickable { + + @Override + public boolean hitBox(float x, float y) { + // TODO Auto-generated method stub + return false; + } + + @Override + public List getToolTip() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/machinemuse/powersuits/gui/ClickableItem.java b/machinemuse/powersuits/gui/ClickableItem.java new file mode 100644 index 0000000..5efff1b --- /dev/null +++ b/machinemuse/powersuits/gui/ClickableItem.java @@ -0,0 +1,29 @@ +package machinemuse.powersuits.gui; + +import java.util.List; + +import machinemuse.general.geometry.Point2D; +import net.minecraft.item.ItemStack; + +public class ClickableItem extends Clickable { + public static final Point2D offset = new Point2D(8, 8); + private ItemStack item; + + public ClickableItem(ItemStack item, Point2D pos) { + super(pos); + this.item = item; + } + + @Override + public boolean hitBox(float x, float y) { + boolean hitx = Math.abs(x - getPosition().getX()) < offset.getX(); + boolean hity = Math.abs(y - getPosition().getY()) < offset.getY(); + return hitx && hity; + } + + @Override + public List getToolTip() { + return item.getTooltip(null, false); + } + +} diff --git a/machinemuse/powersuits/gui/GuiTinkerTable.java b/machinemuse/powersuits/gui/GuiTinkerTable.java new file mode 100644 index 0000000..b350c73 --- /dev/null +++ b/machinemuse/powersuits/gui/GuiTinkerTable.java @@ -0,0 +1,87 @@ +package machinemuse.powersuits.gui; + +import java.util.ArrayList; + +import machinemuse.general.geometry.Colour; +import machinemuse.powersuits.common.item.IModularItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +public class GuiTinkerTable extends MuseGui { + protected EntityPlayer player; + protected ArrayList modularItems; + + public GuiTinkerTable(EntityPlayer player) { + this.player = player; + this.modularItems = new ArrayList(); + this.xSize = 256; + this.ySize = 226; + } + + /** + * Adds the buttons (and other controls) to the screen in question. + */ + public void initGui() + { + super.initGui(); + for (int i = 0; i < player.inventory.getSizeInventory(); i++) { + ItemStack stack = player.inventory.getStackInSlot(i); + if (stack != null && stack.getItem() instanceof IModularItem) { + modularItems.add(stack); + } + } + } + + public void refresh() { + for (int i = 0; i < 4; i++) { + + } + } + + // public void drawNthItem(ItemStack stack, int n) { + // // TBI + // // draw item + // // draw a button if it's moddable + // } + // + // public void drawSelection() { + // // if(selectedSlot != null) { + // // drawCircleAround(selectedSlot.position, renderEngine, selectedSlot); + // // } + // // for (Augmentation a : Augmentation.getAllAugs()) { + // // if (a.canGoInSlot(selectedSlot.getType())) { + // // + // // } + // // } + // + // } + + // public void drawLayout(AugLayout layout) { + // + // } + // + public void drawBackground() { + this.drawDefaultBackground(); + this.drawRectangularBackground(); + } + + public void drawScreen(int par1, int par2, float par3) { + super.drawScreen(par1, par2, par3); + drawBackground(); + drawItemList(); + Colour colour = Colour.getGreyscale(1.0F, 1.0F); + // if (editingItem != null && editingLayout != null) { + // drawLayout(editingLayout); + // if (selectedSlot != null) { + // drawSelection(); + // } + // } + } + + public void drawItemList() { + this.drawItemsOnVerticalLine(modularItems, -0.9F, 0.0F, + 0.9f, + this.mc.renderEngine); + } + +} diff --git a/machinemuse/powersuits/gui/MuseGui.java b/machinemuse/powersuits/gui/MuseGui.java new file mode 100644 index 0000000..1ab710b --- /dev/null +++ b/machinemuse/powersuits/gui/MuseGui.java @@ -0,0 +1,212 @@ +package machinemuse.powersuits.gui; + +import java.util.ArrayList; + +import machinemuse.general.geometry.Colour; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.RenderEngine; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.item.ItemStack; + +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; + +public class MuseGui extends GuiScreen { + protected static RenderItem itemRenderer = new RenderItem(); + private final boolean usePretty = true; + private static final int numSegments = 360; + private static final int xcenter = 8; + private static final int ycenter = 8; + private static final Tessellator tesselator = Tessellator.instance; + private long creationTime; + int xSize, ySize; + + public static final double theta = (2 * Math.PI) / numSegments; + + /** + * Adds the buttons (and other controls) to the screen in question. + */ + public void initGui() { + super.initGui(); + this.controlList.clear(); + Keyboard.enableRepeatEvents(true); + creationTime = System.currentTimeMillis(); + } + + public void drawRectangularBackground() { + int xpadding = (width - xSize) / 2; + int ypadding = (height - ySize) / 2; + + drawGradientRect( + xpadding, ypadding, + xpadding + xSize, ypadding + ySize, + Colour.getGreyscale(0.8f, 0.8f), + Colour.getGreyscale(0.3f, 0.8f)); + + // GL11.glEnable(GL11.GL_BLEND); + // GL11.glEnable(GL11.GL_LINE_SMOOTH); + // GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + // GL11.glBegin(GL11.GL_QUADS); + // GL11.glColor4f(0.5f, 0.5f, 0.5f, 0.8f); + // GL11.glVertex2d(0, 0); + // GL11.glVertex2d(width - 10, 0); + // GL11.glVertex2d(width - 10, height - 10); + // GL11.glVertex2d(0, height - 10); + // GL11.glEnd(); + } + + public void drawItemsOnVerticalLine(ArrayList items, + float xoffset, + float yoffset, + float lineheight, RenderEngine engine) { + if (items.size() < 1) { + return; + } else if (items.size() < 2) { + drawItemAt(xoffset, yoffset, engine, items.get(0)); + } else { + float step = 2 * lineheight / (items.size() - 1); + for (int i = 0; i < items.size(); i++) { + drawItemAt(xoffset, yoffset - lineheight + i * step, engine, + items.get(i)); + } + } + } + + /** + * Returns absolute screen coordinates (0 to width) from a relative + * coordinate (-1.0F to +1.0F) + * + * @param relx + * Relative X coordinate + * @return Absolute X coordinate + */ + public int absX(float relx) { + int absx = (int) ((relx + 1) * xSize / 2); + int xpadding = (width - xSize) / 2; + return absx + xpadding; + } + + /** + * Returns absolute screen coordinates (0 to width) from a relative + * coordinate (-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; + } + + /** + * Draws the specified itemstack at the *relative* coordinates x,y. Used + * mainly in clickables. + */ + public void drawItemAt(float x, float y, RenderEngine engine, + ItemStack item) { + GL11.glEnable(GL11.GL_DEPTH_TEST); + // GL11.glDepthFunc(GL11.GL_GREATER); + GL11.glDisable(GL11.GL_LIGHTING); + + itemRenderer.zLevel = 100.0F; + itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, engine, + item, absX(x) - xcenter, absY(y) - ycenter); + Minecraft.getMinecraft().fontRenderer.drawString( + item.getItem().getItemDisplayName(item).substring(12, 16), + absX(x) - xcenter, absY(y) - ycenter, + Colour.getGreyscale(1.0F, 1.0F).getInt()); + // drawCircleAround(absX(x), absY(y), 8); + itemRenderer.zLevel = 0.0F; + GL11.glDisable(GL11.GL_DEPTH_TEST); + // GL11.glDepthFunc(GL11.GL_LEQUAL); + GL11.glEnable(GL11.GL_LIGHTING); + } + + public static void drawCircleAround(float xoffset, float yoffset, + float radius) { + int start = (int) (System.currentTimeMillis() / 4 % 360); + 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(); + + 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(); + } + + /** + * Call before doing any pure geometry (ie. with colours rather than + * textures). + */ + public static void texturelessOn() { + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + GL11.glEnable(GL11.GL_LINE_SMOOTH); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glShadeModel(GL11.GL_SMOOTH); + } + + /** + * Call after doing pure geometry (ie. with colours) to go back to the + * texture mode (default). + */ + public static void texturelessOff() { + GL11.glShadeModel(GL11.GL_FLAT); + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL11.GL_TEXTURE_2D); + } + + /** + * Draws a rectangle with a vertical gradient between the specified colors. + */ + protected void drawGradientRect(int left, int top, int right, int bottom, + Colour c1, Colour c2) + { + texturelessOn(); + + Tessellator tessellator = Tessellator.instance; + + tessellator.startDrawingQuads(); + tessellator.setColorRGBA_F(c1.r, c1.g, c1.b, c1.a); + tessellator.addVertex((double) right, (double) top, + (double) this.zLevel); + tessellator + .addVertex((double) left, (double) top, (double) this.zLevel); + + tessellator.setColorRGBA_F(c2.r, c2.g, c2.b, c2.a); + tessellator.addVertex((double) left, (double) bottom, + (double) this.zLevel); + tessellator.addVertex((double) right, (double) bottom, + (double) this.zLevel); + tessellator.draw(); + + texturelessOff(); + } +}