| |
| package net.legacymod.items; |
| |
| import cpw.mods.fml.relauncher.Side; |
| import cpw.mods.fml.relauncher.SideOnly; |
| import net.legacymod.LegacyMod; |
| import net.legacymod.packets.Packet5Arrow; |
| import net.legacymod.packets.PacketArrow; |
| import net.legacymod.packets.PacketFireArrow; |
| import net.legacymod.proxy.ClientProxy; |
| import net.minecraft.client.renderer.texture.IIconRegister; |
| import net.minecraft.creativetab.CreativeTabs; |
| import net.minecraft.enchantment.Enchantment; |
| import net.minecraft.enchantment.EnchantmentHelper; |
| import net.minecraft.entity.Entity; |
| import net.minecraft.entity.EntityLivingBase; |
| import net.minecraft.entity.player.EntityPlayer; |
| import net.minecraft.entity.projectile.EntityArrow; |
| import net.minecraft.entity.projectile.EntityLargeFireball; |
| import net.minecraft.init.Items; |
| import net.minecraft.item.EnumAction; |
| import net.minecraft.item.Item; |
| import net.minecraft.item.ItemBow; |
| import net.minecraft.item.ItemStack; |
| import net.minecraft.nbt.NBTTagCompound; |
| import net.minecraft.util.DamageSource; |
| import net.minecraft.util.IIcon; |
| import net.minecraft.util.Vec3; |
| import net.minecraft.world.World; |
| import net.minecraftforge.common.MinecraftForge; |
| import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; |
| import net.minecraftforge.event.entity.player.ArrowLooseEvent; |
| import net.minecraftforge.event.entity.player.ArrowNockEvent; |
| |
| public class FlameBow extends ItemBow { |
| |
| public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"}; |
| @SideOnly(Side.CLIENT) |
| private IIcon[] iconArray; |
| |
| public boolean isExplosive; |
| |
| public FlameBow() |
| { |
| this.maxStackSize = 1; |
| this.setMaxDamage(1000); |
| this.setFull3D(); |
| this.setCreativeTab(CreativeTabs.tabCombat); |
| } |
| |
| |
| |
| |
| public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int p_77615_4_) |
| { |
| int j = this.getMaxItemUseDuration(stack) - p_77615_4_; |
| |
| ArrowLooseEvent event = new ArrowLooseEvent(player, stack, j); |
| EntityLargeFireball fire = new EntityLargeFireball(world); |
| MinecraftForge.EVENT_BUS.post(event); |
| if (event.isCanceled()) |
| { |
| return; |
| } |
| j = event.charge; |
| |
| boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0; |
| |
| if (flag || player.inventory.hasItem(Items.arrow)) |
| { |
| float f = (float)j / 20.0F; |
| f = (f * f + f * 2.0F) / 3.0F; |
| |
| if ((double)f < 0.1D) |
| { |
| return; |
| } |
| |
| if (f > 1.0F) |
| { |
| f = 1.0F; |
| } |
| |
| EntityArrow entityarrow = new EntityArrow(world, player, f * 2.0F); |
| EntityArrow entityarrow2 = new EntityArrow(world, player, f * 2.0F); |
| EntityArrow entityarrow3 = new EntityArrow(world, player, f * 2.0F); |
| EntityArrow entityarrow4 = new EntityArrow(world, player, f * 2.0F); |
| EntityArrow entityarrow5 = new EntityArrow(world, player, f * 2.0F); |
| |
| if (f == 1.0F) |
| { |
| entityarrow.setIsCritical(true); |
| } |
| |
| int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack); |
| |
| if (k > 0) |
| { |
| entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D); |
| } |
| |
| int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack); |
| |
| if (l > 0) |
| { |
| entityarrow.setKnockbackStrength(l); |
| } |
| |
| if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) |
| { |
| entityarrow.setFire(100); |
| } |
| |
| stack.damageItem(1, player); |
| world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); |
| |
| if (flag) |
| { |
| entityarrow.canBePickedUp = 2; |
| } |
| if(!world.isRemote && ClientProxy.keyBindSortG2.isPressed() && stack.getTagCompound().getInteger("timer") >= 1) |
| { |
| entityarrow.getEntityData().setBoolean("isExplosive", true); |
| LegacyMod.network.sendToServer(new PacketArrow(f * 2.0F)); |
| System.out.println("flèche explosive"); |
| stack.getTagCompound().setInteger("timer", 0); |
| } |
| |
| if (!world.isRemote && ClientProxy.keyBindSortG1.isPressed()) |
| { |
| LegacyMod.network.sendToServer(new PacketFireArrow(f * 2.0F)); |
| System.out.println("flèche en feu"); |
| stack.getTagCompound().setInteger("timer2", 0); |
| } |
| if (player.isSneaking() && !world.isRemote) |
| { |
| System.out.println("5 flèches"); |
| LegacyMod.network.sendToServer(new Packet5Arrow(2.0F)); |
| |
| stack.getTagCompound().setInteger("timer3", 0); |
| |
| }else if(!world.isRemote) |
| { |
| world.spawnEntityInWorld(entityarrow); |
| System.out.println("flèche normale"); |
| } |
| } |
| } |
| |
| public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer p_77654_3_) |
| { |
| return p_77654_1_; |
| } |
| |
| |
| |
| |
| public int getMaxItemUseDuration(ItemStack p_77626_1_) |
| { |
| return 72000; |
| } |
| |
| |
| |
| |
| public EnumAction getItemUseAction(ItemStack p_77661_1_) |
| { |
| return EnumAction.bow; |
| } |
| |
| |
| |
| |
| public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) |
| { |
| ArrowNockEvent event = new ArrowNockEvent(p_77659_3_, p_77659_1_); |
| MinecraftForge.EVENT_BUS.post(event); |
| if (event.isCanceled()) |
| { |
| return event.result; |
| } |
| |
| if (p_77659_3_.capabilities.isCreativeMode || p_77659_3_.inventory.hasItem(Items.arrow)) |
| { |
| p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_)); |
| } |
| |
| return p_77659_1_; |
| } |
| |
| |
| |
| |
| public int getItemEnchantability() |
| { |
| return 1; |
| } |
| |
| @SideOnly(Side.CLIENT) |
| public void registerIcons(IIconRegister p_94581_1_) |
| { |
| this.itemIcon = p_94581_1_.registerIcon(this.getIconString() + "_standby"); |
| this.iconArray = new IIcon[bowPullIconNameArray.length]; |
| |
| for (int i = 0; i < this.iconArray.length; ++i) |
| { |
| this.iconArray* = p_94581_1_.registerIcon(this.getIconString() + "_" + bowPullIconNameArray*); |
| } |
| } |
| |
| |
| |
| |
| @SideOnly(Side.CLIENT) |
| public IIcon getItemIconForUseDuration(int p_94599_1_) |
| { |
| return this.iconArray[p_94599_1_]; |
| } |
| |
| public void onUpdate(ItemStack item, World world, Entity player, int slotIndex, boolean inHand) { |
| if(!item.hasTagCompound() && !world.isRemote) { |
| item.setTagCompound(new NBTTagCompound()); |
| } |
| if(!world.isRemote){ |
| int timer = !item.getTagCompound().hasKey("timer") ? 0 : item.getTagCompound().getInteger("timer"); |
| timer++; |
| item.getTagCompound().setInteger("timer", timer); |
| |
| int timer2 = !item.getTagCompound().hasKey("timer2") ? 0 : item.getTagCompound().getInteger("timer2"); |
| timer2++; |
| item.getTagCompound().setInteger("timer2", timer2); |
| |
| int timer3 = !item.getTagCompound().hasKey("timer3") ? 0 : item.getTagCompound().getInteger("timer3"); |
| timer3++; |
| item.getTagCompound().setInteger("timer3", timer3); |
| |
| super.onUpdate(item, world, player, slotIndex, inHand); |
| } |
| } |
| |
| @Override |
| public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) |
| { |
| if(usingItem != null && usingItem.getItem() == LegacyMod.FlameBow) |
| { |
| int k = usingItem.getMaxItemUseDuration() - useRemaining; |
| if(k >= 18) |
| return iconArray[2]; |
| if(k > 13) |
| return iconArray[1]; |
| if(k > 0) |
| return iconArray[0]; |
| } |
| return getIconIndex(stack); |
| } |
| |
| } |