Jump to content

Recommended Posts

Posted

Would it be possible to make an array of enumToolMaterials in the config file? If so than how. Also if that's not possible would there be a way to do it with the tools forge already gives you.  Or would I need to make my own config type file.

Posted

You do not need a enumTools material to make a tool.

 

 

 

you can make your own toolclass

 

like this:

 

public class TestTool extends Item

{

    float ToolSpeed;

    float minspeed;

 

    public Testool(int id, int uses, int speed, int speedmin)

    {

            super(id);

            setMaxDamage(uses);

            ToolSpeed = (float)speed;

            minspeed = (float)speedmin;

    }

 

    public float getStrVsBlock(ItemStack stack, Block block)

    {

        return minspeed;

    }

 

 

    public float getStrVsBlock(ItemStack stack, Block block, int meta)

    {

        if (ForgeHooks.isToolEffective(stack, block, meta))

        {

            return ToolSpeed;

        }

        return getStrVsBlock(stack, block);

    }

}

 

this is a way to add tools without enumtoolmaterial (at the moment i have no enchantmentsensitive version of it)

.

 

And the item have to look like this:

 

public static int miningSpeed = 10;

public static int minSpeed = 1;

public static int uses = 1000;

public static int toolstrenth = 3;

public static int id = 10000;

 

public static Item testTool = (new TestTool(id, uses, miningspeed, minspeed));

MinecraftForge.setToolClass(testTool, "pickaxe", toolstrenth);

 

 

and the integer you can make configs with it ^^ Hope it helps.

 

 

Posted

is this what you mean?

 

public static final EnumToolMaterial herpaDerpMaterials[] =
{
		EnumHelper.addToolMaterial("Herp", 3, 900, 15F, 3, 15),
		EnumHelper.addToolMaterial("Derp", 3, 9001, 15F, 3, 15)
};

 

this can go in your main class

Posted

is this what you mean?

 

public static final EnumToolMaterial herpaDerpMaterials[] =
{
		EnumHelper.addToolMaterial("Herp", 3, 900, 15F, 3, 15),
		EnumHelper.addToolMaterial("Derp", 3, 9001, 15F, 3, 15)
};

 

this can go in your main class

 

No he asked how can i make an enumtoolmaterial configabel. so that you can change the toolstrenth, speed and how long it holds.

Posted

I know how to make enumtoolmaterials, but I don't even use them I use my own enum file I made. What I want to do is make an array of all the enum materials and then the player can go enable and disable whatever he/she wants in the config.

 

Would I have to do this with XML, and if so could someone point me towards a good tutorial, I already found one that generates a config.txt and puts a string in it, I'm just haveing trouble turning the string into an array and calling it back.

Posted

hmm you could do what I do when an object needs to have multiple block ids

 

save the necessary values as a string

 

so for instance

"Herp, 3, 900, 15, 3, 15"

then just do a string.split(,)

then with the split string

  EnumHelper.addToolMaterial(string[0], string[1], string[2], string[3], string[4], string[5])

 

obviously you need to convert the strings to int/floats before parsing

 

and if you wanted to load infinite possibilies just do the same but use another delimiter for seperating the tool mats

"Herp, 3, 900, 15, 3, 15; Derp, 5, 1463, 3, 15"

string.split(;)

then you need to loop over the split string and then string.split(1) and do what i said above

 

is this what you wanted?

Posted

Yes and no. No that isn't what I needed but yes I could totally use it, and it isn't really that far from what I need anyway  ;D. I need an array of all the tool material names, like array = {HERP, DERP}. It shouldn't be too hard though to change your code into something that will work for me.

 

However I don't know how to call the string from the config, I was reading the tutorial off the forge forum and it didn't go over that. I'll do some more research on it but for now I'm stuck.

 

Also in the minecraft forge configuration.java file I found this...

 

public Property get(String category, String key, String[] defaultValue)

    {

        return get(category, key, defaultValue, null);

    }

 

String[] being the important part here. Does this mean you could do an array of strings for the config or would it be more impractical and less user friendly than your method?

 

One last thing, how would I parse a string to a tool material? I know how to do numbers to strings but that's where my knowledge on the subject ends.

Posted

I think this is what you want

 

Configuration cfg = new Configuration(e.getSuggestedConfigurationFile());
	cfg.load();

String someInputThingy = cfg.get(Configuration.CATEGORY_GENERAL, "Material List", "Herp, Derp, HerpDerp, DerpHerp").getString();
	String[] toStringArray = someInputThingy.split(",");
	for(int i = 0; i < toStringArray.length; i++) System.out.println(toStringArray[i]);

Posted

I think this is what you want

 

Configuration cfg = new Configuration(e.getSuggestedConfigurationFile());
	cfg.load();

String someInputThingy = cfg.get(Configuration.CATEGORY_GENERAL, "Material List", "Herp, Derp, HerpDerp, DerpHerp").getString();
	String[] toStringArray = someInputThingy.split(",");
	for(int i = 0; i < toStringArray.length; i++) System.out.println(toStringArray[i]);

 

Yes that is exactly what I had, I'm just having trouble getting the stringArray to be read out of the preInit. For example putting the for line in the load section. I've tried making a variable for it but it doesn't see it, am I stuck with having all of my code in the preInit method?

 

Also I still don't know how to parse it, would something like this work?

for(int i = 0; i < toStringArray.length; i++) EnumToolMaterial x = EnumToolMaterial.valueOf(toStringArray);

Posted

 

 

public static String[] weaponMatsArray;

 

@PreInit

    public void preInit(FMLPreInitializationEvent event) {

Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());

  cfg.load();

 

String weaponMats = cfg.get(Configuration.CATEGORY_GENERAL, "Material List", "WOOD, STONE, IRON, DIAMOND, GOLD").getString();

  String[] weaponMatsArray = weaponMats.split(", ");

  for(int i = 0; i < weaponMatsArray.length; i++)

  {

  System.out.println(weaponMatsArray);

  }

 

  cfg.save();

    }

 

@Init

public void load(FMLInitializationEvent event)

{

 

System.out.println("The weapon mat at position 0 is: " + weaponMatsArray[0]);

        }

 

 

 

When I run it like this it gives me an npe although weaponMatsArray is defined in the preInit

Posted

 

 

public static String[] weaponMatsArray;

 

@PreInit

    public void preInit(FMLPreInitializationEvent event) {

Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());

  cfg.load();

 

String weaponMats = cfg.get(Configuration.CATEGORY_GENERAL, "Material List", "WOOD, STONE, IRON, DIAMOND, GOLD").getString();

  String[] weaponMatsArray = weaponMats.split(", ");

  for(int i = 0; i < weaponMatsArray.length; i++)

  {

  System.out.println(weaponMatsArray);

  }

 

  cfg.save();

    }

 

@Init

public void load(FMLInitializationEvent event)

{

 

System.out.println("The weapon mat at position 0 is: " + weaponMatsArray[0]);

        }

 

 

 

When I run it like this it gives me an npe although weaponMatsArray is defined in the preInit

there is a slight error in the code see striketrough above

Posted

Awesome, that works! Now, one last thing, I added some stuff to the for loop, what it should do now is add the enum material to the array in the EnumWeaponMaterial file (public static EnumWeaponMaterial[] weaponMats;) but instead it gives me another npe.

 

 

@PreInit

    public void preInit(FMLPreInitializationEvent event) {

Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());

  cfg.load();

 

String weaponMats = cfg.get(Configuration.CATEGORY_GENERAL, "Material List", "WOOD, STONE, IRON, DIAMOND, GOLD").getString();

  weaponMatsArray = weaponMats.split(", ");

  for(int ii = 0; ii < weaponMatsArray.length; ii++)

  {

  System.out.println(weaponMatsArray[ii]);

  weaponMatsEnum = EnumWeaponMaterial.valueOf(weaponMatsArray[ii]);

  System.out.println("WeaponMats Enum = " + weaponMatsEnum);

  EnumWeaponMaterial.weaponMats[ii]= weaponMatsEnum;

  }

 

  cfg.save();

    }

 

 

 

When I disable the last line minecraft starts but nothing has happened.

Posted

what is EnumWeaponMaterial

 

That was my own enumtoolmaterial file. Anyways I got it to work, I used this code for the config...

 

@PreInit

    public void preInit(FMLPreInitializationEvent event) {

Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());

  cfg.load();

 

String weaponMats = cfg.get(Configuration.CATEGORY_GENERAL, "Material List", "WOOD, STONE, IRON, DIAMOND, GOLD").getString();

  weaponMatsArray = weaponMats.split(", ");

  for(int ii = 0; ii < weaponMatsArray.length; ii++)

  {

  System.out.println("WeaponMat in pos" + ii + " = " + weaponMatsArray[ii]);

  EnumWeaponMaterial.weaponMats[ii] = EnumWeaponMaterial.valueOf(weaponMatsArray[ii]);

  }

 

  cfg.save();

    }

 

 

And this for the array in enumweaponmaterials...

 

public static EnumWeaponMaterial[] weaponMats = new EnumWeaponMaterial[TuxWeaponsCore.weaponMatsArray.length];

 

 

Thank you Jordan so much for you help I couldn't have done it without you  ;D

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



×
×
  • Create New...

Important Information

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