LevelDebugSynchronizers.java

net.minecraft.util.debug.LevelDebugSynchronizers

信息

  • 全限定名:net.minecraft.util.debug.LevelDebugSynchronizers
  • 类型:public class
  • 包:net.minecraft.util.debug
  • 源码路径:src/main/java/net/minecraft/util/debug/LevelDebugSynchronizers.java
  • 起始行号:L25
  • 职责:

    TODO

字段/常量

  • level

    • 类型: ServerLevel
    • 修饰符: private final
    • 源码定位: L26
    • 说明:

      TODO

  • allSynchronizers

    • 类型: List<TrackingDebugSynchronizer<?>>
    • 修饰符: private final
    • 源码定位: L27
    • 说明:

      TODO

  • sourceSynchronizers

    • 类型: Map<DebugSubscription<?>,TrackingDebugSynchronizer.SourceSynchronizer<?>>
    • 修饰符: private final
    • 源码定位: L28
    • 说明:

      TODO

  • poiSynchronizer

    • 类型: TrackingDebugSynchronizer.PoiSynchronizer
    • 修饰符: private final
    • 源码定位: L29
    • 说明:

      TODO

  • villageSectionSynchronizer

    • 类型: TrackingDebugSynchronizer.VillageSectionSynchronizer
    • 修饰符: private final
    • 源码定位: L30
    • 说明:

      TODO

  • sleeping

    • 类型: boolean
    • 修饰符: private
    • 源码定位: L31
    • 说明:

      TODO

  • enabledSubscriptions

    • 类型: Set<DebugSubscription<?>>
    • 修饰符: private
    • 源码定位: L32
    • 说明:

      TODO

内部类/嵌套类型

构造器

public LevelDebugSynchronizers(ServerLevel level) @ L34

  • 构造器名:LevelDebugSynchronizers
  • 源码定位:L34
  • 修饰符:public

参数:

  • level: ServerLevel

说明:

TODO

方法

下面的方法块按源码顺序生成。

public void tick(ServerDebugSubscribers serverSubscribers) @ L48

  • 方法名:tick
  • 源码定位:L48
  • 返回类型:void
  • 修饰符:public

参数:

  • serverSubscribers: ServerDebugSubscribers

说明:

TODO

private void wakeUp() @ L69

  • 方法名:wakeUp
  • 源码定位:L69
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

private <T> TrackingDebugSynchronizer.SourceSynchronizer<T> getSourceSynchronizer(DebugSubscription<T> subscription) @ L80

  • 方法名:getSourceSynchronizer
  • 源码定位:L80
  • 返回类型: TrackingDebugSynchronizer.SourceSynchronizer
  • 修饰符:private

参数:

  • subscription: DebugSubscription

说明:

TODO

public void registerChunk(LevelChunk chunk) @ L84

  • 方法名:registerChunk
  • 源码定位:L84
  • 返回类型:void
  • 修饰符:public

参数:

  • chunk: LevelChunk

说明:

TODO

public void dropChunk(ChunkPos chunkPos) @ L100

  • 方法名:dropChunk
  • 源码定位:L100
  • 返回类型:void
  • 修饰符:public

参数:

  • chunkPos: ChunkPos

说明:

TODO

public void registerBlockEntity(BlockEntity blockEntity) @ L108

  • 方法名:registerBlockEntity
  • 源码定位:L108
  • 返回类型:void
  • 修饰符:public

参数:

  • blockEntity: BlockEntity

说明:

TODO

public void dropBlockEntity(BlockPos blockPos) @ L123

  • 方法名:dropBlockEntity
  • 源码定位:L123
  • 返回类型:void
  • 修饰符:public

参数:

  • blockPos: BlockPos

说明:

TODO

public void registerEntity(Entity entity) @ L131

  • 方法名:registerEntity
  • 源码定位:L131
  • 返回类型:void
  • 修饰符:public

参数:

  • entity: Entity

说明:

TODO

public void dropEntity(Entity entity) @ L146

  • 方法名:dropEntity
  • 源码定位:L146
  • 返回类型:void
  • 修饰符:public

参数:

  • entity: Entity

说明:

TODO

public void startTrackingChunk(ServerPlayer player, ChunkPos chunkPos) @ L154

  • 方法名:startTrackingChunk
  • 源码定位:L154
  • 返回类型:void
  • 修饰符:public

参数:

  • player: ServerPlayer
  • chunkPos: ChunkPos

说明:

TODO

public void startTrackingEntity(ServerPlayer player, Entity entity) @ L162

  • 方法名:startTrackingEntity
  • 源码定位:L162
  • 返回类型:void
  • 修饰符:public

参数:

  • player: ServerPlayer
  • entity: Entity

说明:

TODO

public void registerPoi(PoiRecord poi) @ L170

  • 方法名:registerPoi
  • 源码定位:L170
  • 返回类型:void
  • 修饰符:public

参数:

  • poi: PoiRecord

说明:

TODO

public void updatePoi(BlockPos pos) @ L177

  • 方法名:updatePoi
  • 源码定位:L177
  • 返回类型:void
  • 修饰符:public

参数:

  • pos: BlockPos

说明:

TODO

public void dropPoi(BlockPos pos) @ L183

  • 方法名:dropPoi
  • 源码定位:L183
  • 返回类型:void
  • 修饰符:public

参数:

  • pos: BlockPos

说明:

TODO

public boolean hasAnySubscriberFor(DebugSubscription<?> subscription) @ L190

  • 方法名:hasAnySubscriberFor
  • 源码定位:L190
  • 返回类型:boolean
  • 修饰符:public

参数:

  • subscription: DebugSubscription<?>

说明:

TODO

public <T> void sendBlockValue(BlockPos blockPos, DebugSubscription<T> subscription, T value) @ L194

  • 方法名:sendBlockValue
  • 源码定位:L194
  • 返回类型: void
  • 修饰符:public

参数:

  • blockPos: BlockPos
  • subscription: DebugSubscription
  • value: T

说明:

TODO

public <T> void clearBlockValue(BlockPos blockPos, DebugSubscription<T> subscription) @ L202

  • 方法名:clearBlockValue
  • 源码定位:L202
  • 返回类型: void
  • 修饰符:public

参数:

  • blockPos: BlockPos
  • subscription: DebugSubscription

说明:

TODO

public <T> void sendEntityValue(Entity entity, DebugSubscription<T> subscription, T value) @ L208

  • 方法名:sendEntityValue
  • 源码定位:L208
  • 返回类型: void
  • 修饰符:public

参数:

  • entity: Entity
  • subscription: DebugSubscription
  • value: T

说明:

TODO

public <T> void clearEntityValue(Entity entity, DebugSubscription<T> subscription) @ L214

  • 方法名:clearEntityValue
  • 源码定位:L214
  • 返回类型: void
  • 修饰符:public

参数:

  • entity: Entity
  • subscription: DebugSubscription

说明:

TODO

public <T> void broadcastEventToTracking(BlockPos blockPos, DebugSubscription<T> subscription, T value) @ L220

  • 方法名:broadcastEventToTracking
  • 源码定位:L220
  • 返回类型: void
  • 修饰符:public

参数:

  • blockPos: BlockPos
  • subscription: DebugSubscription
  • value: T

说明:

TODO

private void broadcastToTracking(ChunkPos trackedChunk, DebugSubscription<?> subscription, Packet<?super ClientGamePacketListener> packet) @ L226

  • 方法名:broadcastToTracking
  • 源码定位:L226
  • 返回类型:void
  • 修饰符:private

参数:

  • trackedChunk: ChunkPos
  • subscription: DebugSubscription<?>
  • packet: Packet<?super ClientGamePacketListener>

说明:

TODO

private void broadcastToTracking(Entity trackedEntity, DebugSubscription<?> subscription, Packet<?super ClientGamePacketListener> packet) @ L236

  • 方法名:broadcastToTracking
  • 源码定位:L236
  • 返回类型:void
  • 修饰符:private

参数:

  • trackedEntity: Entity
  • subscription: DebugSubscription<?>
  • packet: Packet<?super ClientGamePacketListener>

说明:

TODO

代码

public class LevelDebugSynchronizers {
    private final ServerLevel level;
    private final List<TrackingDebugSynchronizer<?>> allSynchronizers = new ArrayList<>();
    private final Map<DebugSubscription<?>, TrackingDebugSynchronizer.SourceSynchronizer<?>> sourceSynchronizers = new HashMap<>();
    private final TrackingDebugSynchronizer.PoiSynchronizer poiSynchronizer = new TrackingDebugSynchronizer.PoiSynchronizer();
    private final TrackingDebugSynchronizer.VillageSectionSynchronizer villageSectionSynchronizer = new TrackingDebugSynchronizer.VillageSectionSynchronizer();
    private boolean sleeping = true;
    private Set<DebugSubscription<?>> enabledSubscriptions = Set.of();
 
    public LevelDebugSynchronizers(ServerLevel level) {
        this.level = level;
 
        for (DebugSubscription<?> subscription : BuiltInRegistries.DEBUG_SUBSCRIPTION) {
            if (subscription.valueStreamCodec() != null) {
                this.sourceSynchronizers.put(subscription, new TrackingDebugSynchronizer.SourceSynchronizer<>(subscription));
            }
        }
 
        this.allSynchronizers.addAll(this.sourceSynchronizers.values());
        this.allSynchronizers.add(this.poiSynchronizer);
        this.allSynchronizers.add(this.villageSectionSynchronizer);
    }
 
    public void tick(ServerDebugSubscribers serverSubscribers) {
        this.enabledSubscriptions = serverSubscribers.enabledSubscriptions();
        boolean shouldSleep = this.enabledSubscriptions.isEmpty();
        if (this.sleeping != shouldSleep) {
            this.sleeping = shouldSleep;
            if (shouldSleep) {
                for (TrackingDebugSynchronizer<?> synchronizer : this.allSynchronizers) {
                    synchronizer.clear();
                }
            } else {
                this.wakeUp();
            }
        }
 
        if (!this.sleeping) {
            for (TrackingDebugSynchronizer<?> synchronizer : this.allSynchronizers) {
                synchronizer.tick(this.level);
            }
        }
    }
 
    private void wakeUp() {
        ChunkMap chunkMap = this.level.getChunkSource().chunkMap;
        chunkMap.forEachReadyToSendChunk(this::registerChunk);
 
        for (Entity entity : this.level.getAllEntities()) {
            if (chunkMap.isTrackedByAnyPlayer(entity)) {
                this.registerEntity(entity);
            }
        }
    }
 
    private <T> TrackingDebugSynchronizer.SourceSynchronizer<T> getSourceSynchronizer(DebugSubscription<T> subscription) {
        return (TrackingDebugSynchronizer.SourceSynchronizer<T>)this.sourceSynchronizers.get(subscription);
    }
 
    public void registerChunk(LevelChunk chunk) {
        if (!this.sleeping) {
            chunk.registerDebugValues(this.level, new DebugValueSource.Registration() {
                {
                    Objects.requireNonNull(LevelDebugSynchronizers.this);
                }
 
                @Override
                public <T> void register(DebugSubscription<T> subscription, DebugValueSource.ValueGetter<T> getter) {
                    LevelDebugSynchronizers.this.getSourceSynchronizer(subscription).registerChunk(chunk.getPos(), getter);
                }
            });
            chunk.getBlockEntities().values().forEach(this::registerBlockEntity);
        }
    }
 
    public void dropChunk(ChunkPos chunkPos) {
        if (!this.sleeping) {
            for (TrackingDebugSynchronizer.SourceSynchronizer<?> synchronizer : this.sourceSynchronizers.values()) {
                synchronizer.dropChunk(chunkPos);
            }
        }
    }
 
    public void registerBlockEntity(BlockEntity blockEntity) {
        if (!this.sleeping) {
            blockEntity.registerDebugValues(this.level, new DebugValueSource.Registration() {
                {
                    Objects.requireNonNull(LevelDebugSynchronizers.this);
                }
 
                @Override
                public <T> void register(DebugSubscription<T> subscription, DebugValueSource.ValueGetter<T> getter) {
                    LevelDebugSynchronizers.this.getSourceSynchronizer(subscription).registerBlockEntity(blockEntity.getBlockPos(), getter);
                }
            });
        }
    }
 
    public void dropBlockEntity(BlockPos blockPos) {
        if (!this.sleeping) {
            for (TrackingDebugSynchronizer.SourceSynchronizer<?> synchronizer : this.sourceSynchronizers.values()) {
                synchronizer.dropBlockEntity(this.level, blockPos);
            }
        }
    }
 
    public void registerEntity(Entity entity) {
        if (!this.sleeping) {
            entity.registerDebugValues(this.level, new DebugValueSource.Registration() {
                {
                    Objects.requireNonNull(LevelDebugSynchronizers.this);
                }
 
                @Override
                public <T> void register(DebugSubscription<T> subscription, DebugValueSource.ValueGetter<T> getter) {
                    LevelDebugSynchronizers.this.getSourceSynchronizer(subscription).registerEntity(entity.getUUID(), getter);
                }
            });
        }
    }
 
    public void dropEntity(Entity entity) {
        if (!this.sleeping) {
            for (TrackingDebugSynchronizer.SourceSynchronizer<?> synchronizer : this.sourceSynchronizers.values()) {
                synchronizer.dropEntity(entity);
            }
        }
    }
 
    public void startTrackingChunk(ServerPlayer player, ChunkPos chunkPos) {
        if (!this.sleeping) {
            for (TrackingDebugSynchronizer<?> synchronizer : this.allSynchronizers) {
                synchronizer.startTrackingChunk(player, chunkPos);
            }
        }
    }
 
    public void startTrackingEntity(ServerPlayer player, Entity entity) {
        if (!this.sleeping) {
            for (TrackingDebugSynchronizer<?> synchronizer : this.allSynchronizers) {
                synchronizer.startTrackingEntity(player, entity);
            }
        }
    }
 
    public void registerPoi(PoiRecord poi) {
        if (!this.sleeping) {
            this.poiSynchronizer.onPoiAdded(this.level, poi);
            this.villageSectionSynchronizer.onPoiAdded(this.level, poi);
        }
    }
 
    public void updatePoi(BlockPos pos) {
        if (!this.sleeping) {
            this.poiSynchronizer.onPoiTicketCountChanged(this.level, pos);
        }
    }
 
    public void dropPoi(BlockPos pos) {
        if (!this.sleeping) {
            this.poiSynchronizer.onPoiRemoved(this.level, pos);
            this.villageSectionSynchronizer.onPoiRemoved(this.level, pos);
        }
    }
 
    public boolean hasAnySubscriberFor(DebugSubscription<?> subscription) {
        return this.enabledSubscriptions.contains(subscription);
    }
 
    public <T> void sendBlockValue(BlockPos blockPos, DebugSubscription<T> subscription, T value) {
        if (this.hasAnySubscriberFor(subscription)) {
            this.broadcastToTracking(
                ChunkPos.containing(blockPos), subscription, new ClientboundDebugBlockValuePacket(blockPos, subscription.packUpdate(value))
            );
        }
    }
 
    public <T> void clearBlockValue(BlockPos blockPos, DebugSubscription<T> subscription) {
        if (this.hasAnySubscriberFor(subscription)) {
            this.broadcastToTracking(ChunkPos.containing(blockPos), subscription, new ClientboundDebugBlockValuePacket(blockPos, subscription.emptyUpdate()));
        }
    }
 
    public <T> void sendEntityValue(Entity entity, DebugSubscription<T> subscription, T value) {
        if (this.hasAnySubscriberFor(subscription)) {
            this.broadcastToTracking(entity, subscription, new ClientboundDebugEntityValuePacket(entity.getId(), subscription.packUpdate(value)));
        }
    }
 
    public <T> void clearEntityValue(Entity entity, DebugSubscription<T> subscription) {
        if (this.hasAnySubscriberFor(subscription)) {
            this.broadcastToTracking(entity, subscription, new ClientboundDebugEntityValuePacket(entity.getId(), subscription.emptyUpdate()));
        }
    }
 
    public <T> void broadcastEventToTracking(BlockPos blockPos, DebugSubscription<T> subscription, T value) {
        if (this.hasAnySubscriberFor(subscription)) {
            this.broadcastToTracking(ChunkPos.containing(blockPos), subscription, new ClientboundDebugEventPacket(subscription.packEvent(value)));
        }
    }
 
    private void broadcastToTracking(ChunkPos trackedChunk, DebugSubscription<?> subscription, Packet<? super ClientGamePacketListener> packet) {
        ChunkMap chunkMap = this.level.getChunkSource().chunkMap;
 
        for (ServerPlayer player : chunkMap.getPlayers(trackedChunk, false)) {
            if (player.debugSubscriptions().contains(subscription)) {
                player.connection.send(packet);
            }
        }
    }
 
    private void broadcastToTracking(Entity trackedEntity, DebugSubscription<?> subscription, Packet<? super ClientGamePacketListener> packet) {
        ChunkMap chunkMap = this.level.getChunkSource().chunkMap;
        chunkMap.sendToTrackingPlayersFiltered(trackedEntity, packet, player -> player.debugSubscriptions().contains(subscription));
    }
}

引用的其他类