diff --git a/assets/modtutoriel/lang/en_US.lang b/assets/modtutoriel/lang/en_US.lang index f7dcc0d..a15674a 100644 --- a/assets/modtutoriel/lang/en_US.lang +++ b/assets/modtutoriel/lang/en_US.lang @@ -54,6 +54,7 @@ item.TutorialAxe.name=Tutorial Axe item.TutorialShovel.name=Tutorial Shovel item.TutorialHoe.name=Tutorial Hoe item.bucketTutorial.name=Tutorial Bucket +item.Tuto_Bow.name=Bow tutorial item.record.cd.desc=Tutorial record @@ -65,4 +66,4 @@ container.bigchest=Big Chest container.cupboard=Cupboard #Other -last.users=Last users : %s \ No newline at end of file +last.users=Last users : %s diff --git a/assets/modtutoriel/lang/fr_FR.lang b/assets/modtutoriel/lang/fr_FR.lang index 5c5e682..6cd0990 100644 --- a/assets/modtutoriel/lang/fr_FR.lang +++ b/assets/modtutoriel/lang/fr_FR.lang @@ -54,6 +54,7 @@ item.TutorialAxe.name=Hache tutoriel item.TutorialShovel.name=Pelle tutoriel item.TutorialHoe.name=Houe tutoriel item.bucketTutorial.name=Seau tutoriel +item.Tuto_Bow.name=Arc tutoriel item.record.cd.desc=Cd disque @@ -65,4 +66,4 @@ container.bigchest=Grand coffre container.cupboard=Placard #Other -last.users=Derniers utilisateurs : %s \ No newline at end of file +last.users=Derniers utilisateurs : %s diff --git a/assets/modtutoriel/textures/items/tuto_bow.png b/assets/modtutoriel/textures/items/tuto_bow.png new file mode 100644 index 0000000..aabe7eb Binary files /dev/null and b/assets/modtutoriel/textures/items/tuto_bow.png differ diff --git a/assets/modtutoriel/textures/items/tuto_bow_1.png b/assets/modtutoriel/textures/items/tuto_bow_1.png new file mode 100644 index 0000000..33e1cd3 Binary files /dev/null and b/assets/modtutoriel/textures/items/tuto_bow_1.png differ diff --git a/assets/modtutoriel/textures/items/tuto_bow_2.png b/assets/modtutoriel/textures/items/tuto_bow_2.png new file mode 100644 index 0000000..548c8e7 Binary files /dev/null and b/assets/modtutoriel/textures/items/tuto_bow_2.png differ diff --git a/assets/modtutoriel/textures/items/tuto_bow_3.png b/assets/modtutoriel/textures/items/tuto_bow_3.png new file mode 100644 index 0000000..1a5f2fc Binary files /dev/null and b/assets/modtutoriel/textures/items/tuto_bow_3.png differ diff --git a/tutoriel/common/ModTutoriel.java b/tutoriel/common/ModTutoriel.java index 3a265ef..cf9ca85 100644 --- a/tutoriel/common/ModTutoriel.java +++ b/tutoriel/common/ModTutoriel.java @@ -41,7 +41,7 @@ public class ModTutoriel // declaration des blocs - blocks statement public static Block BlockTutorial, TutorialMetadata, StairsTutorial, DoubleSlabTuto, SingleSlabTuto, BlockTutorialCake, BlockNewFenceTutorial, BlockNewWallTutorial, blockFluidTutorial, blockTable, blockSculpture; - public static Item ItemTutorial, ItemWithMetadata, TutorialHelmet, TutorialChestPlate, TutorialLeggings, TutorialBoots, TutorialEgg, TutorialSword, TutorialPickaxe, TutorialAxe, TutorialShovel, TutorialHoe, ItemTutorialCake, ItemCdTutorial, bucketTutorial; + public static Item ItemTutorial, ItemWithMetadata, TutorialHelmet, TutorialChestPlate, TutorialLeggings, TutorialBoots, TutorialEgg, TutorialSword, TutorialPickaxe, TutorialAxe, TutorialShovel, TutorialHoe, ItemTutorialCake, ItemCdTutorial, bucketTutorial, Tuto_Bow; public static Fluid fluidTutorial; static ArmorMaterial TutorialArmor = EnumHelper.addArmorMaterial("Tutorial", 20, new int[] {2, 8, 4, 2}, 15); @@ -110,7 +110,8 @@ public void PreInit(FMLPreInitializationEvent event) ItemTutorialCake = new ItemTutorialCake().setUnlocalizedName("TurorialGateauItem").setTextureName("modtutoriel:TutorialCake"); ItemCdTutorial = new ItemCdTutorial("cd").setUnlocalizedName("record").setCreativeTab(ModTutoriel.TutorialCreativeTabs); bucketTutorial = new ItemBucketTutorial(blockFluidTutorial).setUnlocalizedName("bucketTutorial").setTextureName("modtutoriel:bucketTutorial"); - + Tuto_Bow = new Tuto_Bow().setUnlocalizedName("Tuto_Bow").setTextureName("modtutoriel:tuto_bow"); + // Enregistrement des items - Item registry GameRegistry.registerItem(ItemTutorial, "ItemTutorial", "ModTutoriel"); GameRegistry.registerItem(ItemWithMetadata, "ItemWithMetadata", "ModTutoriel"); @@ -127,6 +128,7 @@ public void PreInit(FMLPreInitializationEvent event) GameRegistry.registerItem(ItemTutorialCake, "TutorialGateauItem", "ModTutoriel"); GameRegistry.registerItem(ItemCdTutorial, "item_cd_tutoriel"); GameRegistry.registerItem(bucketTutorial, "BucketTutorial", "ModTutoriel"); + GameRegistry.registerItem(Tuto_Bow, "Tuto_Bow", "ModTutoriel"); FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluidStack("tutorial", FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(bucketTutorial), FluidContainerRegistry.EMPTY_BUCKET); @@ -182,4 +184,4 @@ public void serverStarting(FMLServerStartingEvent event) { event.registerServerCommand(new CommandTutoriel()); } -} \ No newline at end of file +} diff --git a/tutoriel/common/Tuto_Bow.java b/tutoriel/common/Tuto_Bow.java new file mode 100644 index 0000000..a17bb56 --- /dev/null +++ b/tutoriel/common/Tuto_Bow.java @@ -0,0 +1,188 @@ +package tutoriel.common; + +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.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +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.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.ArrowLooseEvent; +import net.minecraftforge.event.entity.player.ArrowNockEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class Tuto_Bow extends Item +{ + public static final String[] bowPullIconNameArray = new String[] {"1", "2", "3"}; + @SideOnly(Side.CLIENT) + private IIcon[] iconArray; + + + public Tuto_Bow() + { + this.maxStackSize = 1; + this.setMaxDamage(700); + this.setFull3D(); + } + + /** + * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount + */ + + public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) + { + int j = this.getMaxItemUseDuration(par1ItemStack) - par4; + + ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j); + MinecraftForge.EVENT_BUS.post(event); + if (event.isCanceled()) + { + return; + } + j = event.charge; + + boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; + + if (flag || par3EntityPlayer.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(par2World, par3EntityPlayer, f * 3.0F); + + if (f == 1.0F) + { + entityarrow.setIsCritical(true); + } + + int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); + + if (k > 0) + { + entityarrow.setDamage(entityarrow.getDamage() + (double)k * 1D + 1D); + } + + int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); + + if (l > 0) + { + entityarrow.setKnockbackStrength(0); + } + + if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) + { + entityarrow.setFire(130); + } + + par1ItemStack.damageItem(1, par3EntityPlayer); + par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); + + if (flag) + { + entityarrow.canBePickedUp = 2; + } + else + { + par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow); + } + + if (!par2World.isRemote) + { + par2World.spawnEntityInWorld(entityarrow); + } + } + } + /** + * How long it takes to use or consume an item + */ + + public int getMaxItemUseDuration(ItemStack par1ItemStack) + { + return 8000; //temps avant chaque utilisation + } + + /** + * returns the action that specifies what animation to play when the items is being used + */ + + public EnumAction getItemUseAction(ItemStack par1ItemStack) + { + return EnumAction.bow; + } + /** + * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer + */ + public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) + { + ArrowNockEvent event = new ArrowNockEvent(par3EntityPlayer, par1ItemStack); + MinecraftForge.EVENT_BUS.post(event); + if (event.isCanceled()) + { + return event.result; + } + + if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Items.arrow)) + { + par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); + } + + return par1ItemStack; + } + + /** + * Return the enchantability factor of the item, most of the time is based on material. + */ + public int getItemEnchantability() + { + return 1; + } + + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister par1IconRegister) + { + this.itemIcon = par1IconRegister.registerIcon(this.getIconString()); + this.iconArray = new IIcon[bowPullIconNameArray.length]; + + for (int i = 0; i < this.iconArray.length; ++i) + { + this.iconArray[i] = par1IconRegister.registerIcon(this.getIconString() + "_" + bowPullIconNameArray[i]); + } + } + + /** + * used to cycle through icons based on their used duration, i.e. for the bow + */ + @Override + public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) + { + if(usingItem != null && usingItem.getItem().equals(this)) + { + 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); + } +}