#[Fabric] [1.20.1] Custom Item CustomPotionEffects duration changes after attacking mobs.

4 messages · Page 1 of 1 (latest)

violet field
#

Bug shown in the video. The potion effect duration is decreasing after hitting a mob, and decreasing even faster after hitting several mobs. World restart doesn't fix it, I need to close the game or create a new item. What can be a problem? I can't find it even with debug.

#

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());
    }
}
dusky wing
#
        effects = effects
                        .stream()
                        .map(StatusEffectInstance::new)
                        .toList();
#

@violet field