Jump to content

[Solved][1.10.2] Potion metadata for 1.10


jabelar

Recommended Posts

Okay, so I'm continuing to port my mods from 1.8 to 1.10 and have come up with another thing I can't seem to figure out.

 

In my mod I generate a structure that has loot in it, in this case there is a brewing stand where the inventory already contains some potions.

 

To create the potions, previously in 1.8 and earlier it worked fine to do the following:

 

theTileEntity.setInventorySlotContents(slot, new ItemStack(Items.POTIONITEM, 1, 8259)); // should be fire breathing

 

However, now in 1.10 when I open the brewing stand inventory it shows pink and black default textures in the slot where I put the potion, and if I hover over it says that it is water with no effect.

 

Looking at how potions are created in the 1.10 vanilla source, I see that it now has a registry and is doing combinations with potion type to create a unique id.

 

Anyway what is the proper way in 1.10 to create an ItemStack containing a fire resistance potion?

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Potion.REGISTRY.getObject(new ResourceLocation("fire_resistance"));

This is what I would try to use (I don't know, if it works)

And then I would do the Stack like this:

int id = Potion.REGISTRY.getObject(new ResourceLocation("fire_resistance"));
theTileEntity.setInventorySlotContents(slot, new ItemStack(Items.POTIONITEM, 1, id));

Bringing the best mod back alive! Our mod REFORGED!

Balkon's Weapons for 1.8: https://github.com/TheOnlySilverClaw/Reforged/releases

Link to comment
Share on other sites

Well, I tried some similar ideas.

 

Your idea doesn't really work because getObject() returns something like "net.minecraft.potion.Potion@919086". And even if I just used the 919086 part it wouldn't be a proper potion metadata.

 

There is though ways to get an id for the potion type using PotionType.getID(PotionTypes.FIRE_RESISTANCE) but that isn't a full potion definition since it could be strong, could be splash, etc. I'm pretty sure that doesn't give the metadata value. But could be wrong.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Potion items don't use metadata any more, they use NBT. Standard, splash and lingering potions are now separate

Item

s that use the same NBT format. Tipped arrows also use this format for their effects.

 

There is now the concept of a

PotionType

, which is a singleton collection of zero or more

PotionEffect

s (e.g.

PotionTypes.LONG_FIRE_RESISTANCE

, 8 minutes of Fire Resistance). Vanilla stores its

PotionType

s in the

PotionTypes

class and its

Potion

s in the

MobEffects

class.

 

A potion item may have either zero or one

PotionType

as well as zero or more custom

PotionEffect

s. Use

PotionUtils.addPotionToItemStack

to set the

PotionType

of a potion

ItemStack

and

PotionUtils.appendEffects

to add custom

PotionEffect

s to a stack.

 

Use

PotionUtils.getEffectsFromStack

to get all

PotionEffect

s from a potion

ItemStack

. This includes both the

PotionType

's effects and the custom effects.

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

Thanks, it definitely seems that things have changed a lot. So I'm still a bit lost on how to simply create an ItemStack containing a specific potion. ItemStack still takes metadata so I need to convert to that, I think, unless there is some other potion util method for creating item stacks. The mob effects class seems to contain the basic effect (like FIRE_RESISTANCE) but not the combined (strong and long-lasting).

 

Sorry for asking to be spoon-fed but it I tried various combinations of mob effects and potion classes and methods and can't seem to create an item stack for strong long-lasting fire resistance...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Thanks, it definitely seems that things have changed a lot. So I'm still a bit lost on how to simply create an ItemStack containing a specific potion. ItemStack still takes metadata so I need to convert to that, I think, unless there is some other potion util method for creating item stacks. The mob effects class seems to contain the basic effect (like FIRE_RESISTANCE) but not the combined (strong and long-lasting).

 

Sorry for asking to be spoon-fed but it I tried various combinations of mob effects and potion classes and methods and can't seem to create an item stack for strong long-lasting fire resistance...

This may not be the best way to do it, but you could add the NBT directly because all it does it look for a certain tag.

I happened to stumble across this in PotionUtils

PotionType.getPotionTypeForName(tag.getString("Potion"))

Mainly the tag.getString("potion") part which you could set to the PotionType name which does contain LONG and STRONG in there names.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Thanks, it definitely seems that things have changed a lot. So I'm still a bit lost on how to simply create an ItemStack containing a specific potion. ItemStack still takes metadata so I need to convert to that, I think, unless there is some other potion util method for creating item stacks. The mob effects class seems to contain the basic effect (like FIRE_RESISTANCE) but not the combined (strong and long-lasting).

 

Sorry for asking to be spoon-fed but it I tried various combinations of mob effects and potion classes and methods and can't seem to create an item stack for strong long-lasting fire resistance...

 

Create the

ItemStack

with metadata 0, then use the

PotionUtils

methods to set its NBT. The potion code itself doesn't care what the metadata is (all the effects are stored in NBT), but vanilla only registers the item models for metadata 0 (so other metadata values will be rendered as the missing model).

 

Vanilla doesn't allow you to brew Strong Fire Resistance (because the amplifier doesn't do anything), so there's no

PotionType

for it. Vanilla doesn't allow you to brew a potion that's both Strong and Long, so there are no

PotionType

s for it.

 

If you want to use an effect that doesn't have a

PotionType

registered for it, you can either create and register your own

PotionType

(using

GameRegistry.register

, like other

IForgeRegistryEntry

singletons) or add the

PotionEffect

directly to the potion

ItemStack

.

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



×
×
  • Create New...

Important Information

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