IntegratedServer.java

net.minecraft.client.server.IntegratedServer

信息

  • 全限定名:net.minecraft.client.server.IntegratedServer
  • 类型:public class
  • 包:net.minecraft.client.server
  • 源码路径:src/main/java/net/minecraft/client/server/IntegratedServer.java
  • 起始行号:L54
  • 继承:MinecraftServer
  • 职责:

    TODO

字段/常量

  • LOGGER

    • 类型: Logger
    • 修饰符: private static final
    • 源码定位: L55
    • 说明:

      TODO

  • MIN_SIM_DISTANCE

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L56
    • 说明:

      TODO

  • MAX_PLAYERS

    • 类型: int
    • 修饰符: public static final
    • 源码定位: L57
    • 说明:

      TODO

  • minecraft

    • 类型: Minecraft
    • 修饰符: private final
    • 源码定位: L58
    • 说明:

      TODO

  • paused

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

      TODO

  • publishedPort

    • 类型: int
    • 修饰符: private
    • 源码定位: L60
    • 说明:

      TODO

  • publishedGameType

    • 类型: GameType
    • 修饰符: private
    • 源码定位: L61
    • 说明:

      TODO

  • lanPinger

    • 类型: LanServerPinger
    • 修饰符: private
    • 源码定位: L62
    • 说明:

      TODO

  • uuid

    • 类型: UUID
    • 修饰符: private
    • 源码定位: L63
    • 说明:

      TODO

  • previousSimulationDistance

    • 类型: int
    • 修饰符: private
    • 源码定位: L64
    • 说明:

      TODO

  • latestTicksGizmos

    • 类型: List<SimpleGizmoCollector.GizmoInstance>
    • 修饰符: private volatile
    • 源码定位: L65
    • 说明:

      TODO

  • gizmoCollector

    • 类型: SimpleGizmoCollector
    • 修饰符: private final
    • 源码定位: L66
    • 说明:

      TODO

内部类/嵌套类型

构造器

public IntegratedServer(Thread serverThread, Minecraft minecraft, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Optional<GameRules> gameRules, Services services, LevelLoadListener levelLoadListener) @ L68

  • 构造器名:IntegratedServer
  • 源码定位:L68
  • 修饰符:public

参数:

  • serverThread: Thread
  • minecraft: Minecraft
  • levelStorageAccess: LevelStorageSource.LevelStorageAccess
  • packRepository: PackRepository
  • worldStem: WorldStem
  • gameRules: Optional
  • services: Services
  • levelLoadListener: LevelLoadListener

说明:

TODO

方法

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

protected boolean initServer() @ L96

  • 方法名:initServer
  • 源码定位:L96
  • 返回类型:boolean
  • 修饰符:protected

参数:

说明:

TODO

public boolean isPaused() @ L109

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

参数:

说明:

TODO

protected void processPacketsAndTick(boolean sprinting) @ L114

  • 方法名:processPacketsAndTick
  • 源码定位:L114
  • 返回类型:void
  • 修饰符:protected

参数:

  • sprinting: boolean

说明:

TODO

protected void tickServer(BooleanSupplier haveTime) @ L125

  • 方法名:tickServer
  • 源码定位:L125
  • 返回类型:void
  • 修饰符:protected

参数:

  • haveTime: BooleanSupplier

说明:

TODO

protected LocalSampleLogger getTickTimeLogger() @ L160

  • 方法名:getTickTimeLogger
  • 源码定位:L160
  • 返回类型:LocalSampleLogger
  • 修饰符:protected

参数:

说明:

TODO

public boolean isTickTimeLoggingEnabled() @ L164

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

参数:

说明:

TODO

private void tickPaused() @ L169

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

参数:

说明:

TODO

public boolean shouldRconBroadcast() @ L177

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

参数:

说明:

TODO

public boolean shouldInformAdmins() @ L182

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

参数:

说明:

TODO

public Path getServerDirectory() @ L187

  • 方法名:getServerDirectory
  • 源码定位:L187
  • 返回类型:Path
  • 修饰符:public

参数:

说明:

TODO

public boolean isDedicatedServer() @ L192

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

参数:

说明:

TODO

public int getRateLimitPacketsPerSecond() @ L197

  • 方法名:getRateLimitPacketsPerSecond
  • 源码定位:L197
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public boolean useNativeTransport() @ L202

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

参数:

说明:

TODO

protected void onServerCrash(CrashReport report) @ L207

  • 方法名:onServerCrash
  • 源码定位:L207
  • 返回类型:void
  • 修饰符:protected

参数:

  • report: CrashReport

说明:

TODO

public SystemReport fillServerSystemReport(SystemReport systemReport) @ L212

  • 方法名:fillServerSystemReport
  • 源码定位:L212
  • 返回类型:SystemReport
  • 修饰符:public

参数:

  • systemReport: SystemReport

说明:

TODO

public ModCheck getModdedStatus() @ L220

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

参数:

说明:

TODO

public boolean publishServer(GameType gameMode, boolean allowCommands, int port) @ L225

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

参数:

  • gameMode: GameType
  • allowCommands: boolean
  • port: int

说明:

TODO

public void stopServer() @ L251

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

参数:

说明:

TODO

public void halt(boolean wait) @ L260

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

参数:

  • wait: boolean

说明:

TODO

public boolean isPublished() @ L276

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

参数:

说明:

TODO

public int getPort() @ L281

  • 方法名:getPort
  • 源码定位:L281
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public void setDefaultGameType(GameType gameType) @ L286

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

参数:

  • gameType: GameType

说明:

TODO

public LevelBasedPermissionSet operatorUserPermissions() @ L292

  • 方法名:operatorUserPermissions
  • 源码定位:L292
  • 返回类型:LevelBasedPermissionSet
  • 修饰符:public

参数:

说明:

TODO

public LevelBasedPermissionSet getFunctionCompilationPermissions() @ L297

  • 方法名:getFunctionCompilationPermissions
  • 源码定位:L297
  • 返回类型:LevelBasedPermissionSet
  • 修饰符:public

参数:

说明:

TODO

public void setUUID(UUID uuid) @ L301

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

参数:

  • uuid: UUID

说明:

TODO

public boolean isSingleplayerOwner(NameAndId nameAndId) @ L305

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

参数:

  • nameAndId: NameAndId

说明:

TODO

public int getScaledTrackingDistance(int baseRange) @ L310

  • 方法名:getScaledTrackingDistance
  • 源码定位:L310
  • 返回类型:int
  • 修饰符:public

参数:

  • baseRange: int

说明:

TODO

public boolean forceSynchronousWrites() @ L315

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

参数:

说明:

TODO

public GameType getForcedGameType() @ L320

  • 方法名:getForcedGameType
  • 源码定位:L320
  • 返回类型:GameType
  • 修饰符:public

参数:

说明:

TODO

protected GlobalPos selectLevelLoadFocusPos() @ L325

  • 方法名:selectLevelLoadFocusPos
  • 源码定位:L325
  • 返回类型:GlobalPos
  • 修饰符:protected

参数:

说明:

TODO

public void sendLowDiskSpaceWarning() @ L348

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

参数:

说明:

TODO

public void reportChunkLoadFailure(Throwable throwable, RegionStorageInfo storageInfo, ChunkPos pos) @ L354

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

参数:

  • throwable: Throwable
  • storageInfo: RegionStorageInfo
  • pos: ChunkPos

说明:

TODO

public void reportChunkSaveFailure(Throwable throwable, RegionStorageInfo storageInfo, ChunkPos pos) @ L361

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

参数:

  • throwable: Throwable
  • storageInfo: RegionStorageInfo
  • pos: ChunkPos

说明:

TODO

public int getMaxPlayers() @ L368

  • 方法名:getMaxPlayers
  • 源码定位:L368
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public Collection<SimpleGizmoCollector.GizmoInstance> getPerTickGizmos() @ L373

  • 方法名:getPerTickGizmos
  • 源码定位:L373
  • 返回类型:Collection<SimpleGizmoCollector.GizmoInstance>
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class IntegratedServer extends MinecraftServer {
    private static final Logger LOGGER = LogUtils.getLogger();
    private static final int MIN_SIM_DISTANCE = 2;
    public static final int MAX_PLAYERS = 8;
    private final Minecraft minecraft;
    private boolean paused = true;
    private int publishedPort = -1;
    private @Nullable GameType publishedGameType;
    private @Nullable LanServerPinger lanPinger;
    private @Nullable UUID uuid;
    private int previousSimulationDistance = 0;
    private volatile List<SimpleGizmoCollector.GizmoInstance> latestTicksGizmos = new ArrayList<>();
    private final SimpleGizmoCollector gizmoCollector = new SimpleGizmoCollector();
 
    public IntegratedServer(
        Thread serverThread,
        Minecraft minecraft,
        LevelStorageSource.LevelStorageAccess levelStorageAccess,
        PackRepository packRepository,
        WorldStem worldStem,
        Optional<GameRules> gameRules,
        Services services,
        LevelLoadListener levelLoadListener
    ) {
        super(
            serverThread,
            levelStorageAccess,
            packRepository,
            worldStem,
            gameRules,
            minecraft.getProxy(),
            minecraft.getFixerUpper(),
            services,
            levelLoadListener,
            false
        );
        this.setSingleplayerProfile(minecraft.getGameProfile());
        this.setDemo(minecraft.isDemo());
        this.setPlayerList(new IntegratedPlayerList(this, this.registries(), this.playerDataStorage));
        this.minecraft = minecraft;
    }
 
    @Override
    protected boolean initServer() {
        LOGGER.info("Starting integrated minecraft server version {}", SharedConstants.getCurrentVersion().name());
        this.setUsesAuthentication(true);
        this.initializeKeyPair();
        this.loadLevel();
        GameProfile host = this.getSingleplayerProfile();
        String levelName = this.getWorldData().getLevelName();
        this.setMotd(host != null ? host.name() + " - " + levelName : levelName);
        this.saveEverything(false, true, true);
        return true;
    }
 
    @Override
    public boolean isPaused() {
        return this.paused;
    }
 
    @Override
    protected void processPacketsAndTick(boolean sprinting) {
        try (Gizmos.TemporaryCollection ignored = Gizmos.withCollector(this.gizmoCollector)) {
            super.processPacketsAndTick(sprinting);
        }
 
        if (this.tickRateManager().runsNormally()) {
            this.latestTicksGizmos = this.gizmoCollector.drainGizmos();
        }
    }
 
    @Override
    protected void tickServer(BooleanSupplier haveTime) {
        boolean wasPaused = this.paused;
        this.paused = Minecraft.getInstance().isPaused() || this.getPlayerList().getPlayers().isEmpty();
        ProfilerFiller profiler = Profiler.get();
        if (!wasPaused && this.paused) {
            profiler.push("autoSave");
            LOGGER.info("Saving and pausing game...");
            this.saveEverything(false, false, false);
            profiler.pop();
        }
 
        if (this.paused) {
            this.tickPaused();
        } else {
            if (wasPaused) {
                this.forceGameTimeSynchronization();
            }
 
            super.tickServer(haveTime);
            int serverViewDistance = Math.max(2, this.minecraft.options.renderDistance().get());
            if (serverViewDistance != this.getPlayerList().getViewDistance()) {
                LOGGER.info("Changing view distance to {}, from {}", serverViewDistance, this.getPlayerList().getViewDistance());
                this.getPlayerList().setViewDistance(serverViewDistance);
            }
 
            int serverSimulationDistance = Math.max(2, this.minecraft.options.simulationDistance().get());
            if (serverSimulationDistance != this.previousSimulationDistance) {
                LOGGER.info("Changing simulation distance to {}, from {}", serverSimulationDistance, this.previousSimulationDistance);
                this.getPlayerList().setSimulationDistance(serverSimulationDistance);
                this.previousSimulationDistance = serverSimulationDistance;
            }
        }
    }
 
    protected LocalSampleLogger getTickTimeLogger() {
        return this.minecraft.getDebugOverlay().getTickTimeLogger();
    }
 
    @Override
    public boolean isTickTimeLoggingEnabled() {
        return true;
    }
 
    private void tickPaused() {
        this.tickConnection();
 
        for (ServerPlayer player : this.getPlayerList().getPlayers()) {
            player.awardStat(Stats.TOTAL_WORLD_TIME);
        }
    }
 
    @Override
    public boolean shouldRconBroadcast() {
        return true;
    }
 
    @Override
    public boolean shouldInformAdmins() {
        return true;
    }
 
    @Override
    public Path getServerDirectory() {
        return this.minecraft.gameDirectory.toPath();
    }
 
    @Override
    public boolean isDedicatedServer() {
        return false;
    }
 
    @Override
    public int getRateLimitPacketsPerSecond() {
        return 0;
    }
 
    @Override
    public boolean useNativeTransport() {
        return this.minecraft.options.useNativeTransport();
    }
 
    @Override
    protected void onServerCrash(CrashReport report) {
        BlockableEventLoop.relayDelayCrash(report);
    }
 
    @Override
    public SystemReport fillServerSystemReport(SystemReport systemReport) {
        systemReport.setDetail("Type", "Integrated Server");
        systemReport.setDetail("Is Modded", () -> this.getModdedStatus().fullDescription());
        systemReport.setDetail("Launched Version", this.minecraft::getLaunchedVersion);
        return systemReport;
    }
 
    @Override
    public ModCheck getModdedStatus() {
        return Minecraft.checkModStatus().merge(super.getModdedStatus());
    }
 
    @Override
    public boolean publishServer(@Nullable GameType gameMode, boolean allowCommands, int port) {
        try {
            this.minecraft.prepareForMultiplayer();
            this.minecraft.getConnection().prepareKeyPair();
            this.getConnection().startTcpServerListener(null, port);
            LOGGER.info("Started serving on {}", port);
            this.publishedPort = port;
            this.lanPinger = new LanServerPinger(this.getMotd(), port + "");
            this.lanPinger.start();
            this.publishedGameType = gameMode;
            this.getPlayerList().setAllowCommandsForAllPlayers(allowCommands);
            PermissionSet newProfilePermissions = this.getProfilePermissions(this.minecraft.player.nameAndId());
            this.minecraft.player.setPermissions(newProfilePermissions);
            this.minecraft.player.refreshChatAbilities();
 
            for (ServerPlayer player : this.getPlayerList().getPlayers()) {
                this.getCommands().sendCommands(player);
            }
 
            return true;
        } catch (IOException var7) {
            return false;
        }
    }
 
    @Override
    public void stopServer() {
        super.stopServer();
        if (this.lanPinger != null) {
            this.lanPinger.interrupt();
            this.lanPinger = null;
        }
    }
 
    @Override
    public void halt(boolean wait) {
        this.executeBlocking(() -> {
            for (ServerPlayer player : Lists.newArrayList(this.getPlayerList().getPlayers())) {
                if (!player.getUUID().equals(this.uuid)) {
                    this.getPlayerList().remove(player);
                }
            }
        });
        super.halt(wait);
        if (this.lanPinger != null) {
            this.lanPinger.interrupt();
            this.lanPinger = null;
        }
    }
 
    @Override
    public boolean isPublished() {
        return this.publishedPort > -1;
    }
 
    @Override
    public int getPort() {
        return this.publishedPort;
    }
 
    @Override
    public void setDefaultGameType(GameType gameType) {
        super.setDefaultGameType(gameType);
        this.publishedGameType = null;
    }
 
    @Override
    public LevelBasedPermissionSet operatorUserPermissions() {
        return LevelBasedPermissionSet.GAMEMASTER;
    }
 
    public LevelBasedPermissionSet getFunctionCompilationPermissions() {
        return LevelBasedPermissionSet.GAMEMASTER;
    }
 
    public void setUUID(UUID uuid) {
        this.uuid = uuid;
    }
 
    @Override
    public boolean isSingleplayerOwner(NameAndId nameAndId) {
        return this.getSingleplayerProfile() != null && nameAndId.name().equalsIgnoreCase(this.getSingleplayerProfile().name());
    }
 
    @Override
    public int getScaledTrackingDistance(int baseRange) {
        return (int)(this.minecraft.options.entityDistanceScaling().get() * baseRange);
    }
 
    @Override
    public boolean forceSynchronousWrites() {
        return this.minecraft.options.syncWrites;
    }
 
    @Override
    public @Nullable GameType getForcedGameType() {
        return this.isPublished() && !this.isHardcore() ? MoreObjects.firstNonNull(this.publishedGameType, this.worldData.getGameType()) : null;
    }
 
    @Override
    protected GlobalPos selectLevelLoadFocusPos() {
        UUID lastSinglePlayerOwnerUUID = this.worldData.getSinglePlayerUUID();
        if (lastSinglePlayerOwnerUUID == null) {
            return super.selectLevelLoadFocusPos();
        } else {
            Optional<CompoundTag> playerData = this.playerDataStorage.load(new NameAndId(lastSinglePlayerOwnerUUID, "<single player owner>"));
            if (playerData.isEmpty()) {
                return super.selectLevelLoadFocusPos();
            } else {
                try (ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(LOGGER)) {
                    ValueInput input = TagValueInput.create(reporter, this.registryAccess(), playerData.get());
                    ServerPlayer.SavedPosition loadedPosition = input.read(ServerPlayer.SavedPosition.MAP_CODEC).orElse(ServerPlayer.SavedPosition.EMPTY);
                    if (loadedPosition.dimension().isPresent() && loadedPosition.position().isPresent()) {
                        return new GlobalPos(loadedPosition.dimension().get(), BlockPos.containing(loadedPosition.position().get()));
                    }
                }
 
                return super.selectLevelLoadFocusPos();
            }
        }
    }
 
    @Override
    public void sendLowDiskSpaceWarning() {
        super.sendLowDiskSpaceWarning();
        this.minecraft.sendLowDiskSpaceWarning();
    }
 
    @Override
    public void reportChunkLoadFailure(Throwable throwable, RegionStorageInfo storageInfo, ChunkPos pos) {
        super.reportChunkLoadFailure(throwable, storageInfo, pos);
        this.warnOnLowDiskSpace();
        this.minecraft.execute(() -> SystemToast.onChunkLoadFailure(this.minecraft, pos));
    }
 
    @Override
    public void reportChunkSaveFailure(Throwable throwable, RegionStorageInfo storageInfo, ChunkPos pos) {
        super.reportChunkSaveFailure(throwable, storageInfo, pos);
        this.warnOnLowDiskSpace();
        this.minecraft.execute(() -> SystemToast.onChunkSaveFailure(this.minecraft, pos));
    }
 
    @Override
    public int getMaxPlayers() {
        return 8;
    }
 
    public Collection<SimpleGizmoCollector.GizmoInstance> getPerTickGizmos() {
        return this.latestTicksGizmos;
    }
}

引用的其他类