fixed sit while seated causing sit entities to not be removed for the player

This commit is contained in:
Oth3r 2024-08-26 14:38:21 -05:00
commit 2e1ae46d77
2 changed files with 22 additions and 8 deletions

View file

@ -84,6 +84,26 @@ public class Logic {
Utl.Entity.remove(entity);
}
/**
* spawns a sit entity for the player, they HAVE TO BE in the spawn list
*/
public static void spawnEntity(ServerPlayerEntity player) {
// return if not in the list
if (Data.getSpawnList().get(player) == null) return;
// if the player is already sitting on a sit entity, remove it before spawning a new one
if (FileData.getSitEntity(player) != null) Logic.removeEntity(player);
// get the new entity
DisplayEntity.TextDisplayEntity sitEntity = Data.getSpawnList().get(player);
// spawn and ride the entity
player.getServerWorld().spawnEntity(sitEntity);
player.startRiding(sitEntity);
// add the entity to the list
FileData.addSitEntity(player, sitEntity);
// remove the entity from the spawn list
Data.removeSpawnList(player);
}
/**
* checks if the player should still be sitting, e.g. the block was destroyed ect.
*/

View file

@ -51,16 +51,10 @@ public class LoopManager {
}
}
// spawn entities for everyone in the spawn list
HashMap<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> spawnList = Data.getSpawnList();
for (ServerPlayerEntity player : spawnList.keySet()) {
DisplayEntity.TextDisplayEntity sitEntity = spawnList.get(player);
player.getServerWorld().spawnEntity(sitEntity);
player.startRiding(sitEntity);
// add the entity to the list
FileData.addSitEntity(player, sitEntity);
// remove the entity from the list
Data.removeSpawnList(player);
Logic.spawnEntity(player);
}
}
}