#how do i get Potion from an ItemStack

46 messages · Page 1 of 1 (latest)

fallow river
#

i have the itemstack and i know its a potion but i dont know how im supposed to turn it into a potion

alpine comet
#

probably components

fallow river
#

that only tells if its lingering and stuff

exotic grotto
fallow river
#

wait but how do i get it then

#

the constructor asks for potion

alpine comet
#

bro?

high gyro
#

!!learnjava

errant sigilBOT
#

To start modding Minecraft using Fabric, it's strongly recommended to know Java.
Minecraft, in its codebase, and mods, using Fabric API, use more advanced Java concepts like lambdas, generics and polymorphism.
If you don't know all of these concepts, you may have some difficulties modding.

Here are some online resources that will help learning Java
JetBrains Academy (free online course): https://www.jetbrains.com/academy/
Codecademy (free online course): https://www.codecademy.com/learn/learn-java
University of Helsinki (free online course): https://java-programming.mooc.fi/
Basic Java Tutorials: https://docs.oracle.com/javase/tutorial/
Introduction to Programming using Java by David J. Eck (free online textbook): http://math.hws.edu/javanotes/

After Learning Java
For most mods you will want to make, you will have to use the Spongepowered Mixin Java library.
To learn more about Mixin, you can use the faq/mixin bot tag by typing !!faq/mixin in #bot-posting .

fallow river
high gyro
high gyro
#

ItemStack#get

fallow river
high gyro
fallow river
#

right hand man was right

#

nope

high gyro
sour harbor
#

stack.getItem() instanceof PotionItem

alpine comet
#

no

sour harbor
#

?
yes

alpine comet
#

try to get the potion from an potionitem without using components

#

i dare you

alpine comet
#

get the Potion from an PotionItem instance

#

without components

#

its not possible

#

components are the way

sour harbor
#

ok?
the op asked how to check if an itemstack is a potion

alpine comet
#

"how do i get Potion from an ItemStack"

sour harbor
#

exactly

#

so i answered

alpine comet
#

he knows its a potion

#

theres no need for an instanceof check

sour harbor
#

then maybe he should word his question better

alpine comet
#

?? its worded perfectly fine

#

he wants to get a Potion instance from an ItemStack

sour harbor
sour harbor
alpine comet
#

its already answered

#

you use the POTION_CONTENTS DataComponentType

sour harbor
#

alr