Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teleport pets with player #7400

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

jwkerr
Copy link
Contributor

@jwkerr jwkerr commented May 4, 2024

Description:

When teleporting, pets can get left behind and lost forever if in unloaded chunks. This PR now additionally teleports any non-sitting tamed pets owned by and nearby the player on teleport.

There is also a refactor to have one unified teleportEntities method rather than using PaperLib.teleportAsync multiple times to make it a bit more maintainable now that we are teleporting many things.


New Nodes/Commands/ConfigOptions:

N/A


Relevant Towny Issue ticket:

N/A


  • I have tested this pull request for defects on a server.

By making this pull request, I represent that I have the right to waive copyright and related rights to my contribution, and agree that all copyright and related rights in my contributions are waived, and I acknowledge that the TownyAdvanced organization has the copyright to use and modify my contribution under the Towny License for perpetuity.

@jwkerr
Copy link
Contributor Author

jwkerr commented May 4, 2024

not sure this is something wanted in towny or if it will cause any issues, possible considerations are checking if the location is safe for pets or adding a config node or something just lmk and i will change things

Copy link
Member

@Warriorrrr Warriorrrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether pets are teleported & the radius should have config options at least

*
* @param player The player to get the pets of
*/
public static List<Entity> getPets(Player player) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static List<Entity> getPets(Player player) {
public static Collection<Entity> getPets(Player player) {

AnimalTamer tamer = tameable.getOwner();
if (tamer == null) continue;

if (!(entity instanceof Sittable sittable)) continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about non sittable pets? When #6865 is merged the types of entities that are teleported could be made configurable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what pets are non-sittable that also follow you like a dog or cat

Copy link
Contributor Author

@jwkerr jwkerr May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or do you mean for adding things like horses, camels etc.

if that's the case i could change it to check if they are currently riding something

Comment on lines 694 to 696
for (Entity entity : player.getNearbyEntities(16, 16, 16)) {
if (!(entity instanceof Tameable tameable)) continue;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (Entity entity : player.getNearbyEntities(16, 16, 16)) {
if (!(entity instanceof Tameable tameable)) continue;
for (Tameable tameable : player.getLocation().getNearbyEntitiesByType(Tameable.class, 16)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method doesn't seem to exist

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at the paper javadocs, but the same method exists on World on spigot

* @param entities Entities to teleport
* @param cause What caused the teleport
*/
public static void teleportEntities(Location loc, List<Entity> entities, TeleportCause cause) {
Copy link
Member

@Warriorrrr Warriorrrr May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static void teleportEntities(Location loc, List<Entity> entities, TeleportCause cause) {
public static void teleportEntities(Location loc, Iterable<Entity> entities, TeleportCause cause) {

Comment on lines 71 to 72
List<Entity> pets = SpawnUtil.getPets(player);
pets.add(player);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to call it entities since the player is added to it (and is not a pet)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Came here to say this.

@jwkerr
Copy link
Contributor Author

jwkerr commented May 13, 2024

not sure how i should specifically implement this, it would be easiest to just get all nearby tamed entities owned by the player and tp them but that could be a bit unnatural if we want to build in the ability to teleport "pets" that are rideable like horses and stuff since rideables that are nearby and not being ridden by the player would also be teleported

under that simple implementation most servers would probably limit it to just sittables like wolves, cats, parrots etc. but it would be possible to split it into to two settings like teleport sittables and teleport vehicle with their own lists or something along those lines

@LlmDl
Copy link
Member

LlmDl commented May 14, 2024

This is how I would imagine it would work:

  • Animals that follow you like cats, dogs and parrots would go with you automatically unless sitting.
  • Animals you're actively riding go with you.
  • Animals you have on a leash go with you.

I am guessing that animals which are following you that aren't sitting, cats, dogs, parrots currently sometimes don't teleport with the player? I would have thought when you moved they would teleport with you.

I know that we eject the player off of any horse if they're currently riding for some esoteric reason that's lost to time.

@jwkerr
Copy link
Contributor Author

jwkerr commented May 14, 2024

I would have thought when you moved they would teleport with you.

since the chunk becomes unloaded as the player leaves, unless another player is remaining to load those chunks and trigger a tp to the pet owner's new location they will stay there

i've had pets on earthmc that i've completely forgotten about tp to me from the middle of nowhere presumably because some random new player loaded those chunks while i happened to be online

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants