Jump to content

[1.12.2] [SOLVED] How can I write capability data into a splash potion fired from a dispenser?


WilliHay

Recommended Posts

So, here's the situation: I have injected a capability into a TileEntityDispenser so that I can store some data there, for example a BlockPos. When the dispenser fires a splash potion or tipped arrow that has a custom potion effect of mine, I want to pass this BlockPos data over to these projectiles. (For context, the potion effect is "teleportation" and the BlockPos data that is being transferred are the coordinates where a target that's hit by the projectile should be teleported.)

 

My two-part question is:

1) How do I transfer this data to the potion or tipped arrow when the dispenser fires it?

I looked at using BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY#putObject, but this would seem to require me to register a new Item, and I didn't have to create a new Item for the potion or arrow. I only created a new potion and potion effect.

 

2) Let's say I figure the first part out and I'm able to store the BlockPos data in the EntityPotion and EntityTippedArrow as capability data. When the potion or arrow hits a living target, how/when do I call my teleport method?

Normally the way I do this, when it's a player who throws the potion or shoots the arrow, is call my teleport method from the #affectEntity or #performEffect method in my potion class which extends PotionBase. Those methods allow me to get the player who threw the potion or fired the arrow and read the teleport destination data using a custom capability I injected into EntityPlayer. But in this case when the dispenser throws these projectiles, the dispenser that fired them is not available in those potion methods, i.e. the "attacking entity" is null. So I think I need another way to call my teleport method with the BlockPos data stored in the potion or arrow, but how?

 

Edited by WilliHay
problem solved
Link to comment
Share on other sites

Here's the solution I eventually came up with, in case it helps anyone in the future. The strategy centers on creating a new Item for a new Dispense Behavior, which I think is the right approach in this case.

 

  • Create a new ItemTeleportationSplashPotion that extends Item (not ItemPotion, for reasons below).
  • Create a corresponding EntityTeleportationSplashPotion that extends EntityThrowable. (Registered it using an EntityEntry created from EntityEntryBuilder.)
  • Create a simple item renderer for this entity that extends RenderSnowball.
  • Register a brewing recipe that creates the "splash potion" item (with an Empty PotionType) so I can still use the brewing stand.
  • Then I was able to register a new dispense behavior for the new item in BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject, based on BehaviorProjectileDispense, which is able to create my custom EntityTeleportationSplashPotion using the parameters I need to transfer important information about the dispenser that was missing from the vanilla splash potion dispense behavior.
  • Namely: the constructor for this potion entity stores the IBlockSource that identifies the specific dispenser that threw my potion.
  • On impact, I now have the information I need to perform the teleportation on all nearby entities, using the capability I added to the vanilla dispenser to read the teleport destination data that's stored there.

I tried first simply extending ItemSplashPotion while using a custom TELEPORTATION PotionType but that meant I'd have to deal with all the vanilla potions of teleportation that get automatically created when you do that. Then I realized - I really only needed the splash potion. The regular and lingering versions didn't really add anything to my mod, especially since I already have a Wand of Teleportation for teleporting yourself. So my custom throwable item was the end result.

 

It's a lot of fun now to create teleportation traps for unsuspecting mobs (and players), sending them to all kinds of creative places. :)

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

    • AGENSLOT77 dikenal sebagai salah satu situs judi slot gacor terpercaya. Istilah "gacor" merujuk pada mesin slot yang sering memberikan kemenangan kepada pemainnya. Dengan koleksi permainan slot yang beragam dan canggih, AGENSLOT77 memberikan kesempatan besar bagi para pemain untuk meraih kemenangan yang menggiurkan. 2. Slot88 Terpercaya Slot88 merupakan salah satu permainan slot paling populer di AGENSLOT77. Dengan desain yang menawan dan pembayaran yang besar, Slot88 menjadi favorit di antara pemain judi online. Malam ini, para pemain dapat menikmati berbagai permainan Slot88 yang menarik dan menguntungkan di AGENSLOT77. 3. Peluang Maxwin Malam Ini AGENSLOT77 menawarkan peluang Maxwin yang menarik, terutama malam ini. Dengan fitur yang mudah dimengerti dan diakses, pemain memiliki kesempatan besar untuk meraih kemenangan maksimum dalam setiap permainan yang mereka mainkan. Jadi, jangan lewatkan kesempatan untuk memenangkan hadiah besar di AGENSLOT77 malam ini!   ❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰  
    • Javatogel: Agen BO Terpercaya, Anti Sedot WC, 100% Real, Gampang Menang Dalam dunia perjudian online, menemukan agen yang dapat dipercaya adalah langkah penting untuk pen galaman berjudi yang aman dan menguntungkan. Salah satu agen yang mendapat kepercayaan tinggi dari para pemain adalah Javatogel. Mari kita telusuri lebih dalam mengenai apa yang membuat Javatogel menjadi pilihan utama bagi para pecinta togel. Javatogel: Agen BO Terpercaya                                   DAFTAR SEKARANG AKUN VIP MAXWIN
    • S1288POKER Rasakan sensasi bertaruh Mix Parlay yang tak terlupakan dengan bonus fantastis di situs judi terpercaya kami! Kami menawarkan bonus Mix Parlay terbesar di Asia dengan berbagai pilihan taruhan dan minimal deposit rendah. Dapatkan bonus hingga jutaan rupiah untuk taruhan Mix Parlay Anda dan nikmati keuntungan berlipat ganda.
    • Situs Akun Pro Peru adalah pilihan terbaik bagi Anda yang mencari situs terpercaya untuk bermain slot dan taruhan bola. Berikut adalah beberapa alasan mengapa Anda harus memilih Situs Akun Pro Peru: Slot Populer Kami menyajikan koleksi slot yang populer dan menarik dengan berbagai tema yang beragam. Dari slot klasik hingga slot video modern, setiap pemain dapat menemukan permainan favorit mereka dengan mudah. Taruhan Bola Terpercaya Selain slot, kami juga menyediakan taruhan bola dengan pasaran terlengkap dan odds yang kompetitif. Dengan berbagai pertandingan dan liga yang tersedia, Anda dapat menikmati pengalaman taruhan bola yang seru dan menguntungkan. Transaksi Mudah dengan Bank BTN Kami menyediakan layanan transaksi yang mudah dan aman melalui Bank BTN. Dengan dukungan dari sistem pembayaran yang terpercaya, Anda dapat melakukan deposit dan penarikan dana dengan cepat dan tanpa hambatan.  
    • Ngamenslot adalah pilihan terbaik bagi Anda yang mencari situs terpercaya untuk bermain slot dan taruhan bola. Berikut adalah beberapa alasan mengapa Anda harus memilih Ngamenslot: Kombinasi Slot & Bola Kami menyajikan kombinasi terbaik antara permainan slot yang seru dan taruhan bola yang menegangkan. Dengan pilihan permainan yang beragam, setiap pemain dapat menikmati pengalaman bermain yang unik dan menyenangkan. Transaksi Mudah melalui Bank Ekonomi Kami menyediakan layanan transaksi yang mudah dan aman melalui Bank Ekonomi. Dengan dukungan dari sistem pembayaran yang terpercaya, Anda dapat melakukan deposit dan penarikan dana dengan cepat dan tanpa hambatan. Terpercaya dan Terjamin Ngamenslot telah terbukti sebagai situs terpercaya dengan ribuan pemain yang puas. Kami mengutamakan keamanan dan kenyamanan para pemain, sehingga Anda dapat bermain dengan tenang dan fokus pada permainan.  
  • Topics

×
×
  • Create New...

Important Information

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