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
c0967ef6
Commit
c0967ef6
authored
Apr 25, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Protect changing goalSelector to a single server thread, to prevent crash
parent
6faf3371
Pipeline
#12025
passed with stage
in 26 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
1 deletion
+11
-1
EntityBehaviorManager.java
src/main/java/com/owlmaddie/goals/EntityBehaviorManager.java
+11
-1
No files found.
src/main/java/com/owlmaddie/goals/EntityBehaviorManager.java
View file @
c0967ef6
package
com
.
owlmaddie
.
goals
;
package
com
.
owlmaddie
.
goals
;
import
com.owlmaddie.network.ServerPackets
;
import
net.minecraft.entity.ai.goal.Goal
;
import
net.minecraft.entity.ai.goal.Goal
;
import
net.minecraft.entity.ai.goal.GoalSelector
;
import
net.minecraft.entity.ai.goal.GoalSelector
;
import
net.minecraft.entity.ai.goal.PrioritizedGoal
;
import
net.minecraft.entity.mob.MobEntity
;
import
net.minecraft.entity.mob.MobEntity
;
import
net.minecraft.server.world.ServerWorld
;
import
net.minecraft.server.world.ServerWorld
;
import
net.minecraft.entity.ai.goal.PrioritizedGoal
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -37,9 +38,12 @@ public class EntityBehaviorManager {
...
@@ -37,9 +38,12 @@ public class EntityBehaviorManager {
List
<
Goal
>
goals
=
entityGoals
.
computeIfAbsent
(
entityId
,
k
->
new
ArrayList
<>());
List
<
Goal
>
goals
=
entityGoals
.
computeIfAbsent
(
entityId
,
k
->
new
ArrayList
<>());
goals
.
add
(
goal
);
goals
.
add
(
goal
);
// Ensure that the task is synced with the server thread
ServerPackets
.
serverInstance
.
execute
(()
->
{
GoalSelector
goalSelector
=
GoalUtils
.
getGoalSelector
(
entity
);
GoalSelector
goalSelector
=
GoalUtils
.
getGoalSelector
(
entity
);
goalSelector
.
add
(
priority
.
getPriority
(),
goal
);
goalSelector
.
add
(
priority
.
getPriority
(),
goal
);
LOGGER
.
debug
(
"Goal of type {} added to entity UUID: {}"
,
goal
.
getClass
().
getSimpleName
(),
entityId
);
LOGGER
.
debug
(
"Goal of type {} added to entity UUID: {}"
,
goal
.
getClass
().
getSimpleName
(),
entityId
);
});
}
}
public
static
void
removeGoal
(
MobEntity
entity
,
Class
<?
extends
Goal
>
goalClass
)
{
public
static
void
removeGoal
(
MobEntity
entity
,
Class
<?
extends
Goal
>
goalClass
)
{
...
@@ -47,6 +51,8 @@ public class EntityBehaviorManager {
...
@@ -47,6 +51,8 @@ public class EntityBehaviorManager {
List
<
Goal
>
goals
=
entityGoals
.
get
(
entityId
);
List
<
Goal
>
goals
=
entityGoals
.
get
(
entityId
);
if
(
goals
!=
null
)
{
if
(
goals
!=
null
)
{
// Ensure that the task is synced with the server thread
ServerPackets
.
serverInstance
.
execute
(()
->
{
GoalSelector
goalSelector
=
GoalUtils
.
getGoalSelector
(
entity
);
GoalSelector
goalSelector
=
GoalUtils
.
getGoalSelector
(
entity
);
goals
.
removeIf
(
goal
->
{
goals
.
removeIf
(
goal
->
{
if
(
goalClass
.
isInstance
(
goal
))
{
if
(
goalClass
.
isInstance
(
goal
))
{
...
@@ -56,10 +62,13 @@ public class EntityBehaviorManager {
...
@@ -56,10 +62,13 @@ public class EntityBehaviorManager {
}
}
return
false
;
return
false
;
});
});
});
}
}
}
}
private
static
void
moveConflictingGoals
(
MobEntity
entity
,
GoalPriority
newGoalPriority
)
{
private
static
void
moveConflictingGoals
(
MobEntity
entity
,
GoalPriority
newGoalPriority
)
{
// Ensure that the task is synced with the server thread
ServerPackets
.
serverInstance
.
execute
(()
->
{
GoalSelector
goalSelector
=
GoalUtils
.
getGoalSelector
(
entity
);
GoalSelector
goalSelector
=
GoalUtils
.
getGoalSelector
(
entity
);
// Retrieve the existing goals
// Retrieve the existing goals
...
@@ -90,5 +99,6 @@ public class EntityBehaviorManager {
...
@@ -90,5 +99,6 @@ public class EntityBehaviorManager {
// Increment the priority and re-add the goal
// Increment the priority and re-add the goal
goalSelector
.
add
(
goalToModify
.
getPriority
()
+
1
,
goalToModify
.
getGoal
());
goalSelector
.
add
(
goalToModify
.
getPriority
()
+
1
,
goalToModify
.
getGoal
());
}
}
});
}
}
}
}
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