Posted June 19, 20169 yr I'd like to create an item that is meant to charge up like a bow, and then shoot an enderpearl(meant to be able to shoot enderpearls really far). I've taken a look at the bow class file and I don't understand any of it... Any help is appreciated.
June 19, 20169 yr Override the following methods: Item#onItemRightClick to set the item in use by calling EntityLivingBase#setActiveHand Item#getMaxItemUseDuration to return the maximum use duration of your item Item#getItemUseAction to return EnumAction.BOW so the entity draws the item back like a bow Item#onPlayerStoppedUsing or Item#onItemUseFinish to do something (e.g. spawn a projectile entity) when the entity stops or finishes using item Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 19, 20169 yr Author Override the following methods: Item#onItemRightClick to set the item in use by calling EntityLivingBase#setActiveHand Item#getMaxItemUseDuration to return the maximum use duration of your item Item#getItemUseAction to return EnumAction.BOW so the entity draws the item back like a bow Item#onPlayerStoppedUsing or Item#onItemUseFinish to do something (e.g. spawn a projectile entity) when the entity stops or finishes using item Thank you for the quick response, I have this now: package bloopers.trinkets.items; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityEnderPearl; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.SoundEvents; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.stats.StatList; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.SoundCategory; import net.minecraft.world.World; public class ItemEnderRifle extends Item { public ItemEnderRifle() { this.maxStackSize = 1; this.setMaxDamage(32); this.setCreativeTab(CreativeTabs.MISC); } public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.BOW; } public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { playerIn.setActiveHand(hand); return new ActionResult(EnumActionResult.SUCCESS, itemStackIn); } public void onPlayerStoppedUsing(ItemStack itemStackIn, World worldIn, EntityLivingBase entityLiving, int timeLeft, EntityPlayer playerIn) { if (!worldIn.isRemote) { EntityEnderPearl entityenderpearl = new EntityEnderPearl(worldIn, playerIn); entityenderpearl.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F); worldIn.spawnEntityInWorld(entityenderpearl); itemStackIn.damageItem(1, playerIn); } } } But it doesn't do anything ingame(like a blank item) Any idea what I've done wrong?
June 19, 20169 yr You didn't override Item#getMaxItemUseDuration . Side note: Always annotate override methods with @Override so you get a compilation error if they don't override a super method. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 19, 20169 yr Author You didn't override Item#getMaxItemUseDuration . Side note: Always annotate override methods with @Override so you get a compilation error if they don't override a super method. The item will charge up now like a bow, but it doesn't do anything on release, even though I have written down to throw an enderpearl in the onPlayerStoppedUsing. This is what I have now: package bloopers.trinkets.items; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityEnderPearl; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.SoundEvents; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.stats.StatList; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.SoundCategory; import net.minecraft.world.World; public class ItemEnderRifle extends Item { public ItemEnderRifle() { this.maxStackSize = 1; this.setMaxDamage(32); this.setCreativeTab(CreativeTabs.MISC); } @Override public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.BOW; } /** * How long it takes to use or consume an item */ @Override public int getMaxItemUseDuration(ItemStack stack) { return 5000; } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { playerIn.setActiveHand(hand); return new ActionResult(EnumActionResult.SUCCESS, itemStackIn); } public void onPlayerStoppedUsing(ItemStack itemStackIn, World worldIn, EntityLivingBase entityLiving, int timeLeft, EntityPlayer playerIn) { EntityEnderPearl entityenderpearl = new EntityEnderPearl(worldIn, playerIn); entityenderpearl.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F); worldIn.spawnEntityInWorld(entityenderpearl); itemStackIn.damageItem(1, playerIn); } } I couldn't put @Override ontop of onPlayerStoppedUsing(it gave me an error and told me to remove the @Override annotation)
June 19, 20169 yr I couldn't put @Override ontop of onPlayerStoppedUsing(it gave me an error and told me to remove the @Override annotation) If @Override gives you a compilation error, it's doing its job and telling you that the method doesn't override a super method. The solution is to fix the method signature, not remove the annotation. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 19, 20169 yr Author Didn't know what method signature was before, did a search and it told me that it's the parameters before the method like public, static and void. (is that correct?) I tried multiple combinations of them and I'm still getting the error.
June 19, 20169 yr Didn't know what method signature was before, did a search and it told me that it's the parameters before the method like public, static and void. (is that correct?) I tried multiple combinations of them and I'm still getting the error. That's not correct. This tutorial explains method overriding and method signatures. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 19, 20169 yr You need to change it to: @Override @Nullable public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) { YOUR CODE } I think nullable makes it so it can return null but I'm not totaly sure http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
June 19, 20169 yr I checked in Item.java and the thing he had missed was @Nullable http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
June 19, 20169 yr What why? The issue was that the OP had the wrong method signature (i.e. arguments), not a missing annotation. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 20, 20169 yr Author Didn't know what method signature was before, did a search and it told me that it's the parameters before the method like public, static and void. (is that correct?) I tried multiple combinations of them and I'm still getting the error. That's not correct. This tutorial explains method overriding and method signatures. I'm not sure what I am supposed to do from here still, sorry to bother you again.
June 20, 20169 yr I'm not sure what I am supposed to do from here still, sorry to bother you again. Override the method by creating a method with the same name, return type and parameter types and annotating it with @Override . Your IDE should be able to do this for you. It's not strictly necessary, but you should also annotate your override method with the same annotations as the super method. If you've managed to override the method, post your latest code and describe what the current problem is. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 20, 20169 yr Author I'm not sure what I am supposed to do from here still, sorry to bother you again. Override the method by creating a method with the same name, return type and parameter types and annotating it with @Override . Your IDE should be able to do this for you. It's not strictly necessary, but you should also annotate your override method with the same annotations as the super method. If you've managed to override the method, post your latest code and describe what the current problem is. It's no longer giving me an error when overriding, but when I finish charging up the game crashes. I think I know the problem too. Here's the code first: @Override public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { EntityEnderPearl entityenderpearl = new EntityEnderPearl(worldIn, player); entityenderpearl.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F); worldIn.spawnEntityInWorld(entityenderpearl); stack.damageItem(1, player); } So, I noticed this now, is the onPlayerStoppedUsing method supposed to return something? @Override public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { EntityEnderPearl entityenderpearl = new EntityEnderPearl(worldIn, player); entityenderpearl.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F); worldIn.spawnEntityInWorld(entityenderpearl); stack.damageItem(1, player); } Because onItemRightClick returns EnumActionResult.SUCCESS - I wonder if onPlayerStoppedUsing is supposed to return something.
June 20, 20169 yr onPlayerStoppedUsing is a void method. It doesn't return anything. In the code you posted, you're referencing a player variable. Where is this coming from? You should use the EntityLivingBase argument. Only create and spawn entities on the server (when World#isRemote is false ). In future, always post the error message (if it's a compile-time error) or the FML log (if it's a runtime error). This makes it much easier to help you. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 21, 20169 yr Author It's all fixed now. Thank you so much for the help! I'm going to make another post with other questions related to this item soon.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.