2012-01-26 23:37:39 +01:00
|
|
|
package cpw.mods.ironchest;
|
|
|
|
|
2012-01-27 22:05:42 +01:00
|
|
|
import java.util.Random;
|
|
|
|
|
2012-01-26 23:37:39 +01:00
|
|
|
import net.minecraft.src.BlockContainer;
|
|
|
|
import net.minecraft.src.EntityLiving;
|
|
|
|
import net.minecraft.src.IBlockAccess;
|
|
|
|
import net.minecraft.src.Material;
|
|
|
|
import net.minecraft.src.MathHelper;
|
|
|
|
import net.minecraft.src.TileEntity;
|
|
|
|
import net.minecraft.src.World;
|
|
|
|
import net.minecraft.src.forge.ITextureProvider;
|
|
|
|
|
|
|
|
public class BlockIronChest extends BlockContainer implements ITextureProvider {
|
|
|
|
|
|
|
|
public BlockIronChest(int id) {
|
|
|
|
super(id, Material.iron);
|
2012-01-27 22:05:42 +01:00
|
|
|
setBlockName("IronChest");
|
2012-01-26 23:37:39 +01:00
|
|
|
setHardness(3.0F);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TileEntity getBlockEntity() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getTextureFile() {
|
|
|
|
return "ic2/sprites/ironchest_block_tex.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TileEntity getBlockEntity(int metadata) {
|
2012-01-27 05:50:52 +01:00
|
|
|
return IronChestType.makeEntity(metadata);
|
2012-01-26 23:37:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l) {
|
|
|
|
TileEntity te = worldAccess.getBlockTileEntity(i, j, k);
|
|
|
|
if (te != null && te instanceof TileEntityIronChest) {
|
|
|
|
TileEntityIronChest icte=(TileEntityIronChest) te;
|
|
|
|
if (l==0 || l==1) { // Top and Bottom
|
|
|
|
return icte.getType().getTextureRow()*16+1;
|
2012-01-27 05:50:52 +01:00
|
|
|
} else if (l==icte.getFacing()) { // Front
|
2012-01-26 23:37:39 +01:00
|
|
|
return icte.getType().getTextureRow()*16+2;
|
2012-01-27 05:50:52 +01:00
|
|
|
} else { // Back and Sides
|
|
|
|
return icte.getType().getTextureRow()*16;
|
2012-01-26 23:37:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-27 05:50:52 +01:00
|
|
|
@Override
|
|
|
|
public int getBlockTextureFromSideAndMetadata(int i, int j) {
|
|
|
|
IronChestType typ=IronChestType.values()[j];
|
|
|
|
switch (i) {
|
2012-01-26 23:37:39 +01:00
|
|
|
case 0:
|
|
|
|
case 1:
|
2012-01-27 05:50:52 +01:00
|
|
|
return typ.getTextureRow()*16+1;
|
2012-01-27 22:05:42 +01:00
|
|
|
case 3:
|
2012-01-27 05:50:52 +01:00
|
|
|
return typ.getTextureRow()*16+2;
|
2012-01-26 23:37:39 +01:00
|
|
|
default:
|
2012-01-27 05:50:52 +01:00
|
|
|
return typ.getTextureRow()*16;
|
2012-01-26 23:37:39 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-27 05:50:52 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockAdded(World world, int i, int j, int k) {
|
|
|
|
super.onBlockAdded(world, i, j, k);
|
|
|
|
world.markBlockNeedsUpdate(i, j, k);
|
|
|
|
}
|
|
|
|
|
2012-01-26 23:37:39 +01:00
|
|
|
@Override
|
|
|
|
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving) {
|
|
|
|
byte chestFacing = 0;
|
|
|
|
int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
|
|
|
|
if (facing == 0) {
|
|
|
|
chestFacing = 2;
|
|
|
|
}
|
|
|
|
if (facing == 1) {
|
|
|
|
chestFacing = 5;
|
|
|
|
}
|
|
|
|
if (facing == 2) {
|
|
|
|
chestFacing = 3;
|
|
|
|
}
|
|
|
|
if (facing == 3) {
|
|
|
|
chestFacing = 4;
|
|
|
|
}
|
2012-01-27 05:50:52 +01:00
|
|
|
System.out.printf("Facing %d %d\n", facing,chestFacing);
|
2012-01-26 23:37:39 +01:00
|
|
|
TileEntity te = world.getBlockTileEntity(i, j, k);
|
|
|
|
if (te != null && te instanceof TileEntityIronChest) {
|
|
|
|
((TileEntityIronChest) te).setFacing(chestFacing);
|
2012-01-27 05:50:52 +01:00
|
|
|
world.markBlockNeedsUpdate(i, j, k);
|
2012-01-26 23:37:39 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-27 22:05:42 +01:00
|
|
|
@Override
|
|
|
|
protected int damageDropped(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
2012-01-26 23:37:39 +01:00
|
|
|
}
|