Jump to content

Recommended Posts

Posted

I have a mob. I would like it to have a boss bar when it spawns.
I also have a structure, I would like that when I enter it, this boss will spawn in it at a certain point.
And if possible, how to make the boss not go beyond the structure?

public class Anubis extends Monster implements IAnimatable {
    private AnimationFactory factory = new AnimationFactory(this);

    public Anubis(EntityType<? extends Monster> entityType, Level level) {
        super(entityType, level);
    }

    public static AttributeSupplier setAttributes() {
        return Monster.createMobAttributes()
                .add(Attributes.MAX_HEALTH, 400D)
                .add(Attributes.ARMOR, 10D)
                .add(Attributes.ATTACK_DAMAGE, 20D)
                .add(Attributes.ATTACK_SPEED, 5f)
                .add(Attributes.MOVEMENT_SPEED, 0.2f).build();
    }

    @Override
    protected void registerGoals() {
        this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 2.2D, false));

        this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true));
        this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, IronGolem.class, true));
    }

    private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
        if (event.isMoving()) {
            event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.anubis.walk", true));
            return PlayState.CONTINUE;
        }

        event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.anubis.idle", true));
        return PlayState.CONTINUE;
    }

    private PlayState attackPredicate(AnimationEvent event) {
        if(this.swinging && event.getController().getAnimationState().equals(AnimationState.Stopped)) {
            event.getController().markNeedsReload();
            event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.anubis.attack", false));
            this.swinging = false;
        }

        return PlayState.CONTINUE;
    }

    @Override
    public void registerControllers(AnimationData data) {
        data.addAnimationController(new AnimationController(this, "controller", 0, this::predicate));
        data.addAnimationController(new AnimationController(this, "attackController", 0, this::attackPredicate));
    }

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

 

Posted

First, this isn't a teaching forum. Nor is it a way for you use other people as a search engine.

You need to do your own research (look at how vanilla does it or other mods) and try to implement it yourself.

When you get stuck feel free to ask here.

By that point you will have a better understanding and be able to ask more focused questions. And also better understand the answers.

 

Anyway, obvious answers:

Boss bar -> Look at the WitherBoss.bossEvent and how it gets used. Alternatives in vanilla are raids and the dragon.

Structure -> An obvious vanilla example is OceanMonumentPiece.spawnElder() - the mob at the centre of ocean monuments.

 

As for the staying in the structure, that is something you will have to code into the entity's AI.

I am not aware of a mob that does that. There are plenty of AI goals that move towards different targets you might adapt?

You would also need to consider how that works if some user decides to spawn your entity far away from the structure, e.g. using the /spawn command

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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