Here is my code so far, I have managed to make it give the potion effects to the entity (the poison effect does not do any damage). My problem is my custom damage sources are not working, they do not do any damage to the player with the item in their inventory. The identifier of the damage source is the same as the in game item, I'm not sure whether that is the problem. All this is inside my main mod class.
public static final DamageSource NOVICHOK_DAMAGE = new DamageSource("novichok");
@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent e) {
if (!e.player.world.isRemote) return;
if (e.player.inventory.hasItemStack(new ItemStack(RegistryHandler.NOVICHOK_RAW.get()))) {
e.player.addPotionEffect(new EffectInstance(Effects.POISON, 1000, 5));
e.player.addPotionEffect(new EffectInstance(Effects.NAUSEA, 1000, 5));
if((e.player.getHealth()-0.05) < 0) {
//e.player.
e.player.attackEntityFrom(NOVICHOK_DAMAGE, 1.0F);
} else {
//e.player.playSound();
e.player.attackEntityFrom(NOVICHOK_DAMAGE, 1.0F);
}
//e.player.setHealth((float) (e.player.getHealth()-0.05));
} else {
e.player.removeActivePotionEffect(Effects.POISON);
e.player.removeActivePotionEffect(Effects.NAUSEA);
}
}
Any help with this would be greatly appreciated.