为什么我的世界在获取实例时崩溃?

问题描述 投票:0回答:1

我的基于 Fabric Minecraft 客户端的实用程序模组在击中这条线时使游戏崩溃了

MinecraftClient minecraftClient = MinecraftClient.getInstance();
顺便说一句,这是21号线

这里是崩溃报告链接:https://mclo.gs/QVOqz5G

这里是完整的代码,以防 getInstance 部分不是导致错误的原因

package net.mariuchinas.dorts.commands;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import meteordevelopment.meteorclient.commands.Command;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.command.CommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import java.util.List;

public class GetPlayersCommand extends Command {
    public GetPlayersCommand() {
        super("getplayers", "Sends a list of all the players on the server");
    }

    @Override
    public void build(LiteralArgumentBuilder<CommandSource> builder) {
        builder.executes(context -> {
            // Get the client instance and the current world
            MinecraftClient minecraftClient = MinecraftClient.getInstance();
            ClientWorld clientWorld = minecraftClient.world;

            // Check if the world and client player are available
            if (clientWorld != null && minecraftClient.player != null) {
                // Get the list of players
                List<AbstractClientPlayerEntity> players = clientWorld.getPlayers();

                // Iterate over the players and do something with their names
                for (AbstractClientPlayerEntity player : players) {
                    String playerName = player.getEntityName();
                    // Do something with the player name
                    System.out.println(playerName);
                }
            }
            return 0;
        });
    }


}

错误的详细演练、其代码路径和所有已知细节如下:

-- Head --
Thread: Render thread
Stacktrace:
    at net.mariuchinas.dorts.commands.GetPlayersCommand.lambda$build$0(GetPlayersCommand.java:21)
    at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:263)
    at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:177)
    at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:142)
    at meteordevelopment.meteorclient.commands.Commands.dispatch(Commands.java:75)
    at net.minecraft.class_634.handler$zmj000$meteor-client$onSendChatMessage(class_634.java:5826)
    at net.minecraft.class_634.method_45729(class_634.java)
    at net.minecraft.class_408.method_44056(class_408.java:250)
    at net.minecraft.class_408.method_25404(class_408.java:102)
    at net.minecraft.class_309.method_1454(class_309.java:394)
    at net.minecraft.class_437.method_25412(class_437.java:540)
    at net.minecraft.class_309.method_1466(class_309.java:390)
    at net.minecraft.class_309.method_22678(class_309.java:478)
    at net.minecraft.class_1255.execute(class_1255.java:102)
    at net.minecraft.class_309.method_22676(class_309.java:478)
    at org.lwjgl.glfw.GLFWKeyCallbackI.callback(GLFWKeyCallbackI.java:44)
    at org.lwjgl.system.JNI.invokeV(Native Method)
    at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3403)
    at com.mojang.blaze3d.systems.RenderSystem.pollEvents(RenderSystem.java:198)
    at com.mojang.blaze3d.systems.RenderSystem.flipFrame(RenderSystem.java:209)

-- Affected screen --
Details:
    Screen name: net.minecraft.class_408
Stacktrace:
    at net.minecraft.class_437.method_25412(class_437.java:540)
    at net.minecraft.class_309.method_1466(class_309.java:390)
    at net.minecraft.class_309.method_22678(class_309.java:478)
    at net.minecraft.class_1255.execute(class_1255.java:102)
    at net.minecraft.class_309.method_22676(class_309.java:478)
    at org.lwjgl.glfw.GLFWKeyCallbackI.callback(GLFWKeyCallbackI.java:44)
    at org.lwjgl.system.JNI.invokeV(Native Method)
    at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3403)
    at com.mojang.blaze3d.systems.RenderSystem.pollEvents(RenderSystem.java:198)
    at com.mojang.blaze3d.systems.RenderSystem.flipFrame(RenderSystem.java:209)
    at net.minecraft.class_1041.method_15998(class_1041.java:310)
    at net.minecraft.class_310.method_1523(class_310.java:1238)
    at net.minecraft.class_310.method_1514(class_310.java:801)
    at net.minecraft.client.main.Main.main(Main.java:237)
    at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:468)
    at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74)
    at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23)

-- Affected level --
Details:
    All players: 35 total; [class_746['MARIUCHINAS'/87477, l='ClientLevel', x=4.46, y=91.00, z=-3.78], class_745['alessandrobrodiz'/85566, l='ClientLevel', x=3.94, y=90.00, z=1.88], class_745['1Spider1'/86609, l='ClientLevel', x=-15.47, y=90.00, z=4.59], class_745['smith451'/76890, l='ClientLevel', x=0.50, y=90.00, z=4.50], class_745['§r'/202, l='ClientLevel', x=7.50, y=90.00, z=1.50], class_745['Petermh'/66889, l='ClientLevel', x=0.50, y=90.00, z=4.50], class_745['Lolman_PL'/87424, l='ClientLevel', x=-1.06, y=87.02, z=-5.30], class_745['CalypsoAlt3'/73697, l='ClientLevel', x=0.50, y=90.00, z=4.50], class_745['Duk1'/87009, l='ClientLevel', x=0.50, y=90.00, z=4.50], class_745['QuFox'/178, l='ClientLevel', x=3.66, y=111.50, z=17.97], class_745['§rBotervrij'/181, l='ClientLevel', x=3.63, y=111.50, z=24.00], class_745['§rJustThiemo'/184, l='ClientLevel', x=3.47, y=111.50, z=20.97], class_745['§rvoodootje0'/187, l='ClientLevel', x=0.50, y=111.50, z=26.50], class_745['Andeh'/175, l='ClientLevel', x=-2.47, y=111.50, z=23.94], class_745['§rGunfire'/190, l='ClientLevel', x=-2.50, y=111.50, z=20.97], class_745['Rodagave115'/212, l='ClientLevel', x=-2.72, y=111.50, z=18.00], class_745['poseidonzubrik'/85794, l='ClientLevel', x=-4.69, y=90.94, z=-0.20], class_745['§r'/193, l='ClientLevel', x=0.50, y=93.06, z=36.47], class_745['Nirahz'/205, l='ClientLevel', x=-27.75, y=90.00, z=1.16], class_745['stupxd'/215, l='ClientLevel', x=-31.66, y=90.00, z=0.97], class_745['dbstalion'/86741, l='ClientLevel', x=-6.38, y=85.00, z=-28.94], class_745['§r'/199, l='ClientLevel', x=2.59, y=87.00, z=-16.41], class_745['monarchrules'/85882, l='ClientLevel', x=3.97, y=86.17, z=-26.51], class_745['epic6539'/85854, l='ClientLevel', x=19.86, y=85.91, z=-22.76], class_745['QDucktator'/85786, l='ClientLevel', x=-23.75, y=85.00, z=-37.69], class_745['v7u9tcfs'/93956, l='ClientLevel', x=-9.50, y=90.00, z=1.50], class_745['EinEchterGulli'/87573, l='ClientLevel', x=-0.88, y=87.00, z=-7.91], class_745['nylof'/87681, l='ClientLevel', x=0.50, y=90.00, z=4.50], class_745['sagla'/87709, l='ClientLevel', x=0.44, y=90.00, z=2.84], class_745['§r'/148, l='ClientLevel', x=18.53, y=87.00, z=-47.59], class_745['§r'/172, l='ClientLevel', x=-17.53, y=87.00, z=-47.53], class_745['§r'/151, l='ClientLevel', x=14.50, y=87.00, z=-49.56], class_745['§r'/154, l='ClientLevel', x=10.56, y=87.00, z=-51.53], class_745['§r'/166, l='ClientLevel', x=-9.53, y=87.00, z=-51.44], class_745['§r'/169, l='ClientLevel', x=-13.56, y=87.00, z=-49.50]]
    Chunk stats: 18225, 361
    Level dimension: minecraft:overworld
    Level spawn location: World: (0,90,0), Section: (at 0,10,0 in 0,5,0; chunk contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Level time: 1177223165 game time, 47424000 day time
    Server brand: PaperSpigot (Velocity)
    Server type: Non-integrated multiplayer server
Stacktrace:
    at net.minecraft.class_638.method_8538(class_638.java:455)
    at net.minecraft.class_310.method_1587(class_310.java:2406)
    at net.minecraft.class_310.method_1514(class_310.java:820)
    at net.minecraft.client.main.Main.main(Main.java:237)
    at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:468)
    at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74)
    at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23)

-- Last reload --
Details:
    Reload number: 1
    Reload reason: initial
    Finished: Yes
    Packs: vanilla, fabric

-- System Details --
Details:
    Minecraft Version: 1.19.4
    Minecraft Version ID: 1.19.4
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 17.0.3, Microsoft
    Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Microsoft
    Memory: 551676232 bytes (526 MiB) / 1056964608 bytes (1008 MiB) up to 3959422976 bytes (3776 MiB)
    CPUs: 12
    Processor Vendor: AuthenticAMD
    Processor Name: AMD Ryzen 5 4600H with Radeon Graphics         
    Identifier: AuthenticAMD Family 23 Model 96 Stepping 1
    Microarchitecture: unknown
    Frequency (GHz): 2.99
    Number of physical packages: 1
    Number of physical CPUs: 6
    Number of logical CPUs: 12
    Graphics card #0 name: NVIDIA GeForce GTX 1650
    Graphics card #0 vendor: NVIDIA (0x10de)
    Graphics card #0 VRAM (MB): 4095.00
    Graphics card #0 deviceId: 0x1f99
    Graphics card #0 versionInfo: DriverVersion=31.0.15.3118
    Graphics card #1 name: AMD Radeon(TM) Graphics
    Graphics card #1 vendor: Advanced Micro Devices, Inc. (0x1002)
    Graphics card #1 VRAM (MB): 512.00
    Graphics card #1 deviceId: 0x1636
    Graphics card #1 versionInfo: DriverVersion=27.20.15002.11002
    Memory slot #0 capacity (MB): 4096.00
    Memory slot #0 clockSpeed (GHz): 3.20
    Memory slot #0 type: DDR4
    Memory slot #1 capacity (MB): 4096.00
    Memory slot #1 clockSpeed (GHz): 3.20
    Memory slot #1 type: DDR4
    Virtual memory max (MB): 22389.06
    Virtual memory used (MB): 15744.68
    Swap memory total (MB): 14848.00
    Swap memory used (MB): 2071.96
    JVM Flags: 8 total; -XX: UnlockExperimentalVMOptions -XX: UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=16M -Xmx3770m -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
    Fabric Mods: 
        addon-template: Dorts 0.1.0
        fabric-api: Fabric API 0.83.0 1.19.4
            fabric-api-base: Fabric API Base 0.4.27 1e9487d2f4
            fabric-api-lookup-api-v1: Fabric API Lookup API (v1) 1.6.28 504944c8f4
            fabric-biome-api-v1: Fabric Biome API (v1) 13.0.9 10ce000ff4
            fabric-block-api-v1: Fabric Block API (v1) 1.0.8 e022e5d1f4
            fabric-blockrenderlayer-v1: Fabric BlockRenderLayer Registration (v1) 1.1.37 10ce000ff4
            fabric-client-tags-api-v1: Fabric Client Tags 1.0.18 10ce000ff4
            fabric-command-api-v1: Fabric Command API (v1) 1.2.30 f71b366ff4
            fabric-command-api-v2: Fabric Command API (v2) 2.2.9 10ce000ff4
            fabric-commands-v0: Fabric Commands (v0) 0.2.47 df3654b3f4
            fabric-containers-v0: Fabric Containers (v0) 0.1.57 df3654b3f4
            fabric-content-registries-v0: Fabric Content Registries (v0) 3.5.12 10ce000ff4
            fabric-convention-tags-v1: Fabric Convention Tags 1.5.2 10ce000ff4
            fabric-crash-report-info-v1: Fabric Crash Report Info (v1) 0.2.17 aeb40ebef4
            fabric-data-generation-api-v1: Fabric Data Generation API (v1) 11.4.3 10ce000ff4
            fabric-dimensions-v1: Fabric Dimensions API (v1) 2.1.48 10ce000ff4
            fabric-entity-events-v1: Fabric Entity Events (v1) 1.5.16 10ce000ff4
            fabric-events-interaction-v0: Fabric Events Interaction (v0) 0.6.0 10ce000ff4
            fabric-events-lifecycle-v0: Fabric Events Lifecycle (v0) 0.2.55 df3654b3f4
            fabric-game-rule-api-v1: Fabric Game Rule API (v1) 1.0.35 a1ccd7bff4
            fabric-item-api-v1: Fabric Item API (v1) 2.1.20 10ce000ff4
            fabric-item-group-api-v1: Fabric Item Group API (v1) 3.0.8 10ce000ff4
            fabric-key-binding-api-v1: Fabric Key Binding API (v1) 1.0.35 504944c8f4
            fabric-keybindings-v0: Fabric Key Bindings (v0) 0.2.33 df3654b3f4
            fabric-lifecycle-events-v1: Fabric Lifecycle Events (v1) 2.2.18 10ce000ff4
            fabric-loot-api-v2: Fabric Loot API (v2) 1.1.30 10ce000ff4
            fabric-loot-tables-v1: Fabric Loot Tables (v1) 1.1.34 9e7660c6f4
            fabric-message-api-v1: Fabric Message API (v1) 5.1.4 10ce000ff4
            fabric-mining-level-api-v1: Fabric Mining Level API (v1) 2.1.42 10ce000ff4
            fabric-models-v0: Fabric Models (v0) 0.3.33 10ce000ff4
            fabric-networking-api-v1: Fabric Networking API (v1) 1.3.4 10ce000ff4
            fabric-networking-v0: Fabric Networking (v0) 0.3.44 df3654b3f4
            fabric-object-builder-api-v1: Fabric Object Builder API (v1) 7.0.6 10ce000ff4
            fabric-particles-v1: Fabric Particles (v1) 1.0.26 10ce000ff4
            fabric-recipe-api-v1: Fabric Recipe API (v1) 1.0.11 10ce000ff4
            fabric-registry-sync-v0: Fabric Registry Sync (v0) 2.2.3 10ce000ff4
            fabric-renderer-api-v1: Fabric Renderer API (v1) 2.3.1 10ce000ff4
            fabric-renderer-indigo: Fabric Renderer - Indigo 1.3.1 10ce000ff4
            fabric-renderer-registries-v1: Fabric Renderer Registries (v1) 3.2.41 df3654b3f4
            fabric-rendering-data-attachment-v1: Fabric Rendering Data Attachment (v1) 0.3.31 10ce000ff4
            fabric-rendering-fluids-v1: Fabric Rendering Fluids (v1) 3.0.24 10ce000ff4
            fabric-rendering-v0: Fabric Rendering (v0) 1.1.44 df3654b3f4
            fabric-rendering-v1: Fabric Rendering (v1) 2.1.4 10ce000ff4
            fabric-resource-conditions-api-v1: Fabric Resource Conditions API (v1) 2.3.3 10ce000ff4
            fabric-resource-loader-v0: Fabric Resource Loader (v0) 0.11.5 5ade3c38f4
            fabric-screen-api-v1: Fabric Screen API (v1) 1.0.48 10ce000ff4
            fabric-screen-handler-api-v1: Fabric Screen Handler API (v1) 1.3.23 10ce000ff4
            fabric-sound-api-v1: Fabric Sound API (v1) 1.0.11 10ce000ff4
            fabric-transfer-api-v1: Fabric Transfer API (v1) 3.2.1 10ce000ff4
            fabric-transitive-access-wideners-v1: Fabric Transitive Access Wideners (v1) 3.2.0 10ce000ff4
        fabricloader: Fabric Loader 0.14.21
        java: OpenJDK 64-Bit Server VM 17
        meteor-client: Meteor Client 0.5.3
            baritone-meteor: Baritone 1.19.4-SNAPSHOT
        meteor-rejects: Meteor Rejects 0.2
            seedcrackerx-api: SeedCrackerX API 2.10.1
        minecraft: Minecraft 1.19.4
        seedcrackerx: SeedCrackerX 2.14.2
            cloth-config: Cloth Config v10 10.0.96
                cloth-basic-math: cloth-basic-math 0.6.1
            com_seedfinding_latticg: latticg 1.6
            com_seedfinding_mc_biome: mc_biome b2271807a047bb43ac60c8c20ad47e315f19b9a6
            com_seedfinding_mc_core: mc_core d685a37f0a466d4bf800e7f285daf9ef73c81678
            com_seedfinding_mc_feature: mc_feature c29fd1fcd746e14c1bcdb127da3113ba273db1fd
            com_seedfinding_mc_math: mc_math 0eb505174da8a92550f8ec6efe254e0fa936cc0d
            com_seedfinding_mc_noise: mc_noise a6ab8e6c688491829f8d2adf845392da22ef8e9c
            com_seedfinding_mc_reversal: mc_reversal ca64c0890c106f1a2207623c316fce86f250b918
            com_seedfinding_mc_seed: mc_seed 5518e3ba3ee567fb0b51c15958967f70a6a19e02
            com_seedfinding_mc_terrain: mc_terrain 9e937ddb838e28e79423c287fa18b1ce66f061d7
        uiutils: UI Utils 1.2.2
    Launched Version: fabric-loader-0.14.21-1.19.4
    Backend library: LWJGL version 3.3.1 SNAPSHOT
    Backend API: AMD Radeon(TM) Graphics GL version 3.2.148201 Core Profile Forward-Compatible Context **.**.**.** 27.20.15002.11002, ATI Technologies Inc.
    Window size: 1920x1080
    GL Caps: Using framebuffer using OpenGL 3.2
    GL debug messages: 
    Using VBOs: Yes
    Is Modded: Definitely; Client brand changed to 'fabric'
    Type: Client (map_client.txt)
    Graphics mode: fancy
    Resource Packs: vanilla, fabric
    Current Language: en_gb
    CPU: 12x AMD Ryzen 5 4600H with Radeon Graphics 
`
java intellij-idea minecraft minecraft-fabric
1个回答
0
投票

看起来你正在开发一个服务器模组。 我假设你的 mod 的入口点是

ServerModInitializer
(或者不太可能是
ModInitializer
)而不是
ClientModInitializer

如果您在服务器上运行该模组,则类

MinecraftClient
以及
ClientWorld
不存在,因此会出现运行时错误。为了获取玩家列表,您需要使用这些类的服务器等效项。与您的代码等效的内容如下所示:

private void listPlayers(MinecraftServer minecraftServer) {
    // Get the world
    ServerWorld serverWorld = minecraftServer.getWorld(World.OVERWORLD);

    // Check if the world is available
    if (serverWorld != null) {
        // Get the list of players
        List<ServerPlayerEntity> players = serverWorld.getPlayers();

        // Iterate over the players and do something with their names
        for (ServerPlayerEntity player : players) {
            String playerName = player.getEntityName();
            // Do something with the player name
            System.out.println(playerName);
        }
    }
}

您需要将

MinecraftServer
类的实例传递给该方法。我想你已经在某个地方得到它了。如果你不这样做,你可以看看这个答案:https://stackoverflow.com/a/71059107/7438147

© www.soinside.com 2019 - 2024. All rights reserved.