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:
parent
dab9378a67
commit
20c3c93c06
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user