SmartBrainLib (Forge/Fabric/Quilt)

SmartBrainLib (Forge/Fabric/Quilt)

31M Downloads

Fabric Compatibility - How to Use SmartBrainLib on Fabric?

cprodhomme opened this issue ยท 7 comments

commented

Hello,

I'm working on a Fabric 1.20.1 mod and would like to use SmartBrainLib for entity AI. However, the documentation appears to be focused on Forge, and I couldn't find guidance on how to properly integrate it with Fabric.

Specifically, I'm unsure how to translate the following Forge-specific methods to Fabric:

Replacing the Vanilla Brain System:

@Override
protected Brain.Provider<?> brainProvider() {
    return new SmartBrainProvider<>(this);
}

Fabric does not have Brain.Provider<?>, so what is the recommended way to implement this?

Ticking the Brain:

@Override
protected void customServerAiStep() {
    tickBrain(this);
}

In Fabric, customServerAiStep() does not exist. Should we use mobTick() or another method like serverTick() instead?

If there is a Fabric-specific implementation or any example available, Iโ€™d greatly appreciate any guidance!

Thanks in advance. ๐Ÿ˜Š

Documentation : https://github.com/Tslat/SmartBrainLib/wiki/Making-an-Entity-With-SmartBrainLib

commented

Thanks !

I found the mapping on https://mappings.dev/index.html

commented

The documentation is correct for either fabric or Forge (or any other platform)
The issue here is that you are using Yarn mappings, which causes the names of methods/classes to be different than the standard.

This is Fabric's chosen mappings system for some reason, and as a fabric user you will be expected to understand how to convert mojmap (the standard mappings system) to yarn, as this will be coming up a lot.

I'd recommend asking in the fabric discord how to convert, since they are the ones responsible for causing you problems in the first place

commented

I found the mapping on https://mappings.dev/index.html

What were the replacement Yarn mappings for brainProvider and customServerAiStep that you found? I'm having a similar block in using this lib for fabric. Many thanks in advance!

commented

I found the mapping on https://mappings.dev/index.html

What were the replacement Yarn mappings for brainProvider and customServerAiStep that you found? I'm having a similar block in using this lib for fabric. Many thanks in advance!

Hi @artisticandro

Here is the equivalent for Fabric 1.20.1 with Yarn:

@Override
protected Brain.Profile<?> createBrainProfile() {
  return new SmartBrainProvider<>(this);
}

@Override
protected void mobTick() {
  super.mobTick();
  tickBrain(this);
}

๐Ÿ” How did I find it?

I asked an AI (ChatGPT) which package/class contains the methods customServerAiStep (Mob) and brainProvider (LivingEntity).

Then, I cross-referenced the information on mappings.dev to find the corresponding methods in Yarn for Fabric 1.20.1.

Let me know if you need more details! ๐Ÿš€

commented

Thank you!

It looks like those mappings carry over to 1.21.4 based on what you described (mobTick instead of tickNewAi for serverAiStep):

    @Override
    protected Brain.Profile<?> createBrainProfile() {
        return new SmartBrainProvider<>(this);
    }

    @Override
    protected void tickNewAi() {
        super.tickNewAi();
        tickBrain(this);
    }

I've run into a sort of fork after this: when I use mobTick, the super constructor is expecting an argument (not entirely sure what to insert into it). On the other hand, using tickNewAi as here (for customServerAiStep) prompts an error from IntelliJ that this MobEntity method is finalized on the vanilla side and therefore cannot be overridden in its current syntax.

I'm impartial to either usage but also can't solve either issue. Any thoughts?

commented

Many thanks! Looks like that worked

commented

@artisticandro

You need to use mobTick!

You can check the mapping of Mob in 1.21.4: https://mappings.dev/1.21.4/net/minecraft/world/entity/Mob.html

It seems you need to add a parameter to your mobTick method:

Image

like this:

@Override
protected void mobTick(ServerWorld world) {
  super.mobTick(world);
  tickBrain(this);
}