Posted June 26, 20214 yr Hi! I'm trying to add potion effect and particles to entity that is attaching player that wearing special armor. I've already added potion effect and particles to player and it works perfectly fine. What am I doing wrong with entity? @OnlyIn(Dist.CLIENT) @Override public void onArmorTick(ItemStack stack, World world, PlayerEntity player) { world.addParticle(ParticleTypes.SQUID_INK, (double)player.prevPosX, (double)player.prevPosY - 0.15D, (double)player.prevPosZ, 0.01D, 0.01D, 0.01D); if(world.isNightTime()) { player.addPotionEffect(new EffectInstance(Effects.NIGHT_VISION, 40, 0)); } LivingEntity entityIn = player.getAttackingEntity(); if(player.hitByEntity(entityIn)) { entityIn.addPotionEffect(new EffectInstance(Effects.SLOWNESS, 60, 0)); entityIn.addPotionEffect(new EffectInstance(Effects.POISON, 60, 0)); world.addParticle(ParticleTypes.LARGE_SMOKE, (double)entityIn.prevPosX, (double)entityIn.prevPosY + 1D, (double)entityIn.prevPosZ, 0.01D, 0.01D, 0.01D); } }
June 26, 20214 yr Author Thanks, I think I accidently put it there, i've deleted it. I didn't find anything else, I've just searched in available functions of player.(functions that eclipse suggests) and it was the most applicable one. What function should I use instead? It doesn't really matter for me, but if you tell me how to do it anther way, I would be gla-a-ad.
June 26, 20214 yr Author Sorrrrym what I am trying to do: If some mod is attacking player that wear special armor, this attacking mob shoud get posion effect.
June 26, 20214 yr Author Yes, that's logical... I've done that, but I think that I did something wrong. I placed this into my armor class: @SubscribeEvent public void onLivingAttackEvent(LivingAttackEvent event) { event.getEntityLiving().addPotionEffect(new EffectInstance(Effects.WEAKNESS, 700, 1)); event.getEntityLiving().addPotionEffect(new EffectInstance(Effects.SLOWNESS, 700, 1)); event.getEntityLiving().addPotionEffect(new EffectInstance(Effects.POISON, 700, 1 )); } And i have noooo idea how to add particles to this mob.
June 26, 20214 yr Author Yes, I was considering adding it to EventHandler, but I can't figure out how should I check if player is wearing armor or not. I'm adding particles with function addParticle: public class EventHandler { @SubscribeEvent public void onLivingAttackEvent(LivingAttackEvent event) { event.getEntityLiving().addPotionEffect(new EffectInstance(Effects.WEAKNESS, 700, 1)); event.getEntityLiving().addPotionEffect(new EffectInstance(Effects.SLOWNESS, 700, 1)); event.getEntityLiving().addPotionEffect(new EffectInstance(Effects.POISON, 700, 1 )); event.getEntity().world.addParticle(ParticleTypes.CLOUD, (double) event.getEntity().prevPosX, (double) event.getEntity().prevPosY - 0.15D, (double) event.getEntity().prevPosZ, 0.01D, 0.01D, 0.01D); } } P.s. i'm very sorry for my ignorance, but i'm really really want to learn it
June 26, 20214 yr Author Ok, it seems right for me now, but it still doesn't work I've deleted particles line, because I think it's too much for my Java level right now 😕 public class EventHandler { @SubscribeEvent public void onLivingAttackEvent(LivingAttackEvent event) { if (event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.HEAD).getItem() == ItemInit.CUSTOM_HELMET.get()) { event.getEntityLiving().addPotionEffect(new EffectInstance(Effects.WEAKNESS, 700, 1)); event.getEntityLiving().addPotionEffect(new EffectInstance(Effects.SLOWNESS, 700, 1)); event.getEntityLiving().addPotionEffect(new EffectInstance(Effects.POISON, 700, 1 )); } } }
June 26, 20214 yr Author Yea, I was registering it wrong! Now it's: MinecraftForge.EVENT_BUS.register(EventHandler.class); And, of course, I've change my method to static. So it was working, but it was working wrong, because it was adding potion effect to player, so I've changed it to event.getEntityLiving().getAttackingEntity().addPotionEffect(new EffectInstance(Effects.WEAKNESS, 700, 1)); But now it just breaks as soon as mob attacks me. What can be the reason? May be I should fo it through .getLastDamageSource() or something else?
June 27, 20214 yr Author Yea! @SubscribeEvent public static void onLivingAttackEvent(LivingAttackEvent event) { if (event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.HEAD).getItem() == ItemInit.CUSTOM_HELMET.get()) { event.getSource().getTrueSource().getEntity().onKillCommand(); } } It works this way with onKillCommand, but I can't understand how to convert Entity to EntityLiving, because I can add potion effects only to EntityLiving.
June 29, 20214 yr Author Thank you! It works! In case someone need the same thing, here is the right code: @SubscribeEvent public static void onLivingAttackEvent(LivingAttackEvent event) { if (event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.HEAD).getItem() == ItemInit.CUSTOM_HELMET.get()) { if (event.getSource().getTrueSource().getEntity() instanceof MobEntity) { ((MobEntity)event.getSource().getTrueSource().getEntity()).addPotionEffect(new EffectInstance(Effects.SLOWNESS, 700, 1)); ((MobEntity)event.getSource().getTrueSource().getEntity()).addPotionEffect(new EffectInstance(Effects.WEAKNESS, 700, 1)); } } } But for some reason I can add Poison or Instance damage to mobs 😕 it simply doesn't appear in the game
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.