-
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
dbb3533
commit 011af25
Showing
9 changed files
with
220 additions
and
37 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
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
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
76 changes: 76 additions & 0 deletions
76
src/main/java/lee/code/pets/pets/controllers/ControllerWASDWater.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,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); | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
src/main/java/lee/code/pets/pets/goals/FollowOwnerFlyingGoal.java
This file was deleted.
Oops, something went wrong.
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
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,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; | ||
} | ||
} |
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,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; | ||
} | ||
} |
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,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; | ||
} | ||
} |