Skip to content
Merged

Dev #421

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ stonecutter {
}

repositories {
mavenCentral()
exclusiveContent {
forRepository {
maven {
Expand All @@ -54,6 +55,18 @@ repositories {
name = "WorldEdit Maven"
url = uri("https://maven.enginehub.org/repo/")
}
maven {
name = "kr1v"
url = uri("https://repo.repsy.io/kr1v/maven/")
}
maven {
name = "Sakura Ryoko"
url = uri("https://masa.dy.fi/maven/sakura-ryoko/")
}
maven {
name = "Fallen Breath"
url = uri("https://maven.fallenbreath.me/releases/")
}
}

dependencies {
Expand All @@ -62,7 +75,17 @@ dependencies {
modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}")
modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}")
modImplementation("com.sk89q.worldedit:worldedit-fabric-mc${project.property("worldedit_version")}")
modApi("maven.modrinth:malilib:${project.property("malilib_version")}")
modImplementation("fi.dy.masa.malilib:malilib-fabric-${project.property("malilib_version")}")
modImplementation("net.kr1v:malilib-api:${project.property("malilib_api_version")}") {
exclude(group = "net.fabricmc.fabric-api") // prevent 1.21.5 fabric api modules used by malilib from leaking into 1.21.4
}
annotationProcessor("net.kr1v:malilib-api-processor:1.0.0")
}

configurations.all {
resolutionStrategy {
force("com.google.code.gson:gson:2.13.2")
}
}

loom {
Expand Down Expand Up @@ -92,20 +115,11 @@ tasks.processResources {
}
}

tasks.register<DefaultTask>("collectFile") {
tasks.register<Copy>("collectFile") {
group = "build"
mustRunAfter("build")

doLast {
copy {
from(
file(
"build/libs/${project.property("archives_base_name")}-${project.property("mod_version")}+${project.property("minecraft_version")}.jar"
)
)
into(rootProject.file("build/libs"))
}
}

from(tasks.remapJar)
into(rootProject.layout.buildDirectory.dir("libs/${project.property("mod_version")}"))
}

tasks.register<DefaultTask>("buildAndCollect") {
Expand All @@ -124,6 +138,7 @@ java {
}

tasks.jar {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from("LICENSE") {
rename { "${it}_${project.property("archives_base_name")}" }
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ maven_group = tools.redstone
archives_base_name = redstonetools

loader_version=0.18.4
mod_version = 3.2.0
mod_version = 3.3.0
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
package tools.redstone.redstonetools;

import fi.dy.masa.malilib.event.InitializationHandler;
import kr1v.malilibApi.MalilibApi;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientWorldEvents;
import tools.redstone.redstonetools.malilib.InitHandler;
import tools.redstone.redstonetools.malilib.config.Configs;
import tools.redstone.redstonetools.config.ClientData;
import tools.redstone.redstonetools.packets.RedstoneToolsClientPackets;

import static tools.redstone.redstonetools.RedstoneTools.LOGGER;
import static tools.redstone.redstonetools.RedstoneTools.*;

public class RedstoneToolsClient implements ClientModInitializer {
private static boolean hasRanCommands = false;

@Override
public void onInitializeClient() {
LOGGER.info("Initializing Redstone Tools");
InitializationHandler.getInstance().registerInitializationHandler(new InitHandler());
MalilibApi.registerMod(MOD_ID, MOD_NAME);

ClientWorldEvents.AFTER_CLIENT_WORLD_CHANGE.register((client, clientWorld) -> {
if (client.getNetworkHandler() != null) { // dimension change
String dimensionChange = Configs.ClientData.AUTORUN_DIMENSION_CHANGE.getStringValue();
String dimensionChange = ClientData.AUTORUN_DIMENSION_CHANGE.getStringValue();
if (dimensionChange.startsWith("/")) {
client.getNetworkHandler().sendChatCommand(dimensionChange.substring(1));
} else if (!dimensionChange.isEmpty()){
client.getNetworkHandler().sendChatMessage(dimensionChange);
}
} else { // world entry
String worldEntry = Configs.ClientData.AUTORUN_WORLD_ENTRY.getStringValue();
String worldEntry = ClientData.AUTORUN_WORLD_ENTRY.getStringValue();
if (worldEntry.startsWith("/")) {
client.send(() -> client.getNetworkHandler().sendChatCommand(worldEntry.substring(1)));
} else if (!worldEntry.isEmpty()){
client.send(() -> client.getNetworkHandler().sendChatMessage(worldEntry));
}
if (hasRanCommands) return;
hasRanCommands = true;
String firstWorldEntry = Configs.ClientData.AUTORUN_FIRST_WORLD_ENTRY.getStringValue();
String firstWorldEntry = ClientData.AUTORUN_FIRST_WORLD_ENTRY.getStringValue();
if (firstWorldEntry.startsWith("/")) {
client.send(() -> client.getNetworkHandler().sendChatCommand(firstWorldEntry.substring(1)));
} else if (!firstWorldEntry.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tools.redstone.redstonetools.config;

import fi.dy.masa.malilib.config.options.ConfigBoolean;
import fi.dy.masa.malilib.config.options.ConfigString;
import kr1v.malilibApi.annotation.Config;
import tools.redstone.redstonetools.RedstoneTools;

@Config(RedstoneTools.MOD_ID)
public class ClientData {
public static final ConfigBoolean ENABLE_MATH_VARIABLES = new ConfigBoolean("Enable math and variables for the chat input suggester", true,
"""
Whether or not to try to inject variables and math expressions into the command input suggester.

With this enabled, Redstone tools will attempt to prevent chat suggestion from breaking if you're using variables and or math expressions inside of a command.
With this disabled, variables and math expressions will still be inserted upon sending a chat command""");
public static final ConfigString VARIABLE_BEGIN_STRING = new ConfigString("Variable begin string", "'", "The string that should be used to denote the start of a variable. Can be empty");
public static final ConfigString VARIABLE_END_STRING = new ConfigString("Variable end string", "'", "The string that should be used to denote the end of a variable. Can be empty");
public static final ConfigString MATH_BEGIN_STRING = new ConfigString("Math begin string", "{", "The string that should be used to denote the start of a math expression. Can be empty, unsure if you'd want that though.");
public static final ConfigString MATH_END_STRING = new ConfigString("Math end string", "}", "The string that should be used to denote the end of a math expression. Can be empty, unsure if you'd want that though.");
public static final ConfigString AUTORUN_FIRST_WORLD_ENTRY = new ConfigString("First world entry", "", "Command/message that will be run/sent the first time you join a world in this session");
public static final ConfigString AUTORUN_WORLD_ENTRY = new ConfigString("World entry", "", "Command/message that will be run/sent when you join a world");
public static final ConfigString AUTORUN_DIMENSION_CHANGE = new ConfigString("Dimension change", "", "Command/message that will be run/sent after you change dimensions");
}
28 changes: 28 additions & 0 deletions src/client/java/tools/redstone/redstonetools/config/General.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tools.redstone.redstonetools.config;

import fi.dy.masa.malilib.config.options.ConfigBoolean;
import fi.dy.masa.malilib.config.options.ConfigHotkey;
import fi.dy.masa.malilib.config.options.ConfigInteger;
import kr1v.malilibApi.MalilibApi;
import kr1v.malilibApi.annotation.Config;
import tools.redstone.redstonetools.RedstoneTools;

@Config(value = RedstoneTools.MOD_ID, order = 0)
public class General {
public static final ConfigHotkey HOTKEY_OPEN_GUI = new ConfigHotkey("Hotkey to open menu", "V,C", "Hotkey to open menu");
public static final ConfigBoolean BOOLEAN_IMPROVED_COMMAND_SUGGESTIONS = new ConfigBoolean("Improved command suggestions", true,
"""
Enables/disables improved suggestions when typing commands.

When typing "/give @s redstblock" in chat, with this disabled it will give no suggestions (default behaviour, or "prefix matching"), but with
this enabled it will give "redstone_block" as a suggestion (so called "fuzzy matching").""");
public static final ConfigBoolean AIRPLACE_SHOW_OUTLINE = new ConfigBoolean("Airplace showOutline", true, "If enabled, will show a block outline for the block your holding");
public static final ConfigInteger BIGDUST_HEIGHT_IN_PIXELS = new ConfigInteger("Bigdust heightInPixels", 3, 0, 16, "How tall the redstone hitbox should be");

static {
HOTKEY_OPEN_GUI.getKeybind().setCallback((action, key) -> {
MalilibApi.openScreenFor(RedstoneTools.MOD_ID);
return true;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package tools.redstone.redstonetools.config;

import fi.dy.masa.malilib.hotkeys.KeybindSettings;
import tools.redstone.redstonetools.config.option.ConfigMacro;
import tools.redstone.redstonetools.macros.actions.CommandAction;

import java.util.ArrayList;
import java.util.List;

public class MacroManager {
public static boolean shouldMute;

public static ConfigMacro getMacro(String name) {
for (ConfigMacro macro : Macros.getMacros()) {
if (macro.getMacroName().equals(name)) {
return macro;
}
}

return null;
}

public static boolean nameExists(String name, ConfigMacro exclude) {
for (ConfigMacro macro : Macros.getMacros()) {
if (macro == exclude) continue;
if (macro.getMacroName().equals(name)) return true;
}
return false;
}

public static List<ConfigMacro> getDefaultMacros() {
return new ArrayList<>(List.of(
createCommandMacro("redstoner", new String[]{
"/gamerule doTileDrops false",
"/gamerule doTraderSpawning false",
"/gamerule doWeatherCycle false",
"/gamerule doDaylightCycle false",
"/gamerule doMobSpawning false",
//? if <1.21.11
//"/gamerule doContainerDrops false",
"/time set noon",
"/weather clear"
}),
createCommandMacro("copystate", new String[]{"/copystate" }),
createCommandMacro("itembind", new String[]{"/itembind" }),
createCommandMacro("minsel", new String[]{"//minsel" }),
createCommandMacro("quicktp", new String[]{"/quicktp" }),
createCommandMacro("binaryblockread", new String[]{"//binaryblockread" }),
createCommandMacro("rstack", new String[]{"//rstack" }),
createCommandMacro("update", new String[]{"//update" })
));
}

public static ConfigMacro createCommandMacro(String name, String[] commands) {
var actions = new CommandAction[commands.length];
for (int i = 0; i < commands.length; i++) {
actions[i] = new CommandAction(commands[i]);
}

return new ConfigMacro(name, true, false, List.of(actions), "", KeybindSettings.PRESS_ALLOWEXTRA);
}
}
54 changes: 54 additions & 0 deletions src/client/java/tools/redstone/redstonetools/config/Macros.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package tools.redstone.redstonetools.config;

import fi.dy.masa.malilib.hotkeys.KeybindSettings;
import kr1v.malilibApi.InternalMalilibApi;
import kr1v.malilibApi.ModRepresentation;
import kr1v.malilibApi.annotation.Config;
import kr1v.malilibApi.config._new.ConfigList;
import tools.redstone.redstonetools.RedstoneTools;
import tools.redstone.redstonetools.config.option.ConfigMacro;

import java.util.List;
import java.util.UUID;
import java.util.function.BiFunction;

@Config(RedstoneTools.MOD_ID)
public class Macros {
public static final ConfigList<ConfigMacro> MACROS = new ConfigList<>(
"Macros",
MacroManager.getDefaultMacros(),
() -> {
var newMacro = new ConfigMacro("macro " + (getMacros().size()), true, false, List.of(), "", KeybindSettings.PRESS_ALLOWEXTRA);
if (MacroManager.nameExists(newMacro.getName(), newMacro)) {
newMacro.setMacroName(newMacro.getName() + " " + UUID.randomUUID());
}
return newMacro;
},
"Edit macros"
);

public static List<ConfigMacro> getMacros() {
//noinspection ConstantValue
if (MACROS == null) return List.of();
return MACROS.getList();
}

private static ModRepresentation.Tab TAB;

public static ModRepresentation.Tab getTab() {
if (TAB == null) TAB = initTab();
return TAB;
}

private static ModRepresentation.Tab initTab() {
ModRepresentation.Tab macrosTab = null;
for (ModRepresentation.Tab tab : InternalMalilibApi.getMod(RedstoneTools.MOD_ID).tabs) {
if (tab.translationKey().equals("Macros")) {
macrosTab = tab;
break;
}
}
if (macrosTab == null) throw new IllegalStateException("Macros tab not found");
return macrosTab;
}
}
37 changes: 37 additions & 0 deletions src/client/java/tools/redstone/redstonetools/config/Toggles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tools.redstone.redstonetools.config;

import fi.dy.masa.malilib.config.options.ConfigBooleanHotkeyed;
import kr1v.malilibApi.annotation.Config;
import tools.redstone.redstonetools.RedstoneTools;

@Config(RedstoneTools.MOD_ID)
public class Toggles {
public static final ConfigBooleanHotkeyed AIRPLACE = new ConfigBooleanHotkeyed("Airplace", false, "", "Whether or not airplace should be enabled");
public static final ConfigBooleanHotkeyed AUTODUST = new ConfigBooleanHotkeyed("Autodust", false, "", "Whether or not autodust should be enabled");
public static final ConfigBooleanHotkeyed AUTOROTATE = new ConfigBooleanHotkeyed("Autorotate", false, "", "Whether or not autorotate should be enabled");
public static final ConfigBooleanHotkeyed BIGDUST = new ConfigBooleanHotkeyed("Bigdust", false, "", "Whether or not bigdust should be enabled");
public static final ConfigBooleanHotkeyed CLICKCONTAINERS = new ConfigBooleanHotkeyed("Clickcontainers", false, "", "Whether or not clickcontainer should be enabled");

static {
AIRPLACE.getKeybind().setCallback((t, g) -> {
AIRPLACE.setBooleanValue(!AIRPLACE.getBooleanValue());
return true;
});
AUTODUST.getKeybind().setCallback((t, g) -> {
AUTODUST.setBooleanValue(!AUTODUST.getBooleanValue());
return true;
});
AUTOROTATE.getKeybind().setCallback((t, g) -> {
AUTOROTATE.setBooleanValue(!AUTOROTATE.getBooleanValue());
return true;
});
BIGDUST.getKeybind().setCallback((t, g) -> {
BIGDUST.setBooleanValue(!BIGDUST.getBooleanValue());
return true;
});
CLICKCONTAINERS.getKeybind().setCallback((t, g) -> {
CLICKCONTAINERS.setBooleanValue(!CLICKCONTAINERS.getBooleanValue());
return true;
});
}
}
Loading
Loading