3030import net .minecraft .server .level .ServerLevel ;
3131import net .minecraft .world .entity .EntityType ;
3232import net .minecraft .world .entity .LivingEntity ;
33+ import net .minecraft .world .entity .ai .ActivityData ;
3334import net .minecraft .world .entity .ai .Brain ;
3435import net .minecraft .world .entity .ai .behavior .BehaviorUtils ;
3536import net .minecraft .world .entity .ai .behavior .BlockPosTracker ;
@@ -65,24 +66,7 @@ public class ApparitionAi {
6566 TTSensorTypes .APPARITION_NEAREST_ITEM_SENSOR ,
6667 TTSensorTypes .APPARITION_AIDABLES_SENSOR
6768 );
68-
6969 public static final List <MemoryModuleType <?>> MEMORY_TYPES = List .of (
70- MemoryModuleType .LOOK_TARGET ,
71- MemoryModuleType .NEAREST_LIVING_ENTITIES ,
72- MemoryModuleType .NEAREST_VISIBLE_LIVING_ENTITIES ,
73- MemoryModuleType .NEAREST_ATTACKABLE ,
74- MemoryModuleType .CANT_REACH_WALK_TARGET_SINCE ,
75- MemoryModuleType .ATTACK_TARGET ,
76- MemoryModuleType .WALK_TARGET ,
77- MemoryModuleType .HURT_BY ,
78- MemoryModuleType .HURT_BY_ENTITY ,
79- MemoryModuleType .PATH ,
80- MemoryModuleType .NEAREST_PLAYERS ,
81- MemoryModuleType .NEAREST_VISIBLE_PLAYER ,
82- MemoryModuleType .NEAREST_VISIBLE_ATTACKABLE_PLAYER ,
83- TTMemoryModuleTypes .NEARBY_APPARITIONS ,
84- MemoryModuleType .ITEM_PICKUP_COOLDOWN_TICKS ,
85- MemoryModuleType .NEAREST_VISIBLE_WANTED_ITEM ,
8670 TTMemoryModuleTypes .AID_COOLDOWN ,
8771 TTMemoryModuleTypes .AIDING_TIME ,
8872 TTMemoryModuleTypes .NEARBY_AIDABLES ,
@@ -97,19 +81,20 @@ public class ApparitionAi {
9781 TTMemoryModuleTypes .AIDING_ENTITIES
9882 );
9983
100- @ Contract ("_, _ -> param2" )
101- public static Brain <Apparition > makeBrain (Apparition apparition , Brain <Apparition > brain ) {
102- initCoreActivity (brain );
103- initIdleActivity (brain );
104- initFightActivity (apparition , brain );
105- brain .setCoreActivities (Set .of (Activity .CORE ));
106- brain .setDefaultActivity (Activity .IDLE );
107- brain .useDefaultActivity ();
108- return brain ;
84+ public static Brain .Provider <Apparition > brainProvider (final Apparition body ) {
85+ return Brain .provider (MEMORY_TYPES , SENSOR_TYPES , getActivities (body ));
86+ }
87+
88+ protected static List <ActivityData <Apparition >> getActivities (final Apparition body ) {
89+ return List .of (
90+ initCoreActivity (),
91+ initIdleActivity (),
92+ initFightActivity (body )
93+ );
10994 }
11095
111- private static void initCoreActivity ( Brain <Apparition > brain ) {
112- brain . addActivity (
96+ private static ActivityData <Apparition > initCoreActivity ( ) {
97+ return ActivityData . create (
11398 Activity .CORE ,
11499 0 ,
115100 ImmutableList .of (
@@ -122,8 +107,8 @@ private static void initCoreActivity(Brain<Apparition> brain) {
122107 );
123108 }
124109
125- private static void initIdleActivity ( Brain <Apparition > brain ) {
126- brain . addActivity (
110+ private static ActivityData <Apparition > initIdleActivity ( ) {
111+ return ActivityData . create (
127112 Activity .IDLE ,
128113 10 ,
129114 ImmutableList .of (
@@ -146,21 +131,24 @@ private static void initIdleActivity(Brain<Apparition> brain) {
146131 );
147132 }
148133
149- private static void initFightActivity (Apparition apparition , Brain < Apparition > brain ) {
150- brain . addActivityAndRemoveMemoryWhenStopped (
134+ private static ActivityData < Apparition > initFightActivity (final Apparition body ) {
135+ return ActivityData . create (
151136 Activity .FIGHT ,
152137 10 ,
153138 ImmutableList .of (
154- StopAttackingIfTargetInvalid .create ((level , entity ) -> !apparition .canTargetEntity (entity , level ), ApparitionAi ::onTargetInvalid , true ),
139+ StopAttackingIfTargetInvalid .create ((level , entity ) -> !body .canTargetEntity (entity , level ), ApparitionAi ::onTargetInvalid , true ),
155140 new RunOne <>(
156141 ImmutableList .of (
157142 Pair .of (SetWalkTargetFromAttackTargetIfTargetOutOfReach .create (1F ), 1 ),
158143 Pair .of (new ApparitionAid (), 1 ),
159144 Pair .of (new ApparitionShoot (), 1 ),
160- Pair .of (GoToWantedItem .create (
161- apparition1 -> apparition1 .getInventory ().getItems ().getFirst ().isEmpty (),
162- 1.25F , true , 28
163- ), 1 )
145+ Pair .of (
146+ GoToWantedItem .create (
147+ apparition -> apparition .getInventory ().getItems ().getFirst ().isEmpty (),
148+ 1.25F , true , 28
149+ ),
150+ 1
151+ )
164152 )
165153 )
166154 ),
@@ -172,24 +160,9 @@ private static boolean shouldGoTowardsHome(LivingEntity apparition, GlobalPos po
172160 return ((Apparition )apparition ).shouldReturnToHome (pos );
173161 }
174162
175- @ Nullable
176- public static BlockPos getHome (Apparition apparition ) {
177- Optional <GlobalPos > optional = apparition .getBrain ().getMemory (MemoryModuleType .HOME );
178- return optional .map (GlobalPos ::pos ).orElse (null );
179- }
180-
181- public static boolean isInHomeDimension (Apparition apparition ) {
182- Optional <GlobalPos > optional = apparition .getBrain ().getMemory (MemoryModuleType .HOME );
183- return optional .filter ((globalPos ) -> globalPos .dimension () == apparition .level ().dimension ()).isPresent ();
184- }
185-
186- public static void rememberHome (Apparition apparition , BlockPos pos ) {
187- rememberHome (apparition , apparition .level (), pos );
188- }
189-
190163 public static void rememberHome (Apparition apparition , Level level , BlockPos pos ) {
191- Brain <?> brain = apparition .getBrain ();
192- GlobalPos globalPos = GlobalPos .of (level .dimension (), pos );
164+ final Brain <?> brain = apparition .getBrain ();
165+ final GlobalPos globalPos = GlobalPos .of (level .dimension (), pos );
193166 brain .setMemory (MemoryModuleType .HOME , globalPos );
194167 }
195168
0 commit comments