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
fc9cee19
Commit
fc9cee19
authored
Aug 05, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only start moving towards target when not already moving in that direction.
parent
b53ce384
Pipeline
#12715
passed with stages
in 2 minutes 9 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
LeadPlayerGoal.java
src/main/java/com/owlmaddie/goals/LeadPlayerGoal.java
+13
-5
No files found.
src/main/java/com/owlmaddie/goals/LeadPlayerGoal.java
View file @
fc9cee19
...
...
@@ -6,6 +6,7 @@ import com.owlmaddie.network.ServerPackets;
import
com.owlmaddie.utils.RandomTargetFinder
;
import
net.minecraft.entity.ai.pathing.Path
;
import
net.minecraft.entity.mob.MobEntity
;
import
net.minecraft.entity.mob.PathAwareEntity
;
import
net.minecraft.particle.ParticleEffect
;
import
net.minecraft.particle.ParticleTypes
;
import
net.minecraft.server.network.ServerPlayerEntity
;
...
...
@@ -95,10 +96,14 @@ public class LeadPlayerGoal extends PlayerBaseGoal {
// Make the entity look at the player without moving towards them
LookControls
.
lookAtPosition
(
this
.
currentTarget
,
this
.
entity
);
Path
path
=
this
.
entity
.
getNavigation
().
findPathTo
(
this
.
currentTarget
.
x
,
this
.
currentTarget
.
y
,
this
.
currentTarget
.
z
,
1
);
if
(
path
!=
null
)
{
this
.
entity
.
getNavigation
().
startMovingAlong
(
path
,
this
.
speed
);
if
(
this
.
entity
instanceof
PathAwareEntity
)
{
if
(!
this
.
entity
.
getNavigation
().
isFollowingPath
())
{
Path
path
=
this
.
entity
.
getNavigation
().
findPathTo
(
this
.
currentTarget
.
x
,
this
.
currentTarget
.
y
,
this
.
currentTarget
.
z
,
1
);
if
(
path
!=
null
)
{
LOGGER
.
info
(
"Start moving along path"
);
this
.
entity
.
getNavigation
().
startMovingAlong
(
path
,
this
.
speed
);
}
}
}
else
{
// Move towards the target for non-path aware entities
Vec3d
entityPos
=
this
.
entity
.
getPos
();
...
...
@@ -108,7 +113,7 @@ public class LeadPlayerGoal extends PlayerBaseGoal {
double
currentSpeed
=
this
.
entity
.
getVelocity
().
horizontalLength
();
// Gradually adjust speed towards the target speed
currentSpeed
=
MathHelper
.
stepTowards
((
float
)
currentSpeed
,
(
float
)
this
.
speed
,
(
float
)
(
0.005
*
(
this
.
speed
/
Math
.
max
(
currentSpeed
,
0.1
))));
currentSpeed
=
MathHelper
.
stepTowards
((
float
)
currentSpeed
,
(
float
)
this
.
speed
,
(
float
)
(
0.005
*
(
this
.
speed
/
Math
.
max
(
currentSpeed
,
0.1
))));
// Apply movement with the adjusted speed towards the target
Vec3d
newVelocity
=
new
Vec3d
(
moveDirection
.
x
*
currentSpeed
,
moveDirection
.
y
*
currentSpeed
,
moveDirection
.
z
*
currentSpeed
);
...
...
@@ -128,6 +133,9 @@ public class LeadPlayerGoal extends PlayerBaseGoal {
emitParticleAt
(
this
.
currentTarget
,
ParticleTypes
.
FLAME
);
emitParticlesAlongRaycast
(
this
.
entity
.
getPos
(),
this
.
currentTarget
,
ParticleTypes
.
CLOUD
,
0.5
);
}
// Stop following current path (if any)
this
.
entity
.
getNavigation
().
stop
();
}
private
void
emitParticleAt
(
Vec3d
position
,
ParticleEffect
particleType
)
{
...
...
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