MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"Creates an effect that eliminates damage taken to the player if struck by lightning"
/* This mod creates an effect that eliminates damage taken by the player if struck by lightning. */ public class LightningResistanceEffect extends Effect { public LightningResistanceEffect() { super(EffectType.BENEFICIAL, 0xFFFFFF); } @Override public void applyEffectTick(LivingEntity entity, int amplifier) { if (entity.level.isClientSide) return; // Only run on server side // Check if the entity is a player and if they were struck by lightning if (entity instanceof PlayerEntity && entity.getLastDamageSource() != null && entity.getLastDamageSource().isLightningBolt()) { // Negate the damage entity.heal(entity.getLastDamageSource().getAmount()); } } @Override public boolean isDurationEffectTick(int duration, int amplifier) { return true; // Apply the effect every tick } } /* Now you will need to register your effect. This can be done in a similar way to registering blocks and items. */ public class ModEffects { public static final DeferredRegister<Effect> EFFECTS = DeferredRegister.create(ForgeRegistries.POTIONS, "modid"); public static final RegistryObject<Effect> LIGHTNING_RESISTANCE = EFFECTS.register("lightning_resistance", LightningResistanceEffect::new); } /* Don't forget to add your effect to an item or a potion so that players can actually obtain it. */