#[Fabric] [1.20.1] Custom Item CustomPotionEffects duration changes after attacking mobs.
4 messages · Page 1 of 1 (latest)
Code of item:
public class ThrowingDartItem extends TippedArrowItem {
public ThrowingDartItem(Settings settings) {
super(settings);
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack itemStack = user.getStackInHand(hand);
world.playSound(null, user.getBlockPos(), ExperimentMod.POISON_DART_THROW, SoundCategory.NEUTRAL, 0.5f, 1.0f);
if (!world.isClient) {
PoisonDartEntity poisonDart = new PoisonDartEntity(world, user);
poisonDart.setVelocity(user, user.getPitch(), user.getYaw(), 0.0f, 3.0f, 1.0f);
poisonDart.setDamage(poisonDart.getDamage());
poisonDart.setItem(itemStack);
Potion potion = PotionUtil.getPotion(itemStack);
if (potion != null) {
List<StatusEffectInstance> effects = potion.getEffects();
poisonDart.addEffects(effects);
}
world.spawnEntity(poisonDart);
user.incrementStat(Stats.USED.getOrCreateStat(this));
if (!user.getAbilities().creativeMode) {
itemStack.decrement(1);
}
}
return TypedActionResult.success(itemStack, world.isClient());
}
}