public class BlockDoorWoodColor extends Block {
private static final String[] doorIconNames = new String[] {
"doorWood_down",
"doorWood_up",
"doorIron_lower",
"doorIron_upper"};
private static String doorTypeColor;
@SideOnly(Side.CLIENT)
private Icon[] iconArray;
public BlockDoorWoodColor(int id, String par2) {
super(id, Material.wood);
this.setStepSound(soundWoodFootstep);
//this.setCreativeTab(PackFurniture.tabFurniturePack);
//this.setHardness(0.5F);
//this.setResistance(10.0F);
//this.setLightOpacity(4);
float f = 0.5F;
float f1 = 1.0F;
this.setBlockBounds(0.5F-f, 0.0F, 0.5F-f, 0.5F+f, f1, 0.5F+f);
this.doorTypeColor = par2;
}
@SideOnly(Side.CLIENT)
public Icon getIcon(int par1, int par2) {return this.iconArray[0];}
@SideOnly(Side.CLIENT)
public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) {
if (par5 != 1 && par5 != 0) {
int i1 = this.getFullMetadata(par1IBlockAccess, par2, par3, par4);
int j1 = i1 & 3;
boolean flag = (i1 & 4) != 0;
boolean flag1 = false;
boolean flag2 = (i1 & 8) != 0;
if (flag) {
if (j1 == 0 && par5 == 2) {flag1 = !flag1;}
else if (j1 == 1 && par5 == 5) {flag1 = !flag1;}
else if (j1 == 2 && par5 == 3) {flag1 = !flag1;}
else if (j1 == 3 && par5 == 4) {flag1 = !flag1;}
}else{
if (j1 == 0 && par5 == 5) {flag1 = !flag1;}
else if (j1 == 1 && par5 == 3) {flag1 = !flag1;}
else if (j1 == 2 && par5 == 4) {flag1 = !flag1;}
else if (j1 == 3 && par5 == 2) {flag1 = !flag1;}
if ((i1 & 16) != 0) {flag1 = !flag1;}
}
return this.iconArray[(flag1 ? doorIconNames.length : 0)+(flag2 ? 1 : 0)];
}else{return this.iconArray[0];}
}
public boolean isOpaqueCube() {return false;}
public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
int l = this.getFullMetadata(par1IBlockAccess, par2, par3, par4);
return (l & 4) != 0;
}
public boolean renderAsNormalBlock() {return false;}
public int getRenderType() {return 7;}
@SideOnly(Side.CLIENT)
public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4) {
this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4);
}
public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) {
this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4);
}
public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
this.setDoorRotation(this.getFullMetadata(par1IBlockAccess, par2, par3, par4));
}
public int getDoorOrientation(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
return this.getFullMetadata(par1IBlockAccess, par2, par3, par4) & 3;
}
public boolean isDoorOpen(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
return (this.getFullMetadata(par1IBlockAccess, par2, par3, par4) & 4) != 0;
}
private void setDoorRotation(int par1) {
float f = 0.1875F;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
int j = par1 & 3;
boolean flag = (par1 & 4) != 0;
boolean flag1 = (par1 & 16) != 0;
if (j == 0) {
if (flag) {
if (!flag1) {this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);}
else{this.setBlockBounds(0.0F, 0.0F, 1.0F-f, 1.0F, 1.0F, 1.0F);}
}
else{this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);}
}
else if (j == 1) {
if (flag) {
if (!flag1) {this.setBlockBounds(1.0F-f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);}
else{this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);}
}
else{this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);}
}
else if (j == 2) {
if (flag) {
if (!flag1) {this.setBlockBounds(0.0F, 0.0F, 1.0F-f, 1.0F, 1.0F, 1.0F);}
else{this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);}
}
else{this.setBlockBounds(1.0F-f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);}
}
else if (j == 3) {
if (flag) {
if (!flag1) {this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);}
else{this.setBlockBounds(1.0F-f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);}
}
else{this.setBlockBounds(0.0F, 0.0F, 1.0F-f, 1.0F, 1.0F, 1.0F);
}
}
}
public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) {}
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
if (this.blockMaterial == Material.iron) {return false;}
else{
int i1 = this.getFullMetadata(par1World, par2, par3, par4);
int j1 = i1 & 7;
j1 ^= 4;
if ((i1 & 8) == 0) {
par1World.setBlockMetadataWithNotify(par2, par3, par4, j1, 2);
par1World.markBlockRangeForRenderUpdate(par2, par3, par4, par2, par3, par4);
}
else{
par1World.setBlockMetadataWithNotify(par2, par3-1, par4, j1, 2);
par1World.markBlockRangeForRenderUpdate(par2, par3-1, par4, par2, par3, par4);
}
par1World.playAuxSFXAtEntity(par5EntityPlayer, 1003, par2, par3, par4, 0);
return true;
}
}
public void onPoweredBlockChange(World par1World, int par2, int par3, int par4, boolean par5) {
int l = this.getFullMetadata(par1World, par2, par3, par4);
boolean flag1 = (l & 4) != 0;
if (flag1 != par5) {
int i1 = l & 7;
i1 ^= 4;
if ((l & 8) == 0) {
par1World.setBlockMetadataWithNotify(par2, par3, par4, i1, 2);
par1World.markBlockRangeForRenderUpdate(par2, par3, par4, par2, par3, par4);
}
else{
par1World.setBlockMetadataWithNotify(par2, par3-1, par4, i1, 2);
par1World.markBlockRangeForRenderUpdate(par2, par3-1, par4, par2, par3, par4);
}
par1World.playAuxSFXAtEntity((EntityPlayer)null, 1003, par2, par3, par4, 0);
}
}
public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) {
int i1 = par1World.getBlockMetadata(par2, par3, par4);
if ((i1 & 8) == 0) {
boolean flag = false;
if (par1World.getBlockId(par2, par3+1, par4) != this.blockID) {
par1World.setBlockToAir(par2, par3, par4);
flag = true;
}
if (!par1World.doesBlockHaveSolidTopSurface(par2, par3-1, par4)) {
par1World.setBlockToAir(par2, par3, par4);
flag = true;
if (par1World.getBlockId(par2, par3+1, par4) == this.blockID) {par1World.setBlockToAir(par2, par3+1, par4);}
}
if (flag) {
if (!par1World.isRemote) {this.dropBlockAsItem(par1World, par2, par3, par4, i1, 0);}
}else{
boolean flag1 = par1World.isBlockIndirectlyGettingPowered(par2, par3, par4) || par1World.isBlockIndirectlyGettingPowered(par2, par3+1, par4);
if ((flag1 || par5 > 0 && Block.blocksList[par5].canProvidePower()) && par5 != this.blockID) {
this.onPoweredBlockChange(par1World, par2, par3, par4, flag1);
}
}
}else{
if (par1World.getBlockId(par2, par3-1, par4) != this.blockID) {par1World.setBlockToAir(par2, par3, par4);}
if (par5 > 0 && par5 != this.blockID) {this.onNeighborBlockChange(par1World, par2, par3-1, par4, par5);}
}
}
public int idDropped(int par1, Random par2Random, int par3) {
return (par1 & 8) != 0 ? 0 : (this.blockMaterial == Material.iron ? Item.doorIron.itemID : Item.doorWood.itemID);
}
public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3, Vec3 par6Vec3) {
this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
return super.collisionRayTrace(par1World, par2, par3, par4, par5Vec3, par6Vec3);
}
public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) {
return par3 >= 255 ? false : par1World.doesBlockHaveSolidTopSurface(par2, par3-1, par4) && super.canPlaceBlockAt(par1World, par2, par3, par4) && super.canPlaceBlockAt(par1World, par2, par3+1, par4);
}
public int getMobilityFlag() {return 1;}
public int getFullMetadata(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
boolean flag = (l & 8) != 0;
int i1;
int j1;
if (flag) {
i1 = par1IBlockAccess.getBlockMetadata(par2, par3-1, par4);
j1 = l;
}else{
i1 = l;
j1 = par1IBlockAccess.getBlockMetadata(par2, par3+1, par4);
}
boolean flag1 = (j1 & 1) != 0;
return i1 & 7 | (flag ? 8 : 0) | (flag1 ? 16 : 0);
}
/*
@SideOnly(Side.CLIENT)
public int idPicked(World par1World, int par2, int par3, int par4) {
return this.blockMaterial == Material.iron ? Item.doorIron.itemID : Item.doorWood.itemID;
}
*/
public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer) {
if (par6EntityPlayer.capabilities.isCreativeMode && (par5 & 8) != 0 && par1World.getBlockId(par2, par3-1, par4) == this.blockID) {
par1World.setBlockToAir(par2, par3-1, par4);
}
}
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister ir) {
this.iconArray = new Icon[doorIconNames.length * 2];
if (this.blockID == PackFurniture.proxy.block_door_wood_color_black.blockID) {doorTypeColor = "black";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_blue.blockID) {doorTypeColor = "blue";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_brown.blockID) {doorTypeColor = "brown";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_cyan.blockID) {doorTypeColor = "cyan";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_gray.blockID) {doorTypeColor = "gray";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_green.blockID) {doorTypeColor = "green";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_light_blue.blockID) {doorTypeColor = "light_blue";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_light_gray.blockID) {doorTypeColor = "light_gray";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_light_green.blockID) {doorTypeColor = "light_green";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_magenta.blockID) {doorTypeColor = "magenta";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_orange.blockID) {doorTypeColor = "orange";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_pink.blockID) {doorTypeColor = "pink";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_purple.blockID) {doorTypeColor = "purple";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_red.blockID) {doorTypeColor = "red";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_white.blockID) {doorTypeColor = "white";}
else if (this.blockID == PackFurniture.proxy.block_door_wood_color_yellow.blockID) {doorTypeColor = "yellow";}
else {doorTypeColor = "none";}
this.iconArray[0] = ir.registerIcon("timaxa007:" + "door/" + "doorWood_down_" + doorTypeColor);
this.iconArray[1] = ir.registerIcon("timaxa007:" + "door/" + "doorWood_up_" + doorTypeColor);
this.iconArray[2] = ir.registerIcon("timaxa007:" + "door/" + "doorWood_down_" + doorTypeColor);
this.iconArray[3] = ir.registerIcon("timaxa007:" + "door/" + "doorWood_up_" + doorTypeColor);
for(byte i = 0; i < doorIconNames.length; ++i) {
this.iconArray[i + doorIconNames.length] = new IconFlipped(this.iconArray[i], true, false);
}
}
}