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
ce7ba7b6
Commit
ce7ba7b6
authored
a year ago
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added FlyingEntity support to look controls, fixes Ghast and Phantom
parent
ee52fb31
Pipeline
#11974
passed with stage
in 22 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
4 deletions
+30
-4
LookControls.java
src/main/java/com/owlmaddie/controls/LookControls.java
+30
-4
No files found.
src/main/java/com/owlmaddie/controls/LookControls.java
View file @
ce7ba7b6
package
com
.
owlmaddie
.
controls
;
import
net.minecraft.entity.mob.FlyingEntity
;
import
net.minecraft.entity.mob.MobEntity
;
import
net.minecraft.entity.mob.SlimeEntity
;
import
net.minecraft.entity.passive.SquidEntity
;
import
net.minecraft.server.network.ServerPlayerEntity
;
import
net.minecraft.util.math.MathHelper
;
import
net.minecraft.util.math.Vec3d
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* The {@code LookControls} class enables entities to look at the player,
* with specific adjustments for certain mobs like Slimes and Squids.
*/
public
class
LookControls
{
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
"mobgpt"
);
public
static
void
lookAtPlayer
(
ServerPlayerEntity
player
,
MobEntity
entity
)
{
if
(
entity
instanceof
SlimeEntity
)
{
handleSlimeLook
((
SlimeEntity
)
entity
,
player
);
}
else
if
(
entity
instanceof
SquidEntity
)
{
handleSquidLook
((
SquidEntity
)
entity
,
player
);
}
else
if
(
entity
instanceof
FlyingEntity
)
{
handleFlyingEntity
((
FlyingEntity
)
entity
,
player
);
}
else
{
// Make the entity look at the player
entity
.
getLookControl
().
lookAt
(
player
,
10.0
F
,
(
float
)
entity
.
getMaxLookPitchChange
());
...
...
@@ -48,6 +47,33 @@ public class LookControls {
}
}
// Ghast, Phantom, etc...
private
static
void
handleFlyingEntity
(
FlyingEntity
flyingEntity
,
ServerPlayerEntity
player
)
{
Vec3d
playerPosition
=
player
.
getPos
();
Vec3d
flyingPosition
=
flyingEntity
.
getPos
();
Vec3d
toPlayer
=
playerPosition
.
subtract
(
flyingPosition
).
normalize
();
// Calculate the yaw to align the flyingEntity's facing direction with the movement direction
float
targetYaw
=
(
float
)(
MathHelper
.
atan2
(
toPlayer
.
z
,
toPlayer
.
x
)
*
(
180
/
Math
.
PI
)
-
90
);
flyingEntity
.
setYaw
(
targetYaw
);
// Look at player while adjusting yaw
flyingEntity
.
getLookControl
().
lookAt
(
player
,
10.0
F
,
(
float
)
flyingEntity
.
getMaxLookPitchChange
());
float
initialSpeed
=
0.15
F
;
flyingEntity
.
setVelocity
(
(
float
)
toPlayer
.
x
*
initialSpeed
,
(
float
)
toPlayer
.
y
*
initialSpeed
,
(
float
)
toPlayer
.
z
*
initialSpeed
);
double
distanceToPlayer
=
flyingEntity
.
getPos
().
distanceTo
(
player
.
getPos
());
if
(
distanceToPlayer
<
9
F
)
{
// Stop motion when close
flyingEntity
.
setVelocity
(
0
,
0
,
0
);
}
}
public
static
float
calculateYawChangeToPlayer
(
MobEntity
entity
,
ServerPlayerEntity
player
)
{
Vec3d
toPlayer
=
calculateNormalizedDirection
(
entity
,
player
);
float
targetYaw
=
(
float
)
Math
.
toDegrees
(
Math
.
atan2
(
toPlayer
.
z
,
toPlayer
.
x
))
-
90.0
F
;
...
...
This diff is collapsed.
Click to expand it.
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