Guest User

Untitled

a guest
Dec 30th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. package RUMatter.blocks;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.BlockContainer;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.client.renderer.texture.IconRegister;
  7. import net.minecraft.entity.EntityLivingBase;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.tileentity.TileEntity;
  11. import net.minecraft.util.Icon;
  12. import net.minecraft.util.MathHelper;
  13. import net.minecraft.world.World;
  14. import RUMatter.RUCraft;
  15. import RUMatter.RUCreativeTabs;
  16. import RUMatter.tileEntities.TileEntityRUMad;
  17. import cpw.mods.fml.relauncher.Side;
  18. import cpw.mods.fml.relauncher.SideOnly;
  19.  
  20. public class BlockRUMad extends BlockContainer {
  21.  
  22. public BlockRUMad(int id) {
  23. super(id, Material.iron);
  24.  
  25. this.setCreativeTab(RUCreativeTabs.RUTab);
  26. this.setHardness(2F);
  27. this.setStepSound(soundMetalFootstep);
  28. this.setUnlocalizedName(BlockInfo.RUMad_UNLOCALISED_NAME);
  29. }
  30.  
  31. @Override
  32. public void onBlockAdded(World world, int x, int y, int z) {
  33. super.onBlockAdded(world, x, y, z);
  34. setDefaultDirection(world, x, y, z);
  35. }
  36.  
  37. // @param World, the world instance,
  38. // @param int x, y, z, the blocks x, y, and z coords
  39. // @param EntityPlayer, the player
  40. // @param int i, this is not really used in this along with the rest (float
  41. // f, float g, and float t)
  42. @Override
  43. public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int i, float f, float g, float t) {
  44. TileEntityRUMad tile = (TileEntityRUMad) world.getBlockTileEntity(x, y, z);
  45. if (tile != null || player.isSneaking()) {
  46. if (!world.isRemote) {
  47. player.addChatMessage("RUMad energy level: " + tile.energy);
  48. return true;
  49. } else if (world.isRemote) player.openGui(RUCraft.instance, 1, world, x, y, z);
  50. }
  51. return false;
  52. }
  53.  
  54. @SideOnly(Side.CLIENT)
  55. Icon bottomTexture;
  56. @SideOnly(Side.CLIENT)
  57. Icon frontTexture;
  58. @SideOnly(Side.CLIENT)
  59. Icon sideTexture;
  60.  
  61. @Override
  62. @SideOnly(Side.CLIENT)
  63. public void registerIcons(IconRegister register) {
  64. this.blockIcon = register.registerIcon(BlockInfo.Textures.RUMadTop.toString());
  65. this.bottomTexture = register.registerIcon(BlockInfo.Textures.RUMadBottom.toString());
  66. this.frontTexture = register.registerIcon(BlockInfo.Textures.RUMadFront.toString());
  67. this.sideTexture = register.registerIcon(BlockInfo.Textures.RUMadSide.toString());
  68. }
  69.  
  70. @Override
  71. @SideOnly(Side.CLIENT)
  72. public Icon getIcon(int side, int metadata) {
  73. if (side == 0)
  74. return bottomTexture;
  75. else if (side == 1)
  76. return blockIcon;
  77. else if (side == metadata)
  78. return frontTexture;
  79. else return sideTexture;
  80. }
  81.  
  82. /**
  83. * set a blocks direction
  84. */
  85. private void setDefaultDirection(World par1World, int par2, int par3, int par4) {
  86. if (!par1World.isRemote) {
  87. int l = par1World.getBlockId(par2, par3, par4 - 1);
  88. int i1 = par1World.getBlockId(par2, par3, par4 + 1);
  89. int j1 = par1World.getBlockId(par2 - 1, par3, par4);
  90. int k1 = par1World.getBlockId(par2 + 1, par3, par4);
  91. byte b0 = 3;
  92.  
  93. if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1]) {
  94. b0 = 3;
  95. }
  96.  
  97. if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l]) {
  98. b0 = 2;
  99. }
  100.  
  101. if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1]) {
  102. b0 = 5;
  103. }
  104.  
  105. if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1]) {
  106. b0 = 4;
  107. }
  108.  
  109. par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);
  110. }
  111. }
  112.  
  113. /**
  114. * Called when the block is placed in the world.
  115. */
  116. public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) {
  117. int l = MathHelper.floor_double((double) (par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  118.  
  119. if (l == 0) {
  120. par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
  121. }
  122.  
  123. if (l == 1) {
  124. par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
  125. }
  126.  
  127. if (l == 2) {
  128. par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
  129. }
  130.  
  131. if (l == 3) {
  132. par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
  133. }
  134. }
  135.  
  136. @Override
  137. public TileEntity createNewTileEntity(World world) {
  138. return new TileEntityRUMad();
  139. }
  140.  
  141. @Override
  142. public boolean hasTileEntity() {
  143. return true;
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment