#giving an item stack nbt
10 messages · Page 1 of 1 (latest)
For the detection this should work.
ItemStack item = player.getMainHandStack();
if (item != null && item.getItem() instanceof PotionItem) {
System.out.println("Used bottle");
}
return ActionResult.PASS;
});```
yeah but won't that react to every type of potion?
yes, you are right, i'm getting the Potion component type
ItemStack item = player.getMainHandStack();
PotionContentsComponent potionContentsComponent = item.getOrDefault(DataComponentTypes.POTION_CONTENTS, PotionContentsComponent.DEFAULT);
if (item != null && item.getItem() instanceof PotionItem && !potionContentsComponent.hasEffects()) {
System.out.println("Water bottle used");
}
return ActionResult.PASS;
});```
thank you very much, i'll try that out
Simple way I think but only checks for Water Bottle only, not Mundane, Awkward etc
ItemStack item = player.getMainHandStack();
PotionContentsComponent potionContentsComponent = item.get(DataComponentTypes.POTION_CONTENTS);
if (potionContentsComponent != null && potionContentsComponent.matches(Potions.WATER)) {
System.out.println("Water bottle used");
}
return ActionResult.PASS;
});```
and what about when i would like to give the player a water potion too? how would that work?
you mean how to create a water bottle stack?
ItemStack itemStack = new ItemStack(Items.POTION);
itemStack.set(DataComponentTypes.POTION_CONTENTS, new PotionContentsComponent(Potions.WATER));
return itemStack;
}```