Jump to content

Recommended Posts

Posted

How do I make custom potions? I want it to follow the bottle format ie be drinkable and then return an empty bottle.

 

Here is what I want to do:

1) Decide how it is crafted

2) Decide its various duration and amplifiers (on my own, I don't want MCForge to just do it for me)

3) Decide what happens upon drinking the potion

4) Set my own textures

Posted

There's an entire BrewingRecipe class now. Take a look at it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

You need to distinguish between

Potion

and

PotionType

.

Potion

is a single effect, like slowness.

PotionType

is a brewable potion with one or multiple effects (= Potions) on it. E.g.: Slowness II for 3 minutes.

 

Right, so I create a single potion, and I derive multiple PotionTypes from it?

 

If you want a custom effect type, create a subclass of the Potion class. First decide if it as an instant potion or a long-term effect, you do this via the

isInstant

method. If your effect is instant, affectEntity will be called when it is applied to an entity.

If it is not instant, isReady will be called every tick while the potion is active. The parameters are remaining duration in ticks and the amplifier (e.g. Slowness II). If isReady returns true, performEffect will also be called that tick.

Moreover for non-instant effects applyAttributesModifiersToEntity will be called when your potion starts affecting an entity and removeAttributesModifiersFromEntity will be called when the effect runs out.

 

I got this, but what is the difference between isReady and performEffect?

 

If you now want your effect in a brewable potion, create a PotionType first. This PotionType captures the PotionEffect (=effect type, duration, amplifier). To create an ItemStack of your new PotionType use PotionUtils.addPotionToItemStack(new ItemStack(Items.potionitem), <PotionType>). You can use Items.splash_potion or Items.lingering_potion instead to create a splash, resp. lingering potion.

 

Once you have the PotionType you can create a BrewingRecipe that produces an ItemStack for your PotionType.

 

To register both your Potion and the PotionType call setRegistryName on them and register them using GameRegistry.register.

 

Well see here's the thing. I don't want my potion to be craftable by vanilla methods (crafting table/furnace/brewing stand), but I do want it to be craftable through my own methods.

a) So would I create a PotionType or not?

b) If not, how do I go about the registration stuff?

c) Also, will registering automatically create the bottle(s) for me?

 

What kind of textures do you mean?

I mean this: http://www.minecraftopia.com/images/blocks/potion_of_swiftness.png and also the potion effect icon, like in this: https://i.gyazo.com/3ce9e9d573bfe34cb599424877b50815.png

 

To help you answer these questions, I'll try and tell you what I want to do. I want to create custom potion effects, with various amplifiers (I, II, III), durations (1:00, 2:00 etc), splash and lingering type, BUT I DON'T WANT IT TO BE BREWABLE/CRAFTABLE. I want to handle the crafting on my own, possibly through PotionUtils.addPotionToItemStack(new ItemStack(Items.potionitem), <PotionType>).

Posted

Right, so I create a single potion, and I derive multiple PotionTypes from it?

If you were to have e.g. MyPotion I and MyPotion II (different amplifiers): Yes.

 

I got this, but what is the difference between isReady and performEffect?
isReady does not have the entity available or anything. isReady is designed to allow use-cases like "this potion does something every 10 ticks". Then you can keep this counting logic out of performEffect. But technically only performEffect is needed. I just mention isReady because it returns false by default for non-vanilla potions, so your performEffect will never be called if you do not override isReady.

 

Well see here's the thing. I don't want my potion to be craftable by vanilla methods (crafting table/furnace/brewing stand), but I do want it to be craftable through my own methods.

a) So would I create a PotionType or not?

Yes.

c) Also, will registering automatically create the bottle(s) for me?

What do you mean by "create"?

 

There is not an easy (compatible) way to set this except making your own item, which would not be a vanilla potion anymore.

and also the potion effect icon, like in this: https://i.gyazo.com/3ce9e9d573bfe34cb599424877b50815.png

Override renderInventoryEffect in your Potion class.

 

I suppose a good example for "create" would be Forge's UniversalBucket system, afaik there's a method in FluidRegistry that creates a UniversalBucket for you given a fluid. Is there a version of this with potions? Like it creates all the potion bottles given the PotionType(s)?

 

Also I didn't really understand what you meant by "There is not an easy (compatible) way to set this except making your own item, which would not be a vanilla potion anymore.". Could you please explain again?

Posted

I suppose a good example for "create" would be Forge's UniversalBucket system, afaik there's a method in FluidRegistry that creates a UniversalBucket for you given a fluid. Is there a version of this with potions? Like it creates all the potion bottles given the PotionType(s)?
Right. ItemPotion does this in getSubItems. It iterates all registered PotionTypes and adds them to the creative tab.

Also I didn't really understand what you meant by "There is not an easy (compatible) way to set this except making your own item, which would not be a vanilla potion anymore.". Could you please explain again?

I actually did some investigation again and the following hack should work:

 

  • Create a static final field holding a
    ResourceLocation

    . Call it something like "mymod:is_xyz_potion".
     

  • Create a class implementing
    IItemPropertyGetter

    . From the sole method inside it return

    1

    if the passed in ItemStack is your potion,

    0

    otherwise. Register a new instance of this class from preInit in your client proxy using

    Items.potionitem.addPropertyOverride(<RL from step 1>, <property getter instance>)

    .
     

  • Subscribe to
    ModelBakeEvent

    . In there get the vanilla potion model using

    event.getModelRegistry().getModel(new ModelResourceLocation("bottle_drinkable", "inventory"))

    . Get it's

    ItemOverrideList

    using

    getOverrides

    . Reflectively get the field

    ItemOverrideList#overrides

    and add your own

    ItemOverride

    into it. To create the

    ItemOverride

    use

    new ItemOverride(<ModelResourceLocation that points to your desired potion model>, ImmutableMap.of(<RL from step 1>, 1f))

    .
     

  • Tell Minecraft to load your model by calling
    ModelBakery.registerItemVariants

    with the ModelResourceLocation for your model in preInit from your ClientProxy.

 

So that RL from step 1 can be anything? Does it need to correspond to some name?

Posted

So that RL from step 1 can be anything? Does it need to correspond to some name?

It can be anything. It is simply an identifier for the
IItemPropertyGetter

so that the

ItemOverride

can reference it. You can name it whatever you want as long as you keep your ModID as the resource domain (to avoid clashes).

 

Gotcha. Thanks for explaining everything to me.

 

Also,

 

Right. ItemPotion does this in getSubItems. It iterates all registered PotionTypes and adds them to the creative tab.

 

Do I need to call this method from somewhere, or is it automatically done?

Posted

Do I need to call this method from somewhere, or is it automatically done?

This happens automatically. Any registered PotionType produces an entry in the creative tab.

 

Thanks for all the help :)

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.