Want to change some AI

Hey, I want to modify the AI of the creeper so that it can target other entities as well. I’m considering adding a new goal to its initGoals method. Since I’m new to this, I have a few questions. I am new to this stuff, so here are my questions:

  1. Can I add something to the AI code?
  2. If yes, I tried doing this stuff:
@Mixin(CreeperEntity.class)
public class ChangeAI extends HostileEntity {

	protected ChangeAI(EntityType<? extends HostileEntity> entityType, World world) {
		super(entityType, world);
	}

	@Inject(method = "initGoals", at = @At("TAIL"))
	private void inject(){
		CreeperEntity creeperEntity = (CreeperEntity)(Object)this;
		targetSelector.add(3, new ActiveTargetGoal<>(creeperEntity, IronGolemEntity.class,true ));
	}


}

And it gives me these errors:
1)

Caused by: java.lang.BootstrapMethodError: java.lang.RuntimeException: Mixin transformation of net.minecraft.entity.mob.CreeperEntity failed
Caused by: java.lang.RuntimeException: Mixin transformation of net.minecraft.entity.mob.CreeperEntity failed
Caused by: org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError: An unexpected critical error was encountered
Caused by: org.spongepowered.asm.mixin.throwables.MixinApplyError: Mixin [templatemod.mixins.json:ChangeAI from mod template-mod] from phase [DEFAULT] in config [templatemod.mixins.json] FAILED during APPLY
Caused by: org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException: Invalid descriptor on templatemod.mixins.json:ChangeAI from mod template-mod->@Inject::inject()V! Expected (Lorg/spongepowered/asm/mixin/injection/callback/CallbackInfo;)V but found ()V [INJECT_APPLY Applicator Phase -> templatemod.mixins.json:ChangeAI from mod template-mod -> Apply Injections ->  -> Inject -> templatemod.mixins.json:ChangeAI from mod template-mod->@Inject::inject()V]

As your using sponge. You can build your own goal

Never used it myself, so dont know how. But saves you using mixins

1 Like

Thx. I will try that out and sorry for the late response, I was kinda busy.
(Edit: I was trying stuff using mixins and this worked:

@Mixin(IronGolemEntity.class)
public abstract class ChangeAI extends GolemEntity {

    protected ChangeAI(EntityType<? extends GolemEntity> entityType, World world) {
        super(entityType, world);
    }



    @Overwrite
    public void pushAway(Entity entity) {
        IronGolemEntity ironGolem = (IronGolemEntity) (Object) this;
        if (entity instanceof Monster){
            ironGolem.setTarget((LivingEntity) entity);
        }
        super.pushAway(entity);
    }



}

Instead of the creeper class, i changed the irongolem class instead.

1 Like