Skip to content

Commit

Permalink
feat: Support Chat Action Successfully !
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhoues committed Feb 8, 2024
1 parent 7611c1a commit d69b85a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions scripts/mcp_patch.diff
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ diff -u1 -rN MCP-Reborn-vanilla/src/main/java/com/minerl/multiagent/RandomHelper
diff -u1 -rN MCP-Reborn-vanilla/src/main/java/com/minerl/multiagent/env/EnvServer.java MCP-Reborn/src/main/java/com/minerl/multiagent/env/EnvServer.java
--- MCP-Reborn-vanilla/src/main/java/com/minerl/multiagent/env/EnvServer.java 1970-01-01 01:00:00.000000000 +0100
+++ MCP-Reborn/src/main/java/com/minerl/multiagent/env/EnvServer.java 2022-06-23 00:28:31.911515382 +0100
@@ -0,0 +1,715 @@
@@ -0,0 +1,727 @@
+package com.minerl.multiagent.env;
+
+import com.google.common.base.Charsets;
Expand Down Expand Up @@ -2240,7 +2240,7 @@ diff -u1 -rN MCP-Reborn-vanilla/src/main/java/com/minerl/multiagent/env/EnvServe
+ }
+
+
+ WorldSettings worldSettings = new WorldSettings(worldName, GameType.SURVIVAL, false, Difficulty.HARD, false, new GameRules(), DatapackCodec.VANILLA_CODEC);
+ WorldSettings worldSettings = new WorldSettings(worldName, GameType.SURVIVAL, false, Difficulty.HARD, true, new GameRules(), DatapackCodec.VANILLA_CODEC);
+ DimensionGeneratorSettings dms = DimensionGeneratorSettings.fromDynamicRegistries(DynamicRegistries.getImpl(), seed, generateFeatures, bonusChest);
+ mc.createWorld(worldName, worldSettings, DynamicRegistries.getImpl(), dms);
+ }
Expand Down Expand Up @@ -2418,17 +2418,29 @@ diff -u1 -rN MCP-Reborn-vanilla/src/main/java/com/minerl/multiagent/env/EnvServe
+ }
+
+ public static void execActions(String actions, int options) {
+ doChatActions(actions);
+ KeyboardListener.State keysState = constructKeyboardState(actions);
+ MouseHelper.State mouseState = constructMouseState(actions);
+ PlayRecorder.getInstance().setMouseKeyboardState(mouseState, keysState);
+ ReplaySender.getInstance().addAction(mouseState, keysState);
+ }
+
+
+ public static void doChatActions(String actions) {
+ for (String action: actions.split("\n")) {
+ String[] splitAction = action.trim().split(" ");
+ if (splitAction[0].equals("chat") && splitAction.length > 1) {
+ String chatMessage = action.trim().substring(splitAction[0].length()).trim();
+ Minecraft.getInstance().player.sendChatMessage(chatMessage);
+ }
+ }
+ }
+
+ private static KeyboardListener.State constructKeyboardState(String actions) {
+ List<String> keysPressed = new ArrayList<>();
+ for (String action: actions.split("\n")) {
+ String[] splitAction = action.trim().split(" ");
+ if (!splitAction[0].equals("camera") && !splitAction[0].equals("dwheel")) {
+ if (!splitAction[0].equals("camera") && !splitAction[0].equals("dwheel") && !splitAction[0].equals("chat")) {
+ if (splitAction.length > 1 && Integer.parseInt(splitAction[1]) == 1) {
+ String key = actionToKey(splitAction[0]);
+ if (key != null) {
Expand Down Expand Up @@ -2459,7 +2471,7 @@ diff -u1 -rN MCP-Reborn-vanilla/src/main/java/com/minerl/multiagent/env/EnvServe
+ dy = Double.parseDouble(splitAction[1]) * sensitivity;
+ } else if (splitAction[0].equals("dwheel")) {
+ dwheel = Double.parseDouble(splitAction[1]);
+ } else {
+ } else if (!splitAction[0].equals("chat")) {
+ if (splitAction.length > 1 && Integer.parseInt(splitAction[1]) == 1) {
+ Integer key = actionToMouseButton(splitAction[0]);
+ if (key != null) {
Expand Down

0 comments on commit d69b85a

Please sign in to comment.