Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Ahinnsu

Members
  • Joined

  • Last visited

  1. Ahinnsu joined the community
  2. So i have a 1.20.4 mod that saves data and loads it using commands. but the problem is that its not saving separately for each world. so i was looking through the docs and stumbled upon (SD) but the docs arent really helpful. heres my script to save data package com.example.coordinatesmod.commands; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.storage.LevelResource; import java.io.*; import java.util.HashMap; import java.util.Map; public class SaveCoordsCommand { private static final Map<String, String> namedCoordinates = new HashMap<>(); private static File saveFile; public static void register(CommandDispatcher<CommandSourceStack> dispatcher) { dispatcher.register(Commands.literal("savecoords") .then(Commands.argument("name", StringArgumentType.string()) .executes(context -> { ServerPlayer player = context.getSource().getPlayerOrException(); String name = StringArgumentType.getString(context, "name"); String coords = String.format("X: %.1f Y: %.1f Z: %.1f", player.getX(), player.getY(), player.getZ()); namedCoordinates.put(name, coords); saveFile = getSaveFile(context.getSource().getServer()); saveCoordinatesToFile(); player.sendSystemMessage(Component.literal("Coordinates saved: " + name + " " + coords)); return 1; })) ); loadCoordinatesFromFile(); } public static Map<String, String> getNamedCoordinates() { return namedCoordinates; } private static void saveCoordinatesToFile() { try (PrintWriter writer = new PrintWriter(new FileWriter(saveFile))) { for (Map.Entry<String, String> entry : namedCoordinates.entrySet()) { writer.println(entry.getKey() + ":" + entry.getValue()); } } catch (IOException e) { e.printStackTrace(); } } private static void loadCoordinatesFromFile() { if (saveFile == null || !saveFile.exists()) { return; } try (BufferedReader reader = new BufferedReader(new FileReader(saveFile))) { String line; while ((line = reader.readLine()) != null) { String[] parts = line.split(":", 2); if (parts.length == 2) { namedCoordinates.put(parts[0], parts[1]); } } } catch (IOException e) { e.printStackTrace(); } } public static void clearCoordinates() { namedCoordinates.clear(); saveCoordinatesToFile(); } private static File getSaveFile(MinecraftServer server) { File worldDirectory = server.getWorldPath(LevelResource.ROOT).toFile(); return new File(worldDirectory, "coordinates.txt"); } }

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.