Adds a few fixes which seem to make leash teleportation work as expected

Un-leashes and re-leashes teleported leashed entities
Delays leashed creature teleportation and the re-leashing to prevent odd behavior such as infinite leash or no-ai creature
This commit is contained in:
Kristian Knarvik 2021-11-01 17:54:38 +01:00
parent dab9378a67
commit 20c3c93c06
3 changed files with 28 additions and 6 deletions

View File

@ -48,7 +48,7 @@ public class PlayerTeleporter extends Teleporter {
//Load chunks to make sure not to teleport to the void
loadChunks();
//Teleport any creatures leashed by the player in a 10-block range
//Teleport any creatures leashed by the player in a 15-block range
teleportLeashedCreatures(player, origin);
//If no event is passed in, assume it's a teleport, and act as such

View File

@ -257,13 +257,34 @@ public abstract class Teleporter {
*/
protected void teleportLeashedCreatures(Player player, Portal origin) {
//Find any nearby leashed entities to teleport with the player
List<Entity> nearbyEntities = player.getNearbyEntities(15, 15, 15);
for (Entity entity : nearbyEntities) {
//Teleport all creatures leashed by the player to the portal the player is to exit from
if (entity instanceof Creature creature && creature.isLeashed() && creature.getLeashHolder() == player) {
List<Creature> nearbyEntities = getLeashedCreatures(player);
//Teleport all creatures leashed by the player to the portal the player is to exit from
for (Creature creature : nearbyEntities) {
creature.setLeashHolder(null);
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(), () -> {
new EntityTeleporter(portal, creature).teleport(origin);
}
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(), () -> creature.setLeashHolder(player), 3);
}, 2);
}
}
/**
* Gets all creatures leashed by a player within the given range
*
* @param player <p>The player to check</p>
* @return <p>A list of all creatures the player is holding in a leash (lead)</p>
*/
protected List<Creature> getLeashedCreatures(Player player) {
List<Creature> leashedCreatures = new ArrayList<>();
//Find any nearby leashed entities to teleport with the player
List<Entity> nearbyEntities = player.getNearbyEntities(15, 15, 15);
//Teleport all creatures leashed by the player to the portal the player is to exit from
for (Entity entity : nearbyEntities) {
if (entity instanceof Creature creature && creature.isLeashed() && creature.getLeashHolder() == player) {
leashedCreatures.add(creature);
}
}
return leashedCreatures;
}
}

View File

@ -151,6 +151,7 @@ public class VehicleTeleporter extends EntityTeleporter {
passenger.eject();
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(), () -> {
if (passenger instanceof Player player) {
//Teleport any creatures leashed by the player in a 15-block range
teleportLeashedCreatures(player, origin);
}
teleportAndAddPassenger(vehicle, passenger);