Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rwtema.extrautils.item;
- import com.rwtema.extrautils.ExtraUtils;
- import com.rwtema.extrautils.LogHelper;
- import com.rwtema.extrautils.XUHelper;
- import cpw.mods.fml.common.Loader;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import java.lang.reflect.Field;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockLiquid;
- import net.minecraft.block.BlockSapling;
- import net.minecraft.block.IGrowable;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.renderer.texture.IIconRegister;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.monster.EntityEnderman;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.item.EnumAction;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemBlock;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.IIcon;
- import net.minecraft.util.MovingObjectPosition;
- import net.minecraft.util.MovingObjectPosition.MovingObjectType;
- import net.minecraft.util.Vec3;
- import net.minecraft.world.World;
- import net.minecraft.world.biome.BiomeGenBase;
- import net.minecraftforge.common.IPlantable;
- public class ItemWateringCan
- extends Item
- {
- public static ArrayList<ItemStack> flowers = null;
- private static Random rand = new Random();
- IIcon busted = null;
- IIcon reinforced = null;
- public ItemWateringCan()
- {
- func_77637_a(ExtraUtils.creativeTabExtraUtils);
- func_77655_b("extrautils:watering_can");
- func_111206_d("extrautils:watering_can");
- func_77627_a(false);
- func_77625_d(1);
- }
- @SideOnly(Side.CLIENT)
- public IIcon func_77617_a(int par1)
- {
- if (par1 == 2) {
- return this.busted;
- }
- if (par1 == 3) {
- return this.reinforced;
- }
- return this.field_77791_bV;
- }
- @SideOnly(Side.CLIENT)
- public void func_94581_a(IIconRegister par1IIconRegister)
- {
- this.field_77791_bV = par1IIconRegister.func_94245_a(func_111208_A());
- this.busted = par1IIconRegister.func_94245_a("extrautils:watering_can_bust");
- this.reinforced = par1IIconRegister.func_94245_a("extrautils:watering_can_reinforced");
- }
- public int func_77626_a(ItemStack par1ItemStack)
- {
- return 72000;
- }
- 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)
- {
- if ((par1ItemStack.func_77960_j() != 3) || (!XUHelper.isPlayerFake(par2EntityPlayer))) {
- return false;
- }
- waterLocation(par3World, par4 + 0.5D, par5 + 0.5D, par6 + 0.5D, par7, par1ItemStack, par2EntityPlayer);
- return true;
- }
- public ItemStack func_77659_a(ItemStack par1ItemStack, World world, EntityPlayer player)
- {
- if (par1ItemStack.func_77960_j() != 1)
- {
- if (XUHelper.isPlayerFake(player))
- {
- if (par1ItemStack.func_77960_j() != 3) {
- par1ItemStack.func_77964_b(2);
- } else {
- onUsingTick(par1ItemStack, player, 0);
- }
- }
- else if ((par1ItemStack.func_77960_j() == 2) &&
- (XUHelper.isThisPlayerACheatyBastardOfCheatBastardness(player))) {
- par1ItemStack.func_77964_b(4);
- }
- player.func_71008_a(par1ItemStack, func_77626_a(par1ItemStack));
- }
- else
- {
- MovingObjectPosition movingobjectposition = func_77621_a(world, player, true);
- if (movingobjectposition == null) {
- return par1ItemStack;
- }
- if (movingobjectposition.field_72313_a == MovingObjectPosition.MovingObjectType.BLOCK)
- {
- int i = movingobjectposition.field_72311_b;
- int j = movingobjectposition.field_72312_c;
- int k = movingobjectposition.field_72309_d;
- if (world.func_147439_a(i, j, k).func_149688_o() == Material.field_151586_h)
- {
- if (XUHelper.isThisPlayerACheatyBastardOfCheatBastardness(player)) {
- par1ItemStack.func_77964_b(3);
- } else {
- par1ItemStack.func_77964_b(0);
- }
- return par1ItemStack;
- }
- }
- return par1ItemStack;
- }
- return par1ItemStack;
- }
- public String func_77667_c(ItemStack par1ItemStack)
- {
- if (par1ItemStack.func_77960_j() == 1) {
- return super.func_77658_a() + ".empty";
- }
- if (par1ItemStack.func_77960_j() == 2) {
- return super.func_77658_a() + ".busted";
- }
- if (par1ItemStack.func_77960_j() == 3) {
- return super.func_77658_a() + ".reinforced";
- }
- return super.func_77658_a();
- }
- public EnumAction func_77661_b(ItemStack par1ItemStack)
- {
- return EnumAction.none;
- }
- @SideOnly(Side.CLIENT)
- public void func_150895_a(Item par1, CreativeTabs par2CreativeTabs, List par3List)
- {
- par3List.add(new ItemStack(par1, 1, 0));
- par3List.add(new ItemStack(par1, 1, 1));
- par3List.add(new ItemStack(par1, 1, 2));
- par3List.add(new ItemStack(par1, 1, 3));
- }
- public void initFlowers()
- {
- if (flowers != null) {
- return;
- }
- flowers = new ArrayList();
- if (!Loader.isModLoaded("Forestry")) {
- return;
- }
- try
- {
- Class flowerManager = Class.forName("forestry.api.apiculture.FlowerManager");
- ArrayList<ItemStack> temp = (ArrayList)flowerManager.getField("plainFlowers").get(null);
- flowers.addAll(temp);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public void onUsingTick(ItemStack stack, EntityPlayer player, int count)
- {
- MovingObjectPosition pos = func_77621_a(player.field_70170_p, player, true);
- if (pos != null) {
- 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);
- }
- }
- public void waterLocation(World worldObj, double hitX, double hitY, double hitZ, int side, ItemStack stack, EntityPlayer play)
- {
- int range = 1;
- if (stack.func_77960_j() == 3) {
- range = 3;
- }
- if (stack.func_77960_j() == 4) {
- range = 4;
- }
- 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));
- if (enderman != null) {
- for (Object anEnderman : enderman) {
- ((EntityEnderman)anEnderman).func_70097_a(DamageSource.field_76369_e, 1.0F);
- }
- }
- boolean cheat = (stack.func_77960_j() == 4) && ((XUHelper.isThisPlayerACheatyBastardOfCheatBastardness(play)) || (LogHelper.isDeObf)) && (!XUHelper.isPlayerFake(play));
- if (worldObj.field_72995_K)
- {
- 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];
- double x2 = hitX + dx * 0.1D;double y2 = hitY + dy * 0.1D;double z2 = hitZ + dz * 0.1D;
- for (int i = 0; i < (stack.func_77960_j() == 3 ? 100 : stack.func_77960_j() == 2 ? 1 : 10); i++) {
- 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);
- }
- }
- else
- {
- 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));
- if (ents != null) {
- for (Object ent : ents) {
- if (((Entity)ent).func_70027_ad())
- {
- float p = 0.01F;
- if ((ent instanceof EntityPlayer)) {
- p = 0.333F;
- }
- ((Entity)ent).func_70066_B();
- if (worldObj.field_73012_v.nextDouble() < p)
- {
- if (stack.func_77960_j() < 3) {
- stack.func_77964_b(1);
- }
- if (play != null) {
- play.func_71034_by();
- }
- return;
- }
- }
- }
- }
- int blockX = (int)Math.floor(hitX);
- int blockY = (int)Math.floor(hitY);
- int blockZ = (int)Math.floor(hitZ);
- for (int x = blockX - range; x <= blockX + range; x++) {
- for (int y = blockY - range; y <= blockY + range; y++) {
- for (int z = blockZ - range; z <= blockZ + range; z++)
- {
- Block id = worldObj.func_147439_a(x, y, z);
- if (!worldObj.func_147437_c(x, y, z))
- {
- if (id == Blocks.field_150480_ab) {
- worldObj.func_147468_f(x, y, z);
- }
- if ((id == Blocks.field_150356_k) &&
- (worldObj.field_73012_v.nextInt(2) == 0)) {
- Blocks.field_150356_k.func_149674_a(worldObj, x, y, z, worldObj.field_73012_v);
- }
- if ((id == Blocks.field_150458_ak) &&
- (worldObj.func_72805_g(x, y, z) < 7)) {
- worldObj.func_72921_c(x, y, z, 7, 2);
- }
- int timer = -1;
- if (id == Blocks.field_150349_c)
- {
- timer = 20;
- if ((!cheat) && (worldObj.field_73012_v.nextInt(4500) == 0) &&
- (worldObj.func_147437_c(x, y + 1, z)))
- {
- initFlowers();
- if ((flowers.size() > 0) && (worldObj.field_73012_v.nextInt(5) == 0))
- {
- ItemStack flower = (ItemStack)flowers.get(worldObj.field_73012_v.nextInt(flowers.size()));
- if (((flower.func_77973_b() instanceof ItemBlock)) &&
- (play != null)) {
- ((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()));
- }
- }
- else
- {
- worldObj.func_72807_a(x, z).plantFlower(worldObj, rand, x, y + 1, z);
- }
- }
- }
- else if (id == Blocks.field_150391_bh)
- {
- timer = 20;
- }
- else if (id == Blocks.field_150464_aj)
- {
- timer = 40;
- }
- else if ((id instanceof BlockSapling))
- {
- timer = 50;
- }
- else if (((id instanceof IPlantable)) || ((id instanceof IGrowable)))
- {
- timer = 40;
- }
- else if (id.func_149688_o() == Material.field_151577_b)
- {
- timer = 20;
- }
- if (stack.func_77960_j() == 2) {
- timer *= 20;
- }
- timer /= range;
- if ((timer > 0) &&
- (id.func_149653_t())) {
- worldObj.func_147464_a(x, y, z, id, worldObj.field_73012_v.nextInt(timer));
- }
- }
- }
- }
- }
- if (cheat) {
- for (int i = 0; i < 100; i++) {
- for (int x = blockX - range; x <= blockX + range; x++) {
- for (int y = blockY - range; y <= blockY + range; y++) {
- for (int z = blockZ - range; z <= blockZ + range; z++)
- {
- Block block = worldObj.func_147439_a(x, y, z);
- block.func_149674_a(worldObj, x, y, z, worldObj.field_73012_v);
- TileEntity tile = worldObj.func_147438_o(x, y, z);
- if ((tile != null) && (tile.canUpdate()) && (!tile.func_145837_r())) {
- tile.func_145845_h();
- }
- }
- }
- }
- }
- }
- }
- }
- @SideOnly(Side.CLIENT)
- public void func_77624_a(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
- {
- if (par1ItemStack.func_77960_j() == 2)
- {
- par3List.add("It appears that mechanical hands are not delicate enough");
- par3List.add("to use the watering can properly.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement