Always remove entities from cache

This commit is contained in:
AJ Ferguson 2024-04-17 01:30:17 -04:00
parent a24f684123
commit 1d75749f3d
7 changed files with 17 additions and 19 deletions

View File

@ -200,11 +200,9 @@ public class Entity implements GeyserEntity {
/**
* Despawns the entity
*
* @return can be deleted
*/
public boolean despawnEntity() {
if (!valid) return true;
public void despawnEntity() {
if (!valid) return;
for (Entity passenger : passengers) { // Make sure all passengers on the despawned entity are updated
if (passenger == null) continue;
@ -218,7 +216,6 @@ public class Entity implements GeyserEntity {
session.sendUpstreamPacket(removeEntityPacket);
valid = false;
return true;
}
public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) {

View File

@ -148,7 +148,7 @@ public class ItemFrameEntity extends Entity {
}
@Override
public boolean despawnEntity() {
public void despawnEntity() {
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(bedrockPosition);
@ -161,7 +161,6 @@ public class ItemFrameEntity extends Entity {
session.getItemFrameCache().remove(bedrockPosition, this);
valid = false;
return true;
}
private NbtMap getDefaultTag() {

View File

@ -170,14 +170,14 @@ public class ThrowableEntity extends Entity implements Tickable {
}
@Override
public boolean despawnEntity() {
public void despawnEntity() {
if (definition.entityType() == EntityType.ENDER_PEARL) {
LevelEventPacket particlePacket = new LevelEventPacket();
particlePacket.setType(LevelEvent.PARTICLE_TELEPORT);
particlePacket.setPosition(position);
session.sendUpstreamPacket(particlePacket);
}
return super.despawnEntity();
super.despawnEntity();
}
@Override

View File

@ -99,11 +99,11 @@ public class ArmorStandEntity extends LivingEntity {
}
@Override
public boolean despawnEntity() {
public void despawnEntity() {
if (secondEntity != null) {
secondEntity.despawnEntity();
}
return super.despawnEntity();
super.despawnEntity();
}
@Override

View File

@ -148,11 +148,11 @@ public class EnderDragonEntity extends MobEntity implements Tickable {
}
@Override
public boolean despawnEntity() {
public void despawnEntity() {
for (EnderDragonPartEntity part : allParts) {
part.despawnEntity();
}
return super.despawnEntity();
super.despawnEntity();
}
@Override

View File

@ -85,27 +85,29 @@ public class EntityCache {
return false;
}
public boolean removeEntity(Entity entity, boolean force) {
public void removeEntity(Entity entity) {
if (entity instanceof PlayerEntity player) {
session.getPlayerWithCustomHeads().remove(player.getUuid());
}
if (entity != null && entity.isValid() && (force || entity.despawnEntity())) {
if (entity != null) {
if (entity.isValid()) {
entity.despawnEntity();
}
long geyserId = entityIdTranslations.remove(entity.getEntityId());
entities.remove(geyserId);
if (entity instanceof Tickable) {
tickableEntities.remove(entity);
}
return true;
}
return false;
}
public void removeAllEntities() {
List<Entity> entities = new ArrayList<>(this.entities.values());
for (Entity entity : entities) {
removeEntity(entity, false);
removeEntity(entity);
}
session.getPlayerWithCustomHeads().clear();

View File

@ -39,7 +39,7 @@ public class JavaRemoveEntitiesTranslator extends PacketTranslator<ClientboundRe
for (int entityId : packet.getEntityIds()) {
Entity entity = session.getEntityCache().getEntityByJavaId(entityId);
if (entity != null) {
session.getEntityCache().removeEntity(entity, false);
session.getEntityCache().removeEntity(entity);
}
}
}