player.curePotionEffects()
. Также как в молоке(MilkBucketItem
)Переопредели в своем эффекте getCurativeItems, возвращай пустой списокчтобы эффект не лечился молоком
Ловить событиекогда эффект выдохнется
PotionRemoveEvent
и PotionExpiryEvent
А если эффект будет снят чем-нибудь (в моде будет лекарство), а не истечёт время?Ловить событие PotionRemoveEvent
PotionRemoveEvent
вызывается при удалении до истечения, а PotionExpiryEvent
по истечению@SubscribeEvent
public void onZombieVirusExpired(PotionEvent.PotionExpiryEvent event) {
if(event.getPotionEffect().getEffect() == PotionsRegistry.POTION_ZOMBIE_VIRUS) {
event.getEntity().hurt(DamageSource.WITHER, Float.MAX_VALUE);
}
}
@Override
public List<ItemStack> getCurativeItems() {
List<ItemStack> cure=new ArrayList<ItemStack>();
cure.add(new ItemStack(Items.PUFFERFISH));
return(cure);
}
player.curePotionEffects()
. Также как в молоке(MilkBucketItem
)public class ItemAntizombine extends Item {
public ItemAntizombine() {
super(new Properties().food(
new Food.Builder()
.alwaysEat()
.build()));
}
//То же, что у молока, только вместо ведра бутылка
@Override
public ItemStack finishUsingItem(ItemStack p_77654_1_, World p_77654_2_, LivingEntity p_77654_3_) {
if (!p_77654_2_.isClientSide) p_77654_3_.curePotionEffects(p_77654_1_); // FORGE - move up so stack.shrink does not turn stack into air
return p_77654_1_.isEmpty() ? new ItemStack(Items.GLASS_BOTTLE) : p_77654_1_;
}
@Override
public UseAction getUseAnimation(ItemStack p_77661_1_) {
return UseAction.DRINK;
}
}
public class PotionZombieVirus extends Effect {
public PotionZombieVirus(EffectType type, int color) {
super(type, color);
}
public boolean isReady(int duration, int amplifier) {
return duration <= 1;
}
public void performEffect(LivingEntity entity, int amplifier) {
}
@Override
public List<ItemStack> getCurativeItems() {
List<ItemStack> cure=new ArrayList<ItemStack>();
cure.add(new ItemStack(ModItems.ANTIZOMBINE.get()));
return(cure);
}
}
player.removeEffectNoUpdate(effect)
player.removeEffectNoUpdate(effect)
снимает эффект, но он возвращается спустя некоторое время!