Doing it right dot jpeg

This commit is contained in:
MachineMuse 2012-12-17 14:24:42 -07:00
commit b958f0d07f
22 changed files with 1582 additions and 0 deletions

22
.gitattributes vendored Normal file
View file

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

163
.gitignore vendored Normal file
View file

@ -0,0 +1,163 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover
## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
# ReSharper is a .NET coding add-in
_ReSharper*
# Installshield output folder
[Ee]xpress
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish
# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
############
## Windows
############
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
# Mac crap
.DS_Store

View file

@ -0,0 +1,19 @@
package machinemuse.powersuits.client;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
public class ClientPacketHandler implements IPacketHandler {
@Override
public void onPacketData(INetworkManager manager,
Packet250CustomPayload payload, Player player) {
DataInputStream data = new DataInputStream(new ByteArrayInputStream(
payload.data));
}
}

View file

@ -0,0 +1,25 @@
package machinemuse.powersuits.client;
import machinemuse.powersuits.common.CommonProxy;
import machinemuse.powersuits.common.PowersuitsMod;
import net.minecraft.item.Item;
import net.minecraftforge.client.MinecraftForgeClient;
public class ClientProxy extends CommonProxy {
private static EquipmentRenderer eRenderer = new EquipmentRenderer();
@Override
public void registerRenderers() {
for (Item i : PowersuitsMod.allItems) {
MinecraftForgeClient.registerItemRenderer(
i.shiftedIndex, eRenderer);
}
// for (Item i : PowersuitsMod.allBlocks) {
// MinecraftForgeClient.registerItemRenderer(
// i.shiftedIndex, eRenderer);
// }
MinecraftForgeClient.preloadTexture("/gui/tinktablegui.png");
}
}

View file

@ -0,0 +1,26 @@
package machinemuse.powersuits.client;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;
public class EquipmentRenderer implements IItemRenderer {
private static final boolean useRenderHelper = true;
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
return useRenderHelper;
}
@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);
}
}

View file

@ -0,0 +1,136 @@
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<ItemStack> items = new ArrayList<ItemStack>();
// 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);
}
}

View file

@ -0,0 +1,147 @@
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<ItemStack> 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);
}
}
}

View file

@ -0,0 +1,8 @@
package machinemuse.powersuits.common;
import java.util.List;
public abstract class AugLayout {
private List<AugSlot> slots;
}

View file

@ -0,0 +1,62 @@
package machinemuse.powersuits.common;
import java.util.ArrayList;
import java.util.List;
public class AugSlot {
private List<AugSlot> connectedSlots;
private SlotType type;
private ItemAugmentation installedAug;
public AugSlot(SlotType type) {
connectedSlots = new ArrayList<AugSlot>();
this.type = type;
}
public List<AugSlot> getConnectedSlots() {
return connectedSlots;
}
public void connectToSlot(AugSlot other) {
if (!this.connectedSlots.contains(other)) {
this.connectedSlots.add(other);
}
if (!other.connectedSlots.contains(this)) {
other.connectedSlots.add(this);
}
}
// Returns true if successful, false otherwise
public boolean installAugmentation(ItemAugmentation aug) {
if (aug.canGoInSlot(type)) {
installedAug = aug;
return true;
} else {
return false;
}
}
public void disconnectFromSlot(AugSlot other) {
if (!this.connectedSlots.contains(other)) {
this.connectedSlots.add(other);
}
if (!other.connectedSlots.contains(this)) {
other.connectedSlots.add(this);
}
}
public SlotType getType() {
return type;
}
public static enum SlotType {
Vision,
Hearing,
Movement,
Generator,
PowerConduit,
Weapon,
Tool,
}
}

View file

@ -0,0 +1,48 @@
package machinemuse.powersuits.common;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
public class BlockTinkerTable extends Block {
public BlockTinkerTable() {
super(Config.getAssignedBlockID(Config.Blocks.TinkerTable),
Config.Blocks.TinkerTable.textureIndex,
Config.Blocks.TinkerTable.material);
setHardness(Config.Blocks.TinkerTable.hardness);
setStepSound(Config.Blocks.TinkerTable.stepSound);
setBlockName(Config.Blocks.TinkerTable.idName);
setCreativeTab(Config.getCreativeTab());
LanguageRegistry.addName(this, Config.Blocks.TinkerTable.englishName);
MinecraftForge.setBlockHarvestLevel(this,
Config.Blocks.TinkerTable.harvestTool,
Config.Blocks.TinkerTable.harvestLevel);
ItemStack recipeResult = new ItemStack(this);
GameRegistry.registerBlock(this);
}
@Override
public String getTextureFile() {
return CommonProxy.BLOCK_PNG;
}
/**
* Called upon block activation (right click on the block.)
*/
public boolean onBlockActivated(World world, int x, int y,
int z, EntityPlayer player, int par6, float par7,
float par8, float par9)
{
if (player.isSneaking()) {
return false;
}
player.openGui(PowersuitsMod.instance, 0, world, x, y, z);
return true;
}
}

View file

@ -0,0 +1,13 @@
package machinemuse.powersuits.common;
public class CommonProxy {
public static String ITEMS_PNG = "/tutorial/generic/items.png";
public static String BLOCK_PNG = "/tutorial/generic/block.png";
// Client stuff
public void registerRenderers() {
// Nothing here as this is the server side proxy
}
}

View file

@ -0,0 +1,121 @@
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.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.registry.GameRegistry;
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;
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();
}
public static CreativeTabs getCreativeTab() {
return CreativeTabs.tabMisc;
}
public static int getAssignedItemID(Items item) {
if (assignedItemIDs[item.ordinal()] == 0) {
assignedItemIDs[item.ordinal()] = config.getItem(item.englishName,
1002).getInt();
}
return assignedItemIDs[item.ordinal()];
}
public static int getAssignedBlockID(Blocks block) {
if (assignedBlockIDs[block.ordinal()] == 0) {
assignedBlockIDs[block.ordinal()] = config.getBlock(
block.englishName, 5000).getInt();
}
return assignedBlockIDs[block.ordinal()];
}
public static int RegisterRecipes() {
ItemStack iron = new ItemStack(Item.ingotIron);
ItemStack lapis = new ItemStack(Item.dyePowder, 1);
GameRegistry.addRecipe(new ItemStack(new BlockTinkerTable()), " I ",
"ILI",
" I ", 'I', iron, 'L', lapis);
return 0;
}
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;
}
}
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"),
Augmentation(5, "modularAugmentation", "Modular Augmentation"),
;
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;
}
}
}

View file

@ -0,0 +1,174 @@
package machinemuse.powersuits.common;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ContainerTinkerTable extends Container {
EntityPlayer player;
private World world;
private int posX;
private int posY;
private int posZ;
private final int inventoryTop = 145;
public InventoryModularItem[] itemInventories;
public SlotArmorInTinkerTable[] armorslots;
public ArrayList<SlotAugmentation> augslots;
public ContainerTinkerTable(EntityPlayer player, World world, int x, int y,
int z) {
this.player = player;
this.world = world;
this.posX = x;
this.posY = y;
this.posZ = z;
int id = 0;
int slotx = 0;
int sloty = 0;
armorslots = new SlotArmorInTinkerTable[4];
itemInventories = new InventoryModularItem[5];
augslots = new ArrayList<SlotAugmentation>();
for (int i = 0; i < 4; i++) {
armorslots[i] = new SlotArmorInTinkerTable(this,
player.inventory,
player.inventory.getSizeInventory() - 1 - i,
8,
8 + i * 18,
i);
this.addSlotToContainer(armorslots[i]);
}
bindPlayerInventory(player);
this.update();
}
public void update() {
this.inventorySlots.removeAll(augslots);
augslots.clear();
for (int i = 0; i < 4; i++) {
ItemStack stack = armorslots[i].getStack();
if (stack != null) {
if (stack.getItem() instanceof ItemPowerArmor) {
itemInventories[i] = InventoryModularItem
.fromItemStack(stack, this);
this.bindItemInventory(itemInventories[i], i);
}
}
}
}
public void bindItemInventory(InventoryModularItem inv, int row) {
for (int i = 0; i < inv.getSizeInventory(); ++i) {
SlotAugmentation slot = new SlotAugmentation(
inv,
i,
32 + i * 18,
9 + row * 18);
this.addSlotToContainer(slot);
this.augslots.add(slot);
}
}
public void bindPlayerInventory(EntityPlayer player) {
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
this.addSlotToContainer(new Slot(
player.inventory,
9 + j + i * 9,
8 + j * 18,
inventoryTop + i * 18));
}
}
for (int i = 0; i < 9; ++i) {
this.addSlotToContainer(new Slot(
player.inventory,
i,
8 + i * 18,
inventoryTop + 58));
}
}
/**
* Callback for when the crafting gui is closed.
*/
public void onCraftGuiClosed(EntityPlayer par1EntityPlayer)
{
}
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
return par1EntityPlayer.getDistanceSq((double) this.posX + 0.5D,
(double) this.posY + 0.5D, (double) this.posZ + 0.5D) <= 64.0D;
}
/**
* Called when a player shift-clicks on a slot. You must override this or
* you will crash when someone does that.
*/
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
{
ItemStack var3 = null;
Slot var4 = (Slot) this.inventorySlots.get(par2);
if (var4 != null && var4.getHasStack())
{
ItemStack var5 = var4.getStack();
var3 = var5.copy();
if (par2 == 0)
{
if (!this.mergeItemStack(var5, 10, 46, true))
{
return null;
}
var4.onSlotChange(var5, var3);
}
else if (par2 >= 10 && par2 < 37)
{
if (!this.mergeItemStack(var5, 37, 46, false))
{
return null;
}
}
else if (par2 >= 37 && par2 < 46)
{
if (!this.mergeItemStack(var5, 10, 37, false))
{
return null;
}
}
else if (!this.mergeItemStack(var5, 10, 46, false))
{
return null;
}
if (var5.stackSize == 0)
{
var4.putStack((ItemStack) null);
}
else
{
var4.onSlotChanged();
}
if (var5.stackSize == var3.stackSize)
{
return null;
}
var4.onPickupFromSlot(par1EntityPlayer, var5);
}
return var3;
}
}

View file

@ -0,0 +1,22 @@
package machinemuse.powersuits.common;
import machinemuse.powersuits.client.GuiTinkerTable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
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);
}
@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));
}
}

View file

@ -0,0 +1,219 @@
package machinemuse.powersuits.common;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class InventoryModularItem implements IInventory {
/** List of the stacks in the crafting matrix. */
private ArrayList<ItemStack> stackList;
private ItemStack associatedWith;
private ContainerTinkerTable container;
/** the width of the crafting inventory */
public InventoryModularItem(ContainerTinkerTable container)
{
this.container = container;
this.stackList = new ArrayList<ItemStack>();
}
/**
* Creates a new Inventory from the nbt tag list associated with an
* itemStack.
*/
public static InventoryModularItem fromItemStack(ItemStack stack,
ContainerTinkerTable container) {
InventoryModularItem inv = null;
if (stack.getItem() instanceof ItemPowerArmor) {
NBTTagCompound tags = stack.getTagCompound();
if (tags != null) {
inv = fromNBT(tags, container);
} else {
inv = new InventoryModularItem(container);
}
inv.associatedWith = stack;
inv.addEmptySlot();
} else if (stack.getItem() instanceof ItemPowerTool) {
NBTTagCompound tags = stack.getTagCompound();
if (tags != null) {
inv = fromNBT(tags, container);
} else {
inv = new InventoryModularItem(container);
}
inv.associatedWith = stack;
inv.addEmptySlot();
}
return inv;
}
/**
* Creates a new Inventory from an nbt tag list.
*/
public static InventoryModularItem fromNBT(NBTTagCompound tags,
ContainerTinkerTable container) {
InventoryModularItem inv = new InventoryModularItem(container);
int[] moduleIDs = tags.getIntArray("Contents");
for (int i = 0; i < moduleIDs.length; i++) {
inv.stackList.add(new ItemStack(ItemAugmentation.index, 1,
moduleIDs[i]));
}
return inv;
}
/**
* Creates an NBT tag list describing the inventory in its current state,
* and associates it with the given ItemStack.
*/
public void toNBTOfStack(ItemStack stack) {
if (stack != null) {
stack.setTagCompound(toNBT());
}
}
/**
* Creates an NBT tag list describing the inventory in its current state.
*/
public NBTTagCompound toNBT() {
NBTTagCompound nbt = new NBTTagCompound();
int[] moduleIDs = new int[stackList.size()];
for (int i = 0; i < stackList.size(); i++) {
if (stackList.get(i) != null) {
moduleIDs[i] = stackList.get(i).getItemDamage();
} else {
moduleIDs[i] = -1;
}
}
nbt.setIntArray("Contents", moduleIDs);
return nbt;
}
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.stackList.size();
}
/**
* Returns the stack in slot i
*/
public ItemStack getStackInSlot(int par1)
{
return par1 >= this.getSizeInventory() ? null : this.stackList
.get(par1);
}
/**
* Returns the name of the inventory.
*/
public String getInvName()
{
return "container.crafting";
}
/**
* When some containers are closed they call this on each slot, then drop
* whatever it returns as an EntityItem - like when you close a workbench
* GUI.
*/
public ItemStack getStackInSlotOnClosing(int par1)
{
if (this.stackList.get(par1) != null)
{
ItemStack var2 = this.stackList.get(par1);
this.stackList.remove(par1);
return var2;
}
else
{
return null;
}
}
/**
* Removes from an inventory slot (first arg) up to a specified number
* (second arg) of items and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int number)
{
if (this.stackList.get(index) != null)
{
ItemStack var3;
if (this.stackList.get(index).stackSize <= number)
{
var3 = this.stackList.get(index);
this.stackList.remove(index);
return var3;
}
else
{
var3 = this.stackList.get(index).splitStack(number);
if (this.stackList.get(index).stackSize == 0)
{
this.stackList.remove(index);
}
return var3;
}
}
else
{
return null;
}
}
/**
* Sets the given item stack to the specified slot in the inventory (can be
* crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
this.stackList.set(index, stack);
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be
* 64, possibly will be extended. *Isn't this more of a set than a get?*
*/
public int getInventoryStackLimit()
{
return 1;
}
/**
* Called when an the contents of an Inventory change, usually
*/
public void onInventoryChanged() {
if (this.associatedWith != null) {
this.toNBTOfStack(associatedWith);
}
container.update();
}
public void addEmptySlot() {
this.stackList.add(null);
}
/**
* Do not make give this method the name canInteractWith because it clashes
* with Container
*/
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
{
return true;
}
public void openChest() {
}
public void closeChest() {
}
}

View file

@ -0,0 +1,77 @@
package machinemuse.powersuits.common;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
public class ItemAugmentation extends Item {
static List<ItemAugmentation> allAugs = new ArrayList<ItemAugmentation>();
public static int index;
public ItemAugmentation(Config.Items item) {
super(Config.getAssignedItemID(item));
index = shiftedIndex;
this.setHasSubtypes(true);
this.setMaxDamage(0);
allAugs.add(this);
}
public static List<ItemAugmentation> getAllAugs() {
return allAugs;
}
public boolean canGoInSlot(AugSlot.SlotType type) {
return true;
}
public static enum AugTypes {
Armor("armor", "Armor Plate", 1),
SteamReceptacle("steamReceptacle", "Steam Receptacle", 2),
;
String idName;
String englishName;
int id;
private AugTypes(String idName, String englishName, int id) {
this.idName = idName;
this.englishName = englishName;
this.id = id;
}
}
@SideOnly(Side.CLIENT)
/**
* Gets an icon index based on an item's damage value
*/
public int getIconFromDamage(int par1)
{
return this.iconIndex;
}
public String getItemNameIS(ItemStack par1ItemStack)
{
int var2 = MathHelper.clamp_int(par1ItemStack.getItemDamage(), 0, 15);
return "augmentation." + AugTypes.values()[var2].idName;
}
@SideOnly(Side.CLIENT)
/**
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
*/
public void getSubItems(int id, CreativeTabs creativeTab,
List tabItems)
{
for (AugTypes i : AugTypes.values())
{
tabItems.add(new ItemStack(id, 1, i.id));
}
}
}

View file

@ -0,0 +1,60 @@
package machinemuse.powersuits.common;
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;
import cpw.mods.fml.common.registry.LanguageRegistry;
public class ItemPowerArmor extends ItemArmor implements ISpecialArmor {
protected ItemPowerArmor(Config.Items item) {
super(Config.getAssignedItemID(item), // itemID
EnumArmorMaterial.IRON, // Material
item.iconIndex, // Texture index
item.ordinal()); // armor type.
setMaxStackSize(1);
setCreativeTab(Config.getCreativeTab());
setIconIndex(item.iconIndex);
setItemName(item.idName);
LanguageRegistry.addName(this, item.englishName);
}
public String getTextureFile() {
return CommonProxy.ITEMS_PNG;
}
@Override
public ArmorProperties getProperties(EntityLiving player, ItemStack armor,
DamageSource source, double damage, int slot) {
// Order in which this armor is assessed for 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.1;
// Maximum damage absorbed by this piece
int absorbMax = 2;
ArmorProperties props = new ArmorProperties(priority, absorbRatio,
absorbMax);
return props;
}
@Override
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
// How many half-shields of armor display on the player's gui from this
// piece
return 4;
}
@Override
public void damageArmor(EntityLiving entity, ItemStack stack,
DamageSource source, int damage, int slot) {
// Damage the armor's durability
}
}

View file

@ -0,0 +1,12 @@
package machinemuse.powersuits.common;
import net.minecraft.item.Item;
public class ItemPowerTool extends Item {
public ItemPowerTool(int par1) {
super(par1);
// TODO Auto-generated constructor stub
}
}

View file

@ -0,0 +1,68 @@
package machinemuse.powersuits.common;
import java.util.ArrayList;
import java.util.List;
import machinemuse.powersuits.client.ClientPacketHandler;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
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;
@Mod(modid = "mmmPowersuits", name = "MachineMuse Modular Powersuits", version = "0.0.1")
@NetworkMod(clientSideRequired = true, serverSideRequired = true,
clientPacketHandlerSpec =
@SidedPacketHandler(channels = { "mmPowersuits" }, packetHandler = ClientPacketHandler.class),
serverPacketHandlerSpec =
@SidedPacketHandler(channels = { "mmPowersuits" }, packetHandler = ServerPacketHandler.class))
public class PowersuitsMod {
// The instance of your mod that Forge uses.
@Instance("PowersuitsMod")
public static PowersuitsMod instance;
// Says where the client and server 'proxy' code is loaded.
@SidedProxy(clientSide = "machinemuse.powersuits.client.ClientProxy", serverSide = "machinemuse.powersuits.common.CommonProxy")
public static CommonProxy proxy;
@PreInit
public void preInit(FMLPreInitializationEvent event) {
instance = this;
Config.init(new Configuration(
event.getSuggestedConfigurationFile()));
}
public static List<Block> allBlocks = new ArrayList<Block>();
public static List<Item> allItems = new ArrayList<Item>();
public static GuiHandler guiHandler = new GuiHandler();
@Init
public void load(FMLInitializationEvent event) {
allBlocks.add(new BlockTinkerTable());
for (int i = 0; i < 4; i++) {
allItems.add(new ItemPowerArmor(
Config.Items.values()[i]));
}
allItems.add(new ItemAugmentation(Config.Items.Augmentation));
proxy.registerRenderers();
NetworkRegistry.instance().registerGuiHandler(this, guiHandler);
}
@PostInit
public void postInit(FMLPostInitializationEvent event) {
// Stub Method
}
}

View file

@ -0,0 +1,22 @@
package machinemuse.powersuits.common;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
public class ServerPacketHandler implements IPacketHandler {
@Override
public void onPacketData(INetworkManager manager,
Packet250CustomPayload packet, Player player) {
DataInputStream data = new DataInputStream(new ByteArrayInputStream(
packet.data));
EntityPlayer sender = (EntityPlayer) player;
}
}

View file

@ -0,0 +1,85 @@
package machinemuse.powersuits.common;
import net.minecraft.block.Block;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
public class SlotArmorInTinkerTable extends Slot {
/**
* The armor type that can be placed on that slot, it uses the same values
* of armorType field on ItemArmor.
*/
final int armorType;
final ContainerTinkerTable table;
private ItemStack stackCache;
/**
* Constructor. Takes an inventory and an index, x and y locations for the
* icon, and armorType.
*/
SlotArmorInTinkerTable(ContainerTinkerTable table, IInventory inventory,
int index, int x, int y,
int armorType)
{
super(inventory, index, x, y);
this.armorType = armorType;
this.table = table;
this.stackCache = this.getStack();
}
/**
* Returns the maximum stack size for a given slot (usually the same as
* getInventoryStackLimit(), but 1 in the case of armor slots)
*/
public int getSlotStackLimit()
{
return 1;
}
/**
* Check if the stack is a valid item for this slot. Always true beside for
* the armor slots.
*/
public boolean isItemValid(ItemStack stack)
{
if (stack == null) {
return false;
} else {
Item stackType = (Item) stack.getItem();
if (stack.getItem() instanceof ItemArmor) {
if (((ItemArmor) stackType).armorType == this.armorType) {
return true;
} else {
return false;
}
} else if (stackType.shiftedIndex == Block.pumpkin.blockID
&& this.armorType == 0) {
return true;
} else if (stackType.shiftedIndex == Item.skull.shiftedIndex
&& this.armorType == 0) {
return true;
} else {
return false;
}
}
}
@SideOnly(Side.CLIENT)
/**
* Returns the icon index on items.png that is used as background image of the slot.
*/
public int getBackgroundIconIndex()
{
return 15 + this.armorType * 16;
}
public void onSlotChanged() {
super.onSlotChanged();
table.update();
}
}

View file

@ -0,0 +1,53 @@
package machinemuse.powersuits.common;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
public class SlotAugmentation extends Slot {
public SlotAugmentation(IInventory par1iInventory, int par2, int par3,
int par4) {
super(par1iInventory, par2, par3, par4);
}
/**
* Returns the maximum stack size for a given slot (usually the same as
* getInventoryStackLimit(), but 1 in the case of armor slots)
*/
public int getSlotStackLimit()
{
return 1;
}
/**
* Check if the stack is a valid item for this slot. Always true beside for
* the armor slots.
*/
public boolean isItemValid(ItemStack stack)
{
if (stack == null) {
return false;
} else {
Item stackType = (Item) stack.getItem();
if (stack.getItem() instanceof ItemAugmentation) {
return true;
} else {
return false;
}
}
}
@SideOnly(Side.CLIENT)
/**
* Returns the icon index on items.png that is used as background image of the slot.
*/
public int getBackgroundIconIndex()
{
return 18;
}
}