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.

Featured Replies

Posted

I may just be going about this all wrong, but I am trying to get a reference to the name of the world so that I can write a text file that loads with each world. I can get the coordinates.txt file to appear in the directory above the 'saves' folder, but I need it to be different for each world. Each new map I make loads the same coordinates file created from the last world. Here is the java file im using the code in.

 

package com.exline.dbzmod;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

import com.exline.dbzmod.block.ModWorldGen;
import com.exline.dbzmod.block.ModWorldGenAgain;

import net.minecraft.client.Minecraft;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerList;
import net.minecraft.world.World;
import net.minecraft.world.WorldSavedData;
import net.minecraft.world.WorldSavedDataCallableSave;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.ModClassLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.server.FMLServerHandler;

//find nearest dragonball
//this just updates the radar coordinates when called
//called in DragonBallEventHandler when corresponding block is destroyed

public class FindNearest 
{
	public static int xto;
	public static int zto;
	
	public static void init() throws Exception
	{
		xto = ModWorldGen.x0;
		zto = ModWorldGen.z0;
		String dir;

		MinecraftServer mc = FMLCommonHandler.instance().getMinecraftServerInstance();
		if (mc != null)
		{
			dir = mc.getFolderName();
		}
		else
		{
			dir = null;
		}
		
		if (dir != null)
		{
			File varTmpDir = new File("/saves/"+dir+"/coordinates.txt");
			boolean exists = varTmpDir.exists();
		
			if(exists != true) 
			{
				saveCoordinates();
			}
			else
			{
				loadCoordinates();
			}
		}
	}
	
	public static void findOne() throws Exception
	{
		xto = ModWorldGen.x1;
		zto = ModWorldGen.z1;
		
		saveCoordinates();
	}
	
	public static void findTwo() throws Exception
	{
		xto = ModWorldGen.x2;
		zto = ModWorldGen.z2;
		
		saveCoordinates();
	}
	
	public static void findThree() throws Exception
	{
		xto = ModWorldGen.x3;
		zto = ModWorldGen.z3;
		
		saveCoordinates();
	}
	
	public static void findFour() throws Exception
	{
		xto = ModWorldGen.x4;
		zto = ModWorldGen.z4;
		
		saveCoordinates();
	}
	
	public static void findFive() throws Exception
	{
		xto = ModWorldGen.x5;
		zto = ModWorldGen.z5;
		
		saveCoordinates();
	}
	
	public static void findSix() throws Exception
	{
		xto = ModWorldGen.x6;
		zto = ModWorldGen.z6;
		
		saveCoordinates();
	}
	
	public static void findSeven() throws Exception
	{
		//this method resets the dragon balls positions and re-spawns them in the world
		
		ModWorldGen.x0 += 120;
		ModWorldGen.z0 += 120;
		
		ModWorldGen.x1 -= 120;
		ModWorldGen.z1 -= 120;
		
		ModWorldGen.x2 += 120;
		ModWorldGen.z2 -= 120;
		
		ModWorldGen.x3 -= 120;
		ModWorldGen.z3 += 120;
		
		ModWorldGen.x4 += 120;
		ModWorldGen.z4 -= 120;
		
		ModWorldGen.x5 -= 120;
		ModWorldGen.z5 += 120;
		
		ModWorldGen.x6 -= 300;
		ModWorldGen.z6 += 300;
		
		xto = ModWorldGen.x0;
		zto = ModWorldGen.z0;
		
		saveCoordinates();
		
		GameRegistry.registerWorldGenerator(new ModWorldGenAgain(), 1);
	}
	
	public static void saveCoordinates() throws Exception
	{
		String dir;
		
		MinecraftServer mc = FMLCommonHandler.instance().getMinecraftServerInstance();
		if (mc != null)
		{
			dir = mc.getFolderName();
		}
		else
		{
			dir = null;
		}
		
		if (dir != null)
		{
		
			FileWriter saveFile = new FileWriter("/saves/"+dir+"/coordinates.txt");
			//write data to file now!!!
			saveFile.write("\n");
			saveFile.write(xto + "\n");
			saveFile.write(zto + "\n");
			saveFile.write("\n");
			//close filewriter
			saveFile.close();
		}
	}
	public static void loadCoordinates() throws Exception
	{
		String dir;
		
		MinecraftServer mc = FMLCommonHandler.instance().getMinecraftServerInstance();
		if (mc != null)
		{
			dir = mc.getFolderName();
		}
		else
		{
			dir = null;
		}
		
		if (dir != null)
		{		
			BufferedReader saveFile = new BufferedReader(new FileReader("/saves/"+dir+"/coordinates.txt"));
			// Throw away the blank line at the top.
			saveFile.readLine(); 
			// Get the integer value from the String.
			xto = Integer.parseInt(saveFile.readLine()); 
			zto = Integer.parseInt(saveFile.readLine());
		    
			saveFile.close();
		}
	}
		
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

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.