Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.29 KB | None | 0 0
  1. public class BlockARField extends Block implements ITileEntityProvider
  2. {
  3. @SideOnly(Side.CLIENT)
  4. private IIcon field_149824_a;
  5. @SideOnly(Side.CLIENT)
  6. private IIcon field_149823_b;
  7. private static final String __OBFID = "CL_00000241";
  8.  
  9. public int compostTimer;
  10. public boolean hasCompost;
  11.  
  12. public BlockARField()
  13. {
  14. super(Material.ground);
  15. this.setTickRandomly(true);
  16. this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.9375F, 1.0F);
  17. this.setLightOpacity(255);
  18. this.setBlockName("ARField");
  19. this.setBlockTextureName("ARField");
  20. this.compostTimer = 0;
  21. this.hasCompost = false;
  22. this.setCreativeTab(ARMain.TabARBlocks);
  23. }
  24.  
  25. public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
  26. {
  27. return AxisAlignedBB.getBoundingBox((double)(p_149668_2_ + 0), (double)(p_149668_3_ + 0), (double)(p_149668_4_ + 0), (double)(p_149668_2_ + 1), (double)(p_149668_3_ + 1), (double)(p_149668_4_ + 1));
  28. }
  29.  
  30. public boolean isOpaqueCube()
  31. {
  32. return false;
  33. }
  34.  
  35. public boolean renderAsNormalBlock()
  36. {
  37. return false;
  38. }
  39.  
  40. @SideOnly(Side.CLIENT)
  41. public IIcon getIcon(int p_149691_1_, int p_149691_2_)
  42. {
  43. return p_149691_1_ == 1 ? (p_149691_2_ > 0 ? this.field_149824_a : this.field_149823_b) : Blocks.dirt.getBlockTextureFromSide(p_149691_1_);
  44. }
  45.  
  46. public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer player, int par6, float par7, float par8, float par9)
  47. {
  48. if (par1World.isRemote)
  49. {
  50. Item item = player.inventory.getCurrentItem().getItem();
  51. if(item == ItemHandler.CompostBucket)
  52. {
  53. this.hasCompost = true;
  54. return true;
  55. }
  56. else
  57. {
  58. return false;
  59. }
  60. }
  61. return false;
  62. }
  63.  
  64. @Override
  65. public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_)
  66. {
  67. if (!this.func_149821_m(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_) && !p_149674_1_.canLightningStrikeAt(p_149674_2_, p_149674_3_ + 1, p_149674_4_))
  68. {
  69. int l = p_149674_1_.getBlockMetadata(p_149674_2_, p_149674_3_, p_149674_4_);
  70.  
  71. if (l > 0)
  72. {
  73. p_149674_1_.setBlockMetadataWithNotify(p_149674_2_, p_149674_3_, p_149674_4_, l - 1, 2);
  74. }
  75. else if (!this.func_149822_e(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_))
  76. {
  77. p_149674_1_.setBlock(p_149674_2_, p_149674_3_, p_149674_4_, Blocks.dirt);
  78. }
  79. }
  80. else
  81. {
  82. p_149674_1_.setBlockMetadataWithNotify(p_149674_2_, p_149674_3_, p_149674_4_, 7, 2);
  83. }
  84. /*
  85. if(!p_149674_1_.isRemote)
  86. {
  87. long compostTime = p_149674_1_.getWorldTime() - p_149674_1_.getWorldTime() + this.compostTimer;
  88. if(compostTime < 10 && !hasCompost)
  89. {
  90. this.compostTimer++;
  91. }
  92. if(compostTime >= 10 && !hasCompost)
  93. {
  94. p_149674_1_.setBlock(p_149674_2_, p_149674_3_, p_149674_4_, Blocks.dirt);
  95. }
  96. if(this.hasCompost)
  97. {
  98. //p_149674_1_.setBlockMetadataWithNotify(p_149674_2_, p_149674_3_, p_149674_4_, 7, 2);
  99. }
  100. System.out.println("has compost: "+this.hasCompost);
  101. System.out.println("Timer: "+compostTime);
  102. }*/
  103. }
  104.  
  105. @Override
  106. public void onFallenUpon(World p_149746_1_, int p_149746_2_, int p_149746_3_, int p_149746_4_, Entity p_149746_5_, float p_149746_6_)
  107. {
  108. if (!p_149746_1_.isRemote && p_149746_1_.rand.nextFloat() < p_149746_6_ - 0.5F)
  109. {
  110. if (!(p_149746_5_ instanceof EntityPlayer) && !p_149746_1_.getGameRules().getGameRuleBooleanValue("mobGriefing"))
  111. {
  112. return;
  113. }
  114.  
  115. p_149746_1_.setBlock(p_149746_2_, p_149746_3_, p_149746_4_, Blocks.dirt);
  116. }
  117. }
  118.  
  119. @Override
  120. public boolean canSustainPlant(IBlockAccess world, int x, int y, int z, ForgeDirection direction, IPlantable plantable)
  121. {
  122. Block plant = plantable.getPlant(world, x, y + 1, z);
  123. if (plantable instanceof BlockARCrop && ((BlockARCrop)plantable).canPlaceBlockOn(this))
  124. {
  125. return true;
  126. }
  127. return false;
  128. }
  129.  
  130. private boolean func_149822_e(World p_149822_1_, int p_149822_2_, int p_149822_3_, int p_149822_4_)
  131. {
  132. byte b0 = 0;
  133.  
  134. for (int l = p_149822_2_ - b0; l <= p_149822_2_ + b0; ++l)
  135. {
  136. for (int i1 = p_149822_4_ - b0; i1 <= p_149822_4_ + b0; ++i1)
  137. {
  138. Block block = p_149822_1_.getBlock(l, p_149822_3_ + 1, i1);
  139.  
  140. if (block instanceof IPlantable && canSustainPlant(p_149822_1_, p_149822_2_, p_149822_3_, p_149822_4_, ForgeDirection.UP, (IPlantable)block))
  141. {
  142. return true;
  143. }
  144. }
  145. }
  146.  
  147. return false;
  148. }
  149.  
  150. private boolean func_149821_m(World p_149821_1_, int p_149821_2_, int p_149821_3_, int p_149821_4_)
  151. {
  152. for (int l = p_149821_2_ - 4; l <= p_149821_2_ + 4; ++l)
  153. {
  154. for (int i1 = p_149821_3_; i1 <= p_149821_3_ + 1; ++i1)
  155. {
  156. for (int j1 = p_149821_4_ - 4; j1 <= p_149821_4_ + 4; ++j1)
  157. {
  158. if (p_149821_1_.getBlock(l, i1, j1).getMaterial() == Material.water)
  159. {
  160. return true;
  161. }
  162. }
  163. }
  164. }
  165.  
  166. return false;
  167. }
  168.  
  169. /**
  170. * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
  171. * their own) Args: x, y, z, neighbor Block
  172. */
  173. public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
  174. {
  175. super.onNeighborBlockChange(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_, p_149695_5_);
  176. Material material = p_149695_1_.getBlock(p_149695_2_, p_149695_3_ + 1, p_149695_4_).getMaterial();
  177.  
  178. if (material.isSolid())
  179. {
  180. p_149695_1_.setBlock(p_149695_2_, p_149695_3_, p_149695_4_, Blocks.dirt);
  181. }
  182. }
  183.  
  184. public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
  185. {
  186. return Blocks.dirt.getItemDropped(0, p_149650_2_, p_149650_3_);
  187. }
  188.  
  189. /**
  190. * Gets an item for the block being called on. Args: world, x, y, z
  191. */
  192. @SideOnly(Side.CLIENT)
  193. public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_)
  194. {
  195. return Item.getItemFromBlock(Blocks.dirt);
  196. }
  197.  
  198. @SideOnly(Side.CLIENT)
  199. public void registerBlockIcons(IIconRegister p_149651_1_)
  200. {
  201. this.field_149824_a = p_149651_1_.registerIcon(this.getTextureName() + "_wet");
  202. this.field_149823_b = p_149651_1_.registerIcon(this.getTextureName() + "_dry");
  203. }
  204.  
  205. @Override
  206. public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
  207. {
  208. return new TileEntitySoil();
  209. }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement