Advertisement
Guest User

Untitled

a guest
Feb 18th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.30 KB | None | 0 0
  1. package com.scriph.luckybox.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.scriph.luckybox.LuckyBox;
  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.IIconRegister;
  11. import net.minecraft.entity.EntityLivingBase;
  12. import net.minecraft.entity.item.EntityItem;
  13. import net.minecraft.entity.player.EntityPlayer;
  14. import net.minecraft.init.Blocks;
  15. import net.minecraft.inventory.Container;
  16. import net.minecraft.inventory.IInventory;
  17. import net.minecraft.item.Item;
  18. import net.minecraft.item.ItemStack;
  19. import net.minecraft.nbt.NBTTagCompound;
  20. import net.minecraft.tileentity.TileEntity;
  21. import com.scriph.luckybox.blocks.TileEntityFurnace;
  22. import net.minecraft.util.IIcon;
  23. import net.minecraft.util.MathHelper;
  24. import net.minecraft.world.World;
  25. import cpw.mods.fml.relauncher.Side;
  26. import cpw.mods.fml.relauncher.SideOnly;
  27.  
  28. public class blockFurnaceLap extends BlockContainer
  29. {
  30. private final Random field_149933_a = new Random();
  31. private final boolean field_149932_b;
  32. private static boolean field_149934_M;
  33. @SideOnly(Side.CLIENT)
  34. private IIcon field_149935_N;
  35. @SideOnly(Side.CLIENT)
  36. private IIcon field_149936_O;
  37. private static final String __OBFID = "CL_00000248";
  38.  
  39. public blockFurnaceLap(boolean p_i45407_1_)
  40. {
  41. super(Material.rock);
  42. this.field_149932_b = p_i45407_1_;
  43.  
  44. }
  45.  
  46. public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
  47. {
  48. return Item.getItemFromBlock(Blocks.furnace);
  49. }
  50.  
  51. /**
  52. * Called whenever the block is added into the world. Args: world, x, y, z
  53. */
  54. public void onBlockAdded(World p_149726_1_, int p_149726_2_, int p_149726_3_, int p_149726_4_)
  55. {
  56. super.onBlockAdded(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_);
  57. this.func_149930_e(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_);
  58. }
  59.  
  60. private void func_149930_e(World p_149930_1_, int p_149930_2_, int p_149930_3_, int p_149930_4_)
  61. {
  62. if (!p_149930_1_.isRemote)
  63. {
  64. Block block = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ - 1);
  65. Block block1 = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ + 1);
  66. Block block2 = p_149930_1_.getBlock(p_149930_2_ - 1, p_149930_3_, p_149930_4_);
  67. Block block3 = p_149930_1_.getBlock(p_149930_2_ + 1, p_149930_3_, p_149930_4_);
  68. byte b0 = 3;
  69.  
  70. if (block.func_149730_j() && !block1.func_149730_j())
  71. {
  72. b0 = 3;
  73. }
  74.  
  75. if (block1.func_149730_j() && !block.func_149730_j())
  76. {
  77. b0 = 2;
  78. }
  79.  
  80. if (block2.func_149730_j() && !block3.func_149730_j())
  81. {
  82. b0 = 5;
  83. }
  84.  
  85. if (block3.func_149730_j() && !block2.func_149730_j())
  86. {
  87. b0 = 4;
  88. }
  89.  
  90. p_149930_1_.setBlockMetadataWithNotify(p_149930_2_, p_149930_3_, p_149930_4_, b0, 2);
  91. }
  92. }
  93.  
  94. /**
  95. * Gets the block's texture. Args: side, meta
  96. */
  97. @SideOnly(Side.CLIENT)
  98. public IIcon getIcon(int p_149691_1_, int p_149691_2_)
  99. {
  100. return p_149691_1_ == 1 ? this.field_149935_N : (p_149691_1_ == 0 ? this.field_149935_N : (p_149691_1_ != p_149691_2_ ? this.blockIcon : this.field_149936_O));
  101. }
  102.  
  103. @SideOnly(Side.CLIENT)
  104. public void registerBlockIcons(IIconRegister p_149651_1_)
  105. {
  106. this.blockIcon = p_149651_1_.registerIcon("furnace_side");
  107. this.field_149936_O = p_149651_1_.registerIcon(this.field_149932_b ? "furnace_front_on" : "furnace_front_off");
  108. this.field_149935_N = p_149651_1_.registerIcon("furnace_top");
  109. }
  110.  
  111. /**
  112. * Called upon block activation (right click on the block.)
  113. */
  114. public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
  115. {
  116. if (p_149727_1_.isRemote)
  117. {
  118. return true;
  119. }
  120. else
  121. {
  122. TileEntityFurnace tileentityfurnace = (TileEntityFurnace)p_149727_1_.getTileEntity(p_149727_2_, p_149727_3_, p_149727_4_);
  123.  
  124. if (tileentityfurnace != null)
  125. {
  126. p_149727_5_.func_146101_a(tileentityfurnace);
  127. }
  128.  
  129. return true;
  130. }
  131. }
  132.  
  133. /**
  134. * Update which block the furnace is using depending on whether or not it is burning
  135. */
  136. public static void updateFurnaceBlockState(boolean p_149931_0_, World p_149931_1_, int p_149931_2_, int p_149931_3_, int p_149931_4_)
  137. {
  138. int l = p_149931_1_.getBlockMetadata(p_149931_2_, p_149931_3_, p_149931_4_);
  139. TileEntity tileentity = p_149931_1_.getTileEntity(p_149931_2_, p_149931_3_, p_149931_4_);
  140. field_149934_M = true;
  141.  
  142. if (p_149931_0_)
  143. {
  144. p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, LuckyBox.lit_furnacelap);
  145. }
  146. else
  147. {
  148. p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, LuckyBox.furnacelap);
  149. }
  150.  
  151. field_149934_M = false;
  152. p_149931_1_.setBlockMetadataWithNotify(p_149931_2_, p_149931_3_, p_149931_4_, l, 2);
  153.  
  154. if (tileentity != null)
  155. {
  156. tileentity.validate();
  157. p_149931_1_.setTileEntity(p_149931_2_, p_149931_3_, p_149931_4_, tileentity);
  158. }
  159. }
  160.  
  161. /**
  162. * Returns a new instance of a block's tile entity class. Called on placing the block.
  163. */
  164. public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
  165. {
  166. return new TileEntityFurnace();
  167. }
  168.  
  169. /**
  170. * Called when the block is placed in the world.
  171. */
  172. public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_)
  173. {
  174. int l = MathHelper.floor_double((double)(p_149689_5_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  175.  
  176. if (l == 0)
  177. {
  178. p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 2, 2);
  179. }
  180.  
  181. if (l == 1)
  182. {
  183. p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 5, 2);
  184. }
  185.  
  186. if (l == 2)
  187. {
  188. p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 3, 2);
  189. }
  190.  
  191. if (l == 3)
  192. {
  193. p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 4, 2);
  194. }
  195.  
  196. if (p_149689_6_.hasDisplayName())
  197. {
  198. ((TileEntityFurnace)p_149689_1_.getTileEntity(p_149689_2_, p_149689_3_, p_149689_4_)).func_145951_a(p_149689_6_.getDisplayName());
  199. }
  200. }
  201.  
  202. public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)
  203. {
  204. if (!field_149934_M)
  205. {
  206. TileEntityFurnace tileentityfurnace = (TileEntityFurnace)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);
  207.  
  208. if (tileentityfurnace != null)
  209. {
  210. for (int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1)
  211. {
  212. ItemStack itemstack = tileentityfurnace.getStackInSlot(i1);
  213.  
  214. if (itemstack != null)
  215. {
  216. float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
  217. float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
  218. float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
  219.  
  220. while (itemstack.stackSize > 0)
  221. {
  222. int j1 = this.field_149933_a.nextInt(21) + 10;
  223.  
  224. if (j1 > itemstack.stackSize)
  225. {
  226. j1 = itemstack.stackSize;
  227. }
  228.  
  229. itemstack.stackSize -= j1;
  230. EntityItem entityitem = new EntityItem(p_149749_1_, (double)((float)p_149749_2_ + f), (double)((float)p_149749_3_ + f1), (double)((float)p_149749_4_ + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
  231.  
  232. if (itemstack.hasTagCompound())
  233. {
  234. entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
  235. }
  236.  
  237. float f3 = 0.05F;
  238. entityitem.motionX = (double)((float)this.field_149933_a.nextGaussian() * f3);
  239. entityitem.motionY = (double)((float)this.field_149933_a.nextGaussian() * f3 + 0.2F);
  240. entityitem.motionZ = (double)((float)this.field_149933_a.nextGaussian() * f3);
  241. p_149749_1_.spawnEntityInWorld(entityitem);
  242. }
  243. }
  244. }
  245.  
  246. p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_);
  247. }
  248. }
  249.  
  250. super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
  251. }
  252.  
  253. /**
  254. * A randomly called display update to be able to add particles or other items for display
  255. */
  256. @SideOnly(Side.CLIENT)
  257. public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3_, int p_149734_4_, Random p_149734_5_)
  258. {
  259. if (this.field_149932_b)
  260. {
  261. int l = p_149734_1_.getBlockMetadata(p_149734_2_, p_149734_3_, p_149734_4_);
  262. float f = (float)p_149734_2_ + 0.5F;
  263. float f1 = (float)p_149734_3_ + 0.0F + p_149734_5_.nextFloat() * 6.0F / 16.0F;
  264. float f2 = (float)p_149734_4_ + 0.5F;
  265. float f3 = 0.52F;
  266. float f4 = p_149734_5_.nextFloat() * 0.6F - 0.3F;
  267.  
  268. if (l == 4)
  269. {
  270. p_149734_1_.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
  271. p_149734_1_.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
  272. }
  273. else if (l == 5)
  274. {
  275. p_149734_1_.spawnParticle("smoke", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
  276. p_149734_1_.spawnParticle("flame", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
  277. }
  278. else if (l == 2)
  279. {
  280. p_149734_1_.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
  281. p_149734_1_.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
  282. }
  283. else if (l == 3)
  284. {
  285. p_149734_1_.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
  286. p_149734_1_.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
  287. }
  288. }
  289. }
  290.  
  291. /**
  292. * If this returns true, then comparators facing away from this block will use the value from
  293. * getComparatorInputOverride instead of the actual redstone signal strength.
  294. */
  295. public boolean hasComparatorInputOverride()
  296. {
  297. return true;
  298. }
  299.  
  300. /**
  301. * If hasComparatorInputOverride returns true, the return value from this is used instead of the redstone signal
  302. * strength when this block inputs to a comparator.
  303. */
  304. public int getComparatorInputOverride(World p_149736_1_, int p_149736_2_, int p_149736_3_, int p_149736_4_, int p_149736_5_)
  305. {
  306. return Container.calcRedstoneFromInventory((IInventory)p_149736_1_.getTileEntity(p_149736_2_, p_149736_3_, p_149736_4_));
  307. }
  308.  
  309. /**
  310. * Gets an item for the block being called on. Args: world, x, y, z
  311. */
  312. @SideOnly(Side.CLIENT)
  313. public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_)
  314. {
  315. return Item.getItemFromBlock(LuckyBox.furnacelap);
  316. }
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement