Skip to content

Commit 296fa4e

Browse files
authored
Merge pull request #398 from kr1viah/dev
Dev
2 parents fa5ed2b + c4889d0 commit 296fa4e

Some content is hidden

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

55 files changed

+1170
-492
lines changed

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: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
package tools.redstone.redstonetools;
22

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

611
public class ClientCommands {
7-
public static void registerCommands() {
8-
BaseConvertClient.INSTANCE.registerCommand();
9-
EditMacroFeature.INSTANCE.registerCommand();
10-
MacroFeature.INSTANCE.registerCommand();
11-
ReachClient.INSTANCE.registerCommand();
12-
GiveMeClient.INSTANCE.registerCommand();
13-
AirPlaceFeature.INSTANCE.registerCommand();
14-
AutoRotateFeature.INSTANCE.registerCommand();
15-
ClickContainerFeature.INSTANCE.registerCommand();
16-
RstFeature.INSTANCE.registerCommand();
17-
BigDustFeature.INSTANCE.registerCommand();
18-
QuickTpClient.INSTANCE.registerCommand();
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);
1926
}
2027
}

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,48 @@
22

33
import fi.dy.masa.malilib.event.InitializationHandler;
44
import net.fabricmc.api.ClientModInitializer;
5-
import net.fabricmc.loader.api.FabricLoader;
6-
import org.lwjgl.util.tinyfd.TinyFileDialogs;
5+
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientWorldEvents;
76
import tools.redstone.redstonetools.malilib.InitHandler;
7+
import tools.redstone.redstonetools.malilib.config.Configs;
88
import tools.redstone.redstonetools.packets.RedstoneToolsClientPackets;
99

1010
import static tools.redstone.redstonetools.RedstoneTools.LOGGER;
1111

1212
public class RedstoneToolsClient implements ClientModInitializer {
13+
private static boolean hasRanCommands = false;
1314

1415
@Override
1516
public void onInitializeClient() {
1617
LOGGER.info("Initializing Redstone Tools");
1718
InitializationHandler.getInstance().registerInitializationHandler(new InitHandler());
1819

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+
1946
RedstoneToolsClientPackets.registerPackets();
20-
ClientCommands.registerCommands();
2147
Commands.registerCommands();
2248
}
2349
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
package tools.redstone.redstonetools.features.commands;
22

3+
import com.mojang.brigadier.CommandDispatcher;
34
import com.mojang.brigadier.arguments.IntegerArgumentType;
45
import com.mojang.brigadier.arguments.StringArgumentType;
56
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;
69

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

911
public class BaseConvertClient {
1012
public static final BaseConvertClient INSTANCE = new BaseConvertClient();
1113

1214
protected BaseConvertClient() {
1315
}
14-
public void registerCommand() {
15-
EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("base")
16+
public void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
17+
dispatcher.register(
18+
ClientCommandManager.literal("base")
1619
.then(ClientCommandManager.argument("inputNum", StringArgumentType.word())
1720
.then(ClientCommandManager.argument("toBase", IntegerArgumentType.integer(2, 16))
1821
.executes(context -> BaseConvertFeature.INSTANCE.execute(
1922
StringArgumentType.getString(context, "inputNum"),
2023
IntegerArgumentType.getInteger(context, "toBase"),
2124
(t) -> context.getSource().sendFeedback(t)
22-
))))));
25+
)))));
2326
}
2427
}
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +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 {
1012
public static final EditMacroFeature INSTANCE = new EditMacroFeature();
1113

1214
protected EditMacroFeature() {
1315
}
1416

15-
public void registerCommand() {
16-
EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("edit-macros")
17+
public void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
18+
dispatcher.register(ClientCommandManager.literal("edit-macros")
1719
.executes(commandContext -> {
1820
MinecraftClient.getInstance().send(() -> MinecraftClient.getInstance().setScreen(new GuiMacroManager()));
1921
return 1;
20-
})));
22+
}));
2123
}
2224
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package tools.redstone.redstonetools.features.commands;
22

3+
import com.mojang.brigadier.CommandDispatcher;
34
import com.mojang.brigadier.arguments.IntegerArgumentType;
45
import com.mojang.brigadier.context.CommandContext;
56
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
67
import net.minecraft.command.CommandRegistryAccess;
78
import net.minecraft.command.argument.ItemStackArgument;
89
import net.minecraft.command.argument.ItemStackArgumentType;
910

10-
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback.EVENT;
1111
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
1212
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
1313

@@ -17,8 +17,8 @@ public class GiveMeClient {
1717
protected GiveMeClient() {
1818
}
1919

20-
public void registerCommand() {
21-
EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
20+
public void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
21+
dispatcher.register(
2222
literal("g")
2323
.requires(source -> source.getPlayer().hasPermissionLevel(2))
2424
.then(argument("item", ItemStackArgumentType.itemStack(registryAccess))
@@ -32,7 +32,7 @@ public void registerCommand() {
3232
context,
3333
registryAccess,
3434
ItemStackArgumentType.getItemStackArgument(context, "item"),
35-
IntegerArgumentType.getInteger(context, "count")))))));
35+
IntegerArgumentType.getInteger(context, "count"))))));
3636
}
3737

3838
private int execute(CommandContext<FabricClientCommandSource> context, CommandRegistryAccess registryAccess, ItemStackArgument itemArgument, int count) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package tools.redstone.redstonetools.features.commands;
22

3+
import com.mojang.brigadier.CommandDispatcher;
34
import com.mojang.brigadier.context.CommandContext;
45
import com.mojang.brigadier.exceptions.CommandSyntaxException;
56
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
7+
import net.minecraft.command.CommandRegistryAccess;
68
import tools.redstone.redstonetools.features.commands.argument.MacroArgumentType;
79
import tools.redstone.redstonetools.malilib.widget.macro.MacroBase;
810

9-
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback.EVENT;
1011
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
1112
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
1213

@@ -16,15 +17,13 @@ public class MacroFeature {
1617
protected MacroFeature() {
1718
}
1819

19-
public void registerCommand() {
20-
EVENT.register((dispatcher, registryAccess) -> {
20+
public void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
2121
dispatcher.register(literal("macro")
2222
.then(argument("macro", MacroArgumentType.macro())
2323
.executes(this::execute)));
2424
dispatcher.register(literal("m")
2525
.then(argument("macro", MacroArgumentType.macro())
2626
.executes(this::execute)));
27-
});
2827
}
2928

3029
protected int execute(CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
10+
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
11+
12+
public class PrintFeature {
13+
public static final PrintFeature INSTANCE = new PrintFeature();
14+
15+
public void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
16+
dispatcher.register(literal("print")
17+
.then(argument("text", StringArgumentType.greedyString())
18+
.executes((context -> {
19+
context.getSource().sendFeedback(Text.of(StringArgumentType.getString(context, "text")));
20+
return 1;
21+
})
22+
)
23+
)
24+
);
25+
}
26+
}

0 commit comments

Comments
 (0)