1 package com.irtimaled.bbor.client.interop;
3 import com.irtimaled.bbor.client.ClientRenderer;
4 import com.irtimaled.bbor.client.Player;
5 import com.irtimaled.bbor.client.commands.*;
6 import com.irtimaled.bbor.client.events.DisconnectedFromRemoteServer;
7 import com.irtimaled.bbor.client.events.UpdateWorldSpawnReceived;
8 import com.irtimaled.bbor.client.providers.SlimeChunkProvider;
9 import com.irtimaled.bbor.common.EventBus;
10 import com.irtimaled.bbor.common.TypeHelper;
11 import com.mojang.brigadier.CommandDispatcher;
12 import com.mojang.brigadier.exceptions.CommandSyntaxException;
13 import net.minecraft.client.Minecraft;
14 import net.minecraft.client.entity.EntityPlayerSP;
15 import net.minecraft.client.network.NetHandlerPlayClient;
16 import net.minecraft.command.CommandSource;
17 import net.minecraft.command.ISuggestionProvider;
18 import net.minecraft.util.math.BlockPos;
19 import net.minecraft.util.text.*;
20 import net.minecraft.util.text.event.ClickEvent;
22 public class ClientInterop {
23 public static void disconnectedFromRemoteServer() {
24 EventBus.publish(new DisconnectedFromRemoteServer());
27 public static void render(float partialTicks, EntityPlayerSP player) {
28 Player.setPosition(partialTicks, player);
29 ClientRenderer.render(player.dimension.getId());
32 public static boolean interceptChatMessage(String message) {
33 if (message.startsWith("/bbor:")) {
34 NetHandlerPlayClient connection = Minecraft.getInstance().getConnection();
35 if (connection != null) {
36 CommandDispatcher<ISuggestionProvider> commandDispatcher = connection.func_195515_i();
37 CommandSource commandSource = Minecraft.getInstance().player.getCommandSource();
39 commandDispatcher.execute(message.substring(1), commandSource);
40 } catch (CommandSyntaxException exception) {
41 commandSource.sendErrorMessage(TextComponentUtils.toTextComponent(exception.getRawMessage()));
42 if (exception.getInput() != null && exception.getCursor() >= 0) {
43 ITextComponent suggestion = new TextComponentString("")
44 .applyTextStyle(TextFormatting.GRAY)
45 .applyTextStyle(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message)));
46 int textLength = Math.min(exception.getInput().length(), exception.getCursor());
47 if (textLength > 10) {
48 suggestion.appendText("...");
51 suggestion.appendText(exception.getInput().substring(Math.max(0, textLength - 10), textLength));
52 if (textLength < exception.getInput().length()) {
53 suggestion.appendSibling(new TextComponentString(exception.getInput().substring(textLength))
54 .applyTextStyles(TextFormatting.RED, TextFormatting.UNDERLINE));
57 suggestion.appendSibling(new TextComponentTranslation("command.context.here")
58 .applyTextStyles(TextFormatting.RED, TextFormatting.ITALIC));
59 commandSource.sendErrorMessage(suggestion);
68 public static void updateWorldSpawnReceived(BlockPos blockPos) {
69 EventBus.publish(new UpdateWorldSpawnReceived(blockPos.getX(), blockPos.getZ()));
72 public static int getRenderDistanceChunks() {
73 return Minecraft.getInstance().gameSettings.renderDistanceChunks;
76 public static void handleSeedMessage(ITextComponent chatComponent) {
77 TypeHelper.doIfType(chatComponent, TextComponentTranslation.class, message -> {
78 if (!message.getKey().equals("commands.seed.success")) return;
81 long seed = Long.parseLong(message.getFormatArgs()[0].toString());
82 SlimeChunkProvider.setSeed(seed);
83 } catch (Exception ignored) {
88 public static void registerClientCommands(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
89 SeedCommand.register(commandDispatcher);
90 SpawningSphereCommand.register(commandDispatcher);
91 BoxCommand.register(commandDispatcher);
92 BeaconCommand.register(commandDispatcher);
93 ConfigCommand.register(commandDispatcher);