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



×
×
  • Create New...

Important Information

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