This commit is contained in:
Aidan Brady 2013-08-05 11:56:52 -04:00
commit b0ffec41d3
2 changed files with 47 additions and 72 deletions

View file

@ -42,77 +42,9 @@ public class BlockMultimeter extends BlockBase implements ITileEntityProvider
* Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY,
* hitZ, block metadata
*/
public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float side, float hitX, float hitY, int hitZ)
public int onBlockPlaced(World par1World, int par2, int par3, int par4, int side, float hitX, float hitY, float hitZ, int metadata)
{
int metadata = hitZ;
if (par5 == 1 && this.canPlaceOn(par1World, par2, par3 - 1, par4))
{
metadata = 5;
}
if (par5 == 2 && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH, true))
{
metadata = 4;
}
if (par5 == 3 && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH, true))
{
metadata = 3;
}
if (par5 == 4 && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST, true))
{
metadata = 2;
}
if (par5 == 5 && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST, true))
{
metadata = 1;
}
return metadata;
}
private boolean canPlaceOn(World par1World, int par2, int par3, int par4)
{
if (par1World.doesBlockHaveSolidTopSurface(par2, par3, par4))
{
return true;
}
else
{
int l = par1World.getBlockId(par2, par3, par4);
return (Block.blocksList[l] != null && Block.blocksList[l].canPlaceTorchOnTop(par1World, par2, par3, par4));
}
}
public static int determineOrientation(World par0World, int par1, int par2, int par3, EntityLivingBase par4EntityLivingBase)
{
if (MathHelper.abs((float) par4EntityLivingBase.posX - par1) < 2.0F && MathHelper.abs((float) par4EntityLivingBase.posZ - par3) < 2.0F)
{
double d0 = par4EntityLivingBase.posY + 1.82D - par4EntityLivingBase.yOffset;
if (d0 - par2 > 2.0D)
{
return 1;
}
if (par2 - d0 > 0.0D)
{
return 0;
}
}
int l = MathHelper.floor_double(par4EntityLivingBase.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
return l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0)));
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
{
int l = determineOrientation(world, x, y, z, par5EntityLivingBase);
world.setBlockMetadataWithNotify(x, y, z, l, 2);
return ForgeDirection.getOrientation(side).ordinal();
}
@Override

View file

@ -3,9 +3,13 @@
*/
package resonantinduction.multimeter;
import java.util.List;
import resonantinduction.base.Vector3;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
/**
@ -21,18 +25,57 @@ public class ItemBlockMultimeter extends ItemBlock
super(par1);
}
@Override
public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
par3List.add("Shift-right click to place,");
par3List.add("Right click to scan data.");
float detection = this.getDetection(itemStack);
if (detection != -1)
{
par3List.add("Last Detection: " + detection + " KJ");
}
else
{
par3List.add("No detection saved.");
}
}
@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
{
if (par2EntityPlayer.isSneaking())
if (!par2EntityPlayer.isSneaking())
{
if (!world.isRemote)
{
par2EntityPlayer.addChatMessage("Energy: " + TileEntityMultimeter.getDetectedEnergy(world.getBlockTileEntity(x, y, z)) + " J");
}
return true;
}
return super.onItemUse(par1ItemStack, par2EntityPlayer, world, x, y, z, par7, par8, par9, par10);
}
public float getDetection(ItemStack itemStack)
{
if (itemStack.stackTagCompound == null || !itemStack.getTagCompound().hasKey("detection"))
{
return -1;
}
return itemStack.stackTagCompound.getFloat("detection");
}
public void setDetection(ItemStack itemStack, float detection)
{
if (itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
itemStack.stackTagCompound.setFloat("detection", detection);
}
}