Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
CreatureChat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Public
CreatureChat
Commits
0511f9e1
Commit
0511f9e1
authored
Apr 30, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call goalSelector remove method, which stops running goals and fixes the broken custom goals.
parent
fd4e2200
Pipeline
#12067
passed with stage
in 20 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
EntityBehaviorManager.java
src/main/java/com/owlmaddie/goals/EntityBehaviorManager.java
+16
-2
No files found.
src/main/java/com/owlmaddie/goals/EntityBehaviorManager.java
View file @
0511f9e1
...
...
@@ -8,6 +8,7 @@ import net.minecraft.entity.mob.MobEntity;
import
net.minecraft.server.world.ServerWorld
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.function.Predicate
;
import
java.util.Comparator
;
import
java.util.List
;
...
...
@@ -30,7 +31,7 @@ public class EntityBehaviorManager {
GoalSelector
goalSelector
=
GoalUtils
.
getGoalSelector
(
entity
);
// First clear any existing goals of the same type to avoid duplicates
goalSelector
.
clear
(
g
->
g
.
getClass
().
isAssignableFrom
(
goal
.
getClass
())
);
clearAndRemove
(
g
->
goal
.
getClass
().
equals
(
g
.
getClass
()),
goalSelector
);
// Handle potential priority conflicts before adding the new goal
moveConflictingGoals
(
goalSelector
,
priority
);
...
...
@@ -41,10 +42,23 @@ public class EntityBehaviorManager {
});
}
public
static
void
clearAndRemove
(
Predicate
<
Goal
>
predicate
,
GoalSelector
goalSelector
)
{
// Collect all goals that need to be removed
List
<
PrioritizedGoal
>
toBeRemoved
=
goalSelector
.
getGoals
().
stream
()
.
filter
(
prioritizedGoal
->
predicate
.
test
(
prioritizedGoal
.
getGoal
()))
.
collect
(
Collectors
.
toList
());
// Stop if running and remove each goal
toBeRemoved
.
forEach
(
prioritizedGoal
->
{
goalSelector
.
remove
(
prioritizedGoal
.
getGoal
());
// Remove the goal
});
}
public
static
void
removeGoal
(
MobEntity
entity
,
Class
<?
extends
Goal
>
goalClass
)
{
ServerPackets
.
serverInstance
.
execute
(()
->
{
GoalSelector
goalSelector
=
GoalUtils
.
getGoalSelector
(
entity
);
goalSelector
.
clear
(
g
->
goalClass
.
isInstance
(
g
));
// First clear any existing goals of the same type to avoid duplicates
clearAndRemove
(
g
->
goalClass
.
equals
(
g
.
getClass
()),
goalSelector
);
LOGGER
.
debug
(
"All goals of type {} removed."
,
goalClass
.
getSimpleName
());
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment