Guest User

Untitled

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