Advertisement
djoveryde

Watering Can, ExtraUtilities

Jun 7th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.35 KB | None | 0 0
  1. package com.rwtema.extrautils.item;
  2.  
  3. import com.rwtema.extrautils.ExtraUtils;
  4. import com.rwtema.extrautils.LogHelper;
  5. import com.rwtema.extrautils.XUHelper;
  6. import cpw.mods.fml.common.Loader;
  7. import cpw.mods.fml.relauncher.Side;
  8. import cpw.mods.fml.relauncher.SideOnly;
  9. import java.lang.reflect.Field;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import java.util.Random;
  13. import net.minecraft.block.Block;
  14. import net.minecraft.block.BlockLiquid;
  15. import net.minecraft.block.BlockSapling;
  16. import net.minecraft.block.IGrowable;
  17. import net.minecraft.block.material.Material;
  18. import net.minecraft.client.renderer.texture.IIconRegister;
  19. import net.minecraft.creativetab.CreativeTabs;
  20. import net.minecraft.entity.Entity;
  21. import net.minecraft.entity.monster.EntityEnderman;
  22. import net.minecraft.entity.player.EntityPlayer;
  23. import net.minecraft.init.Blocks;
  24. import net.minecraft.item.EnumAction;
  25. import net.minecraft.item.Item;
  26. import net.minecraft.item.ItemBlock;
  27. import net.minecraft.item.ItemStack;
  28. import net.minecraft.tileentity.TileEntity;
  29. import net.minecraft.util.AxisAlignedBB;
  30. import net.minecraft.util.DamageSource;
  31. import net.minecraft.util.IIcon;
  32. import net.minecraft.util.MovingObjectPosition;
  33. import net.minecraft.util.MovingObjectPosition.MovingObjectType;
  34. import net.minecraft.util.Vec3;
  35. import net.minecraft.world.World;
  36. import net.minecraft.world.biome.BiomeGenBase;
  37. import net.minecraftforge.common.IPlantable;
  38.  
  39. public class ItemWateringCan
  40. extends Item
  41. {
  42. public static ArrayList<ItemStack> flowers = null;
  43. private static Random rand = new Random();
  44. IIcon busted = null;
  45. IIcon reinforced = null;
  46.  
  47. public ItemWateringCan()
  48. {
  49. func_77637_a(ExtraUtils.creativeTabExtraUtils);
  50. func_77655_b("extrautils:watering_can");
  51. func_111206_d("extrautils:watering_can");
  52. func_77627_a(false);
  53. func_77625_d(1);
  54. }
  55.  
  56. @SideOnly(Side.CLIENT)
  57. public IIcon func_77617_a(int par1)
  58. {
  59. if (par1 == 2) {
  60. return this.busted;
  61. }
  62. if (par1 == 3) {
  63. return this.reinforced;
  64. }
  65. return this.field_77791_bV;
  66. }
  67.  
  68. @SideOnly(Side.CLIENT)
  69. public void func_94581_a(IIconRegister par1IIconRegister)
  70. {
  71. this.field_77791_bV = par1IIconRegister.func_94245_a(func_111208_A());
  72. this.busted = par1IIconRegister.func_94245_a("extrautils:watering_can_bust");
  73. this.reinforced = par1IIconRegister.func_94245_a("extrautils:watering_can_reinforced");
  74. }
  75.  
  76. public int func_77626_a(ItemStack par1ItemStack)
  77. {
  78. return 72000;
  79. }
  80.  
  81. public boolean func_77648_a(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
  82. {
  83. if ((par1ItemStack.func_77960_j() != 3) || (!XUHelper.isPlayerFake(par2EntityPlayer))) {
  84. return false;
  85. }
  86. waterLocation(par3World, par4 + 0.5D, par5 + 0.5D, par6 + 0.5D, par7, par1ItemStack, par2EntityPlayer);
  87. return true;
  88. }
  89.  
  90. public ItemStack func_77659_a(ItemStack par1ItemStack, World world, EntityPlayer player)
  91. {
  92. if (par1ItemStack.func_77960_j() != 1)
  93. {
  94. if (XUHelper.isPlayerFake(player))
  95. {
  96. if (par1ItemStack.func_77960_j() != 3) {
  97. par1ItemStack.func_77964_b(2);
  98. } else {
  99. onUsingTick(par1ItemStack, player, 0);
  100. }
  101. }
  102. else if ((par1ItemStack.func_77960_j() == 2) &&
  103. (XUHelper.isThisPlayerACheatyBastardOfCheatBastardness(player))) {
  104. par1ItemStack.func_77964_b(4);
  105. }
  106. player.func_71008_a(par1ItemStack, func_77626_a(par1ItemStack));
  107. }
  108. else
  109. {
  110. MovingObjectPosition movingobjectposition = func_77621_a(world, player, true);
  111. if (movingobjectposition == null) {
  112. return par1ItemStack;
  113. }
  114. if (movingobjectposition.field_72313_a == MovingObjectPosition.MovingObjectType.BLOCK)
  115. {
  116. int i = movingobjectposition.field_72311_b;
  117. int j = movingobjectposition.field_72312_c;
  118. int k = movingobjectposition.field_72309_d;
  119. if (world.func_147439_a(i, j, k).func_149688_o() == Material.field_151586_h)
  120. {
  121. if (XUHelper.isThisPlayerACheatyBastardOfCheatBastardness(player)) {
  122. par1ItemStack.func_77964_b(3);
  123. } else {
  124. par1ItemStack.func_77964_b(0);
  125. }
  126. return par1ItemStack;
  127. }
  128. }
  129. return par1ItemStack;
  130. }
  131. return par1ItemStack;
  132. }
  133.  
  134. public String func_77667_c(ItemStack par1ItemStack)
  135. {
  136. if (par1ItemStack.func_77960_j() == 1) {
  137. return super.func_77658_a() + ".empty";
  138. }
  139. if (par1ItemStack.func_77960_j() == 2) {
  140. return super.func_77658_a() + ".busted";
  141. }
  142. if (par1ItemStack.func_77960_j() == 3) {
  143. return super.func_77658_a() + ".reinforced";
  144. }
  145. return super.func_77658_a();
  146. }
  147.  
  148. public EnumAction func_77661_b(ItemStack par1ItemStack)
  149. {
  150. return EnumAction.none;
  151. }
  152.  
  153. @SideOnly(Side.CLIENT)
  154. public void func_150895_a(Item par1, CreativeTabs par2CreativeTabs, List par3List)
  155. {
  156. par3List.add(new ItemStack(par1, 1, 0));
  157. par3List.add(new ItemStack(par1, 1, 1));
  158. par3List.add(new ItemStack(par1, 1, 2));
  159. par3List.add(new ItemStack(par1, 1, 3));
  160. }
  161.  
  162. public void initFlowers()
  163. {
  164. if (flowers != null) {
  165. return;
  166. }
  167. flowers = new ArrayList();
  168. if (!Loader.isModLoaded("Forestry")) {
  169. return;
  170. }
  171. try
  172. {
  173. Class flowerManager = Class.forName("forestry.api.apiculture.FlowerManager");
  174. ArrayList<ItemStack> temp = (ArrayList)flowerManager.getField("plainFlowers").get(null);
  175. flowers.addAll(temp);
  176. }
  177. catch (Exception e)
  178. {
  179. e.printStackTrace();
  180. }
  181. }
  182.  
  183. public void onUsingTick(ItemStack stack, EntityPlayer player, int count)
  184. {
  185. MovingObjectPosition pos = func_77621_a(player.field_70170_p, player, true);
  186. if (pos != null) {
  187. waterLocation(player.field_70170_p, pos.field_72307_f.field_72450_a, pos.field_72307_f.field_72448_b, pos.field_72307_f.field_72449_c, pos.field_72310_e, stack, player);
  188. }
  189. }
  190.  
  191. public void waterLocation(World worldObj, double hitX, double hitY, double hitZ, int side, ItemStack stack, EntityPlayer play)
  192. {
  193. int range = 1;
  194. if (stack.func_77960_j() == 3) {
  195. range = 3;
  196. }
  197. if (stack.func_77960_j() == 4) {
  198. range = 4;
  199. }
  200. List enderman = worldObj.func_72872_a(EntityEnderman.class, AxisAlignedBB.func_72330_a(hitX - range, hitY - range, hitZ - range, hitX + range, hitY + 6.0D, hitZ + range));
  201. if (enderman != null) {
  202. for (Object anEnderman : enderman) {
  203. ((EntityEnderman)anEnderman).func_70097_a(DamageSource.field_76369_e, 1.0F);
  204. }
  205. }
  206. boolean cheat = (stack.func_77960_j() == 4) && ((XUHelper.isThisPlayerACheatyBastardOfCheatBastardness(play)) || (LogHelper.isDeObf)) && (!XUHelper.isPlayerFake(play));
  207. if (worldObj.field_72995_K)
  208. {
  209. double dx = net.minecraft.util.Facing.field_71586_b[side];double dy = net.minecraft.util.Facing.field_71587_c[side];double dz = net.minecraft.util.Facing.field_71585_d[side];
  210. double x2 = hitX + dx * 0.1D;double y2 = hitY + dy * 0.1D;double z2 = hitZ + dz * 0.1D;
  211. for (int i = 0; i < (stack.func_77960_j() == 3 ? 100 : stack.func_77960_j() == 2 ? 1 : 10); i++) {
  212. worldObj.func_72869_a("splash", x2 + worldObj.field_73012_v.nextGaussian() * 0.6D * range, y2, z2 + worldObj.field_73012_v.nextGaussian() * 0.6D * range, 0.0D, 0.0D, 0.0D);
  213. }
  214. }
  215. else
  216. {
  217. List ents = worldObj.func_72872_a(Entity.class, AxisAlignedBB.func_72330_a(hitX - range, hitY - range, hitZ - range, hitX + range, hitY + range + 6.0D, hitZ + range));
  218. if (ents != null) {
  219. for (Object ent : ents) {
  220. if (((Entity)ent).func_70027_ad())
  221. {
  222. float p = 0.01F;
  223. if ((ent instanceof EntityPlayer)) {
  224. p = 0.333F;
  225. }
  226. ((Entity)ent).func_70066_B();
  227. if (worldObj.field_73012_v.nextDouble() < p)
  228. {
  229. if (stack.func_77960_j() < 3) {
  230. stack.func_77964_b(1);
  231. }
  232. if (play != null) {
  233. play.func_71034_by();
  234. }
  235. return;
  236. }
  237. }
  238. }
  239. }
  240. int blockX = (int)Math.floor(hitX);
  241. int blockY = (int)Math.floor(hitY);
  242. int blockZ = (int)Math.floor(hitZ);
  243. for (int x = blockX - range; x <= blockX + range; x++) {
  244. for (int y = blockY - range; y <= blockY + range; y++) {
  245. for (int z = blockZ - range; z <= blockZ + range; z++)
  246. {
  247. Block id = worldObj.func_147439_a(x, y, z);
  248. if (!worldObj.func_147437_c(x, y, z))
  249. {
  250. if (id == Blocks.field_150480_ab) {
  251. worldObj.func_147468_f(x, y, z);
  252. }
  253. if ((id == Blocks.field_150356_k) &&
  254. (worldObj.field_73012_v.nextInt(2) == 0)) {
  255. Blocks.field_150356_k.func_149674_a(worldObj, x, y, z, worldObj.field_73012_v);
  256. }
  257. if ((id == Blocks.field_150458_ak) &&
  258. (worldObj.func_72805_g(x, y, z) < 7)) {
  259. worldObj.func_72921_c(x, y, z, 7, 2);
  260. }
  261. int timer = -1;
  262. if (id == Blocks.field_150349_c)
  263. {
  264. timer = 20;
  265. if ((!cheat) && (worldObj.field_73012_v.nextInt(4500) == 0) &&
  266. (worldObj.func_147437_c(x, y + 1, z)))
  267. {
  268. initFlowers();
  269. if ((flowers.size() > 0) && (worldObj.field_73012_v.nextInt(5) == 0))
  270. {
  271. ItemStack flower = (ItemStack)flowers.get(worldObj.field_73012_v.nextInt(flowers.size()));
  272. if (((flower.func_77973_b() instanceof ItemBlock)) &&
  273. (play != null)) {
  274. ((ItemBlock)flower.func_77973_b()).placeBlockAt(flower, play, worldObj, x, y + 1, z, 1, 0.5F, 1.0F, 0.5F, flower.func_77973_b().func_77647_b(flower.func_77960_j()));
  275. }
  276. }
  277. else
  278. {
  279. worldObj.func_72807_a(x, z).plantFlower(worldObj, rand, x, y + 1, z);
  280. }
  281. }
  282. }
  283. else if (id == Blocks.field_150391_bh)
  284. {
  285. timer = 20;
  286. }
  287. else if (id == Blocks.field_150464_aj)
  288. {
  289. timer = 40;
  290. }
  291. else if ((id instanceof BlockSapling))
  292. {
  293. timer = 50;
  294. }
  295. else if (((id instanceof IPlantable)) || ((id instanceof IGrowable)))
  296. {
  297. timer = 40;
  298. }
  299. else if (id.func_149688_o() == Material.field_151577_b)
  300. {
  301. timer = 20;
  302. }
  303. if (stack.func_77960_j() == 2) {
  304. timer *= 20;
  305. }
  306. timer /= range;
  307. if ((timer > 0) &&
  308. (id.func_149653_t())) {
  309. worldObj.func_147464_a(x, y, z, id, worldObj.field_73012_v.nextInt(timer));
  310. }
  311. }
  312. }
  313. }
  314. }
  315. if (cheat) {
  316. for (int i = 0; i < 100; i++) {
  317. for (int x = blockX - range; x <= blockX + range; x++) {
  318. for (int y = blockY - range; y <= blockY + range; y++) {
  319. for (int z = blockZ - range; z <= blockZ + range; z++)
  320. {
  321. Block block = worldObj.func_147439_a(x, y, z);
  322.  
  323. block.func_149674_a(worldObj, x, y, z, worldObj.field_73012_v);
  324.  
  325. TileEntity tile = worldObj.func_147438_o(x, y, z);
  326. if ((tile != null) && (tile.canUpdate()) && (!tile.func_145837_r())) {
  327. tile.func_145845_h();
  328. }
  329. }
  330. }
  331. }
  332. }
  333. }
  334. }
  335. }
  336.  
  337. @SideOnly(Side.CLIENT)
  338. public void func_77624_a(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
  339. {
  340. if (par1ItemStack.func_77960_j() == 2)
  341. {
  342. par3List.add("It appears that mechanical hands are not delicate enough");
  343. par3List.add("to use the watering can properly.");
  344. }
  345. }
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement