Jump to content

[1.9.4] Creating a custom bow


Bloopers

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • LINK ADA DI BAWAH INI  LINK LOGIN LINK DAFTAR EXTRAWD ADALAH AGEN SLOT , TOGEL DAN BOLA TERBESAR INDONESIA YANG MERUPAKAN SITUS ONLINE PERTAMA YANG MENYEDIAKAN BERBAGAI JENIS PERMAINAN DAN BETTING ONLINE TELENGKAP, SEPERTI PERMAINAN CASINO ONLINE, SLOT ONLINE, TOGEL ONLINE, BOLA ONLINE, DAN MASIH BANYAK JENIS PILIHAN 
    • Platform tempat untuk melangsungkan perjudian togel yang paling aman saat ini dan bisa merasakan sensasi hadiah JP jeda tentunya hanya bisa menggunakan situs agen toto togel resmi EXTRAWD . Bersama website agen togel ini anda akan mendapatkan jaminan bahwa hadiah kemenangan pasti dibayar tanpa ada potongan biaya administrasi. Hal terpenting di dalam permainan judi togel melalui situs EXTRAWD adalah wajib memiliki legalitas demi menghindari risiko terhadap hadiah kemenangan. Legalitas tersebut merupakan badan hukum untuk mengawasi terjadinya proses pengundian, sehingga cita-cita untuk mendapatkan JP togel semakin mudah untuk direalisasikan.  
    • I'm having trouble updating my mod Primal Magick to MC1.20.4 on Forge 49.0.48 with JEI 17.3.0.49. I believe I've followed the Forge and JEI instructions correctly, but I'm getting the following exception when I try to run the data generator: java.lang.module.ResolutionException: Modules jei._1._20._4.common.api and jei export package mezz.jei.api.runtime to module primalmagick Full output sample here, and the build.gradle file in question is here. Trying to run the game client results in a different type of exception, but with the same inner error. It looks like I'm getting two separate JEI modules which are interfering with each other, but I'm not sure why that would be. Things I've discovered in my investigations so far: Blowing away my repository and re-cloning from remote does not fix the error, even in combination with nuking my entire gradle cache.  I'm *mostly* sure that it's not just because my workspace is in a bad state. Commenting out line 144 of the build.gradle file, where it specifies the runtime-only deobf dependency of JEI makes the exception not get thrown, but means that JEI is not active in my debug runtime.  While this is a partial workaround for the issue, it leaves me unable to debug any of my JEI integration code, and so is far from ideal. Most maddeningly, running the client and/or data generator from the gradle CLI *also* causes the bug to not reproduce.  Data files get generated, and the client even runs with JEI; it just leaves me unable to trace through the code. I've already reached out to Mezz on the JEI Discord and he's stumped as well.  If I didn't know better, I'd say that one of the "compileOnly" or "runtimeOnly" directives are being executed when they shouldn't be, but why that would be happening now, or happening only when run in Eclipse, is beyond me.  If anyone knows how to resolve this issue, I would be very grateful.  Thank you, and stay safe.
    • Jos77 adalah situs slot terpercaya yang menawarkan proses pendaftaran dan login yang mudah. Dengan deposit minimal hanya 5000 rupiah, Jos77 membuat perjudian slot online menjadi lebih terjangkau untuk semua orang. Bergabunglah sekarang dan nikmati pengalaman bermain yang seru dan menguntungkan dengan Jos77!  
    • EXTRAWD disini menjadi salah satu situs agen judi slot gacor terpercaya yang memungkinkan pemainnya bisa memenangkan jackpot uang asli dengan mudah setiap harinya. HOEXTRAWD  I77 memiliki berbagai jenis game slot gacor resmi terbaik hari ini yang memungkinkan member untuk menikmati permainan yang menyenangkan dan menarik. Ada banyak variasi permainan yang dapat dipilih mulai dari game jackpot, game mesin slot, dan banyak lagi. Selain itu, disini juga memberikan banyak bonus dan hadiah yang membuat member setia lebih tertarik untuk bermain di agen situs judi slot gacor gampang menang JP Maxwin. EXTRAWD  merupakan platform yang memiliki link demo gratis tanpa daftar dan kini akan memberikan kalian banyak sekali bocoran yang lebih efektif untuk memperoleh kemudahan menang jackpot terbesar dan bisa mencapai puluhan hingga ratusan juta rupiah. Pasti kalian sudah tidak sabar untuk menunggunya bukan? Langsung saja kalian kunjungi EXTRAWD  dimana seluruh permainan dapat memberikan untung ratusan juta bahkan hingga puluhan juta rupiah hanya dengan bet yang rendah. Sebagai tempat bertaruh gampang menang tentu kami memiliki fasilitas terbaik untuk seluruh member setia yang telah bergabung bersama website EXTRAWD  . Anda dapat menikmati berbagai layanan di situs EXTRAWD  yang selalu online 24jam dihadirkan dengan fasilitas seperti anda bisa memaksimalkan setiap bermain dengan mendapatkan kemenangan besar. Maka dari itu tidak ada salahnya jika kini anda bisa untuk mencobanya sekarang juga dengan meraih keuntungan dengan bisa langsung WD sekarang juga. Skema Jackpot ! 8 Provider Slot Gacor Maxwin Hari Ini Demi menyajikan permainan slot gacor online gampang menang berkualitas maka EXTRAWD sebagai situs judi slot online terbaik no 1 di Indonesia berkerja sama dengan beberapa provider slot terbaik. Dan game-game slot dari provider terkemuka ini bisa anda mainkan kapan saja dan dimana saja. Penasaran siapa saja yang membantu menghadirkan game slot gacor maxwin? Berikut adalah daftar 8 provider judi slot online yang wajib untuk dimainkan. Slot Gacor Pragmatic Play Semua player slot pasti sudah mengenal provider slot yang populer ini. Ya dia adalah Pragmatic Play yang merupakan salah satu penyedia game slot gacor terbaik yang masih beroperasi hingga saat ini. Pragmatic Play sangat populer karena produk-produknya terkenal mudah untuk dimainkan. Slot Gacor Habanero Selanjutnya adalah Habanero yang merupakan salah satu pemasok game slot gacor yang populer di Indonesia. Game slot dari Habanero sudah dilengkapi dengan grafik bagus dan efek suara yang terdengar nyata sehingga akan memberikan pengalaman bermain yang lebih menyenangkan. Slot Gacor Joker123 Joker123 atau Joker Gaming adalah salah satu provider yang membantu kami menghadirkan game slot gacor gampang maxwin. Joker123 termasuk salah satu provider yang sudah beroperasi lama dan tentunya bisa dipercaya. Sudah banyak produk slot yang dihadirkan oleh Joker123 ini diminati masyarakat di Indonesia. Slot Gacor Microgaming Sudah tidak diragukan lagi kualitas dari provider slot satu ini. Provider tersebut ialah Microgaming yang telah memproduksi ratusan macam game slot gacor gampang menang JP dengan tema menarik. Banyak slotter yang bersaksi bahwa mereka dapat dengan mudah memperoleh uang tunai bila memainkan game judi slot online dari Microgaming. Slot Gacor Spadegaming Spadegaming sangat cocok untuk kalian yang mencari game judi slot online gacor dengan winrate yang tinggi. Biasanya, para pemain baru akan mencoba game slot spadegaming ini karena sangat mudah dimainkan dan mudah menang. Selain itu, terdapat fitur-fitur bonus yang menarik dan menggiurkan di setiap mesin slot Spadegaming. Slot Gacor Playtech Playtech merupakan sebuah provider slot online yang sedang populer-populernya di tahun 2024 ini karena banyak game dari Playtech yang menarik perhatian para bettor untuk mencobanya. Mungkin salah satu faktornya adalah terdapat hadiah Jackpot yang besar bila memainkan produk slot dari Playtech. Slot Gacor EXTRAWD Slot88 adalah perusahaan penyedia permainan slot terbaik yang populer sejak tahun 2022-2024. Yang menjadi ciri khas dari provider ini ialah anda dapat bermain dengan menggunakan modal yang kecil namun berkesempatan memperoleh uang tunai yang banyak. Tidak heran banyak bettor memfavoritkan permainan slot online EXTRAWD ini. Slot Gacor PG Soft PG Soft atau Pocket Game Soft merupakan provider slot yang sudah lama berdiri dan tetap konsisten menyajikan permainan slot terbaik hingga saat ini. Lebih dari 100 game slot gacor sudah disajikan oleh PG Soft. Selain itu, tidak sedikit bettor yang menyukai game dari PG Soft karena seru dan menguntungkan. Daftar Game Slot Gacor Terbaru Viral di Tahun 2024 Permainan mesin slot gacor telah berkembang dengan pesat saat ini. Berbagai macam game mesin slot terbaru gampang menang tumbuh setiap hari dan permainan ini sering memberikan cuan yang begitu sensasional, menawarkan berbagai macam variasi mesin slot online gacor yang unik dan menarik. Banyak pilihan yang bisa kalian mainkan dari berbagai provider terbaik seperti pragmatic play, EXTRAWD , joker123, playtech dan lain sebagainya. Game online telah menjadi salah satu jenis taruhan yang viral dan sangat populer dikalangan pecintanya. Sehingga Platform EXTRAWD dipenuhi oleh pemain yang berhasil mengumpulkan kemanangan jackpot terbesar yang dapat di withdraw kapan pun. Lalu apa saja sih game yang dimainkan oleh pemainnya untuk mendapatkan kemenangan besar, inilah daftar game yang sering dimainkan di website EXTRAWD : Great Rhino Megaways : RTP 98,01% Aztec Gems : RTP 87,42% Mahjong Ways : RTP 91,06% Koi Gates : RTP 95% Spaceman : RTP 92,85% Madame Destiny : RTP 77,93% Gates of Olympus : RTP 54% Zeus : RTP 96% Gates of Gatot Kaca : RTP 90% Queen of Wands : RTP 94,81% Itulah deretan game slot gacor hari ini gampang menang yang disediakan oleh EXTRAWD dimana hampir seluruh permainan memiliki tingkat kemenangan yang sangat tinggi sehingga diyakini oleh bettor sebagai tempat untuk mencari cuan. Website Slot Gacor Hari ini EXTRAWD Provider Slot Terbaik 🔵 PRAGMATIC PLAY, 🟢 HABANERO SLOT, 🟠 PG SOFT. Game Slot Online Gacor 🔱 Gates Of Olympus, 🍭 Sweet Bonanza Xmas, 🀄️ Mahjong Ways 2, Bonanza Gold 💎. Winrate RTP 98.54% Metode Deposit BCA, BRI, BNI, MANDIRI, CIMB, PULSA, E-Walet (DANA, OVO, GOPAY). Minimal Deposit 💰 Min Deposit Rp 10.000 Minimal WD 💰 Min WD Rp 25.000 BONUS Hoki77 Bonus Deposit Harian 50%, Bonus Mingguan 20%, Bonus New Member 100%, Bonus Referral 100% Link Daftar EXTRAWD Website EXTRAWD
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.