diff --git a/src/main/java/lee/code/pets/pets/SheepPet.java b/src/main/java/lee/code/pets/pets/SheepPet.java index 98cb14b..7ceabb2 100644 --- a/src/main/java/lee/code/pets/pets/SheepPet.java +++ b/src/main/java/lee/code/pets/pets/SheepPet.java @@ -1,6 +1,6 @@ package lee.code.pets.pets; -import lee.code.pets.pets.logic.ControllerWASD; +import lee.code.pets.pets.controllers.ControllerLookFlying; import lee.code.pets.pets.logic.FollowOwnerGoal; import lee.code.pets.utils.CoreUtil; import net.minecraft.nbt.CompoundTag; @@ -17,7 +17,7 @@ public class SheepPet extends Mob { public SheepPet(Player player, Location loc, String name) { - super(EntityType.SHEEP, ((CraftWorld) loc.getWorld()).getHandle()); + super(EntityType.BEE, ((CraftWorld) loc.getWorld()).getHandle()); this.setPos(loc.getX(), loc.getY(), loc.getZ()); this.setInvulnerable(true); this.setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(name))); @@ -25,9 +25,8 @@ public SheepPet(Player player, Location loc, String name) { this.collides = false; this.setPersistenceRequired(true); this.setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false); - this.moveControl = new ControllerWASD(this, player.getUniqueId()); + this.moveControl = new ControllerLookFlying(this, player.getUniqueId()); setAttributes(); - setNavSettings(); } @Override @@ -41,11 +40,6 @@ private void setAttributes() { this.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.23000000417232513D); } - private void setNavSettings() { - this.getNavigation().pathFinder.nodeEvaluator.setCanOpenDoors(true); - this.getNavigation().pathFinder.nodeEvaluator.setCanFloat(true); - } - @Override public boolean save(CompoundTag compoundTag) { return false; diff --git a/src/main/java/lee/code/pets/pets/controllers/ControllerLookFlying.java b/src/main/java/lee/code/pets/pets/controllers/ControllerLookFlying.java new file mode 100644 index 0000000..a53a830 --- /dev/null +++ b/src/main/java/lee/code/pets/pets/controllers/ControllerLookFlying.java @@ -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); + } +} diff --git a/src/main/java/lee/code/pets/pets/logic/ControllerWASD.java b/src/main/java/lee/code/pets/pets/controllers/ControllerWASD.java similarity index 78% rename from src/main/java/lee/code/pets/pets/logic/ControllerWASD.java rename to src/main/java/lee/code/pets/pets/controllers/ControllerWASD.java index 2a8487c..b1f6235 100644 --- a/src/main/java/lee/code/pets/pets/logic/ControllerWASD.java +++ b/src/main/java/lee/code/pets/pets/controllers/ControllerWASD.java @@ -1,6 +1,5 @@ -package lee.code.pets.pets.logic; +package lee.code.pets.pets.controllers; -import net.minecraft.util.Mth; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.player.Player; @@ -9,8 +8,8 @@ import java.util.UUID; public class ControllerWASD extends MoveControl { - private final UUID owner; - private Player rider; + protected final UUID owner; + protected Player rider; public ControllerWASD(Mob mob, UUID owner) { super(mob); @@ -63,7 +62,7 @@ public void tick() { if (rider.jumping) jump(); } - private Vec3 getRiddenInput(Player rider) { + protected Vec3 getRiddenInput(Player rider) { final float f = rider.xxa * 0.5F; float f1 = rider.zza; @@ -71,17 +70,8 @@ private Vec3 getRiddenInput(Player rider) { return new Vec3(f, 0.0D, f1); } - private void jump() { + protected void jump() { if (!mob.onGround()) return; - final double jumpHeight = 3; - final Vec3 motion = mob.getDeltaMovement(); - - mob.setDeltaMovement(motion.x, jumpHeight, motion.z); - - float f1 = Mth.sin(mob.getYRot() * 0.017453292F); - float f2 = Mth.cos(mob.getYRot() * 0.017453292F); - - mob.setDeltaMovement(motion.add((-0.4F * f1), 0.0D, (0.4F * f2))); mob.getJumpControl().jump(); } }