Compare commits

2 Commits
pre ... main

Author SHA1 Message Date
3619df118b Refactor
All checks were successful
build / build (push) Successful in 3m43s
2026-03-16 21:02:06 +01:00
6e86c47bbb Better conf dir 2026-03-16 20:57:15 +01:00
2 changed files with 9 additions and 10 deletions

View File

@@ -26,7 +26,7 @@ public class Utils {
}); });
} }
private static double round1(double value) { public static double round1(double value) {
return Math.round(value * 10.0) / 10.0; return Math.round(value * 10.0) / 10.0;
} }
} }

View File

@@ -1,10 +1,12 @@
package ciomek.quetzal.commands; package ciomek.quetzal.commands;
import ciomek.quetzal.IWorldUtils; import ciomek.quetzal.IWorldUtils;
import ciomek.quetzal.Utils;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.ArgumentBuilderLiteral; import com.mojang.brigadier.builder.ArgumentBuilderLiteral;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.entity.player.Player; import net.minecraft.core.entity.player.Player;
import net.minecraft.core.net.command.CommandManager; import net.minecraft.core.net.command.CommandManager;
import net.minecraft.core.net.command.CommandSource; import net.minecraft.core.net.command.CommandSource;
@@ -22,7 +24,8 @@ import java.util.Map;
public class HomeCommand implements CommandManager.CommandRegistry, ModInitializer { public class HomeCommand implements CommandManager.CommandRegistry, ModInitializer {
private static final Map<String, double[]> homes = new HashMap<>(); private static final Map<String, double[]> homes = new HashMap<>();
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
private static final File homesFile = new File("homes.json"); private static final File homesFile =
new File(FabricLoader.getInstance().getConfigDir().toFile(), "homes.json");
@Override @Override
public void onInitialize() { public void onInitialize() {
@@ -90,14 +93,14 @@ public class HomeCommand implements CommandManager.CommandRegistry, ModInitializ
double[] home = homes.get(player.username); double[] home = homes.get(player.username);
double startX = round1(player.x); double startX = Utils.round1(player.x);
double startY = round1(player.y); double startY = Utils.round1(player.y);
double startZ = round1(player.z); double startZ = Utils.round1(player.z);
player.sendMessage("Teleporting home. Don't move for 5 seconds..."); player.sendMessage("Teleporting home. Don't move for 5 seconds...");
worldUtils.addTickCallback(100, (w) -> { worldUtils.addTickCallback(100, (w) -> {
if (round1(player.x) != startX || round1(player.y) != startY || round1(player.z) != startZ) { if (Utils.round1(player.x) != startX || Utils.round1(player.y) != startY || Utils.round1(player.z) != startZ) {
player.sendMessage("Teleport cancelled because you moved."); player.sendMessage("Teleport cancelled because you moved.");
return; return;
} }
@@ -110,8 +113,4 @@ public class HomeCommand implements CommandManager.CommandRegistry, ModInitializ
}) })
); );
} }
private double round1(double value) {
return Math.round(value * 10.0) / 10.0;
}
} }