MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"Create a sword that makes you immune to lightning damage"
/* This mod creates a sword that makes the player immune to lightning damage. */ public class LightningImmunitySword extends SwordItem { public LightningImmunitySword(IItemTier tier, int attackDamageIn, float attackSpeedIn, Properties builder) { super(tier, attackDamageIn, attackSpeedIn, builder); } @Override public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if (entityIn instanceof PlayerEntity && isSelected) { /* Make the player immune to lightning damage */ ((PlayerEntity) entityIn).addEffect(new MobEffectInstance(MobEffects.LIGHTNING_IMMUNITY, 20, 0, false, false, true)); } } } /* You would also need to create a custom MobEffect that makes an entity immune to lightning damage. This is just a placeholder and may not actually work. */ public class LightningImmunityEffect extends MobEffect { public LightningImmunityEffect() { super(MobEffectCategory.BENEFICIAL, 0xFFFFFF); } @Override public void applyEffectTick(LivingEntity entity, int amplifier) { /* Prevent lightning damage */ if (entity.getLastDamageSource() instanceof LightningBoltEntity) { entity.setHealth(entity.getHealth() + entity.getLastDamage()); } } @Override public boolean isDurationEffectTick(int duration, int amplifier) { return true; // Apply the effect every tick } }