Guest User

BlockForge

a guest
Mar 9th, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1.  
  2. public class BlockForge extends BlockContainer
  3. {
  4. private final boolean isActive;
  5.  
  6. @SideOnly(Side.CLIENT)
  7. private Icon iconFront;
  8.  
  9. private static boolean keepInventory;
  10.  
  11. public BlockForge(int id, boolean isActive)
  12. {
  13. super(id, Material.iron);
  14. this.isActive = isActive;
  15. }
  16.  
  17. @SideOnly(Side.CLIENT)
  18. public void registerIcons(IconRegister iconRegister)
  19. {
  20. this.blockIcon = iconRegister.registerIcon("skyrim:Forge_Side");
  21. this.iconFront = iconRegister.registerIcon(this.isActive ? "skyrim:Forge_Front_Active" : "skyrim:Forge_Front_Idle");
  22. }
  23.  
  24. @SideOnly(Side.CLIENT)
  25. public Icon getIcon(int side, int metadata)
  26. {
  27. return side == metadata ? this.iconFront : this.blockIcon;
  28. }
  29.  
  30. public int idDropped(int par, Random rand, int par3)
  31. {
  32. return SkyrimMain.inactiveForge.blockID;
  33. }
  34.  
  35. public void onBlockAdded(World world, int x, int y, int z)
  36. {
  37. super.onBlockAdded(world, x, y, z);
  38. this.setDefaultDirection(world, x, y, z);
  39. }
  40.  
  41. private void setDefaultDirection(World world, int x, int y, int z)
  42. {
  43. if(!world.isRemote)
  44. {
  45. int l = world.getBlockId(x, y, z - 1);
  46. int il = world.getBlockId(x, y, z + 1);
  47. int jl = world.getBlockId(x - 1, y, z);
  48. int kl = world.getBlockId(x + 1, y, z);
  49.  
  50. byte b0 = 3;
  51.  
  52. if(Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[il])
  53. {
  54. b0 = 3;
  55. }
  56.  
  57. if(Block.opaqueCubeLookup[il] && !Block.opaqueCubeLookup[l])
  58. {
  59. b0 = 2;
  60. }
  61.  
  62. if(Block.opaqueCubeLookup[kl] && !Block.opaqueCubeLookup[jl])
  63. {
  64. b0 = 5;
  65. }
  66.  
  67. if(Block.opaqueCubeLookup[jl] && !Block.opaqueCubeLookup[kl])
  68. {
  69. b0 = 5;
  70. }
  71.  
  72. world.setBlockMetadataWithNotify(x, y, z, b0, 2);
  73. }
  74. }
  75.  
  76. public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
  77. {
  78. if(!world.isRemote)
  79. {
  80. TileEntityForge tileentityforge = (TileEntityForge)world.getBlockTileEntity(x, y, z);
  81.  
  82. if (tileentityforge != null)
  83. {
  84. player.openGui(SkyrimMain.instance, 0, world, x, y, z);
  85. }
  86.  
  87. return true;
  88. }
  89. else
  90. {
  91. return true;
  92. }
  93.  
  94. }
  95.  
  96. public TileEntity createNewTileEntity(World world)
  97. {
  98. return new TileEntityForge();
  99. }
  100.  
  101. public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entitylivingbase, ItemStack itemstack)
  102. {
  103. int l = MathHelper.floor_double((double)(entitylivingbase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  104.  
  105. if(l == 0)
  106. {
  107. world.setBlockMetadataWithNotify(x, y, z, 2, 2);
  108. }
  109.  
  110. if(l == 1)
  111. {
  112. world.setBlockMetadataWithNotify(x, y, z, 5, 2);
  113. }
  114.  
  115. if(l == 2)
  116. {
  117. world.setBlockMetadataWithNotify(x, y, z, 3, 2);
  118. }
  119.  
  120. if(l == 3)
  121. {
  122. world.setBlockMetadataWithNotify(x, y, z, 4, 2);
  123. }
  124.  
  125. if(itemstack.hasDisplayName())
  126. {
  127. ((TileEntityForge)world.getBlockTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName());
  128. }
  129. }
  130.  
  131. public static void updateForgeBlockState(boolean active, World worldObj, int xCoord, int yCoord, int zCoord)
  132. {
  133. int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
  134.  
  135. TileEntity tileentity = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);
  136. keepInventory = true;
  137.  
  138. if(active)
  139. {
  140. worldObj.setBlock(xCoord, yCoord, zCoord, SkyrimMain.activeForge.blockID);
  141. }
  142. else
  143. {
  144. worldObj.setBlock(xCoord, yCoord, zCoord, SkyrimMain.inactiveForge.blockID);
  145. }
  146.  
  147. keepInventory = false;
  148.  
  149. worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2);
  150.  
  151. if(tileentity != null)
  152. {
  153. tileentity.validate();
  154. worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, tileentity);
  155. }
  156. }
  157.  
  158. public boolean hasComparatorInputOverride()
  159. {
  160. return true;
  161. }
  162.  
  163. public int getComparatorInputOverride(World world, int x, int y, int z, int i)
  164. {
  165. return Container.calcRedstoneFromInventory((IInventory)world.getBlockTileEntity(x, y, z));
  166. }
  167.  
  168. public int idPicked(World world, int x, int y, int z)
  169. {
  170. return SkyrimMain.inactiveForge.blockID;
  171. }
  172.  
  173.  
  174. }
Advertisement
Add Comment
Please, Sign In to add comment