Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How can I make my mob completely invincibile to all types of damage [1.17]

Featured Replies

Posted

I found one method on Entity class called isInvulnerable, I used it but it doesn't work any tips

  • Author
public class Electricity extends Zombie implements IAnimatable
{

    public static final EntityDataAccessor<Integer> STATE = SynchedEntityData.defineId(Electricity.class, EntityDataSerializers.INT);
    private boolean invulnerable;

    private int lifeTicks = 42;

    private final AnimationFactory factory = new AnimationFactory(this);

    private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event)
    {
            event.getController().setAnimation(new AnimationBuilder().addAnimation("lightning", true));
            return PlayState.CONTINUE;
    }
    @Override
    public void registerControllers(AnimationData data)
    {
        data.addAnimationController(new AnimationController<Electricity>
                (this, "controller", 0, this::predicate));
    }

    @Override
    public AnimationFactory getFactory()
    {
        return this.factory;
    }

    public Electricity(EntityType<? extends Zombie> p_i48549_1_, Level p_i48549_2_)
    {
        super(p_i48549_1_, p_i48549_2_);
    }

    public static AttributeSupplier.Builder createAttributes()
    {
        return Mob.createMobAttributes()
                .add(Attributes.MAX_HEALTH, 1000.0D)
                .add(Attributes.MOVEMENT_SPEED, 0.0D)
                .add(Attributes.ATTACK_DAMAGE, 25.0D)
                .add(Attributes.FOLLOW_RANGE, 45.0D)
                .add(Attributes.SPAWN_REINFORCEMENTS_CHANCE);
    }


    @Override
    public boolean doHurtTarget(Entity entityIn)
    {
        if (!super.doHurtTarget(entityIn))
        {
            return false;
        }
        else
        {
            if (entityIn instanceof LivingEntity)
            {
                ((LivingEntity)entityIn).addEffect(new MobEffectInstance(MobEffects.CONFUSION, 140));
            }
            return true;
        }
    }

    @Override
    protected void defineSynchedData()
    {
        super.defineSynchedData();
        this.entityData.define(STATE, 0);
    }

    @Override
    protected void registerGoals()
    {
        super.registerGoals();
        this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true));
        this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Monster.class, false));
        this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, FlyingMob.class, false));
        this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Animal.class, false));
    }


    public boolean isInvulnerableTo(DamageSource p_20122_) {
        return this.isRemoved() || this.invulnerable && p_20122_ != DamageSource.OUT_OF_WORLD && !p_20122_.isCreativePlayer();
    }

    public boolean isInvulnerable() {
        return this.invulnerable;
    }

    public void setInvulnerable(boolean p_20332_) {
        this.invulnerable = p_20332_;
    }
    @Nullable
    @Override
    protected SoundEvent getHurtSound(@Nonnull DamageSource damageSourceIn)
    {
        this.playSound(SoundEvents.GHAST_HURT, 0.0F, 0.0F);
        return null;
    }

    @Nullable
    @Override
    protected SoundEvent getDeathSound()
    {
        this.playSound(SoundEvents.LIGHTNING_BOLT_IMPACT, 7.0F, 1.0F);
        this.playSound(SoundEvents.LIGHTNING_BOLT_IMPACT, 7.0F, 1.0F);
        this.playSound(SoundEvents.LIGHTNING_BOLT_IMPACT, 7.0F, 1.0F);
        this.playSound(SoundEvents.LIGHTNING_BOLT_IMPACT, 7.0F, 1.0F);
        return null;
    }

    @Nullable
    @Override
    protected SoundEvent getAmbientSound()
    {
        this.playSound(SoundEvents.LIGHTNING_BOLT_THUNDER, 7.0F, 1.0F);
        this.playSound(SoundEvents.LIGHTNING_BOLT_THUNDER, 7.0F, 1.0F);
        this.playSound(SoundEvents.LIGHTNING_BOLT_THUNDER, 7.0F, 1.0F);
        this.playSound(SoundEvents.LIGHTNING_BOLT_THUNDER, 7.0F, 1.0F);
        this.playSound(SoundEvents.LIGHTNING_BOLT_THUNDER, 7.0F, 1.0F);
        return null;
    }

    public void tick()
    {
        super.tick();
            if (--this.lifeTicks < 0)
            {
                this.remove(RemovalReason.DISCARDED);
            }
    }

    @Override
    public boolean isBaby()
    {
        return false;
    }

    @Override
    public boolean isPushable()
    {
        return false;
    }

    @Override
    protected void pushEntities()
    {
    }
}

There it is

  • Author
5 minutes ago, diesieben07 said:

This is not how you use these methods. Do not play sounds in these methods.

 

Why did you copy-paste this from the Entity class? Doing this makes zero sense and achieves nothing. If you want your entity to actually be invulnerable, you need to either call setInvulnerable(true) from the constructor or override isInvulnerable and isInvulnerableTo to always return true. The difference is that the first options allows users to still override it using e.g. the data command.

Oh my goodness I actually forgot I could do that I apologize but thank you again!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.