Jump to content

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


Recommended Posts

Posted (edited)

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
Posted

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. :)

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

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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