From cd6f1a4caea6aced1ce943169cd57630ae110cda Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Sat, 13 Oct 2012 21:48:29 -0400 Subject: [PATCH] v4.2.2 Beta #3 *Code cleanup, first attempt to remove all MCP 'parX' rubbish. *Added 'ItemRetriever' class to get items/blocks out of the ObsidianIngots class. *Changed API package to 'obsidian.api.' --- .../uberkat/obsidian/common/BlockMachine.java | 12 +-- .../obsidian/common/BlockObsidianTNT.java | 96 +++++++------------ .../ContainerAdvancedElectricMachine.java | 14 +-- .../common/ContainerElectricMachine.java | 24 ++--- .../obsidian/common/ContainerPowerUnit.java | 14 +-- .../obsidian/common/ItemEnergized.java | 3 +- .../obsidian/common/PacketHandler.java | 3 +- .../uberkat/obsidian/common/SlotEnergy.java | 2 +- .../TileEntityAdvancedElectricMachine.java | 3 +- .../common/TileEntityBasicMachine.java | 3 +- .../common/TileEntityElectricMachine.java | 3 +- .../obsidian/common/TileEntityPowerUnit.java | 5 +- .../obsidian/api/IElectricMachine.java | 2 +- .../obsidian/api/IEnergizedItem.java | 2 +- .../obsidian/api/INetworkedMachine.java | 2 +- src/common/obsidian/api/ItemRetriever.java | 65 +++++++++++++ 16 files changed, 147 insertions(+), 106 deletions(-) rename src/common/{net/uberkat => }/obsidian/api/IElectricMachine.java (97%) rename src/common/{net/uberkat => }/obsidian/api/IEnergizedItem.java (96%) rename src/common/{net/uberkat => }/obsidian/api/INetworkedMachine.java (95%) create mode 100644 src/common/obsidian/api/ItemRetriever.java diff --git a/src/common/net/uberkat/obsidian/common/BlockMachine.java b/src/common/net/uberkat/obsidian/common/BlockMachine.java index e5ed5d52b..6b298c771 100644 --- a/src/common/net/uberkat/obsidian/common/BlockMachine.java +++ b/src/common/net/uberkat/obsidian/common/BlockMachine.java @@ -249,9 +249,9 @@ public class BlockMachine extends BlockContainer return false; } - public void breakBlock(World world, int par2, int par3, int par4, int i1, int i2) + public void breakBlock(World world, int x, int y, int z, int i1, int i2) { - TileEntityBasicMachine var5 = (TileEntityBasicMachine)world.getBlockTileEntity(par2, par3, par4); + TileEntityBasicMachine var5 = (TileEntityBasicMachine)world.getBlockTileEntity(x, y, z); if (var5 != null) { @@ -275,7 +275,7 @@ public class BlockMachine extends BlockContainer } var7.stackSize -= var11; - EntityItem var12 = new EntityItem(world, (double)((float)par2 + var8), (double)((float)par3 + var9), (double)((float)par4 + var10), new ItemStack(var7.itemID, var11, var7.getItemDamage())); + EntityItem var12 = new EntityItem(world, (double)((float)x + var8), (double)((float)y + var9), (double)((float)z + var10), new ItemStack(var7.itemID, var11, var7.getItemDamage())); if (var7.hasTagCompound()) { @@ -293,10 +293,10 @@ public class BlockMachine extends BlockContainer var5.invalidate(); } - super.breakBlock(world, par2, par3, par4, i1, i2); + super.breakBlock(world, x, y, z, i1, i2); } - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int i1, float f1, float f2, float f3) + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int facing, float playerX, float playerY, float playerZ) { if (world.isRemote) { @@ -361,7 +361,7 @@ public class BlockMachine extends BlockContainer } } - //This method is not used, metadata manipulation is required to create a Tile Entity. + /*This method is not used, metadata manipulation is required to create a Tile Entity.*/ public TileEntity createNewTileEntity(World world) { return null; diff --git a/src/common/net/uberkat/obsidian/common/BlockObsidianTNT.java b/src/common/net/uberkat/obsidian/common/BlockObsidianTNT.java index d2e7c6e52..56c2aa37e 100644 --- a/src/common/net/uberkat/obsidian/common/BlockObsidianTNT.java +++ b/src/common/net/uberkat/obsidian/common/BlockObsidianTNT.java @@ -16,16 +16,13 @@ public class BlockObsidianTNT extends Block setResistance(0.0F); } - /** - * Returns the block texture based on the side being looked at. Args: side - */ - public int getBlockTextureFromSide(int par1) + public int getBlockTextureFromSide(int side) { - if(par1 == 1) + if(side == 1) { return 5; } - if(par1 == 0) + if(side == 0) { return 7; } @@ -34,105 +31,78 @@ public class BlockObsidianTNT extends Block } } - /** - * Called whenever the block is added into the world. Args: world, x, y, z - */ - public void onBlockAdded(World par1World, int par2, int par3, int par4) + public void onBlockAdded(World world, int x, int y, int z) { - super.onBlockAdded(par1World, par2, par3, par4); + super.onBlockAdded(world, x, y, z); - if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) + if (world.isBlockIndirectlyGettingPowered(x, y, z)) { - this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1); - par1World.setBlockWithNotify(par2, par3, par4, 0); + onBlockDestroyedByPlayer(world, x, y, z, 1); + world.setBlockWithNotify(x, y, z, 0); } } - /** - * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are - * their own) Args: x, y, z, neighbor blockID - */ - public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) + public void onNeighborBlockChange(World world, int x, int y, int z, int blockID) { - if (par5 > 0 && Block.blocksList[par5].canProvidePower() && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) + if (blockID > 0 && Block.blocksList[blockID].canProvidePower() && world.isBlockIndirectlyGettingPowered(x, y, z)) { - this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1); - par1World.setBlockWithNotify(par2, par3, par4, 0); + onBlockDestroyedByPlayer(world, x, y, z, 1); + world.setBlockWithNotify(x, y, z, 0); } } - /** - * Returns the quantity of items to drop on block destruction. - */ - public int quantityDropped(Random par1Random) + public int quantityDropped(Random random) { return 0; } - /** - * Called upon the block being destroyed by an explosion - */ - public void onBlockDestroyedByExplosion(World par1World, int par2, int par3, int par4) + public void onBlockDestroyedByExplosion(World world, int x, int y, int z) { - if (!par1World.isRemote) + if (!world.isRemote) { - EntityObsidianTNT var5 = new EntityObsidianTNT(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F)); - var5.fuse = par1World.rand.nextInt(var5.fuse / 4) + var5.fuse / 8; - par1World.spawnEntityInWorld(var5); + EntityObsidianTNT entity = new EntityObsidianTNT(world, (double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F)); + entity.fuse = world.rand.nextInt(entity.fuse / 4) + entity.fuse / 8; + world.spawnEntityInWorld(entity); } } - /** - * Called right before the block is destroyed by a player. Args: world, x, y, z, metaData - */ - public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) + public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta) { - if (!par1World.isRemote) + if (!world.isRemote) { - if ((par5 & 1) == 0) + if ((meta & 1) == 0) { - this.dropBlockAsItem_do(par1World, par2, par3, par4, new ItemStack(ObsidianIngots.ObsidianTNT, 1, 0)); + dropBlockAsItem_do(world, x, y, z, new ItemStack(ObsidianIngots.ObsidianTNT, 1, 0)); } else { - EntityObsidianTNT var6 = new EntityObsidianTNT(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F)); - par1World.spawnEntityInWorld(var6); - par1World.playSoundAtEntity(var6, "random.fuse", 1.0F, 1.0F); + EntityObsidianTNT entity = new EntityObsidianTNT(world, (double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F)); + world.spawnEntityInWorld(entity); + world.playSoundAtEntity(entity, "random.fuse", 1.0F, 1.0F); } } } - /** - * Called when the block is clicked by a player. Args: x, y, z, entityPlayer - */ - public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) + public void onBlockClicked(World world, int x, int y, int z, EntityPlayer entityplayer) { - super.onBlockClicked(par1World, par2, par3, par4, par5EntityPlayer); + super.onBlockClicked(world, x, y, z, entityplayer); } - /** - * Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the - * block. - */ - public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int i1, float f1, float f2, float f3) + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int i1, float f1, float f2, float f3) { - if (par5EntityPlayer.getCurrentEquippedItem() != null && par5EntityPlayer.getCurrentEquippedItem().itemID == Item.flintAndSteel.shiftedIndex) + if (entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID == Item.flintAndSteel.shiftedIndex) { - this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1); - par1World.setBlockWithNotify(par2, par3, par4, 0); + onBlockDestroyedByPlayer(world, x, y, z, 1); + world.setBlockWithNotify(x, y, z, 0); return true; } else { - return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, i1, f1, f2, f3); + return super.onBlockActivated(world, x, y, z, entityplayer, i1, f1, f2, f3); } } - /** - * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage - * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null. - */ - protected ItemStack createStackedBlock(int par1) + protected ItemStack createStackedBlock(int i) { return null; } diff --git a/src/common/net/uberkat/obsidian/common/ContainerAdvancedElectricMachine.java b/src/common/net/uberkat/obsidian/common/ContainerAdvancedElectricMachine.java index 218189d9b..901edcb6e 100644 --- a/src/common/net/uberkat/obsidian/common/ContainerAdvancedElectricMachine.java +++ b/src/common/net/uberkat/obsidian/common/ContainerAdvancedElectricMachine.java @@ -1,9 +1,9 @@ package net.uberkat.obsidian.common; +import obsidian.api.IEnergizedItem; import ic2.api.IElectricItem; import universalelectricity.implement.IItemElectric; import net.minecraft.src.*; -import net.uberkat.obsidian.api.IEnergizedItem; public class ContainerAdvancedElectricMachine extends Container { @@ -16,19 +16,19 @@ public class ContainerAdvancedElectricMachine extends Container addSlotToContainer(new Slot(tentity, 1, 56, 53)); addSlotToContainer(new SlotFurnace(inventory.player, tentity, 2, 116, 35)); addSlotToContainer(new SlotEnergy(tentity, 3, 31, 35)); - int var3; + int slotX; - for (var3 = 0; var3 < 3; ++var3) + for (slotX = 0; slotX < 3; ++slotX) { - for (int var4 = 0; var4 < 9; ++var4) + for (int slotY = 0; slotY < 9; ++slotY) { - addSlotToContainer(new Slot(inventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18)); } } - for (var3 = 0; var3 < 9; ++var3) + for (slotX = 0; slotX < 9; ++slotX) { - addSlotToContainer(new Slot(inventory, var3, 8 + var3 * 18, 142)); + addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142)); } } diff --git a/src/common/net/uberkat/obsidian/common/ContainerElectricMachine.java b/src/common/net/uberkat/obsidian/common/ContainerElectricMachine.java index d0f87293b..36adeb4b8 100644 --- a/src/common/net/uberkat/obsidian/common/ContainerElectricMachine.java +++ b/src/common/net/uberkat/obsidian/common/ContainerElectricMachine.java @@ -1,9 +1,9 @@ package net.uberkat.obsidian.common; +import obsidian.api.IEnergizedItem; import ic2.api.IElectricItem; import universalelectricity.implement.IItemElectric; import net.minecraft.src.*; -import net.uberkat.obsidian.api.IEnergizedItem; public class ContainerElectricMachine extends Container { @@ -11,29 +11,29 @@ public class ContainerElectricMachine extends Container public ContainerElectricMachine(InventoryPlayer inventory, TileEntityElectricMachine tentity) { - this.tileEntity = tentity; - this.addSlotToContainer(new Slot(tentity, 0, 56, 17)); - this.addSlotToContainer(new SlotEnergy(tentity, 1, 56, 53)); - this.addSlotToContainer(new SlotFurnace(inventory.player, tentity, 2, 116, 35)); - int var3; + tileEntity = tentity; + addSlotToContainer(new Slot(tentity, 0, 56, 17)); + addSlotToContainer(new SlotEnergy(tentity, 1, 56, 53)); + addSlotToContainer(new SlotFurnace(inventory.player, tentity, 2, 116, 35)); + int slotX; - for (var3 = 0; var3 < 3; ++var3) + for (slotX = 0; slotX < 3; ++slotX) { - for (int var4 = 0; var4 < 9; ++var4) + for (int slotY = 0; slotY < 9; ++slotY) { - this.addSlotToContainer(new Slot(inventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18)); } } - for (var3 = 0; var3 < 9; ++var3) + for (slotX = 0; slotX < 9; ++slotX) { - this.addSlotToContainer(new Slot(inventory, var3, 8 + var3 * 18, 142)); + addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142)); } } public boolean canInteractWith(EntityPlayer par1EntityPlayer) { - return this.tileEntity.isUseableByPlayer(par1EntityPlayer); + return tileEntity.isUseableByPlayer(par1EntityPlayer); } /** diff --git a/src/common/net/uberkat/obsidian/common/ContainerPowerUnit.java b/src/common/net/uberkat/obsidian/common/ContainerPowerUnit.java index 25fb25a96..5faadd971 100644 --- a/src/common/net/uberkat/obsidian/common/ContainerPowerUnit.java +++ b/src/common/net/uberkat/obsidian/common/ContainerPowerUnit.java @@ -1,8 +1,8 @@ package net.uberkat.obsidian.common; +import obsidian.api.*; import ic2.api.IElectricItem; import universalelectricity.implement.IItemElectric; -import net.uberkat.obsidian.api.*; import net.minecraft.src.*; public class ContainerPowerUnit extends Container @@ -15,19 +15,19 @@ public class ContainerPowerUnit extends Container addSlotToContainer(new SlotEnergy(unit, 0, 8, 8)); addSlotToContainer(new SlotEnergy(unit, 1, 8, 40)); - int var3; + int slotX; - for (var3 = 0; var3 < 3; ++var3) + for (slotX = 0; slotX < 3; ++slotX) { - for (int var4 = 0; var4 < 9; ++var4) + for (int slotY = 0; slotY < 9; ++slotY) { - addSlotToContainer(new Slot(inventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18)); } } - for (var3 = 0; var3 < 9; ++var3) + for (slotX = 0; slotX < 9; ++slotX) { - addSlotToContainer(new Slot(inventory, var3, 8 + var3 * 18, 142)); + addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142)); } } diff --git a/src/common/net/uberkat/obsidian/common/ItemEnergized.java b/src/common/net/uberkat/obsidian/common/ItemEnergized.java index 507d47e6a..76e5b1298 100644 --- a/src/common/net/uberkat/obsidian/common/ItemEnergized.java +++ b/src/common/net/uberkat/obsidian/common/ItemEnergized.java @@ -2,12 +2,13 @@ package net.uberkat.obsidian.common; import java.util.List; +import obsidian.api.IEnergizedItem; + import universalelectricity.UniversalElectricity; import universalelectricity.implement.IItemElectric; import ic2.api.IElectricItem; import net.minecraft.src.*; -import net.uberkat.obsidian.api.IEnergizedItem; public class ItemEnergized extends Item implements IEnergizedItem, IItemElectric { diff --git a/src/common/net/uberkat/obsidian/common/PacketHandler.java b/src/common/net/uberkat/obsidian/common/PacketHandler.java index 59d9e1f76..a8cf8c5bf 100644 --- a/src/common/net/uberkat/obsidian/common/PacketHandler.java +++ b/src/common/net/uberkat/obsidian/common/PacketHandler.java @@ -6,6 +6,8 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import obsidian.api.INetworkedMachine; + import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; @@ -16,7 +18,6 @@ import net.minecraft.src.Packet; import net.minecraft.src.Packet250CustomPayload; import net.minecraft.src.TileEntity; import net.minecraft.src.World; -import net.uberkat.obsidian.api.INetworkedMachine; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.network.IPacketHandler; diff --git a/src/common/net/uberkat/obsidian/common/SlotEnergy.java b/src/common/net/uberkat/obsidian/common/SlotEnergy.java index 52c683ac6..2a76935e9 100644 --- a/src/common/net/uberkat/obsidian/common/SlotEnergy.java +++ b/src/common/net/uberkat/obsidian/common/SlotEnergy.java @@ -1,9 +1,9 @@ package net.uberkat.obsidian.common; +import obsidian.api.IEnergizedItem; import universalelectricity.implement.IItemElectric; import ic2.api.IElectricItem; import net.minecraft.src.*; -import net.uberkat.obsidian.api.IEnergizedItem; public class SlotEnergy extends Slot { diff --git a/src/common/net/uberkat/obsidian/common/TileEntityAdvancedElectricMachine.java b/src/common/net/uberkat/obsidian/common/TileEntityAdvancedElectricMachine.java index 723f61ac0..ef8ebe74e 100644 --- a/src/common/net/uberkat/obsidian/common/TileEntityAdvancedElectricMachine.java +++ b/src/common/net/uberkat/obsidian/common/TileEntityAdvancedElectricMachine.java @@ -2,6 +2,8 @@ package net.uberkat.obsidian.common; import java.util.List; +import obsidian.api.IEnergizedItem; + import universalelectricity.UniversalElectricity; import universalelectricity.implement.IItemElectric; @@ -16,7 +18,6 @@ import ic2.api.IWrenchable; import net.minecraft.src.*; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ISidedInventory; -import net.uberkat.obsidian.api.IEnergizedItem; public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicMachine { diff --git a/src/common/net/uberkat/obsidian/common/TileEntityBasicMachine.java b/src/common/net/uberkat/obsidian/common/TileEntityBasicMachine.java index 31c7ac17f..643bd8b6b 100644 --- a/src/common/net/uberkat/obsidian/common/TileEntityBasicMachine.java +++ b/src/common/net/uberkat/obsidian/common/TileEntityBasicMachine.java @@ -1,5 +1,7 @@ package net.uberkat.obsidian.common; +import obsidian.api.IElectricMachine; + import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.Side; @@ -10,7 +12,6 @@ import ic2.api.IWrenchable; import net.minecraft.src.*; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ISidedInventory; -import net.uberkat.obsidian.api.IElectricMachine; public abstract class TileEntityBasicMachine extends TileEntity implements IElectricMachine { diff --git a/src/common/net/uberkat/obsidian/common/TileEntityElectricMachine.java b/src/common/net/uberkat/obsidian/common/TileEntityElectricMachine.java index 6311c9953..1ee962c02 100644 --- a/src/common/net/uberkat/obsidian/common/TileEntityElectricMachine.java +++ b/src/common/net/uberkat/obsidian/common/TileEntityElectricMachine.java @@ -2,6 +2,8 @@ package net.uberkat.obsidian.common; import java.util.List; +import obsidian.api.IEnergizedItem; + import universalelectricity.UniversalElectricity; import universalelectricity.implement.IItemElectric; @@ -16,7 +18,6 @@ import ic2.api.IWrenchable; import net.minecraft.src.*; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ISidedInventory; -import net.uberkat.obsidian.api.IEnergizedItem; public abstract class TileEntityElectricMachine extends TileEntityBasicMachine { diff --git a/src/common/net/uberkat/obsidian/common/TileEntityPowerUnit.java b/src/common/net/uberkat/obsidian/common/TileEntityPowerUnit.java index a80545804..e13316a31 100644 --- a/src/common/net/uberkat/obsidian/common/TileEntityPowerUnit.java +++ b/src/common/net/uberkat/obsidian/common/TileEntityPowerUnit.java @@ -4,6 +4,9 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import obsidian.api.IEnergizedItem; +import obsidian.api.INetworkedMachine; + import universalelectricity.UniversalElectricity; import universalelectricity.electricity.ElectricInfo; import universalelectricity.electricity.ElectricityManager; @@ -40,8 +43,6 @@ import ic2.api.IElectricItem; import net.minecraft.src.*; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ISidedInventory; -import net.uberkat.obsidian.api.IEnergizedItem; -import net.uberkat.obsidian.api.INetworkedMachine; public class TileEntityPowerUnit extends TileEntityDisableable implements IInventory, ISidedInventory, INetworkedMachine, IWrenchable, IEnergySink, IEnergySource, IEnergyStorage, IPowerReceptor, IElectricityStorage, IElectricityReceiver, IPeripheral { diff --git a/src/common/net/uberkat/obsidian/api/IElectricMachine.java b/src/common/obsidian/api/IElectricMachine.java similarity index 97% rename from src/common/net/uberkat/obsidian/api/IElectricMachine.java rename to src/common/obsidian/api/IElectricMachine.java index 8df3eec27..89be9c719 100644 --- a/src/common/net/uberkat/obsidian/api/IElectricMachine.java +++ b/src/common/obsidian/api/IElectricMachine.java @@ -1,4 +1,4 @@ -package net.uberkat.obsidian.api; +package obsidian.api; import java.util.List; diff --git a/src/common/net/uberkat/obsidian/api/IEnergizedItem.java b/src/common/obsidian/api/IEnergizedItem.java similarity index 96% rename from src/common/net/uberkat/obsidian/api/IEnergizedItem.java rename to src/common/obsidian/api/IEnergizedItem.java index 3e1492ba9..91f57e8ec 100644 --- a/src/common/net/uberkat/obsidian/api/IEnergizedItem.java +++ b/src/common/obsidian/api/IEnergizedItem.java @@ -1,4 +1,4 @@ -package net.uberkat.obsidian.api; +package obsidian.api; import net.minecraft.src.*; diff --git a/src/common/net/uberkat/obsidian/api/INetworkedMachine.java b/src/common/obsidian/api/INetworkedMachine.java similarity index 95% rename from src/common/net/uberkat/obsidian/api/INetworkedMachine.java rename to src/common/obsidian/api/INetworkedMachine.java index f016d1457..e1bfd73c8 100644 --- a/src/common/net/uberkat/obsidian/api/INetworkedMachine.java +++ b/src/common/obsidian/api/INetworkedMachine.java @@ -1,4 +1,4 @@ -package net.uberkat.obsidian.api; +package obsidian.api; import net.minecraft.src.EntityPlayer; import net.minecraft.src.NetworkManager; diff --git a/src/common/obsidian/api/ItemRetriever.java b/src/common/obsidian/api/ItemRetriever.java new file mode 100644 index 000000000..f486106dd --- /dev/null +++ b/src/common/obsidian/api/ItemRetriever.java @@ -0,0 +1,65 @@ +package obsidian.api; + +import net.minecraft.src.*; + +/** + * Use this class's 'getItem()' method to retrieve ItemStacks from the 'ObsidianIngots' + * class. + * @author AidanBrady + * + */ +public final class ItemRetriever +{ + /** The 'ObsidianIngots' class that items and blocks are retrieved from. */ + private static Class ObsidianIngots; + + /** + * Attempts to retrieve an ItemStack of an item or block with the declared identifier. + * + * ObsidianIngots identifiers follow an easy-to-remember pattern. All identifiers + * are identical to the String returned by 'getItemName().' None include spaces, + * and always make sure you start with a capital letter. The name that shows up + * in-game can be stripped down to identifier form by removing spaces and all non- + * alphabetic characters (,./'=-_). Below is an example: + * + * ItemStack enrichedAlloy = ItemRetriever.getItem("EnrichedAlloy"); + * + * The same also works for blocks. + * + * ItemStack refinedObsidian = ItemRetriever.getItem("RefinedObsidian"); + * + * Make sure you run this in or after FMLPostInitializationEvent runs, because most + * items are registered when FMLInitializationEvent runs. However, some items ARE + * registered later in order to hook into other mods. In a rare circumstance you may + * have to add "after:ObsidianIngots" in the @Mod 'dependencies' annotation. + * + * Note that you will be able to retrieve items that Obsidian Ingots has retrieved + * from other mods. In other words, if IC2 is installed, 'getItem("GoldDust")' will + * return IndustrialCraft gold dust. + * + * @param identifier - a String to be searched in the 'ObsidianIngots' class + * @return an ItemStack of the declared identifier, otherwise null. + */ + public static ItemStack getItem(String identifier) + { + try { + if(ObsidianIngots == null) + { + ObsidianIngots = Class.forName("net.uberkat.obsidian.common.ObsidianIngots"); + } + + Object ret = ObsidianIngots.getField(identifier).get(null); + + if(ret instanceof Item) + { + return new ItemStack((Item)ret, 1); + } + else { + return null; + } + } catch(Exception e) { + System.err.println("[ObsidianIngots] Error retrieving item with identifier '" + identifier + "': " + e.getMessage()); + return null; + } + } +}