Jump to content

[1.7.10] How to include and reference text file?


Recommended Posts

Posted

Hi,

 

I'd like to include a plain text file in my forge mod.  I'm guessing it goes somewhere in the assets folder, but I do not know where to place it or how to find it once the mod is running.

 

Any pointers?

 

Thanks!

Posted

I'm a little out of my water, being new to Forge Mod development.  I'd like for each user to have their own config file, which if it doesn't exist, I want to copy it out of the mod and into the user's config file space.  It's a non-standard config file, so I can't use the easier read/write config file methods. ... Dumb question, where can I find more info on MyMod.class.getResourceAsStream in the forge javadocs?  What class does that belong to? ... Thanks!

Posted
Class.class.getResourceAsStream

isn't related to Forge anyway. It's plain Java, so look up on that.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Here's a class I use to unpack some custom COG files, which is based off how COG unpacks its config files (COG is also open source).

 

package com.draco18s.hardlib;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import cpw.mods.fml.common.Loader;

public class CogConfig {
private static List<String> extraModules = new ArrayList<String>();

public static void addCogModule(String name) {
	extraModules.add(name);
}

public static void unpackConfigs() {
	File configPath = getConfigDir();
        	
        	File defaultModulesDir = new File(modulesDir, "custom"); //TODO change this if you don't need a sub-folder or want a different name
        	if (!defaultModulesDir.exists()) {
        		defaultModulesDir.mkdir();
        	}
        
        	for (String module : extraModules) {
        		File writeFile = new File(defaultModulesDir, module);
        		if(!writeFile.exists()) {
        			unpackConfigFile(module, writeFile);
        		}
        	}
}

private static boolean unpackConfigFile(String configName, File destination) {
    	String resourceName = "cog_config/" + configName; //TODO: change this to point to your resource location, which is inside "src/main/resources", eg. this currently points to "src/main/resources/cog_config"
        try {
    	    InputStream ex = HardLib.class.getClassLoader().getResourceAsStream(resourceName);
            BufferedOutputStream streamOut = new BufferedOutputStream(new FileOutputStream(destination));
            byte[] buffer = new byte[1024];
            boolean len = false;
            int len1;

            while ((len1 = ex.read(buffer)) >= 0)
            {
                streamOut.write(buffer, 0, len1);
            }

            ex.close();
            streamOut.close();
            return true;
        }
        catch (Exception var6) {
            throw new RuntimeException("Failed to unpack resource \'" + resourceName + "\'", var6);
        }
    }

private static File getConfigDir() {
    		return new File(Loader.instance().getConfigDir(), "CustomOreGen");//TODO: change this to point to you desired config location
    	}
}

 

It's flexible enough that you should be able to alter it to handle whatever file or files you want.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Ouch at that manual copying :P Why do people always reinvent the wheel?

 

Likely because we don't know the wheel exists. :D

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello , when I try to launch the forge installer it just crash with a message for 0,5 secondes. I'm using java 17 to launch it. Here's the link of the error :https://cdn.corenexis.com/view/?img=d/ma24/qs7u4U.jpg  
    • You will find the crash-report or log in your minecraft directory (crash-report or logs folder)
    • Use a modpack which is using these 2 mods as working base:   https://www.curseforge.com/minecraft/modpacks/life-in-the-village-3
    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona. es la version 1.18.2
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
  • Topics

×
×
  • Create New...

Important Information

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