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.'
This commit is contained in:
Aidan Brady 2012-10-13 21:48:29 -04:00
parent b8781cc3e4
commit cd6f1a4cae
16 changed files with 147 additions and 106 deletions

View file

@ -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;

View file

@ -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;
}

View file

@ -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));
}
}

View file

@ -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);
}
/**

View file

@ -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));
}
}

View file

@ -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
{

View file

@ -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;

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -1,4 +1,4 @@
package net.uberkat.obsidian.api;
package obsidian.api;
import java.util.List;

View file

@ -1,4 +1,4 @@
package net.uberkat.obsidian.api;
package obsidian.api;
import net.minecraft.src.*;

View file

@ -1,4 +1,4 @@
package net.uberkat.obsidian.api;
package obsidian.api;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.NetworkManager;

View file

@ -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;
}
}
}