pryingtuna85649

Grass Block class

May 17th, 2014
1,007
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.70 KB | None | 0 0
  1. package com.wizardofoz.basic.block;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockGrass;
  7. import net.minecraft.block.IGrowable;
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.client.renderer.texture.IIconRegister;
  10. import net.minecraft.creativetab.CreativeTabs;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.util.IIcon;
  14. import net.minecraft.world.ColorizerGrass;
  15. import net.minecraft.world.IBlockAccess;
  16. import net.minecraft.world.World;
  17.  
  18. import org.apache.logging.log4j.LogManager;
  19. import org.apache.logging.log4j.Logger;
  20.  
  21. import com.wizardofoz.basic.Gillikins;
  22. import com.wizardofoz.basic.Munchkins;
  23. import com.wizardofoz.basic.Quadlings;
  24. import com.wizardofoz.basic.Winkies;
  25.  
  26. import cpw.mods.fml.relauncher.Side;
  27. import cpw.mods.fml.relauncher.SideOnly;
  28.  
  29. public class GrassBlock extends Block implements IGrowable {
  30.  
  31. private static final Logger logger = LogManager.getLogger();
  32. @SideOnly(Side.CLIENT)
  33. private IIcon field_149991_b;
  34. @SideOnly(Side.CLIENT)
  35. private IIcon field_149993_M;
  36. @SideOnly(Side.CLIENT)
  37. private IIcon field_149994_N;
  38. private static final String __OBFID = "CL_00000251";
  39.  
  40. public GrassBlock(Material material) {
  41. super(Material.grass);
  42. this.setTickRandomly(true);
  43. this.setCreativeTab(CreativeTabs.tabBlock);
  44. //this.getItemDropped(lightOpacity, null, lightOpacity);
  45.  
  46. }
  47.  
  48. /**
  49. * Gets the block's texture. Args: side, meta
  50. */
  51. @SideOnly(Side.CLIENT)
  52. public IIcon getIcon(int p_149691_1_, int p_149691_2_) {
  53. return p_149691_1_ == 1 ? this.field_149991_b : (p_149691_1_ == 0 ? Blocks.dirt.getBlockTextureFromSide(p_149691_1_) : this.blockIcon);
  54. }
  55.  
  56. /**
  57. * Ticks the block if it's been scheduled
  58. */
  59. public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_) {
  60. if (!p_149674_1_.isRemote) {
  61. if (p_149674_1_.getBlockLightValue(p_149674_2_, p_149674_3_ + 1, p_149674_4_) < 4 && p_149674_1_.getBlockLightOpacity(p_149674_2_, p_149674_3_ + 1, p_149674_4_) > 2) {
  62. p_149674_1_.setBlock(p_149674_2_, p_149674_3_, p_149674_4_, Blocks.dirt);
  63. }
  64.  
  65. else if (p_149674_1_.getBlockLightValue(p_149674_2_, p_149674_3_ + 1, p_149674_4_) >= 9) {
  66. for (int l = 0; l < 4; ++l) {
  67. int i1 = p_149674_2_ + p_149674_5_.nextInt(3) - 1;
  68. int j1 = p_149674_3_ + p_149674_5_.nextInt(5) - 3;
  69. int k1 = p_149674_4_ + p_149674_5_.nextInt(3) - 1;
  70. Block block = p_149674_1_.getBlock(i1, j1 + 1, k1);
  71.  
  72. if (p_149674_1_.getBlock(i1, j1, k1) == Blocks.dirt && p_149674_1_.getBlockMetadata(i1, j1, k1) == 0 && p_149674_1_.getBlockLightValue(i1, j1 + 1, k1) >= 4 && p_149674_1_.getBlockLightOpacity(i1, j1 + 1, k1) <= 2) {
  73. p_149674_1_.setBlock(i1, j1, k1, Blocks.grass);
  74. }
  75. }
  76. }
  77. }
  78. }
  79.  
  80. //public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) {
  81. // return Blocks.dirt.getItemDropped(0, p_149650_2_, p_149650_3_);
  82. //}
  83.  
  84. //public Item getItemFromBlock(Block block) {
  85. // return getItemFromBlock(OzBlocks.DirtBlock);
  86. //change Item.getItemFromBlock?
  87. //}
  88.  
  89. public boolean func_149851_a(World p_149851_1_, int p_149851_2_, int p_149851_3_, int p_149851_4_, boolean p_149851_5_) {
  90. return true;
  91. }
  92.  
  93. public boolean func_149852_a(World p_149852_1_, Random p_149852_2_, int p_149852_3_, int p_149852_4_, int p_149852_5_) {
  94. return true;
  95. }
  96.  
  97. @SideOnly(Side.CLIENT)
  98. public IIcon getIcon(IBlockAccess p_149673_1_, int p_149673_2_, int p_149673_3_, int p_149673_4_, int p_149673_5_) {
  99. if (p_149673_5_ == 1) {
  100. return this.field_149991_b;
  101. }
  102. else if (p_149673_5_ == 0) {
  103. return Blocks.dirt.getBlockTextureFromSide(p_149673_5_);
  104. }
  105. else {
  106. Material material = p_149673_1_.getBlock(p_149673_2_, p_149673_3_ + 1, p_149673_4_).getMaterial();
  107. return material != Material.snow && material != Material.craftedSnow ? this.blockIcon : this.field_149993_M;
  108. }
  109. }
  110.  
  111. @SideOnly(Side.CLIENT)
  112. public void registerBlockIcons(IIconRegister p_149651_1_) {
  113. this.blockIcon = p_149651_1_.registerIcon(this.getTextureName() + "_side");
  114. this.field_149991_b = p_149651_1_.registerIcon(this.getTextureName() + "_top");
  115. this.field_149993_M = p_149651_1_.registerIcon(this.getTextureName() + "_side_snowed");
  116. this.field_149994_N = p_149651_1_.registerIcon(this.getTextureName() + "_side_overlay");
  117. }
  118.  
  119. @SideOnly(Side.CLIENT)
  120. public int getBlockColor() {
  121. double d0 = 0.5D;
  122. double d1 = 1.0D;
  123. return ColorizerGrass.getGrassColor(d0, d1);
  124. }
  125.  
  126. /**
  127. * Returns the color this block should be rendered. Used by leaves.
  128. */
  129.  
  130. // @SideOnly(Side.CLIENT)
  131. // public int getRenderColor(int p_149741_1_) {
  132.  
  133. // return this.getBlockColor();
  134.  
  135. // }
  136.  
  137. /**
  138. * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called
  139. * when first determining what to render.
  140. */
  141.  
  142. // @SideOnly(Side.CLIENT)
  143. // public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_149720_3_, int p_149720_4_) {
  144.  
  145. // int l = 0;
  146. // int i1 = 0;
  147. // int j1 = 0;
  148.  
  149. // for (int k1 = -1; k1 <= 1; ++k1) {
  150.  
  151. // for (int l1 = -1; l1 <= 1; ++l1) {
  152.  
  153. // int i2 = p_149720_1_.getBiomeGenForCoords(p_149720_2_ + l1, p_149720_4_ + k1).getBiomeGrassColor(p_149720_2_ + l1, p_149720_3_, p_149720_4_ + k1);
  154. // l += (i2 & 16711680) >> 16;
  155. // i1 += (i2 & 65280) >> 8;
  156. // j1 += i2 & 255;
  157. // }
  158. // }
  159.  
  160. // return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255;
  161. // }
  162.  
  163. @SideOnly(Side.CLIENT)
  164. public static BlockGrass getIconSideOverlay() {
  165.  
  166. return Blocks.grass;
  167. }
  168.  
  169. public void func_149853_b(World p_149853_1_, Random p_149853_2_, int p_149853_3_, int p_149853_4_, int p_149853_5_) {
  170.  
  171. int l = 0;
  172.  
  173. while (l < 128) {
  174.  
  175. int i1 = p_149853_3_;
  176. int j1 = p_149853_4_ + 1;
  177. int k1 = p_149853_5_;
  178. int l1 = 0;
  179.  
  180. while (true) {
  181.  
  182. if (l1 < l / 16) {
  183.  
  184. i1 += p_149853_2_.nextInt(3) - 1;
  185. j1 += (p_149853_2_.nextInt(3) - 1) * p_149853_2_.nextInt(3) / 2;
  186. k1 += p_149853_2_.nextInt(3) - 1;
  187.  
  188. if (p_149853_1_.getBlock(i1, j1 - 1, k1) == Blocks.grass && !p_149853_1_.getBlock(i1, j1, k1).isNormalCube()) {
  189.  
  190. ++l1;
  191. continue;
  192. }
  193. }
  194. else if (p_149853_1_.getBlock(i1, j1, k1).getMaterial() == Material.air) {
  195.  
  196. if (p_149853_2_.nextInt(8) != 0)
  197. {
  198. if (Blocks.tallgrass.canBlockStay(p_149853_1_, i1, j1, k1))
  199. {
  200. p_149853_1_.setBlock(i1, j1, k1, Blocks.tallgrass, 1, 3);
  201. }
  202. }
  203. else
  204. {
  205. p_149853_1_.getBiomeGenForCoords(i1, k1).plantFlower(p_149853_1_, p_149853_2_, i1, j1, k1);
  206. }
  207. }
  208.  
  209. ++l;
  210. break;
  211. }
  212. }
  213. }
  214.  
  215. }
Advertisement
Add Comment
Please, Sign In to add comment