Advertisement
Guest User

s

a guest
Dec 30th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.59 KB | None | 0 0
  1. package denbukki.indestructibleTools;
  2.  
  3. import cpw.mods.fml.common.network.IGuiHandler;
  4. import cpw.mods.fml.relauncher.Side;
  5. import cpw.mods.fml.relauncher.SideOnly;
  6.  
  7. import java.util.Random;
  8.  
  9. import net.minecraft.block.Block;
  10. import net.minecraft.block.BlockContainer;
  11. import net.minecraft.block.material.Material;
  12. import net.minecraft.client.renderer.texture.IconRegister;
  13. import net.minecraft.entity.EntityLivingBase;
  14. import net.minecraft.entity.item.EntityItem;
  15. import net.minecraft.entity.player.EntityPlayer;
  16. import net.minecraft.inventory.Container;
  17. import net.minecraft.inventory.IInventory;
  18. import net.minecraft.item.ItemStack;
  19. import net.minecraft.nbt.NBTTagCompound;
  20. import net.minecraft.tileentity.TileEntity;
  21. import net.minecraft.util.Icon;
  22. import net.minecraft.util.MathHelper;
  23. import net.minecraft.world.World;
  24.  
  25. public class PresureFurnace extends BlockContainer
  26. {
  27. /**
  28. * Is the random generator used by furnace to drop the inventory contents in random directions.
  29. */
  30. private final Random furnaceRand = new Random();
  31.  
  32. /** True if this is an active furnace, false if idle */
  33. private final boolean isActive;
  34.  
  35. /**
  36. * This flag is used to prevent the furnace inventory to be dropped upon block removal, is used internally when the
  37. * furnace block changes from idle to active and vice-versa.
  38. */
  39. private static boolean keepFurnaceInventory;
  40. @SideOnly(Side.CLIENT)
  41. private Icon furnaceIconTop;
  42. @SideOnly(Side.CLIENT)
  43. private Icon furnaceIconFront;
  44.  
  45. protected PresureFurnace(int par1, boolean par2)
  46. {
  47. super(par1, Material.rock);
  48. this.isActive = par2;
  49. }
  50.  
  51. /**
  52. * Returns the ID of the items to drop on destruction.
  53. */
  54. public int idDropped(int par1, Random par2Random, int par3)
  55. {
  56. return Block.furnaceIdle.blockID;
  57. }
  58.  
  59. /**
  60. * Called whenever the block is added into the world. Args: world, x, y, z
  61. */
  62. public void onBlockAdded(World par1World, int par2, int par3, int par4)
  63. {
  64. super.onBlockAdded(par1World, par2, par3, par4);
  65. this.setDefaultDirection(par1World, par2, par3, par4);
  66. }
  67.  
  68. /**
  69. * set a blocks direction
  70. */
  71. private void setDefaultDirection(World par1World, int par2, int par3, int par4)
  72. {
  73. if (!par1World.isRemote)
  74. {
  75. int l = par1World.getBlockId(par2, par3, par4 - 1);
  76. int i1 = par1World.getBlockId(par2, par3, par4 + 1);
  77. int j1 = par1World.getBlockId(par2 - 1, par3, par4);
  78. int k1 = par1World.getBlockId(par2 + 1, par3, par4);
  79. byte b0 = 3;
  80.  
  81. if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1])
  82. {
  83. b0 = 3;
  84. }
  85.  
  86. if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l])
  87. {
  88. b0 = 2;
  89. }
  90.  
  91. if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1])
  92. {
  93. b0 = 5;
  94. }
  95.  
  96. if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1])
  97. {
  98. b0 = 4;
  99. }
  100.  
  101. par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);
  102. }
  103. }
  104.  
  105. @SideOnly(Side.CLIENT)
  106.  
  107. /**
  108. * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
  109. */
  110. public Icon getIcon(int par1, int par2)
  111. {
  112. return par1 == 1 ? this.furnaceIconTop : (par1 == 0 ? this.furnaceIconTop : (par1 != par2 ? this.blockIcon : this.furnaceIconFront));
  113. }
  114.  
  115. @SideOnly(Side.CLIENT)
  116.  
  117. /**
  118. * When this method is called, your block should register all the icons it needs with the given IconRegister. This
  119. * is the only chance you get to register icons.
  120. */
  121. public void registerIcons(IconRegister par1IconRegister)
  122. {
  123. this.blockIcon = par1IconRegister.registerIcon("indestructibletools:presurefurnace_side");
  124. this.furnaceIconFront = par1IconRegister.registerIcon(this.isActive ? "indestructibletools:presurefurnace_front_on" : "indestructibletools:presurefurnace_front_off");
  125. this.furnaceIconTop = par1IconRegister.registerIcon("indestructibletools:presurefurnace_top");
  126. }
  127.  
  128. /**
  129. * Called upon block activation (right click on the block.)
  130. */
  131. public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
  132. {
  133. if (par1World.isRemote)
  134. {
  135. return true;
  136. }
  137. else if (!par5EntityPlayer.isSneaking())
  138. {
  139. TileEntityPresureFurnace var10 = (TileEntityPresureFurnace) par1World.getBlockTileEntity(par2, par3, par4);
  140. if (var10 != null)
  141. {
  142. par5EntityPlayer.openGui(indestructibleTools.instance, 9999, par1World, par2, par3, par4);
  143. }
  144. return true;
  145. }
  146. else
  147. {
  148. return false;
  149.  
  150. }
  151. }
  152. /**
  153. * Update which block ID the furnace is using depending on whether or not it is burning
  154. */
  155. public static void updateFurnaceBlockState(boolean par0, World par1World, int par2, int par3, int par4)
  156. {
  157. int l = par1World.getBlockMetadata(par2, par3, par4);
  158. TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
  159. keepFurnaceInventory = true;
  160.  
  161. if (par0)
  162. {
  163. par1World.setBlock(par2, par3, par4, indestructibleTools.PresureFurnaceActive.blockID);
  164. }
  165. else
  166. {
  167. par1World.setBlock(par2, par3, par4, indestructibleTools.PresureFurnaceIdle.blockID);
  168. }
  169.  
  170. keepFurnaceInventory = false;
  171. par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
  172.  
  173. if (tileentity != null)
  174. {
  175. tileentity.validate();
  176. par1World.setBlockTileEntity(par2, par3, par4, tileentity);
  177. }
  178. }
  179.  
  180. @SideOnly(Side.CLIENT)
  181.  
  182. /**
  183. * A randomly called display update to be able to add particles or other items for display
  184. */
  185. public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
  186. {
  187. if (this.isActive)
  188. {
  189. int l = par1World.getBlockMetadata(par2, par3, par4);
  190. float f = (float)par2 + 0.5F;
  191. float f1 = (float)par3 + 0.0F + par5Random.nextFloat() * 6.0F / 16.0F;
  192. float f2 = (float)par4 + 0.5F;
  193. float f3 = 0.52F;
  194. float f4 = par5Random.nextFloat() * 0.6F - 0.3F;
  195.  
  196. if (l == 4)
  197. {
  198. par1World.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
  199. par1World.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
  200. }
  201. else if (l == 5)
  202. {
  203. par1World.spawnParticle("smoke", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
  204. par1World.spawnParticle("flame", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
  205. }
  206. else if (l == 2)
  207. {
  208. par1World.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
  209. par1World.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
  210. }
  211. else if (l == 3)
  212. {
  213. par1World.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
  214. par1World.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
  215. }
  216. }
  217. }
  218.  
  219. /**
  220. * Returns a new instance of a block's tile entity class. Called on placing the block.
  221. */
  222. public TileEntity createNewTileEntity(World par1World)
  223. {
  224. return new TileEntityPresureFurnace();
  225. }
  226.  
  227. /**
  228. * Called when the block is placed in the world.
  229. */
  230. public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
  231. {
  232. int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  233.  
  234. if (l == 0)
  235. {
  236. par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
  237. }
  238.  
  239. if (l == 1)
  240. {
  241. par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
  242. }
  243.  
  244. if (l == 2)
  245. {
  246. par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
  247. }
  248.  
  249. if (l == 3)
  250. {
  251. par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
  252. }
  253.  
  254. if (par6ItemStack.hasDisplayName())
  255. {
  256. ((TileEntityPresureFurnace)par1World.getBlockTileEntity(par2, par3, par4)).setGuiDisplayName(par6ItemStack.getDisplayName());
  257. }
  258. }
  259.  
  260. /**
  261. * Called on server worlds only when the block has been replaced by a different block ID, or the same block with a
  262. * different metadata value, but before the new metadata value is set. Args: World, x, y, z, old block ID, old
  263. * metadata
  264. */
  265. public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
  266. {
  267. if (!keepFurnaceInventory)
  268. {
  269. TileEntityPresureFurnace tileentityPresureFurnace = (TileEntityPresureFurnace)par1World.getBlockTileEntity(par2, par3, par4);
  270.  
  271. if (tileentityPresureFurnace != null)
  272. {
  273. for (int j1 = 0; j1 < tileentityPresureFurnace.getSizeInventory(); ++j1)
  274. {
  275. ItemStack itemstack = tileentityPresureFurnace.getStackInSlot(j1);
  276.  
  277. if (itemstack != null)
  278. {
  279. float f = this.furnaceRand.nextFloat() * 0.8F + 0.1F;
  280. float f1 = this.furnaceRand.nextFloat() * 0.8F + 0.1F;
  281. float f2 = this.furnaceRand.nextFloat() * 0.8F + 0.1F;
  282.  
  283. while (itemstack.stackSize > 0)
  284. {
  285. int k1 = this.furnaceRand.nextInt(21) + 10;
  286.  
  287. if (k1 > itemstack.stackSize)
  288. {
  289. k1 = itemstack.stackSize;
  290. }
  291.  
  292. itemstack.stackSize -= k1;
  293. EntityItem entityitem = new EntityItem(par1World, (double)((float)par2 + f), (double)((float)par3 + f1), (double)((float)par4 + f2), new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage()));
  294.  
  295. if (itemstack.hasTagCompound())
  296. {
  297. entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
  298. }
  299.  
  300. float f3 = 0.05F;
  301. entityitem.motionX = (double)((float)this.furnaceRand.nextGaussian() * f3);
  302. entityitem.motionY = (double)((float)this.furnaceRand.nextGaussian() * f3 + 0.2F);
  303. entityitem.motionZ = (double)((float)this.furnaceRand.nextGaussian() * f3);
  304. par1World.spawnEntityInWorld(entityitem);
  305. }
  306. }
  307. }
  308.  
  309. par1World.func_96440_m(par2, par3, par4, par5);
  310. }
  311. }
  312.  
  313. super.breakBlock(par1World, par2, par3, par4, par5, par6);
  314. }
  315.  
  316. /**
  317. * If this returns true, then comparators facing away from this block will use the value from
  318. * getComparatorInputOverride instead of the actual redstone signal strength.
  319. */
  320. public boolean hasComparatorInputOverride()
  321. {
  322. return true;
  323. }
  324.  
  325. /**
  326. * If hasComparatorInputOverride returns true, the return value from this is used instead of the redstone signal
  327. * strength when this block inputs to a comparator.
  328. */
  329. public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5)
  330. {
  331. return Container.calcRedstoneFromInventory((IInventory)par1World.getBlockTileEntity(par2, par3, par4));
  332. }
  333.  
  334. @SideOnly(Side.CLIENT)
  335.  
  336. /**
  337. * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
  338. */
  339. public int idPicked(World par1World, int par2, int par3, int par4)
  340. {
  341. return Block.furnaceIdle.blockID;
  342. }
  343. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement