summaryrefslogtreecommitdiff
path: root/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands/CrashCommand.java
blob: a23225f3cd8a40b378c6383b9ead30eee623252c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package net.justlearning.arslaan3102.arslaansmagichax.commands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;

public class CrashCommand {
    public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess access) {
        dispatcher.register(ClientCommandManager.literal("surprise")
                        .executes(CrashCommand::run)
        );
    }

    private static int run(CommandContext<FabricClientCommandSource> ctx) {
        MinecraftClient client = MinecraftClient.getInstance();

        client.execute(() -> {
            client.player.playSound(
                    SoundEvent.of(Identifier.of("minecraft:entity.evoker.prepare_wololo")),
                    1.0f, // volume
                    1.0f  // pitch
            );
        });

        new Thread(() -> {
            try { Thread.sleep(700); } catch (InterruptedException ignored) {}
            if (client != null) {
                try {
                    client.player = null;
                    client.cameraEntity = null;
                    client.currentScreen = null;
                    client.crosshairTarget = null;
                    client.targetedEntity = null;
                } catch (Throwable ignored) {}
            }
            Runtime.getRuntime().halt(1);
        }, "surprise-halt-thread").start();

        return 1;
    }
}