Advertisement
drackiseries

A New Furnace Part 1 Code

Jul 13th, 2012
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.83 KB | None | 0 0
  1. // BLOCKCOMPRESSOR FILE
  2.  
  3.  
  4. package net.minecraft.src;
  5.  
  6. import java.util.Random;
  7.  
  8. public class BlockCompressor extends BlockContainer
  9. {
  10. /**
  11. * Is the random generator used by furnace to drop the inventory contents in random directions.
  12. */
  13. private Random furnaceRand;
  14.  
  15. /** True if this is an active furnace, false if idle */
  16. private final boolean isActive;
  17.  
  18. /**
  19. * This flag is used to prevent the furnace inventory to be dropped upon block removal, is used internally when the
  20. * furnace block changes from idle to active and vice-versa.
  21. */
  22. private static boolean keepFurnaceInventory = false;
  23.  
  24. protected BlockCompressor(int par1, boolean par2)
  25. {
  26. super(par1, Material.rock);
  27. furnaceRand = new Random();
  28. isActive = par2;
  29. blockIndexInTexture = 189;
  30. }
  31.  
  32. /**
  33. * Returns the ID of the items to drop on destruction.
  34. */
  35. public int idDropped(int par1, Random par2Random, int par3)
  36. {
  37. return Block.stoneOvenIdle.blockID;
  38. }
  39.  
  40. /**
  41. * Called whenever the block is added into the world. Args: world, x, y, z
  42. */
  43. public void onBlockAdded(World par1World, int par2, int par3, int par4)
  44. {
  45. super.onBlockAdded(par1World, par2, par3, par4);
  46. setDefaultDirection(par1World, par2, par3, par4);
  47. }
  48.  
  49. /**
  50. * set a blocks direction
  51. */
  52. private void setDefaultDirection(World par1World, int par2, int par3, int par4)
  53. {
  54. if (par1World.isRemote)
  55. {
  56. return;
  57. }
  58.  
  59. int i = par1World.getBlockId(par2, par3, par4 - 1);
  60. int j = par1World.getBlockId(par2, par3, par4 + 1);
  61. int k = par1World.getBlockId(par2 - 1, par3, par4);
  62. int l = par1World.getBlockId(par2 + 1, par3, par4);
  63. byte byte0 = 3;
  64.  
  65. if (Block.opaqueCubeLookup[i] && !Block.opaqueCubeLookup[j])
  66. {
  67. byte0 = 3;
  68. }
  69.  
  70. if (Block.opaqueCubeLookup[j] && !Block.opaqueCubeLookup[i])
  71. {
  72. byte0 = 2;
  73. }
  74.  
  75. if (Block.opaqueCubeLookup[k] && !Block.opaqueCubeLookup[l])
  76. {
  77. byte0 = 5;
  78. }
  79.  
  80. if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[k])
  81. {
  82. byte0 = 4;
  83. }
  84.  
  85. par1World.setBlockMetadataWithNotify(par2, par3, par4, byte0);
  86. }
  87.  
  88. /**
  89. * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side
  90. */
  91. public int getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
  92. {
  93. if (par5 == 1)
  94. {
  95. return blockIndexInTexture;
  96. }
  97.  
  98. if (par5 == 0)
  99. {
  100. return blockIndexInTexture;
  101. }
  102.  
  103. int i = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
  104.  
  105. if (par5 != i)
  106. {
  107. return blockIndexInTexture;
  108. }
  109.  
  110. if (isActive)
  111. {
  112. return blockIndexInTexture + 2;
  113. }
  114. else
  115. {
  116. return blockIndexInTexture + 1;
  117. }
  118. }
  119.  
  120. /**
  121. * A randomly called display update to be able to add particles or other items for display
  122. */
  123. public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
  124. {
  125. if (!isActive)
  126. {
  127. return;
  128. }
  129.  
  130. int i = par1World.getBlockMetadata(par2, par3, par4);
  131. float f = (float)par2 + 0.5F;
  132. float f1 = (float)par3 + 0.0F + (par5Random.nextFloat() * 6F) / 16F;
  133. float f2 = (float)par4 + 0.5F;
  134. float f3 = 0.52F;
  135. float f4 = par5Random.nextFloat() * 0.6F - 0.3F;
  136.  
  137. if (i == 4)
  138. {
  139. par1World.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
  140. par1World.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
  141. }
  142. else if (i == 5)
  143. {
  144. par1World.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
  145. par1World.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
  146. }
  147. else if (i == 2)
  148. {
  149. par1World.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
  150. par1World.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
  151. }
  152. else if (i == 3)
  153. {
  154. par1World.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
  155. par1World.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
  156. }
  157. }
  158.  
  159. /**
  160. * Returns the block texture based on the side being looked at. Args: side
  161. */
  162. public int getBlockTextureFromSide(int par1)
  163. {
  164. if (par1 == 1)
  165. {
  166. return blockIndexInTexture;
  167. }
  168.  
  169. if (par1 == 0)
  170. {
  171. return blockIndexInTexture;
  172. }
  173.  
  174. if (par1 == 3)
  175. {
  176. return blockIndexInTexture + 1;
  177. }
  178. else
  179. {
  180. return blockIndexInTexture;
  181. }
  182. }
  183.  
  184. /**
  185. * Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
  186. * block.
  187. */
  188. public boolean blockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
  189. {
  190. if (par1World.isRemote)
  191. {
  192. return true;
  193. }
  194.  
  195. TileEntityFurnace tileentityfurnace = (TileEntityFurnace)par1World.getBlockTileEntity(par2, par3, par4);
  196.  
  197. if (tileentityfurnace != null)
  198. {
  199. par5EntityPlayer.displayGUIFurnace(tileentityfurnace);
  200. }
  201.  
  202. return true;
  203. }
  204.  
  205. /**
  206. * Update which block ID the furnace is using depending on whether or not it is burning
  207. */
  208. public static void updateFurnaceBlockState(boolean par0, World par1World, int par2, int par3, int par4)
  209. {
  210. int i = par1World.getBlockMetadata(par2, par3, par4);
  211. TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
  212. keepFurnaceInventory = true;
  213.  
  214. if (par0)
  215. {
  216. par1World.setBlockWithNotify(par2, par3, par4, Block.stoneOvenActive.blockID);
  217. }
  218. else
  219. {
  220. par1World.setBlockWithNotify(par2, par3, par4, Block.stoneOvenIdle.blockID);
  221. }
  222.  
  223. keepFurnaceInventory = false;
  224. par1World.setBlockMetadataWithNotify(par2, par3, par4, i);
  225.  
  226. if (tileentity != null)
  227. {
  228. tileentity.validate();
  229. par1World.setBlockTileEntity(par2, par3, par4, tileentity);
  230. }
  231. }
  232.  
  233. /**
  234. * Returns the TileEntity used by this block.
  235. */
  236. public TileEntity getBlockEntity()
  237. {
  238. return new TileEntityFurnace();
  239. }
  240.  
  241. /**
  242. * Called when the block is placed in the world.
  243. */
  244. public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
  245. {
  246. int i = MathHelper.floor_double((double)((par5EntityLiving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
  247.  
  248. if (i == 0)
  249. {
  250. par1World.setBlockMetadataWithNotify(par2, par3, par4, 2);
  251. }
  252.  
  253. if (i == 1)
  254. {
  255. par1World.setBlockMetadataWithNotify(par2, par3, par4, 5);
  256. }
  257.  
  258. if (i == 2)
  259. {
  260. par1World.setBlockMetadataWithNotify(par2, par3, par4, 3);
  261. }
  262.  
  263. if (i == 3)
  264. {
  265. par1World.setBlockMetadataWithNotify(par2, par3, par4, 4);
  266. }
  267. }
  268.  
  269. /**
  270. * Called whenever the block is removed.
  271. */
  272. public void onBlockRemoval(World par1World, int par2, int par3, int par4)
  273. {
  274. if (!keepFurnaceInventory)
  275. {
  276. TileEntityFurnace tileentityfurnace = (TileEntityFurnace)par1World.getBlockTileEntity(par2, par3, par4);
  277.  
  278. if (tileentityfurnace != null)
  279. {
  280. label0:
  281.  
  282. for (int i = 0; i < tileentityfurnace.getSizeInventory(); i++)
  283. {
  284. ItemStack itemstack = tileentityfurnace.getStackInSlot(i);
  285.  
  286. if (itemstack == null)
  287. {
  288. continue;
  289. }
  290.  
  291. float f = furnaceRand.nextFloat() * 0.8F + 0.1F;
  292. float f1 = furnaceRand.nextFloat() * 0.8F + 0.1F;
  293. float f2 = furnaceRand.nextFloat() * 0.8F + 0.1F;
  294.  
  295. do
  296. {
  297. if (itemstack.stackSize <= 0)
  298. {
  299. continue label0;
  300. }
  301.  
  302. int j = furnaceRand.nextInt(21) + 10;
  303.  
  304. if (j > itemstack.stackSize)
  305. {
  306. j = itemstack.stackSize;
  307. }
  308.  
  309. itemstack.stackSize -= j;
  310. EntityItem entityitem = new EntityItem(par1World, (float)par2 + f, (float)par3 + f1, (float)par4 + f2, new ItemStack(itemstack.itemID, j, itemstack.getItemDamage()));
  311.  
  312. if (itemstack.hasTagCompound())
  313. {
  314. entityitem.item.setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
  315. }
  316.  
  317. float f3 = 0.05F;
  318. entityitem.motionX = (float)furnaceRand.nextGaussian() * f3;
  319. entityitem.motionY = (float)furnaceRand.nextGaussian() * f3 + 0.2F;
  320. entityitem.motionZ = (float)furnaceRand.nextGaussian() * f3;
  321. par1World.spawnEntityInWorld(entityitem);
  322. }
  323. while (true);
  324. }
  325. }
  326. }
  327.  
  328. super.onBlockRemoval(par1World, par2, par3, par4);
  329. }
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement