]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blobdiff - src/main/java/com/irtimaled/bbor/client/interop/ClientInterop.java
Improve performance
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / interop / ClientInterop.java
index d540dd2c0de1a3e7a8983470517846f679b1a554..9d91ad8a7347ccaffb38a516415ae8bb8f1d07ab 100644 (file)
@@ -1,62 +1,74 @@
 package com.irtimaled.bbor.client.interop;
 
 import com.irtimaled.bbor.client.ClientRenderer;
-import com.irtimaled.bbor.client.Player;
-import com.irtimaled.bbor.client.commands.*;
+import com.irtimaled.bbor.client.commands.ConfigCommand;
+import com.irtimaled.bbor.client.commands.CustomCommand;
+import com.irtimaled.bbor.client.commands.SeedCommand;
+import com.irtimaled.bbor.client.commands.SpawningSphereCommand;
+import com.irtimaled.bbor.client.commands.StructuresCommand;
 import com.irtimaled.bbor.client.events.DisconnectedFromRemoteServer;
+import com.irtimaled.bbor.client.events.SaveLoaded;
 import com.irtimaled.bbor.client.events.UpdateWorldSpawnReceived;
 import com.irtimaled.bbor.client.providers.SlimeChunkProvider;
 import com.irtimaled.bbor.common.EventBus;
 import com.irtimaled.bbor.common.TypeHelper;
+import com.irtimaled.bbor.common.models.DimensionId;
 import com.mojang.brigadier.CommandDispatcher;
 import com.mojang.brigadier.exceptions.CommandSyntaxException;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.entity.EntityPlayerSP;
-import net.minecraft.client.network.NetHandlerPlayClient;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.network.ClientPlayNetworkHandler;
+import net.minecraft.client.network.ClientPlayerEntity;
+import net.minecraft.client.util.math.MatrixStack;
 import net.minecraft.command.CommandSource;
-import net.minecraft.command.ISuggestionProvider;
+import net.minecraft.server.command.ServerCommandSource;
+import net.minecraft.text.ClickEvent;
+import net.minecraft.text.LiteralText;
+import net.minecraft.text.MutableText;
+import net.minecraft.text.Text;
+import net.minecraft.text.Texts;
+import net.minecraft.text.TranslatableText;
+import net.minecraft.util.Formatting;
 import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.text.*;
-import net.minecraft.util.text.event.ClickEvent;
 
 public class ClientInterop {
     public static void disconnectedFromRemoteServer() {
+        SaveGameStructureLoader.clear();
         EventBus.publish(new DisconnectedFromRemoteServer());
     }
 
-    public static void render(float partialTicks, EntityPlayerSP player) {
-        Player.setPosition(partialTicks, player);
-        ClientRenderer.render(player.dimension.getId());
+    public static void render(MatrixStack matrixStack, ClientPlayerEntity player) {
+        ClientRenderer.render(matrixStack, DimensionId.from(player.getEntityWorld().getRegistryKey()));
     }
 
     public static boolean interceptChatMessage(String message) {
         if (message.startsWith("/bbor:")) {
-            NetHandlerPlayClient connection = Minecraft.getInstance().getConnection();
+            ClientPlayNetworkHandler connection = MinecraftClient.getInstance().getNetworkHandler();
             if (connection != null) {
-                CommandDispatcher<ISuggestionProvider> commandDispatcher = connection.func_195515_i();
-                CommandSource commandSource = Minecraft.getInstance().player.getCommandSource();
+                CommandDispatcher<CommandSource> commandDispatcher = connection.getCommandDispatcher();
+                ServerCommandSource commandSource = MinecraftClient.getInstance().player.getCommandSource();
                 try {
                     commandDispatcher.execute(message.substring(1), commandSource);
                 } catch (CommandSyntaxException exception) {
-                    commandSource.sendErrorMessage(TextComponentUtils.toTextComponent(exception.getRawMessage()));
+                    commandSource.sendError(Texts.toText(exception.getRawMessage()));
                     if (exception.getInput() != null && exception.getCursor() >= 0) {
-                        ITextComponent suggestion = new TextComponentString("")
-                                .applyTextStyle(TextFormatting.GRAY)
-                                .applyTextStyle(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message)));
+                        MutableText suggestion = new LiteralText("")
+                                .formatted(Formatting.GRAY)
+                                .styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message)));
                         int textLength = Math.min(exception.getInput().length(), exception.getCursor());
                         if (textLength > 10) {
-                            suggestion.appendText("...");
+                            suggestion.append("...");
                         }
 
-                        suggestion.appendText(exception.getInput().substring(Math.max(0, textLength - 10), textLength));
+                        suggestion.append(exception.getInput().substring(Math.max(0, textLength - 10), textLength));
                         if (textLength < exception.getInput().length()) {
-                            suggestion.appendSibling(new TextComponentString(exception.getInput().substring(textLength))
-                                    .applyTextStyles(TextFormatting.RED, TextFormatting.UNDERLINE));
+                            suggestion.append(new LiteralText(exception.getInput().substring(textLength))
+                                    .formatted(Formatting.RED, Formatting.UNDERLINE));
                         }
 
-                        suggestion.appendSibling(new TextComponentTranslation("command.context.here")
-                                .applyTextStyles(TextFormatting.RED, TextFormatting.ITALIC));
-                        commandSource.sendErrorMessage(suggestion);
+                        suggestion.append(new TranslatableText("command.context.here")
+                                .formatted(Formatting.RED, Formatting.ITALIC));
+                        commandSource.sendError(suggestion);
                     }
                 }
             }
@@ -70,26 +82,53 @@ public class ClientInterop {
     }
 
     public static int getRenderDistanceChunks() {
-        return Minecraft.getInstance().gameSettings.renderDistanceChunks;
+        return MinecraftClient.getInstance().options.viewDistance;
     }
 
-    public static void handleSeedMessage(ITextComponent chatComponent) {
-        TypeHelper.doIfType(chatComponent, TextComponentTranslation.class, message -> {
+    public static void handleSeedMessage(Text chatComponent) {
+        TypeHelper.doIfType(chatComponent, TranslatableText.class, message -> {
             if (!message.getKey().equals("commands.seed.success")) return;
 
             try {
-                long seed = Long.parseLong(message.getFormatArgs()[0].toString());
+                long seed = Long.parseLong(message.getArgs()[0].toString());
                 SlimeChunkProvider.setSeed(seed);
             } catch (Exception ignored) {
             }
         });
     }
 
-    public static void registerClientCommands(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
+    public static void registerClientCommands(CommandDispatcher<CommandSource> commandDispatcher) {
         SeedCommand.register(commandDispatcher);
         SpawningSphereCommand.register(commandDispatcher);
-        BoxCommand.register(commandDispatcher);
-        BeaconCommand.register(commandDispatcher);
+        CustomCommand.register(commandDispatcher);
         ConfigCommand.register(commandDispatcher);
+        StructuresCommand.register(commandDispatcher);
+    }
+
+    public static void receivedChunk(int chunkX, int chunkZ) {
+        SaveGameStructureLoader.loadStructures(chunkX, chunkZ);
+    }
+
+    public static void saveLoaded(String fileName, long seed) {
+        displayScreen(null);
+        MinecraftClient.getInstance().mouse.lockCursor();
+
+        clearStructures();
+
+        SlimeChunkProvider.setSeed(seed);
+        SaveGameStructureLoader.loadSaveGame(fileName);
+    }
+
+    public static void clearStructures() {
+        EventBus.publish(new SaveLoaded());
+        SaveGameStructureLoader.clear();
+    }
+
+    public static void displayScreen(Screen screen) {
+        MinecraftClient.getInstance().setScreen(screen);
+    }
+
+    public static long getGameTime() {
+        return MinecraftClient.getInstance().world.getTime();
     }
 }