Guest User

Leaf.java

a guest
Apr 9th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.00 KB | None | 0 0
  1. package com.tristanvo.mod;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import cpw.mods.fml.relauncher.Side;
  7. import cpw.mods.fml.relauncher.SideOnly;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.BlockLeavesBase;
  10. import net.minecraft.block.material.Material;
  11. import net.minecraft.client.Minecraft;
  12. import net.minecraft.client.renderer.texture.IIconRegister;
  13. import net.minecraft.entity.player.EntityPlayer;
  14. import net.minecraft.init.Blocks;
  15. import net.minecraft.item.Item;
  16. import net.minecraft.item.ItemStack;
  17. import net.minecraft.util.IIcon;
  18. import net.minecraft.world.ColorizerFoliage;
  19. import net.minecraft.world.IBlockAccess;
  20. import net.minecraft.world.World;
  21. import net.minecraftforge.common.IShearable;
  22.  
  23. public class mangoLeaf extends BlockLeavesBase implements IShearable
  24. {
  25.  
  26. public static final String[][] leaftypes = new String[][] {{"LeafMango"}, {"LeafMangoOpaque"}};
  27. public static final String[] leaves = new String[] {"Mango"};
  28.  
  29.  
  30. int[] field_150128_a;
  31. @SideOnly(Side.CLIENT)
  32. protected int field_150127_b;
  33. protected IIcon icon1;
  34. protected IIcon icon2;
  35.  
  36. public mangoLeaf()
  37. {
  38. super(Material.leaves, false);
  39. this.setTickRandomly(true);
  40. this.setHardness(0.2F);
  41. this.setLightOpacity(1);
  42. this.setStepSound(soundTypeGrass);
  43. }
  44.  
  45. @SideOnly(Side.CLIENT)
  46. public int getBlockColor()
  47. {
  48. double d0 = 0.5D;
  49. double d1 = 1.0D;
  50. return ColorizerFoliage.getFoliageColor(d0, d1);
  51. }
  52.  
  53. /**
  54. * Returns the color this block should be rendered. Used by leaves.
  55. */
  56. @SideOnly(Side.CLIENT)
  57. public int getRenderColor(int par1)
  58. {
  59. return ColorizerFoliage.getFoliageColorBasic();
  60. }
  61.  
  62. /**
  63. * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called
  64. * when first determining what to render.
  65. */
  66. @SideOnly(Side.CLIENT)
  67. public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_149720_3_, int p_149720_4_)
  68. {
  69. int l = 0;
  70. int i1 = 0;
  71. int j1 = 0;
  72.  
  73. for (int k1 = -1; k1 <= 1; ++k1)
  74. {
  75. for (int l1 = -1; l1 <= 1; ++l1)
  76. {
  77. int i2 = p_149720_1_.getBiomeGenForCoords(p_149720_2_ + l1, p_149720_4_ + k1).getBiomeFoliageColor(p_149720_2_ + l1, p_149720_3_, p_149720_4_ + k1);
  78. l += (i2 & 16711680) >> 16;
  79. i1 += (i2 & 65280) >> 8;
  80. j1 += i2 & 255;
  81. }
  82. }
  83.  
  84. return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255;
  85. }
  86.  
  87. 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_)
  88. {
  89. byte b0 = 1;
  90. int i1 = b0 + 1;
  91.  
  92. if (p_149749_1_.checkChunksExist(p_149749_2_ - i1, p_149749_3_ - i1, p_149749_4_ - i1, p_149749_2_ + i1, p_149749_3_ + i1, p_149749_4_ + i1))
  93. {
  94. for (int j1 = -b0; j1 <= b0; ++j1)
  95. {
  96. for (int k1 = -b0; k1 <= b0; ++k1)
  97. {
  98. for (int l1 = -b0; l1 <= b0; ++l1)
  99. {
  100. Block block = p_149749_1_.getBlock(p_149749_2_ + j1, p_149749_3_ + k1, p_149749_4_ + l1);
  101. if (block.isLeaves(p_149749_1_, p_149749_2_ + j1, p_149749_3_ + k1, p_149749_4_ + l1))
  102. {
  103. block.beginLeavesDecay(p_149749_1_, p_149749_2_ + j1, p_149749_3_ + k1, p_149749_4_ + l1);
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110.  
  111. /**
  112. * Ticks the block if it's been scheduled
  113. */
  114. public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_)
  115. {
  116. if (!p_149674_1_.isRemote)
  117. {
  118. int l = p_149674_1_.getBlockMetadata(p_149674_2_, p_149674_3_, p_149674_4_);
  119.  
  120. if ((l & 8) != 0 && (l & 4) == 0)
  121. {
  122. byte b0 = 4;
  123. int i1 = b0 + 1;
  124. byte b1 = 32;
  125. int j1 = b1 * b1;
  126. int k1 = b1 / 2;
  127.  
  128. if (this.field_150128_a == null)
  129. {
  130. this.field_150128_a = new int[b1 * b1 * b1];
  131. }
  132.  
  133. int l1;
  134.  
  135. if (p_149674_1_.checkChunksExist(p_149674_2_ - i1, p_149674_3_ - i1, p_149674_4_ - i1, p_149674_2_ + i1, p_149674_3_ + i1, p_149674_4_ + i1))
  136. {
  137. int i2;
  138. int j2;
  139.  
  140. for (l1 = -b0; l1 <= b0; ++l1)
  141. {
  142. for (i2 = -b0; i2 <= b0; ++i2)
  143. {
  144. for (j2 = -b0; j2 <= b0; ++j2)
  145. {
  146. Block block = p_149674_1_.getBlock(p_149674_2_ + l1, p_149674_3_ + i2, p_149674_4_ + j2);
  147.  
  148. if (!block.canSustainLeaves(p_149674_1_, p_149674_2_ + l1, p_149674_3_ + i2, p_149674_4_ + j2))
  149. {
  150. if (block.isLeaves(p_149674_1_, p_149674_2_ + l1, p_149674_3_ + i2, p_149674_4_ + j2))
  151. {
  152. this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -2;
  153. }
  154. else
  155. {
  156. this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -1;
  157. }
  158. }
  159. else
  160. {
  161. this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = 0;
  162. }
  163. }
  164. }
  165. }
  166.  
  167. for (l1 = 1; l1 <= 4; ++l1)
  168. {
  169. for (i2 = -b0; i2 <= b0; ++i2)
  170. {
  171. for (j2 = -b0; j2 <= b0; ++j2)
  172. {
  173. for (int k2 = -b0; k2 <= b0; ++k2)
  174. {
  175. if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1] == l1 - 1)
  176. {
  177. if (this.field_150128_a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2)
  178. {
  179. this.field_150128_a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
  180. }
  181.  
  182. if (this.field_150128_a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2)
  183. {
  184. this.field_150128_a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
  185. }
  186.  
  187. if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] == -2)
  188. {
  189. this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] = l1;
  190. }
  191.  
  192. if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] == -2)
  193. {
  194. this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] = l1;
  195. }
  196.  
  197. if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] == -2)
  198. {
  199. this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] = l1;
  200. }
  201.  
  202. if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] == -2)
  203. {
  204. this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] = l1;
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. }
  212.  
  213. l1 = this.field_150128_a[k1 * j1 + k1 * b1 + k1];
  214.  
  215. if (l1 >= 0)
  216. {
  217. p_149674_1_.setBlockMetadataWithNotify(p_149674_2_, p_149674_3_, p_149674_4_, l & -9, 4);
  218. }
  219. else
  220. {
  221. this.removeLeaves(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_);
  222. }
  223. }
  224. }
  225. }
  226.  
  227. /**
  228. * A randomly called display update to be able to add particles or other items for display
  229. */
  230. @SideOnly(Side.CLIENT)
  231. public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3_, int p_149734_4_, Random p_149734_5_)
  232. {
  233. if (p_149734_1_.canLightningStrikeAt(p_149734_2_, p_149734_3_ + 1, p_149734_4_) && !World.doesBlockHaveSolidTopSurface(p_149734_1_, p_149734_2_, p_149734_3_ - 1, p_149734_4_) && p_149734_5_.nextInt(15) == 1)
  234. {
  235. double d0 = (double)((float)p_149734_2_ + p_149734_5_.nextFloat());
  236. double d1 = (double)p_149734_3_ - 0.05D;
  237. double d2 = (double)((float)p_149734_4_ + p_149734_5_.nextFloat());
  238. p_149734_1_.spawnParticle("dripWater", d0, d1, d2, 0.0D, 0.0D, 0.0D);
  239. }
  240. }
  241.  
  242. private void removeLeaves(World p_150126_1_, int p_150126_2_, int p_150126_3_, int p_150126_4_)
  243. {
  244. this.dropBlockAsItem(p_150126_1_, p_150126_2_, p_150126_3_, p_150126_4_, p_150126_1_.getBlockMetadata(p_150126_2_, p_150126_3_, p_150126_4_), 0);
  245. p_150126_1_.setBlockToAir(p_150126_2_, p_150126_3_, p_150126_4_);
  246. }
  247.  
  248. /**
  249. * Returns the quantity of items to drop on block destruction.
  250. */
  251. public int quantityDropped(Random p_149745_1_)
  252. {
  253. return p_149745_1_.nextInt(20) == 0 ? 1 : 0;
  254. }
  255.  
  256. public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
  257. {
  258. return Item.getItemFromBlock(mod.mangoSapling);
  259. }
  260.  
  261. /**
  262. * Drops the block items with a specified chance of dropping the specified items
  263. */
  264. public void dropBlockAsItemWithChance(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)
  265. {
  266. super.dropBlockAsItemWithChance(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, 1.0f, p_149690_7_);
  267. }
  268.  
  269. protected void func_150124_c(World p_150124_1_, int p_150124_2_, int p_150124_3_, int p_150124_4_, int p_150124_5_, int p_150124_6_) {}
  270.  
  271. protected int func_150123_b(int p_150123_1_)
  272. {
  273. return 20;
  274. }
  275.  
  276. /**
  277. * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the
  278. * block and l is the block's subtype/damage.
  279. */
  280. public void harvestBlock(World p_149636_1_, EntityPlayer p_149636_2_, int p_149636_3_, int p_149636_4_, int p_149636_5_, int p_149636_6_)
  281. {
  282. {
  283. super.harvestBlock(p_149636_1_, p_149636_2_, p_149636_3_, p_149636_4_, p_149636_5_, p_149636_6_);
  284. }
  285. }
  286.  
  287. /**
  288. * Determines the damage on the item the block drops. Used in cloth and wood.
  289. */
  290. public int damageDropped(int p_149692_1_)
  291. {
  292. return p_149692_1_ & 3;
  293. }
  294.  
  295. /**
  296. * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
  297. * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
  298. */
  299. public boolean isOpaqueCube()
  300. {
  301. return false;
  302. }
  303.  
  304.  
  305. /**
  306. * Gets the block's texture. Args: side, meta
  307. */
  308. @SideOnly(Side.CLIENT)
  309. public IIcon getIcon(int side, int meta)
  310. {
  311. if(Minecraft.isFancyGraphicsEnabled())
  312. {
  313. return icon1;
  314. }
  315. else
  316. {
  317. return icon2;
  318. }
  319. }
  320. @Override
  321. public void registerBlockIcons(IIconRegister icon)
  322. {
  323. icon1 = icon.registerIcon("moem:mangoleaf_sidefancy");
  324. icon2 = icon.registerIcon("moem:mangoleaf_sidefast");
  325. }
  326.  
  327. @SideOnly(Side.CLIENT)
  328. public void setGraphicsLevel(boolean par1)
  329. {
  330. this.setGraphicsLevel(par1);
  331. this.field_150127_b = par1 ? 0 : 1;
  332. }
  333.  
  334. /**
  335. * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
  336. * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
  337. */
  338. protected ItemStack createStackedBlock(int p_149644_1_)
  339. {
  340. return new ItemStack(Item.getItemFromBlock(this), 1, p_149644_1_ & 3);
  341. }
  342.  
  343. public String[] func_150125_e() {
  344. return null;
  345. }
  346.  
  347.  
  348. @Override
  349. public boolean isShearable(ItemStack item, IBlockAccess world, int x, int y, int z)
  350. {
  351. return true;
  352. }
  353.  
  354. @Override
  355. public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess world, int x, int y, int z, int fortune)
  356. {
  357. ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
  358. ret.add(new ItemStack(this, 1, world.getBlockMetadata(x, y, z) & 3));
  359. return ret;
  360. }
  361.  
  362. @Override
  363. public void beginLeavesDecay(World world, int x, int y, int z)
  364. {
  365.  
  366. int i2 = world.getBlockMetadata(x, y, z);
  367.  
  368. if ((i2 & 8) == 0)
  369. {
  370. world.setBlockMetadataWithNotify(x, y, z, i2 | 8, 4);
  371. }
  372. world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) | 8, 4);
  373. }
  374.  
  375. @Override
  376. public boolean isLeaves(IBlockAccess world, int x, int y, int z)
  377. {
  378. return true;
  379. }
  380.  
  381.  
  382. @Override
  383. public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
  384. {
  385. ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
  386. int chance = this.func_150123_b(metadata);
  387.  
  388. if (fortune > 0)
  389. {
  390. chance -= 2 << fortune;
  391. if (chance < 10) chance = 10;
  392. }
  393.  
  394. if (world.rand.nextInt(chance) == 0)
  395. ret.add(new ItemStack(this.getItemDropped(metadata, world.rand, fortune), 1, this.damageDropped(metadata)));
  396.  
  397. chance = 200;
  398. if (fortune > 0)
  399. {
  400. chance -= 10 << fortune;
  401. if (chance < 40) chance = 40;
  402. }
  403.  
  404. this.captureDrops(true);
  405. this.func_150124_c(world, x, y, z, metadata, chance); // Dammet mojang
  406. ret.addAll(this.captureDrops(false));
  407. return ret;
  408. }
  409. }
Add Comment
Please, Sign In to add comment