Skip to content

Commit

Permalink
fix: some mitigations for entity tracking issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Aug 15, 2024
1 parent 77c4204 commit 465bcb0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,25 @@ private void tickStaging(ServerChunkLoadingManager.TicketManager ticketManager)
}

final List<ServerPlayerEntity> players = ((IThreadedAnvilChunkStorage) ((IThreadedAnvilChunkStorageTicketManager) ticketManager).getField_17443()).getWorld().getPlayers();
for(StagedTracker staged : this.stagingTrackers) {
for (StagedTracker staged : this.stagingTrackers) {
final ServerChunkLoadingManager.EntityTracker entityTracker = staged.tracker();
ChunkSectionPos chunkSectionPos = ((IThreadedAnvilChunkStorageEntityTracker) entityTracker).getTrackedSection();
final Entity entity = ((IThreadedAnvilChunkStorageEntityTracker) entityTracker).getEntity();
ChunkSectionPos chunkSectionPos2 = ChunkSectionPos.from(entity);
boolean bl = !Objects.equals(chunkSectionPos, chunkSectionPos2);
entityTracker.updateTrackedStatus(players);
if (bl) {
entityTracker.updateTrackedStatus(players);
((IThreadedAnvilChunkStorageEntityTracker) entityTracker).setTrackedSection(chunkSectionPos2);
}

if (bl || ticketManager.shouldTickEntities(chunkSectionPos2.toChunkPos().toLong())) {
((EntityTrackerExtension) entityTracker).tryTick();
}
}

for (StagedTracker staged : this.stagingTrackers) {
staged.tracker().updateTrackedStatus(players);
}
}

private void handleTracker(ServerChunkLoadingManager.TicketManager ticketManager, ServerPlayerEntity player, boolean isPlayerPositionUpdated, ServerChunkLoadingManager.EntityTracker entityTracker) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,7 @@ public void updateListeners(Set<ServerPlayerEntity> triedPlayers) {
@Override
public void tryTick() {
this.trackedSection = ChunkSectionPos.from(this.entity);
if (!this.listeners.isEmpty()) {
this.entry.tick();
} else {
final List<Entity> currentPassegers = this.entity.getPassengerList();
if (!((IEntityTrackerEntry) this.entry).getLastPassengers().equals(currentPassegers)) {
((IEntityTrackerEntry) this.entry).setLastPassengers(currentPassegers);
}

if (this.entity instanceof ServerPlayerEntity player) {
// for some reasons mojang decides to sync entity data here, so we need to do it manually

if (this.entity.velocityModified) {
player.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(this.entity));
this.entity.velocityModified = false;
}

((EntityTrackerEntryExtension) this.entry).vmp$syncEntityData();
}
}
this.entry.tick();
}

@Inject(method = "updateTrackedStatus(Lnet/minecraft/server/network/ServerPlayerEntity;)V", at = @At(value = "INVOKE", target = "Ljava/util/Set;add(Ljava/lang/Object;)Z", shift = At.Shift.BEFORE))
Expand Down

0 comments on commit 465bcb0

Please sign in to comment.