3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 14:30:17 +01:00

Always remove entities from cache (#4577)

* Always remove entities from cache

* Despawn throwable entities in the void
Dieser Commit ist enthalten in:
AJ Ferguson 2024-04-17 03:18:17 -04:00 committet von GitHub
Ursprung 5151c25e1a
Commit c8475d8100
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
10 geänderte Dateien mit 40 neuen und 20 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -72,6 +72,9 @@ public class FireballEntity extends ThrowableEntity {
@Override @Override
public void tick() { public void tick() {
if (removedInVoid()) {
return;
}
moveAbsoluteImmediate(tickMovement(position), getYaw(), getPitch(), getHeadYaw(), false, false); moveAbsoluteImmediate(tickMovement(position), getYaw(), getPitch(), getHeadYaw(), false, false);
} }
} }

Datei anzeigen

@ -133,6 +133,9 @@ public class FishingHookEntity extends ThrowableEntity {
@Override @Override
public void tick() { public void tick() {
if (removedInVoid()) {
return;
}
if (hooked || !isInAir() && !isInWater() || isOnGround()) { if (hooked || !isInAir() && !isInWater() || isOnGround()) {
motion = Vector3f.ZERO; motion = Vector3f.ZERO;
return; return;

Datei anzeigen

@ -74,7 +74,7 @@ public class ItemEntity extends ThrowableEntity {
@Override @Override
public void tick() { public void tick() {
if (isInWater()) { if (removedInVoid() || isInWater()) {
return; return;
} }
if (!isOnGround() || (motion.getX() * motion.getX() + motion.getZ() * motion.getZ()) > 0.00001) { if (!isOnGround() || (motion.getX() * motion.getX() + motion.getZ() * motion.getZ()) > 0.00001) {

Datei anzeigen

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

Datei anzeigen

@ -55,6 +55,9 @@ public class ThrowableEntity extends Entity implements Tickable {
*/ */
@Override @Override
public void tick() { public void tick() {
if (removedInVoid()) {
return;
}
moveAbsoluteImmediate(position.add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false); moveAbsoluteImmediate(position.add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false);
float drag = getDrag(); float drag = getDrag();
float gravity = getGravity(); float gravity = getGravity();
@ -170,14 +173,14 @@ public class ThrowableEntity extends Entity implements Tickable {
} }
@Override @Override
public boolean despawnEntity() { public void despawnEntity() {
if (definition.entityType() == EntityType.ENDER_PEARL) { if (definition.entityType() == EntityType.ENDER_PEARL) {
LevelEventPacket particlePacket = new LevelEventPacket(); LevelEventPacket particlePacket = new LevelEventPacket();
particlePacket.setType(LevelEvent.PARTICLE_TELEPORT); particlePacket.setType(LevelEvent.PARTICLE_TELEPORT);
particlePacket.setPosition(position); particlePacket.setPosition(position);
session.sendUpstreamPacket(particlePacket); session.sendUpstreamPacket(particlePacket);
} }
return super.despawnEntity(); super.despawnEntity();
} }
@Override @Override
@ -191,4 +194,17 @@ public class ThrowableEntity extends Entity implements Tickable {
moveAbsoluteImmediate(position, yaw, pitch, headYaw, isOnGround, teleported); moveAbsoluteImmediate(position, yaw, pitch, headYaw, isOnGround, teleported);
lastJavaPosition = position; lastJavaPosition = position;
} }
/**
* Removes the entity if it is 64 blocks below the world.
*
* @return true if the entity was removed
*/
public boolean removedInVoid() {
if (position.getY() < session.getDimensionType().minY() - 64) {
session.getEntityCache().removeEntity(this);
return true;
}
return false;
}
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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