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.SaveLoaded;
8 import com.irtimaled.bbor.client.events.UpdateWorldSpawnReceived;
9 import com.irtimaled.bbor.client.providers.SlimeChunkProvider;
10 import com.irtimaled.bbor.common.EventBus;
11 import com.irtimaled.bbor.common.TypeHelper;
12 import com.mojang.brigadier.CommandDispatcher;
13 import com.mojang.brigadier.exceptions.CommandSyntaxException;
14 import net.minecraft.client.Minecraft;
15 import net.minecraft.client.entity.EntityPlayerSP;
16 import net.minecraft.client.gui.GuiScreen;
17 import net.minecraft.client.network.NetHandlerPlayClient;
18 import net.minecraft.command.CommandSource;
19 import net.minecraft.command.ISuggestionProvider;
20 import net.minecraft.util.math.BlockPos;
21 import net.minecraft.util.text.*;
22 import net.minecraft.util.text.event.ClickEvent;
24 public class ClientInterop {
25 public static void disconnectedFromRemoteServer() {
26 SaveGameStructureLoader.clear();
27 EventBus.publish(new DisconnectedFromRemoteServer());
30 public static void render(float partialTicks, EntityPlayerSP player) {
31 Player.setPosition(partialTicks, player);
32 ClientRenderer.render(player.dimension.getId());
35 public static boolean interceptChatMessage(String message) {
36 if (message.startsWith("/bbor:")) {
37 NetHandlerPlayClient connection = Minecraft.getInstance().getConnection();
38 if (connection != null) {
39 CommandDispatcher<ISuggestionProvider> commandDispatcher = connection.func_195515_i();
40 CommandSource commandSource = Minecraft.getInstance().player.getCommandSource();
42 commandDispatcher.execute(message.substring(1), commandSource);
43 } catch (CommandSyntaxException exception) {
44 commandSource.sendErrorMessage(TextComponentUtils.toTextComponent(exception.getRawMessage()));
45 if (exception.getInput() != null && exception.getCursor() >= 0) {
46 ITextComponent suggestion = new TextComponentString("")
47 .applyTextStyle(TextFormatting.GRAY)
48 .applyTextStyle(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message)));
49 int textLength = Math.min(exception.getInput().length(), exception.getCursor());
50 if (textLength > 10) {
51 suggestion.appendText("...");
54 suggestion.appendText(exception.getInput().substring(Math.max(0, textLength - 10), textLength));
55 if (textLength < exception.getInput().length()) {
56 suggestion.appendSibling(new TextComponentString(exception.getInput().substring(textLength))
57 .applyTextStyles(TextFormatting.RED, TextFormatting.UNDERLINE));
60 suggestion.appendSibling(new TextComponentTranslation("command.context.here")
61 .applyTextStyles(TextFormatting.RED, TextFormatting.ITALIC));
62 commandSource.sendErrorMessage(suggestion);
71 public static void updateWorldSpawnReceived(BlockPos blockPos) {
72 EventBus.publish(new UpdateWorldSpawnReceived(blockPos.getX(), blockPos.getZ()));
75 public static int getRenderDistanceChunks() {
76 return Minecraft.getInstance().gameSettings.renderDistanceChunks;
79 public static void handleSeedMessage(ITextComponent chatComponent) {
80 TypeHelper.doIfType(chatComponent, TextComponentTranslation.class, message -> {
81 if (!message.getKey().equals("commands.seed.success")) return;
84 long seed = Long.parseLong(message.getFormatArgs()[0].toString());
85 SlimeChunkProvider.setSeed(seed);
86 } catch (Exception ignored) {
91 public static void registerClientCommands(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
92 SeedCommand.register(commandDispatcher);
93 SpawningSphereCommand.register(commandDispatcher);
94 BoxCommand.register(commandDispatcher);
95 BeaconCommand.register(commandDispatcher);
96 ConfigCommand.register(commandDispatcher);
97 StructuresCommand.register(commandDispatcher);
100 public static void receivedChunk(int chunkX, int chunkZ) {
101 SaveGameStructureLoader.loadStructures(chunkX, chunkZ);
104 public static void saveLoaded(String fileName, long seed) {
106 Minecraft.getInstance().mouseHelper.grabMouse();
110 SlimeChunkProvider.setSeed(seed);
111 SaveGameStructureLoader.loadSaveGame(fileName);
114 public static void clearStructures() {
115 EventBus.publish(new SaveLoaded());
116 SaveGameStructureLoader.clear();
119 public static void displayScreen(GuiScreen screen) {
120 Minecraft.getInstance().displayGuiScreen(screen);