001package net.minecraft.block; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import java.util.Random; 006import net.minecraft.block.material.Material; 007import net.minecraft.client.renderer.texture.IconRegister; 008import net.minecraft.creativetab.CreativeTabs; 009import net.minecraft.tileentity.TileEntity; 010import net.minecraft.tileentity.TileEntityDaylightDetector; 011import net.minecraft.util.Icon; 012import net.minecraft.util.MathHelper; 013import net.minecraft.world.EnumSkyBlock; 014import net.minecraft.world.IBlockAccess; 015import net.minecraft.world.World; 016 017public class BlockDaylightDetector extends BlockContainer 018{ 019 private Icon[] field_94445_a = new Icon[2]; 020 021 public BlockDaylightDetector(int par1) 022 { 023 super(par1, Material.wood); 024 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.375F, 1.0F); 025 this.setCreativeTab(CreativeTabs.tabRedstone); 026 } 027 028 /** 029 * Updates the blocks bounds based on its current state. Args: world, x, y, z 030 */ 031 public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 032 { 033 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.375F, 1.0F); 034 } 035 036 /** 037 * Returns true if the block is emitting indirect/weak redstone power on the specified side. If isBlockNormalCube 038 * returns true, standard redstone propagation rules will apply instead and this will not be called. Args: World, X, 039 * Y, Z, side. Note that the side is reversed - eg it is 1 (up) when checking the bottom of the block. 040 */ 041 public int isProvidingWeakPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 042 { 043 return par1IBlockAccess.getBlockMetadata(par2, par3, par4); 044 } 045 046 /** 047 * Ticks the block if it's been scheduled 048 */ 049 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) {} 050 051 /** 052 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 053 * their own) Args: x, y, z, neighbor blockID 054 */ 055 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) {} 056 057 /** 058 * Called whenever the block is added into the world. Args: world, x, y, z 059 */ 060 public void onBlockAdded(World par1World, int par2, int par3, int par4) {} 061 062 public void func_94444_j_(World par1World, int par2, int par3, int par4) 063 { 064 if (!par1World.provider.hasNoSky) 065 { 066 int l = par1World.getBlockMetadata(par2, par3, par4); 067 int i1 = par1World.getSavedLightValue(EnumSkyBlock.Sky, par2, par3, par4) - par1World.skylightSubtracted; 068 float f = par1World.getCelestialAngleRadians(1.0F); 069 070 if (f < (float)Math.PI) 071 { 072 f += (0.0F - f) * 0.2F; 073 } 074 else 075 { 076 f += (((float)Math.PI * 2F) - f) * 0.2F; 077 } 078 079 i1 = Math.round((float)i1 * MathHelper.cos(f)); 080 081 if (i1 < 0) 082 { 083 i1 = 0; 084 } 085 086 if (i1 > 15) 087 { 088 i1 = 15; 089 } 090 091 if (l != i1) 092 { 093 par1World.setBlockMetadataWithNotify(par2, par3, par4, i1, 3); 094 } 095 } 096 } 097 098 /** 099 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 100 */ 101 public boolean renderAsNormalBlock() 102 { 103 return false; 104 } 105 106 /** 107 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 108 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 109 */ 110 public boolean isOpaqueCube() 111 { 112 return false; 113 } 114 115 /** 116 * Can this block provide power. Only wire currently seems to have this change based on its state. 117 */ 118 public boolean canProvidePower() 119 { 120 return true; 121 } 122 123 /** 124 * Returns a new instance of a block's tile entity class. Called on placing the block. 125 */ 126 public TileEntity createNewTileEntity(World par1World) 127 { 128 return new TileEntityDaylightDetector(); 129 } 130 131 @SideOnly(Side.CLIENT) 132 133 /** 134 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata 135 */ 136 public Icon getBlockTextureFromSideAndMetadata(int par1, int par2) 137 { 138 return par1 == 1 ? this.field_94445_a[0] : this.field_94445_a[1]; 139 } 140 141 @SideOnly(Side.CLIENT) 142 public void func_94332_a(IconRegister par1IconRegister) 143 { 144 this.field_94445_a[0] = par1IconRegister.func_94245_a("daylightDetector_top"); 145 this.field_94445_a[1] = par1IconRegister.func_94245_a("daylightDetector_side"); 146 } 147}