-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
888da85
commit d86d266
Showing
3 changed files
with
47 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/lee/code/pets/pets/controllers/ControllerLookFlying.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package lee.code.pets.pets.controllers; | ||
|
||
import net.minecraft.world.entity.Mob; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
import java.util.UUID; | ||
|
||
public class ControllerLookFlying extends ControllerWASD { | ||
public ControllerLookFlying(Mob mob, UUID owner) { | ||
super(mob, owner); | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
if (mob.getPassengers().isEmpty()) { | ||
super.tick(); | ||
return; | ||
} | ||
if (!(mob.getPassengers().get(0) instanceof Player player)) return; | ||
if (!player.getUUID().equals(owner)) return; | ||
this.rider = player; | ||
final Vec3 riddenInput = getRiddenInput(rider); | ||
|
||
// Calculate the movement direction based on the player's pitch and yaw angles | ||
final float forward = Math.max(0, (float) riddenInput.z); | ||
final float pitch = rider.getXRot(); | ||
final float yaw = rider.getYRot(); | ||
final double motionX = forward * -Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)); | ||
final double motionY = forward * -Math.sin(Math.toRadians(pitch)); | ||
final double motionZ = forward * Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)); | ||
|
||
// Set the mob's motion | ||
mob.setDeltaMovement(new Vec3(motionX, motionY, motionZ)); | ||
|
||
// Adjust mob's rotation based on the player's yaw | ||
mob.setYRot(yaw); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters