Skip to content

Commit 71c0fcc

Browse files
authored
Merge pull request #399 from RedstoneTools/dev
Merge into main for v.3.1.0
2 parents 69ea544 + 296fa4e commit 71c0fcc

File tree

98 files changed

+2695
-1416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2695
-1416
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab

build.gradle

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ repositories {
5454
}
5555

5656
dependencies {
57-
include implementation("javax.inject:javax.inject:1")
58-
59-
// Json
60-
include implementation("javax.json:javax.json-api:1.1.4")
61-
include implementation("org.glassfish:javax.json:1.1.4")
62-
63-
// AutoService
64-
annotationProcessor implementation("com.google.auto.service:auto-service:1.1.0")
65-
6657
// To change the versions see the gradle.properties file
6758
minecraft("com.mojang:minecraft:${project.minecraft_version}")
6859
mappings("net.fabricmc:yarn:${project.yarn_mappings}:v2")

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ maven_group = tools.redstone
66
archives_base_name = redstonetools
77

88
loader_version=0.16.10
9-
mod_version = v3.0.0
9+
mod_version = v3.1.0
1010

1111
minecraft_version=1.21.8
1212
minecraft_version_out=1.21.8
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package tools.redstone.redstonetools;
22

3-
import tools.redstone.redstonetools.features.commands.BaseConvertFeature;
4-
import tools.redstone.redstonetools.features.commands.EditMacroFeature;
5-
import tools.redstone.redstonetools.features.commands.MacroFeature;
6-
import tools.redstone.redstonetools.features.commands.ReachFeature;
7-
import tools.redstone.redstonetools.features.toggleable.*;
3+
import com.mojang.brigadier.CommandDispatcher;
4+
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
5+
import net.minecraft.command.CommandRegistryAccess;
6+
import tools.redstone.redstonetools.features.commands.*;
7+
import tools.redstone.redstonetools.features.toggleable.AirPlaceFeature;
8+
import tools.redstone.redstonetools.features.toggleable.BigDustFeature;
9+
import tools.redstone.redstonetools.utils.DependencyLookup;
810

911
public class ClientCommands {
10-
public static void registerCommands() {
11-
BaseConvertFeature.registerCommand();
12-
EditMacroFeature.registerCommand();
13-
MacroFeature.registerCommand();
14-
ReachFeature.registerCommand();
15-
AirPlaceFeature.registerCommand();
16-
AutoRotateFeature.registerCommand();
17-
ClickContainerFeature.registerCommand();
18-
BigDustFeature.registerCommand();
19-
AutoDustClient.registerHandler();
20-
AutoRotateClient.registerHandler();
21-
ClickContainerClient.registerHandler();
12+
public static void registerCommands(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
13+
if (!DependencyLookup.REDSTONE_TOOLS_SERVER_PRESENT) {
14+
BaseConvertClient.INSTANCE.registerCommand(dispatcher, registryAccess);
15+
ReachClient.INSTANCE.registerCommand(dispatcher, registryAccess);
16+
GiveMeClient.INSTANCE.registerCommand(dispatcher, registryAccess);
17+
QuickTpClient.INSTANCE.registerCommand(dispatcher, registryAccess);
18+
}
19+
ClientDataFeature.INSTANCE.registerCommand(dispatcher, registryAccess);
20+
PrintFeature.INSTANCE.registerCommand(dispatcher, registryAccess);
21+
EditMacroFeature.INSTANCE.registerCommand(dispatcher, registryAccess);
22+
MacroFeature.INSTANCE.registerCommand(dispatcher, registryAccess);
23+
AirPlaceFeature.INSTANCE.registerCommand(dispatcher, registryAccess);
24+
RstFeature.INSTANCE.registerCommand(dispatcher, registryAccess);
25+
BigDustFeature.INSTANCE.registerCommand(dispatcher, registryAccess);
2226
}
2327
}

src/client/java/tools/redstone/redstonetools/Init.java

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
11
package tools.redstone.redstonetools;
22

3+
import fi.dy.masa.malilib.event.InitializationHandler;
34
import net.fabricmc.api.ClientModInitializer;
4-
import net.fabricmc.loader.api.FabricLoader;
5-
import org.lwjgl.util.tinyfd.TinyFileDialogs;
5+
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientWorldEvents;
6+
import tools.redstone.redstonetools.malilib.InitHandler;
7+
import tools.redstone.redstonetools.malilib.config.Configs;
8+
import tools.redstone.redstonetools.packets.RedstoneToolsClientPackets;
69

710
import static tools.redstone.redstonetools.RedstoneTools.LOGGER;
811

912
public class RedstoneToolsClient implements ClientModInitializer {
13+
private static boolean hasRanCommands = false;
1014

1115
@Override
1216
public void onInitializeClient() {
1317
LOGGER.info("Initializing Redstone Tools");
14-
// check if malilib present, if not open an error window and throw
15-
if (!FabricLoader.getInstance().isModLoaded("malilib")) {
16-
TinyFileDialogs.tinyfd_messageBox(
17-
"Error",
18-
"MaLiLib not present!\nPlease install MaLiLib if you want to use redstonetools",
19-
"ok",
20-
"error",
21-
false
22-
);
23-
throw new IllegalStateException("MaLiLib not present");
24-
}
25-
Init.init();
18+
InitializationHandler.getInstance().registerInitializationHandler(new InitHandler());
19+
20+
ClientWorldEvents.AFTER_CLIENT_WORLD_CHANGE.register((client, clientWorld) -> {
21+
if (client.getNetworkHandler() != null) { // dimension change
22+
String dimensionChange = Configs.ClientData.AUTORUN_DIMENSION_CHANGE.getStringValue();
23+
if (dimensionChange.startsWith("/")) {
24+
client.getNetworkHandler().sendChatCommand(dimensionChange.substring(1));
25+
} else if (!dimensionChange.isEmpty()){
26+
client.getNetworkHandler().sendChatMessage(dimensionChange);
27+
}
28+
} else { // world entry
29+
String worldEntry = Configs.ClientData.AUTORUN_WORLD_ENTRY.getStringValue();
30+
if (worldEntry.startsWith("/")) {
31+
client.send(() -> client.getNetworkHandler().sendChatCommand(worldEntry.substring(1)));
32+
} else if (!worldEntry.isEmpty()){
33+
client.send(() -> client.getNetworkHandler().sendChatMessage(worldEntry));
34+
}
35+
if (hasRanCommands) return;
36+
hasRanCommands = true;
37+
String firstWorldEntry = Configs.ClientData.AUTORUN_FIRST_WORLD_ENTRY.getStringValue();
38+
if (firstWorldEntry.startsWith("/")) {
39+
client.send(() -> client.getNetworkHandler().sendChatCommand(firstWorldEntry.substring(1)));
40+
} else if (!firstWorldEntry.isEmpty()) {
41+
client.send(() -> client.getNetworkHandler().sendChatMessage(firstWorldEntry));
42+
}
43+
}
44+
});
45+
46+
RedstoneToolsClientPackets.registerPackets();
47+
Commands.registerCommands();
2648
}
2749
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package tools.redstone.redstonetools.features.commands;
2+
3+
import com.mojang.brigadier.CommandDispatcher;
4+
import com.mojang.brigadier.arguments.IntegerArgumentType;
5+
import com.mojang.brigadier.arguments.StringArgumentType;
6+
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
7+
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
8+
import net.minecraft.command.CommandRegistryAccess;
9+
10+
11+
public class BaseConvertClient {
12+
public static final BaseConvertClient INSTANCE = new BaseConvertClient();
13+
14+
protected BaseConvertClient() {
15+
}
16+
public void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
17+
dispatcher.register(
18+
ClientCommandManager.literal("base")
19+
.then(ClientCommandManager.argument("inputNum", StringArgumentType.word())
20+
.then(ClientCommandManager.argument("toBase", IntegerArgumentType.integer(2, 16))
21+
.executes(context -> BaseConvertFeature.INSTANCE.execute(
22+
StringArgumentType.getString(context, "inputNum"),
23+
IntegerArgumentType.getInteger(context, "toBase"),
24+
(t) -> context.getSource().sendFeedback(t)
25+
)))));
26+
}
27+
}

src/client/java/tools/redstone/redstonetools/features/commands/BaseConvertFeature.java

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package tools.redstone.redstonetools.features.commands;
2+
3+
import com.mojang.brigadier.CommandDispatcher;
4+
import com.mojang.brigadier.arguments.StringArgumentType;
5+
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
6+
import net.minecraft.command.CommandRegistryAccess;
7+
import net.minecraft.text.Text;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
13+
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
14+
15+
public class ClientDataFeature {
16+
public Map<String, String> variables = new HashMap<>();
17+
public static final ClientDataFeature INSTANCE = new ClientDataFeature();
18+
19+
public void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
20+
dispatcher.register(literal("clientdata")
21+
.then(literal("set")
22+
.then(argument("name", StringArgumentType.word())
23+
.then(argument("value", StringArgumentType.greedyString())
24+
.executes(context -> {
25+
String name = StringArgumentType.getString(context, "name");
26+
String value = StringArgumentType.getString(context, "value");
27+
variables.put(name, value);
28+
context.getSource().sendFeedback(Text.of("Set " + name + " to \"" + value + "\""));
29+
return 1;
30+
}
31+
)
32+
)
33+
)
34+
)
35+
.then(literal("delete")
36+
.then(argument("name", StringArgumentType.word())
37+
.executes(context -> {
38+
variables.remove(StringArgumentType.getString(context, "name"));
39+
return 1;
40+
}
41+
)
42+
)
43+
)
44+
);
45+
}
46+
}
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package tools.redstone.redstonetools.features.commands;
22

3+
import com.mojang.brigadier.CommandDispatcher;
34
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
5+
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
46
import net.minecraft.client.MinecraftClient;
7+
import net.minecraft.command.CommandRegistryAccess;
58
import tools.redstone.redstonetools.malilib.GuiMacroManager;
69

7-
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback.EVENT;
810

911
public class EditMacroFeature {
10-
public static void registerCommand() {
11-
EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("edit-macros")
12+
public static final EditMacroFeature INSTANCE = new EditMacroFeature();
13+
14+
protected EditMacroFeature() {
15+
}
16+
17+
public void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
18+
dispatcher.register(ClientCommandManager.literal("edit-macros")
1219
.executes(commandContext -> {
1320
MinecraftClient.getInstance().send(() -> MinecraftClient.getInstance().setScreen(new GuiMacroManager()));
1421
return 1;
15-
})));
22+
}));
1623
}
1724
}

0 commit comments

Comments
 (0)