diff --git a/src/main/java/lee/code/pets/commands/cmds/TestCMD.java b/src/main/java/lee/code/pets/commands/cmds/TestCMD.java index 01e7269..44265ad 100644 --- a/src/main/java/lee/code/pets/commands/cmds/TestCMD.java +++ b/src/main/java/lee/code/pets/commands/cmds/TestCMD.java @@ -48,7 +48,7 @@ public boolean performAsyncSynchronized() { @Override public void perform(Player player, String[] args) { - pets.getPetManager().spawn(player, EntityType.CREEPER, new String[]{"&d&lMASTER_GAY", "true"}); + pets.getPetManager().spawn(player, EntityType.COD, new String[]{"&d&lMASTER_GAY"}); } @Override diff --git a/src/main/java/lee/code/pets/pets/PetManager.java b/src/main/java/lee/code/pets/pets/PetManager.java index b814c7c..8db5c35 100644 --- a/src/main/java/lee/code/pets/pets/PetManager.java +++ b/src/main/java/lee/code/pets/pets/PetManager.java @@ -2,6 +2,7 @@ import lee.code.pets.pets.pet.animal.*; import lee.code.pets.pets.pet.animal.CatPet; +import lee.code.pets.pets.pet.fish.CodPet; import lee.code.pets.pets.pet.mob.*; import net.minecraft.world.entity.Entity; import org.bukkit.World; @@ -29,6 +30,9 @@ public void spawn(Player player, EntityType entityType, String[] data) { case MAGMA_CUBE -> spawn(player.getWorld(), new MagmaCubePet(player, data[0], data[1])); case RAVAGER -> spawn(player.getWorld(), new RavagerPet(player, data[0])); case CREEPER -> spawn(player.getWorld(), new CreeperPet(player, data[0], Boolean.parseBoolean(data[1]))); + case SKELETON -> spawn(player.getWorld(), new SkeletonPet(player, data[0])); + case HORSE -> spawn(player.getWorld(), new HorsePet(player, Boolean.parseBoolean(data[0]), data[1], data[2], data[3])); + case COD -> spawn(player.getWorld(), new CodPet(player, data[0])); } } diff --git a/src/main/java/lee/code/pets/pets/controllers/ControllerLookFlying.java b/src/main/java/lee/code/pets/pets/controllers/ControllerLookFlying.java index 43b0463..fab9227 100644 --- a/src/main/java/lee/code/pets/pets/controllers/ControllerLookFlying.java +++ b/src/main/java/lee/code/pets/pets/controllers/ControllerLookFlying.java @@ -27,9 +27,7 @@ public void tick() { 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.setSpeed(0.2F); // You can adjust the speed as needed. diff --git a/src/main/java/lee/code/pets/pets/controllers/ControllerWASDWater.java b/src/main/java/lee/code/pets/pets/controllers/ControllerWASDWater.java new file mode 100644 index 0000000..2fe18b5 --- /dev/null +++ b/src/main/java/lee/code/pets/pets/controllers/ControllerWASDWater.java @@ -0,0 +1,76 @@ +package lee.code.pets.pets.controllers; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.AirBlock; +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.WaterFluid; +import net.minecraft.world.phys.Vec3; + +import java.util.UUID; + +public class ControllerWASDWater extends ControllerWASD { + + public ControllerWASDWater(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); + + float forward = (float) riddenInput.z * 0.5F; + float strafe = (float) riddenInput.x * 0.25F; + if (forward <= 0.0F) forward *= 0.5F; + + // Calculate the player's yaw and pitch + float yaw = rider.getBukkitYaw(); + float pitch = rider.getXRot(); + + // Calculate the direction based on yaw and pitch + double motionX = forward * -Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)); + double motionY = forward * -Math.sin(Math.toRadians(pitch)); // Adjust vertical motion based on pitch + double motionZ = forward * Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)); + + // Add upward motion when jumping + if (rider.jumping) { + motionY += 0.5D; + } + + if (!mob.isInWater()) { + // Limit upward motion if out of water + motionY = Math.min(-0.1D, motionY); + + // If solid block below entity out of water, slow down + final BlockPos downPos = mob.blockPosition().relative(Direction.DOWN); + final BlockState frontBlockState = mob.level().getBlockState(downPos); + if (!(frontBlockState.getBlock() instanceof LiquidBlock)) { + motionX *= 0.2D; + motionY *= 0.2D; + motionZ *= 0.2D; + } + } + + // Set the mob's motion + mob.setDeltaMovement(new Vec3(motionX, motionY, motionZ)); + + // Set the yaw rotation of the mob + mob.setYRot(yaw); + + // Set the desired speed and direction of the mob. + mob.setSpeed(1F); + mob.setZza(forward); + mob.setXxa(0.0F); + } +} diff --git a/src/main/java/lee/code/pets/pets/goals/FollowOwnerFlyingGoal.java b/src/main/java/lee/code/pets/pets/goals/FollowOwnerFlyingGoal.java deleted file mode 100644 index f307631..0000000 --- a/src/main/java/lee/code/pets/pets/goals/FollowOwnerFlyingGoal.java +++ /dev/null @@ -1,33 +0,0 @@ -package lee.code.pets.pets.goals; - - -import net.minecraft.core.BlockPos; -import net.minecraft.world.entity.Mob; -import net.minecraft.world.phys.Vec3; - -public class FollowOwnerFlyingGoal extends FollowOwnerGoal { - - public FollowOwnerFlyingGoal(Mob mob, double speed) { - super(mob, speed); - } - - @Override - public void tick() { - // Get the current position of the mob - BlockPos mobPos = mob.blockPosition(); - - // Get the current position of the owner (player) - BlockPos ownerPos = owner.blockPosition(); - - // Calculate the direction vector from the mob to the owner - Vec3 direction = new Vec3(ownerPos.getX() - mobPos.getX(), ownerPos.getY() - mobPos.getY(), ownerPos.getZ() - mobPos.getZ()).normalize(); - - // Calculate the new position for the mob to move towards the owner - double newX = mobPos.getX() + direction.x * speed; // Adjust the speed to control the movement speed - double newY = mobPos.getY() + direction.y * speed; - double newZ = mobPos.getZ() + direction.z * speed; - - // Update the mob's position - mob.getMoveControl().setWantedPosition(newX, newY, newZ, speed); - } -} diff --git a/src/main/java/lee/code/pets/pets/goals/FollowOwnerGoal.java b/src/main/java/lee/code/pets/pets/goals/FollowOwnerGoal.java index 24f437e..5c6f86d 100644 --- a/src/main/java/lee/code/pets/pets/goals/FollowOwnerGoal.java +++ b/src/main/java/lee/code/pets/pets/goals/FollowOwnerGoal.java @@ -50,7 +50,6 @@ public void tick() { final BlockPos frontPos = mob.blockPosition().relative(mob.getDirection()); final BlockState frontBlockState = mob.level().getBlockState(frontPos); if (frontBlockState.isSolidRender(mob.level(), frontPos) || frontBlockState.getBlock() instanceof LeavesBlock) { - // Jump logic here. mob.getJumpControl().jump(); } } diff --git a/src/main/java/lee/code/pets/pets/pet/animal/HorsePet.java b/src/main/java/lee/code/pets/pets/pet/animal/HorsePet.java new file mode 100644 index 0000000..328bdb1 --- /dev/null +++ b/src/main/java/lee/code/pets/pets/pet/animal/HorsePet.java @@ -0,0 +1,54 @@ +package lee.code.pets.pets.pet.animal; + +import lee.code.pets.pets.controllers.ControllerWASD; +import lee.code.pets.pets.goals.FollowOwnerGoal; +import lee.code.pets.utils.CoreUtil; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.animal.horse.Horse; +import net.minecraft.world.entity.animal.horse.Markings; +import net.minecraft.world.entity.animal.horse.Variant; +import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityTargetEvent; + +public class HorsePet extends Horse { + + public HorsePet(Player player, boolean baby, String name, String variant, String markings) { + super(EntityType.HORSE, ((CraftWorld) player.getLocation().getWorld()).getHandle()); + setPos(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()); + setInvulnerable(true); + setCustomNameVisible(true); + setPersistenceRequired(true); + collides = false; + setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(name))); + setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false); + moveControl = new ControllerWASD(this, player.getUniqueId()); + if (baby) setBaby(true); + setVariantAndMarkings(Variant.valueOf(variant), Markings.valueOf(markings)); + } + + @Override + protected void registerGoals() { + goalSelector.addGoal(0, new FollowOwnerGoal(this, 2)); + } + + @Override + public void ageUp(int age) { + } + + @Override + public void ageUp(int age, boolean overGrow) { + } + + @Override + public void load(CompoundTag compoundTag) { + } + + @Override + public boolean save(CompoundTag compoundTag) { + return false; + } +} diff --git a/src/main/java/lee/code/pets/pets/pet/fish/CodPet.java b/src/main/java/lee/code/pets/pets/pet/fish/CodPet.java new file mode 100644 index 0000000..32a4668 --- /dev/null +++ b/src/main/java/lee/code/pets/pets/pet/fish/CodPet.java @@ -0,0 +1,43 @@ +package lee.code.pets.pets.pet.fish; + +import lee.code.pets.pets.controllers.ControllerWASD; +import lee.code.pets.pets.controllers.ControllerWASDWater; +import lee.code.pets.pets.goals.FollowOwnerGoal; +import lee.code.pets.utils.CoreUtil; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.animal.Cod; +import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityTargetEvent; + +public class CodPet extends Cod { + + public CodPet(Player player, String name) { + super(EntityType.COD, ((CraftWorld) player.getLocation().getWorld()).getHandle()); + setPos(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()); + setInvulnerable(true); + setCustomNameVisible(true); + setPersistenceRequired(true); + collides = false; + setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(name))); + setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false); + moveControl = new ControllerWASDWater(this, player.getUniqueId()); + } + + @Override + protected void registerGoals() { + goalSelector.addGoal(0, new FollowOwnerGoal(this, 2)); + } + + @Override + public void load(CompoundTag compoundTag) { + } + + @Override + public boolean save(CompoundTag compoundTag) { + return false; + } +} diff --git a/src/main/java/lee/code/pets/pets/pet/mob/SkeletonPet.java b/src/main/java/lee/code/pets/pets/pet/mob/SkeletonPet.java new file mode 100644 index 0000000..8b108a2 --- /dev/null +++ b/src/main/java/lee/code/pets/pets/pet/mob/SkeletonPet.java @@ -0,0 +1,42 @@ +package lee.code.pets.pets.pet.mob; + +import lee.code.pets.pets.controllers.ControllerWASD; +import lee.code.pets.pets.goals.FollowOwnerGoal; +import lee.code.pets.utils.CoreUtil; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityTargetEvent; + +public class SkeletonPet extends Mob { + + public SkeletonPet(Player player, String name) { + super(EntityType.SKELETON, ((CraftWorld) player.getLocation().getWorld()).getHandle()); + setPos(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()); + setInvulnerable(true); + setCustomNameVisible(true); + setPersistenceRequired(true); + collides = false; + setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(name))); + setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false); + moveControl = new ControllerWASD(this, player.getUniqueId()); + } + + @Override + protected void registerGoals() { + goalSelector.addGoal(0, new FollowOwnerGoal(this, 2)); + } + + @Override + public void load(CompoundTag compoundTag) { + } + + @Override + public boolean save(CompoundTag compoundTag) { + return false; + } +}