Guest User

BlockForge

a guest
Mar 8th, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. public class BlockForge extends BlockContainer
  2. {
  3. private final boolean isActive;
  4.  
  5. @SideOnly(Side.CLIENT)
  6. private Icon iconFront;
  7.  
  8. public BlockForge(int id, boolean isActive)
  9. {
  10. super(id, Material.iron);
  11. this.isActive = isActive;
  12. }
  13.  
  14. @SideOnly(Side.CLIENT)
  15. public void registerIcons(IconRegister iconRegister)
  16. {
  17. this.blockIcon = iconRegister.registerIcon("skyrim:Forge_Side");
  18. this.iconFront = iconRegister.registerIcon(this.isActive ? "skyrim:Forge_Front_Active" : "skyrim:Forge_Front_Idle");
  19. }
  20.  
  21. @SideOnly(Side.CLIENT)
  22. public Icon getIcon(int side, int metadata)
  23. {
  24. return side == metadata ? this.iconFront : this.blockIcon;
  25. }
  26.  
  27. public int idDropped(int par, Random rand, int par3)
  28. {
  29. return SkyrimMain.inactiveForge.blockID;
  30. }
  31.  
  32. public void onBlockAdded(World world, int x, int y, int z)
  33. {
  34. super.onBlockAdded(world, x, y, z);
  35. this.setDefaultDirection(world, x, y, z);
  36. }
  37.  
  38. private void setDefaultDirection(World world, int x, int y, int z)
  39. {
  40. if(!world.isRemote)
  41. {
  42. int l = world.getBlockId(x, y, z - 1);
  43. int il = world.getBlockId(x, y, z + 1);
  44. int jl = world.getBlockId(x - 1, y, z);
  45. int kl = world.getBlockId(x + 1, y, z);
  46.  
  47. byte b0 = 3;
  48.  
  49. if(Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[il])
  50. {
  51. b0 = 3;
  52. }
  53.  
  54. if(Block.opaqueCubeLookup[il] && !Block.opaqueCubeLookup[l])
  55. {
  56. b0 = 2;
  57. }
  58.  
  59. if(Block.opaqueCubeLookup[kl] && !Block.opaqueCubeLookup[jl])
  60. {
  61. b0 = 5;
  62. }
  63.  
  64. if(Block.opaqueCubeLookup[jl] && !Block.opaqueCubeLookup[kl])
  65. {
  66. b0 = 5;
  67. }
  68.  
  69. world.setBlockMetadataWithNotify(x, y, z, b0, 2);
  70. }
  71. }
  72.  
  73. public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
  74. {
  75. if(!world.isRemote)
  76. {
  77. FMLNetworkHandler.openGui(player, SkyrimMain.instance, SkyrimMain.guiIdForge, world, x, y, z);
  78. }
  79.  
  80. return true;
  81. }
  82.  
  83. public TileEntity createNewTileEntity(World world)
  84. {
  85. return new TileEntityForge();
  86. }
  87.  
  88. public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entitylivingbase, ItemStack itemstack)
  89. {
  90. int l = MathHelper.floor_double((double)(entitylivingbase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  91.  
  92. if(l == 0)
  93. {
  94. world.setBlockMetadataWithNotify(x, y, z, 2, 2);
  95. }
  96.  
  97. if(l == 1)
  98. {
  99. world.setBlockMetadataWithNotify(x, y, z, 5, 2);
  100. }
  101.  
  102. if(l == 2)
  103. {
  104. world.setBlockMetadataWithNotify(x, y, z, 3, 2);
  105. }
  106.  
  107. if(l == 3)
  108. {
  109. world.setBlockMetadataWithNotify(x, y, z, 4, 2);
  110. }
  111.  
  112. if(itemstack.hasDisplayName())
  113. {
  114. ((TileEntityForge)world.getBlockTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName());
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment