Skip to content

Commit

Permalink
Cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
senseiwells committed Feb 4, 2024
1 parent a44ff94 commit 3833f8d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import me.senseiwells.replay.chunk.ChunkRecorder;
import me.senseiwells.replay.chunk.ChunkRecorders;
import me.senseiwells.replay.ducks.ServerReplay$ChunkRecordable;
import me.senseiwells.replay.player.PlayerRecorder;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBundlePacket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public interface ChunkMapAccessor {
@Accessor("entityMap")
Int2ObjectMap<ChunkMap.TrackedEntity> getEntityMap();

@Accessor("serverViewDistance")
int getViewDistance();

@Accessor("lightEngine")
ThreadedLevelLightEngine getLightEngine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import net.minecraft.world.level.ChunkPos
import net.minecraft.world.level.Level

@Serializable
class ChunkAreaConfig constructor(
class ChunkAreaConfig(
val name: String,
@SerialName("dimension")
@Serializable(with = ResourceLocationSerializer::class)
Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/me/senseiwells/replay/recorder/ChunkSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface ChunkSender {
fun addTrackedEntity(tracking: TrackedEntity)

fun getViewDistance(): Int {
return (this.level.chunkSource.chunkMap as ChunkMapAccessor).viewDistance
return this.level.server.playerList.viewDistance
}

@NonExtendable
Expand Down Expand Up @@ -87,11 +87,12 @@ interface ChunkSender {
val leashed = ArrayList<Mob>()
val ridden = ArrayList<Entity>()

val viewDistance = this.level.server.playerList.viewDistance
for (tracked in chunks.entityMap.values) {
val entity = (tracked as TrackedEntityAccessor).entity
if (this.isValidEntity(entity) && entity.chunkPosition() == chunk.pos) {
if (!seen.contains(entity.id)) {
val range = min(tracked.getRange(), chunks.viewDistance * 16).toDouble()
val range = min(tracked.getRange(), viewDistance * 16).toDouble()
if (this.shouldTrackEntity(entity, range)) {
this.addTrackedEntity(tracked)
seen.add(entity.id)
Expand Down Expand Up @@ -119,9 +120,10 @@ interface ChunkSender {
fun sendChunkEntities(seen: IntSet) {
val chunks = this.level.chunkSource.chunkMap
val entities = (chunks as ChunkMapAccessor).entityMap
val viewDistance = this.level.server.playerList.viewDistance
for (tracked in entities.values) {
val entity = (tracked as TrackedEntityAccessor).entity
val range = min(tracked.getRange(), chunks.viewDistance * 16).toDouble()
val range = min(tracked.getRange(), viewDistance * 16).toDouble()
if (this.shouldTrackEntity(entity, range)) {
this.addTrackedEntity(tracked)
}
Expand Down

0 comments on commit 3833f8d

Please sign in to comment.