diff --git a/.envrc b/.envrc
new file mode 100644
index 0000000..8392d15
--- /dev/null
+++ b/.envrc
@@ -0,0 +1 @@
+use flake
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 5612e93..704eb3c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,5 @@ hs_err_*.log
replay_*.log
*.hprof
*.jfr
+
+.direnv
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6f40516..7f66d4c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+### [1.3.3]
+- Fixed commands not registering when running `/reload`.
+- Cleaned up commands code a bit.
+- Finally added a nix development flake.
+
### [1.3.2]
- Added Traditional Chinese (Hong Kong) translations. (Thanks to [Dicecan](https://github.com/Dicecan)
- Updated Traditional Chinese (Taiwan) and Simplified Chinese translations. (Thanks to [Dicecan](https://github.com/Dicecan))
diff --git a/README.md b/README.md
index 189f14a..c251d75 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,6 @@ Here is the [Changelog](https://github.com/MrSn0wy/TeleportCommands/blob/main/CH
### TODO:
-
#### Planned commands:
- [ ] `/wild` - Teleports you to a random location in the Overworld
- [x] `/worldspawn` - Teleports you to the worldspawn
@@ -57,18 +56,30 @@ Here is the [Changelog](https://github.com/MrSn0wy/TeleportCommands/blob/main/CH
- [x] Add Quilt support and NeoForge
-#### Want to help?
-
+### Want to help?
1. You can create a translation file so other people can use the mod in their native language: [translations.md](./common/src/main/resources/assets/teleport_commands/lang/translations.md)
-#### How to build
-w.i.p.
-just use correto21 and an intellij idea, then just run the build option that should appear. That's what I do :3
+### How to build
+#### Getting the correct environment
+If you are on nixos you can simply go into the folder of where you cloned the repo, and run `nix develop .`. This will give you the environment I use (apart from the IDE) :3.
+
+On any other linux distro, just install the jetbrains jdk, or try openjdk21.
+
+On windows probably go to the openjdk website and install the 21 version? idk goodluck.
+
+#### Building
+Then on linux just do `./gradlew build` and to make it in a single mod jar `./gradlew mergeJars`.
+
+Or on windows, just do `.\gradlew.bat build` and `.\gradlew.bat mergeJars`.
+Note that this isn't tested for windows, but I think that is how it works.
+#### Getting the jars
+Then you can find your jars in `fabric/build/libs/` (for fabric), `neoforge/build/libs/` (for neoforge) or `merged/build/libs/` (if you made the merged jar file).
-#### Notes
+If you have any issues just make an issue or contact me on Discord `@mrsnowy_`
+### Notes
Colors:
- Green = When something succeeds and an action will happen
- Aqua = When something needs attention
diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/Constants.java b/common/src/main/java/dev/mrsnowy/teleport_commands/Constants.java
index ac72ff6..5b07e1f 100644
--- a/common/src/main/java/dev/mrsnowy/teleport_commands/Constants.java
+++ b/common/src/main/java/dev/mrsnowy/teleport_commands/Constants.java
@@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory;
public class Constants {
public static final String MOD_ID = "teleport_commands";
public static final String MOD_NAME = "Teleport Commands";
- public static final String VERSION = "1.3.2";
+ public static final String VERSION = "1.3.3";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME);
}
diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/TeleportCommands.java b/common/src/main/java/dev/mrsnowy/teleport_commands/TeleportCommands.java
index f815a5b..8dfd2e4 100644
--- a/common/src/main/java/dev/mrsnowy/teleport_commands/TeleportCommands.java
+++ b/common/src/main/java/dev/mrsnowy/teleport_commands/TeleportCommands.java
@@ -1,9 +1,11 @@
package dev.mrsnowy.teleport_commands;
import com.google.gson.*;
+import com.mojang.brigadier.CommandDispatcher;
import dev.mrsnowy.teleport_commands.storage.StorageManager;
import dev.mrsnowy.teleport_commands.commands.*;
import dev.mrsnowy.teleport_commands.storage.DeathLocationStorage;
+import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
@@ -37,15 +39,16 @@ public class TeleportCommands {
StorageManager.STORAGE = storageValidator(); // Initialize the storage file
DeathLocationStorage.clearDeathLocations(); // Clear data of death locations.
- // initialize commands, also allows me to easily disable any when there is a config
- Commands commandManager = server.getCommands();
- back.register(commandManager);
- home.register(commandManager);
- tpa.register(commandManager);
- warp.register(commandManager);
- worldspawn.register(commandManager);
}
+ // initialize commands, also allows me to easily disable any when there is a config
+ public static void registerCommands(CommandDispatcher dispatcher) {
+ back.register(dispatcher);
+ home.register(dispatcher);
+ tpa.register(dispatcher);
+ warp.register(dispatcher);
+ worldspawn.register(dispatcher);
+ }
// Runs when the playerDeath mixin calls it, updates the /back command position
public static void onPlayerDeath(ServerPlayer player) {
diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/back.java b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/back.java
index 4d78d82..cf169f7 100644
--- a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/back.java
+++ b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/back.java
@@ -1,5 +1,6 @@
package dev.mrsnowy.teleport_commands.commands;
+import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import dev.mrsnowy.teleport_commands.Constants;
@@ -9,6 +10,7 @@ import dev.mrsnowy.teleport_commands.storage.DeathLocationStorage;
import dev.mrsnowy.teleport_commands.common.DeathLocation;
import dev.mrsnowy.teleport_commands.utils.tools;
import net.minecraft.ChatFormatting;
+import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.ClickEvent;
@@ -22,9 +24,9 @@ import static net.minecraft.commands.Commands.argument;
public class back {
- public static void register(Commands commandManager) {
+ public static void register(CommandDispatcher commandDispatcher) {
- commandManager.getDispatcher().register(Commands.literal("back")
+ commandDispatcher.register(Commands.literal("back")
.requires(source -> source.getPlayer() != null)
.executes(context -> {
final ServerPlayer player = context.getSource().getPlayerOrException();
diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java
index cc39c63..267c5f5 100644
--- a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java
+++ b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java
@@ -1,5 +1,6 @@
package dev.mrsnowy.teleport_commands.commands;
+import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.mrsnowy.teleport_commands.Constants;
import dev.mrsnowy.teleport_commands.storage.StorageManager;
@@ -12,6 +13,7 @@ import java.util.Optional;
import dev.mrsnowy.teleport_commands.utils.tools;
import net.minecraft.ChatFormatting;
+import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.ClickEvent;
@@ -28,9 +30,9 @@ import static net.minecraft.commands.Commands.argument;
import static dev.mrsnowy.teleport_commands.utils.tools.Teleporter;
public class home {
- public static void register(Commands commandManager) {
+ public static void register(CommandDispatcher commandDispatcher) {
- commandManager.getDispatcher().register(Commands.literal("sethome")
+ commandDispatcher.register(Commands.literal("sethome")
.requires(source -> source.getPlayer() != null)
.then(argument("name", StringArgumentType.string())
.executes(context -> {
@@ -49,7 +51,7 @@ public class home {
})));
- commandManager.getDispatcher().register(Commands.literal("home")
+ commandDispatcher.register(Commands.literal("home")
.requires(source -> source.getPlayer() != null)
.executes(context -> {
final ServerPlayer player = context.getSource().getPlayerOrException();
@@ -82,7 +84,7 @@ public class home {
return 0;
})));
- commandManager.getDispatcher().register(Commands.literal("delhome")
+ commandDispatcher.register(Commands.literal("delhome")
.requires(source -> source.getPlayer() != null)
.then(argument("name", StringArgumentType.string())
.suggests(new HomeSuggestionProvider())
@@ -102,7 +104,7 @@ public class home {
return 0;
})));
- commandManager.getDispatcher().register(Commands.literal("renamehome")
+ commandDispatcher.register(Commands.literal("renamehome")
.requires(source -> source.getPlayer() != null)
.then(argument("name", StringArgumentType.string())
.suggests(new HomeSuggestionProvider())
@@ -125,7 +127,7 @@ public class home {
}))));
- commandManager.getDispatcher().register(Commands.literal("defaulthome")
+ commandDispatcher.register(Commands.literal("defaulthome")
.requires(source -> source.getPlayer() != null)
.then(argument("name", StringArgumentType.string()).suggests(new HomeSuggestionProvider())
.executes(context -> {
@@ -143,7 +145,7 @@ public class home {
return 0;
})));
- commandManager.getDispatcher().register(Commands.literal("homes")
+ commandDispatcher.register(Commands.literal("homes")
.requires(source -> source.getPlayer() != null)
.executes(context -> {
final ServerPlayer player = context.getSource().getPlayerOrException();
diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/tpa.java b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/tpa.java
index 2ebe16a..f35ff4d 100644
--- a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/tpa.java
+++ b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/tpa.java
@@ -2,10 +2,12 @@ package dev.mrsnowy.teleport_commands.commands;
import java.util.*;
+import com.mojang.brigadier.CommandDispatcher;
import dev.mrsnowy.teleport_commands.Constants;
import dev.mrsnowy.teleport_commands.suggestions.tpaSuggestionProvider;
import net.minecraft.ChatFormatting;
+import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.core.BlockPos;
@@ -33,9 +35,9 @@ public class tpa {
}
}
- public static void register(Commands commandManager) {
+ public static void register(CommandDispatcher commandDispatcher) {
- commandManager.getDispatcher().register(Commands.literal("tpa")
+ commandDispatcher.register(Commands.literal("tpa")
.requires(source -> source.getPlayer() != null)
.then(Commands.argument("player", EntityArgument.player())
.executes(context -> {
@@ -54,7 +56,7 @@ public class tpa {
return 0;
})));
- commandManager.getDispatcher().register(Commands.literal("tpahere")
+ commandDispatcher.register(Commands.literal("tpahere")
.requires(source -> source.getPlayer() != null)
.then(Commands.argument("player", EntityArgument.player())
.executes(context -> {
@@ -71,7 +73,7 @@ public class tpa {
return 0;
})));
- commandManager.getDispatcher().register(Commands.literal("tpaaccept")
+ commandDispatcher.register(Commands.literal("tpaaccept")
.requires(source -> source.getPlayer() != null)
.then(Commands.argument("player", EntityArgument.player()).suggests(new tpaSuggestionProvider())
.executes(context -> {
@@ -89,7 +91,7 @@ public class tpa {
return 0;
})));
- commandManager.getDispatcher().register(Commands.literal("tpadeny")
+ commandDispatcher.register(Commands.literal("tpadeny")
.requires(source -> source.getPlayer() != null)
.then(Commands.argument("player", EntityArgument.player()).suggests(new tpaSuggestionProvider())
.executes(context -> {
diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/warp.java b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/warp.java
index e5b85e1..9789be8 100644
--- a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/warp.java
+++ b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/warp.java
@@ -1,11 +1,13 @@
package dev.mrsnowy.teleport_commands.commands;
+import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.mrsnowy.teleport_commands.Constants;
import dev.mrsnowy.teleport_commands.common.NamedLocation;
import dev.mrsnowy.teleport_commands.suggestions.WarpSuggestionProvider;
import dev.mrsnowy.teleport_commands.utils.tools;
import net.minecraft.ChatFormatting;
+import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.ClickEvent;
@@ -25,9 +27,9 @@ import static dev.mrsnowy.teleport_commands.utils.tools.getTranslatedText;
import static net.minecraft.commands.Commands.argument;
public class warp {
- public static void register(Commands commandManager) {
+ public static void register(CommandDispatcher commandDispatcher) {
- commandManager.getDispatcher().register(Commands.literal("setwarp")
+ commandDispatcher.register(Commands.literal("setwarp")
.requires(source ->
source.getPlayer() != null &&
source.hasPermission(4)
@@ -48,7 +50,7 @@ public class warp {
return 0;
})));
- commandManager.getDispatcher().register(Commands.literal("warp")
+ commandDispatcher.register(Commands.literal("warp")
.requires(source -> source.getPlayer() != null)
.then(argument("name", StringArgumentType.string())
.suggests(new WarpSuggestionProvider())
@@ -67,7 +69,7 @@ public class warp {
return 0;
})));
- commandManager.getDispatcher().register(Commands.literal("delwarp")
+ commandDispatcher.register(Commands.literal("delwarp")
.requires(source ->
source.getPlayer() != null &&
source.hasPermission(4)
@@ -88,7 +90,7 @@ public class warp {
return 0;
})));
- commandManager.getDispatcher().register(Commands.literal("renamewarp")
+ commandDispatcher.register(Commands.literal("renamewarp")
.requires(source ->
source.getPlayer() != null &&
source.hasPermission(4)
@@ -111,7 +113,7 @@ public class warp {
return 0;
}))));
- commandManager.getDispatcher().register(Commands.literal("warps")
+ commandDispatcher.register(Commands.literal("warps")
.requires(source -> source.getPlayer() != null)
.executes(context -> {
final ServerPlayer player = context.getSource().getPlayerOrException();
diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/worldspawn.java b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/worldspawn.java
index 0bc6df1..7e5577a 100644
--- a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/worldspawn.java
+++ b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/worldspawn.java
@@ -1,9 +1,11 @@
package dev.mrsnowy.teleport_commands.commands;
+import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import dev.mrsnowy.teleport_commands.Constants;
import dev.mrsnowy.teleport_commands.TeleportCommands;
import net.minecraft.ChatFormatting;
+import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.ClickEvent;
@@ -22,8 +24,8 @@ import static net.minecraft.world.level.Level.OVERWORLD;
public class worldspawn {
- public static void register(Commands commandManager) {
- commandManager.getDispatcher().register(Commands.literal("worldspawn")
+ public static void register(CommandDispatcher commandDispatcher) {
+ commandDispatcher.register(Commands.literal("worldspawn")
.requires(source -> source.getPlayer() != null)
.executes(context -> {
final ServerPlayer player = context.getSource().getPlayerOrException();
diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/mixin/CommandsMixin.java b/common/src/main/java/dev/mrsnowy/teleport_commands/mixin/CommandsMixin.java
new file mode 100644
index 0000000..27cac69
--- /dev/null
+++ b/common/src/main/java/dev/mrsnowy/teleport_commands/mixin/CommandsMixin.java
@@ -0,0 +1,25 @@
+package dev.mrsnowy.teleport_commands.mixin;
+
+import com.mojang.brigadier.CommandDispatcher;
+import dev.mrsnowy.teleport_commands.TeleportCommands;
+import dev.mrsnowy.teleport_commands.commands.*;
+import net.minecraft.commands.CommandBuildContext;
+import net.minecraft.commands.CommandSourceStack;
+import net.minecraft.commands.Commands;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+@Mixin(Commands.class)
+public class CommandsMixin {
+
+ @Inject(method = "", at = @At("RETURN"))
+ private void RegisterTeleportCommands(Commands.CommandSelection selection, CommandBuildContext context, CallbackInfo info) {
+
+ Commands self = (Commands) (Object) this;
+ CommandDispatcher dispatcher = self.getDispatcher();
+
+ TeleportCommands.registerCommands(dispatcher);
+ }
+}
\ No newline at end of file
diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/mixin/PlayerDeathMixin.java b/common/src/main/java/dev/mrsnowy/teleport_commands/mixin/PlayerDeathMixin.java
index a76a7e6..06c0200 100644
--- a/common/src/main/java/dev/mrsnowy/teleport_commands/mixin/PlayerDeathMixin.java
+++ b/common/src/main/java/dev/mrsnowy/teleport_commands/mixin/PlayerDeathMixin.java
@@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public class PlayerDeathMixin {
@Inject(method = "die", at = @At("HEAD"))
- private void notifyDeath(CallbackInfo ci) {
+ private void notifyDeath(CallbackInfo info) {
TeleportCommands.onPlayerDeath((ServerPlayer) (Object) this);
}
diff --git a/common/src/main/resources/teleport_commands.mixins.json b/common/src/main/resources/teleport_commands.mixins.json
index 73ef6b3..6a35adf 100644
--- a/common/src/main/resources/teleport_commands.mixins.json
+++ b/common/src/main/resources/teleport_commands.mixins.json
@@ -6,7 +6,8 @@
"compatibilityLevel": "JAVA_${java_version}",
"mixins": [
"ServerStartMixin",
- "PlayerDeathMixin"
+ "PlayerDeathMixin",
+ "CommandsMixin"
],
"client": [],
"server": [],
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..c4feea0
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,27 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1756125398,
+ "narHash": "sha256-XexyKZpf46cMiO5Vbj+dWSAXOnr285GHsMch8FBoHbc=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "3b9f00d7a7bf68acd4c4abb9d43695afb04e03a5",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..3900ed0
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,74 @@
+{
+ description = "Flake for developing snowstorm!";
+
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+ };
+
+ outputs =
+ {
+ nixpkgs,
+ ...
+ }:
+ let
+ system = "x86_64-linux";
+ pkgs = import nixpkgs {
+ inherit system;
+ };
+ project = "TeleportCommands";
+ in
+ {
+ devShells."${system}" = {
+ default = pkgs.mkShell {
+ packages = with pkgs; [
+ jetbrains.jdk-no-jcef # Jetbrains jdk
+ flite # Make mc not complain
+
+ # Took these from https://github.com/NixOS/nixpkgs/blob/nixos-25.05/pkgs/by-name/pr/prismlauncher/package.nix#L123
+ # Thanks nixos packagers <3!
+ xorg.xrandr
+
+ glfw3-minecraft
+ openal
+
+ alsa-lib
+ libjack2
+ libpulseaudio
+ pipewire
+
+ libGL
+ libx11
+ xorg.libXcursor
+ xorg.libXext
+ xorg.libXrandr
+ xorg.libXxf86vm
+ ];
+
+ LD_LIBRARY_PATH =
+ with pkgs;
+ lib.makeLibraryPath [
+ flite # Make mc not complain
+
+ glfw3-minecraft
+ openal
+
+ alsa-lib
+ libjack2
+ libpulseaudio
+ pipewire
+
+ libGL
+ libx11
+ xorg.libXcursor
+ xorg.libXext
+ xorg.libXrandr
+ xorg.libXxf86vm
+ ];
+
+ shellHook = ''
+ echo -e "\n\x1b[36;1m📦 Welcome to the default flake for \x1b[32;1m${project}\x1b[0m\x1b[36m!\x1b[0m"
+ '';
+ };
+ };
+ };
+}
diff --git a/gradle.properties b/gradle.properties
index d08484c..2ba43c3 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -2,7 +2,7 @@
# Every field you add must be added to the root build.gradle expandProps map.
# Project
-version=1.3.2
+version=1.3.3
group=dev.mrsnowy.teleport_commands
java_version=21
diff --git a/justfile b/justfile
new file mode 100644
index 0000000..f7e92ce
--- /dev/null
+++ b/justfile
@@ -0,0 +1,3 @@
+
+ide:
+ idea-ultimate ./