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
1
Merge Requests
1
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
65311b60
Commit
65311b60
authored
Apr 03, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debug code for follow player goal
parent
101f2c27
Pipeline
#11925
passed with stage
in 22 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
3 deletions
+21
-3
FollowPlayerGoal.java
src/main/java/com/owlmaddie/goals/FollowPlayerGoal.java
+21
-3
No files found.
src/main/java/com/owlmaddie/goals/FollowPlayerGoal.java
View file @
65311b60
...
@@ -6,11 +6,14 @@ import net.minecraft.entity.mob.MobEntity;
...
@@ -6,11 +6,14 @@ import net.minecraft.entity.mob.MobEntity;
import
net.minecraft.server.network.ServerPlayerEntity
;
import
net.minecraft.server.network.ServerPlayerEntity
;
import
java.util.EnumSet
;
import
java.util.EnumSet
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
/**
* The {@code FollowPlayerGoal} class instructs a Mob Entity to follow the current player.
* The {@code FollowPlayerGoal} class instructs a Mob Entity to follow the current player.
*/
*/
public
class
FollowPlayerGoal
extends
Goal
{
public
class
FollowPlayerGoal
extends
Goal
{
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
"mobgpt"
);
private
final
MobEntity
entity
;
private
final
MobEntity
entity
;
private
ServerPlayerEntity
targetPlayer
;
private
ServerPlayerEntity
targetPlayer
;
private
final
EntityNavigation
navigation
;
private
final
EntityNavigation
navigation
;
...
@@ -26,25 +29,40 @@ public class FollowPlayerGoal extends Goal {
...
@@ -26,25 +29,40 @@ public class FollowPlayerGoal extends Goal {
@Override
@Override
public
boolean
canStart
()
{
public
boolean
canStart
()
{
return
this
.
targetPlayer
!=
null
;
boolean
canStart
=
this
.
targetPlayer
!=
null
;
LOGGER
.
info
(
"[FollowPlayerGoal] canStart: "
+
canStart
);
return
canStart
;
}
}
@Override
@Override
public
boolean
shouldContinue
()
{
public
boolean
shouldContinue
()
{
return
this
.
targetPlayer
!=
null
&&
this
.
targetPlayer
.
isAlive
();
boolean
shouldContinue
=
this
.
targetPlayer
!=
null
&&
this
.
targetPlayer
.
isAlive
();
LOGGER
.
info
(
"[FollowPlayerGoal] shouldContinue: "
+
shouldContinue
);
return
shouldContinue
;
}
}
@Override
@Override
public
void
stop
()
{
public
void
stop
()
{
this
.
targetPlayer
=
null
;
this
.
targetPlayer
=
null
;
this
.
navigation
.
stop
();
this
.
navigation
.
stop
();
LOGGER
.
info
(
"[FollowPlayerGoal] stop goal"
);
}
}
@Override
@Override
public
void
tick
()
{
public
void
tick
()
{
this
.
entity
.
getLookControl
().
lookAt
(
this
.
targetPlayer
,
10.0
F
,
(
float
)
this
.
entity
.
getMaxLookPitchChange
());
this
.
entity
.
getLookControl
().
lookAt
(
this
.
targetPlayer
,
10.0
F
,
(
float
)
this
.
entity
.
getMaxLookPitchChange
());
if
(
this
.
entity
.
squaredDistanceTo
(
this
.
targetPlayer
)
>
2.25
)
{
// Calculate the squared distance between the entity and the player
double
squaredDistanceToPlayer
=
this
.
entity
.
squaredDistanceTo
(
this
.
targetPlayer
);
// Check if the entity is further away than 4 blocks (16 when squared)
if
(
squaredDistanceToPlayer
>
16
)
{
// Entity is more than 4 blocks away, start moving towards the player
LOGGER
.
info
(
"[FollowPlayerGoal] tick - Start moving towards player. Squared distance to player: "
+
squaredDistanceToPlayer
);
this
.
navigation
.
startMovingTo
(
this
.
targetPlayer
,
this
.
speed
);
this
.
navigation
.
startMovingTo
(
this
.
targetPlayer
,
this
.
speed
);
}
else
if
(
squaredDistanceToPlayer
<
9
)
{
// Entity is closer than 3 blocks, stop moving to maintain distance
this
.
navigation
.
stop
();
}
}
}
}
}
}
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