Skip to content

Commit

Permalink
Preliminary API for 'new' brains AI system for mobs
Browse files Browse the repository at this point in the history
Would fix PaperMC#10443 if done.

This is a rough proposal for abstracting over the brains AI system for mobs
for plugins to make use of, similar to the Goals API. I don't think it's feasible
to attempt to make the new AI conform to the old interfaces.

At the moment I understand the rough skeleton and arteries of the system, though I'm
still trying to piece together what does what in user-facing terms.
'get the mob to walk somewhere' has been unsuccessful so far.

As far as API stability concerns, as long as the exposed set of tasks isn't too 1:1 with what
Mojang has, then we should be fine (until the next Big Rewrite:tm: whenever that is) considering
the general stability of the system across versions since its introductions.

There are still some unanswered questions in the API design:
- do events make sense to have here? I'd say no considering the amount of lambdas in the Minecraft implementation
  that make any real introspection API unfeasible.
- do we care to expose sensors/make them modifiable? It could probably be done in a followup PR to make custom
  tasks & sensors a thing, as I'm mostly concerned about exposing what exists in Vanilla at the moment.
- is the arrangement of the entrypoints to the new API sensical?

Test plugin is included in PR to ease testing of the new API until it's ready to ship.
  • Loading branch information
pontaoski committed Apr 27, 2024
1 parent f4c7d37 commit 6b9ec9f
Show file tree
Hide file tree
Showing 5 changed files with 728 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
package io.papermc.paper.registry.keys;

import static net.kyori.adventure.key.Key.key;

import io.papermc.paper.entity.ai.Activity;
import io.papermc.paper.generated.GeneratedFrom;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.TypedKey;
import net.kyori.adventure.key.Key;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

/**
* Vanilla keys for {@link RegistryKey#ACTIVITY}.
*
* @apiNote The fields provided here are a direct representation of
* what is available from the vanilla game source. They may be
* changed (including removals) on any Minecraft version
* bump, so cross-version compatibility is not provided on the
* same level as it is on most of the other API.
*/
@SuppressWarnings({
"unused",
"SpellCheckingInspection"
})
@GeneratedFrom("1.20.4")
@ApiStatus.Experimental
public final class ActivityKeys {
/**
* {@code minecraft:core}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> CORE = create(key("core"));

/**
* {@code minecraft:idle}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> IDLE = create(key("idle"));

/**
* {@code minecraft:work}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> WORK = create(key("work"));

/**
* {@code minecraft:play}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> PLAY = create(key("play"));

/**
* {@code minecraft:rest}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> REST = create(key("rest"));

/**
* {@code minecraft:meet}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> MEET = create(key("meet"));

/**
* {@code minecraft:panic}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> PANIC = create(key("panic"));

/**
* {@code minecraft:raid}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> RAID = create(key("raid"));

/**
* {@code minecraft:pre_raid}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> PRE_RAID = create(key("pre_raid"));

/**
* {@code minecraft:hide}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> HIDE = create(key("hide"));

/**
* {@code minecraft:fight}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> FIGHT = create(key("fight"));

/**
* {@code minecraft:celebrate}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> CELEBRATE = create(key("celebrate"));

/**
* {@code minecraft:admire_item}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> ADMIRE_ITEM = create(key("admire_item"));

/**
* {@code minecraft:avoid}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> AVOID = create(key("avoid"));

/**
* {@code minecraft:ride}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> RIDE = create(key("ride"));

/**
* {@code minecraft:play_dead}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> PLAY_DEAD = create(key("play_dead"));

/**
* {@code minecraft:long_jump}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> LONG_JUMP = create(key("long_jump"));

/**
* {@code minecraft:ram}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> RAM = create(key("ram"));

/**
* {@code minecraft:tongue}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> TONGUE = create(key("tongue"));

/**
* {@code minecraft:swim}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> SWIM = create(key("swim"));

/**
* {@code minecraft:lay_spawn}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> LAY_SPAWN = create(key("lay_spawn"));

/**
* {@code minecraft:sniff}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> SNIFF = create(key("sniff"));

/**
* {@code minecraft:investigate}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> INVESTIGATE = create(key("investigate"));

/**
* {@code minecraft:roar}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> ROAR = create(key("roar"));

/**
* {@code minecraft:emerge}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> EMERGE = create(key("emerge"));

/**
* {@code minecraft:dig}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<Activity> DIG = create(key("dig"));

private ActivityKeys() {
}

private static @NotNull TypedKey<Activity> create(final @NotNull Key key) {
return TypedKey.create(RegistryKey.ACTIVITY, key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.generator.structure.StructureType;
import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern;
import io.papermc.paper.entity.ai.Activity;

public interface Generators {

Expand All @@ -23,6 +24,7 @@ public interface Generators {
simpleKey("TrimPatternKeys", TrimPattern.class, Registries.TRIM_PATTERN, RegistryKey.TRIM_PATTERN, true),
simpleKey("StructureKeys", Structure.class, Registries.STRUCTURE, RegistryKey.STRUCTURE, true),
simpleKey("StructureTypeKeys", StructureType.class, Registries.STRUCTURE_TYPE, RegistryKey.STRUCTURE_TYPE, false),
simpleKey("ActivityKeys", Activity.class, Registries.ACTIVITY, RegistryKey.ACTIVITY, false),
new MobGoalGenerator("VanillaGoal", "com.destroystokyo.paper.entity.ai")
};

Expand Down

0 comments on commit 6b9ec9f

Please sign in to comment.