Guest User

Untitled

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