Jump to content

[1.8] [RESOLVED] Changing tool and armor material parameters with config file


xJon

Recommended Posts

Hi,

 

I want to change the parameters of the tool and armor materials with a boolean configuration file that I have setup, but unfortunately my method doesn't really work.

Here's the relevant part of the code:

	public static int harvestLevel, maxUses, enchantability, armorHelm, armorChest, armorLeg, armorBoot;
public static float efficiency, damage;

public static void checks()
{	
	if(!UselessConfiguration.isUseless)
	{
		harvestLevel = 10;
		maxUses = 1000;
		enchantability = 100;
		efficiency = 10.0F;
		damage = 10.0F;

		armorHelm = 4;
		armorChest = 14;
		armorLeg = 10;
		armorBoot = 6;
	}
	else
	{
		harvestLevel = 0;
		maxUses = 11;
		enchantability = 1;
		efficiency = 0.5F;
		damage = 0.5F;

		armorHelm = 1;
		armorChest = 2;
		armorLeg = 2;
		armorBoot = 1;
	}
}

public static final Item.ToolMaterial uselessToolMaterial = EnumHelper.addToolMaterial("uselessToolMaterial", harvestLevel, maxUses, efficiency, damage, enchantability);
public static final ItemArmor.ArmorMaterial uselessArmorMaterial = EnumHelper.addArmorMaterial("uselessArmorMaterial", "useless_armor", maxUses, new int []{armorHelm,armorChest,armorLeg,armorBoot}, enchantability);

 

I tried calling checks() on preInit and on init but it refuses to work. Both tool and armor material are loading with null parameters. Don't know what am I doing wrong!

 

Any help appreciated, thanks! :)

Why are you reading this?

Link to comment
Share on other sites

That code doesn't really seem that relevant.

 

Where is the config file setup?  Assuming that is UselessConfigration, but without seeing it, no way to know what is going on.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

That code doesn't really seem that relevant.

 

Where is the config file setup?  Assuming that is UselessConfigration, but without seeing it, no way to know what is going on.

Basically the configuration is a boolean and it works good (I checked it on other things) so I don't think it has anything to do with the problem. The problem is loading the custom parameters into the tool and armor material, without them being null. :)

You are creating the materials in <clinit> (= when the class is loaded). Anything you do after that will of course not affect them.

So do I need to load checks() before I load the Items? How can I do that? wouldn't putting checks() in preInit and Tools in init problematic?

 

Thanks for all the quick replies :)

Why are you reading this?

Link to comment
Share on other sites

No, there is nothing wrong with creating materials in either preInit or init.

Okay, I tried loading checks() in preInit and Items.init & Items.register in init, yet it didn't work.  :'(

Again, tool and armor material are been loaded with null parameters.

Worth to note that all the configuration things that need to be loaded are been loaded in preInit.

Why are you reading this?

Link to comment
Share on other sites

You need to create the materials before the items as dies said. 

 

What it seems like you said before is that you have the code to register your items and materials inside your Item Class.  Show how you are doing that.

 

You should be making a call to register your material, then a call to register each item using that material.  Your description does not seem to match that.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

You need to create the materials before the items as dies said. 

 

What it seems like you said before is that you have the code to register your items and materials inside your Item Class.  Show how you are doing that.

 

You should be making a call to register your material, then a call to register each item using that material.  Your description does not seem to match that.

Here is the full Items class inside of my init package:

public class UselessItems {

public static Item useless_material;

public static Item useless_sword;
public static Item useless_shovel;
public static Item useless_pickaxe;
public static Item useless_axe;
public static Item useless_hoe;
public static Item useless_multitool;

public static Item useless_bro;
public static Item useless_food;

public static Item useless_helmet;
public static Item useless_chestplate;
public static Item useless_leggings;
public static Item useless_boots;

public static Item useless_bow;
public static Item useless_arrow;

public static int harvestLevel, maxUses, enchantability, armorHelm, armorChest, armorLeg, armorBoot;
public static float efficiency, damage;

public static void checks()
{	
	if(!UselessConfiguration.isUseless)
	{
		harvestLevel = 10;
		maxUses = 1000;
		enchantability = 100;
		efficiency = 10.0F;
		damage = 10.0F;

		armorHelm = 4;
		armorChest = 14;
		armorLeg = 10;
		armorBoot = 6;
	}
	else
	{
		harvestLevel = 0;
		maxUses = 11;
		enchantability = 1;
		efficiency = 0.5F;
		damage = 0.5F;

		armorHelm = 1;
		armorChest = 2;
		armorLeg = 2;
		armorBoot = 1;
	}
}

public static final Item.ToolMaterial uselessToolMaterial = EnumHelper.addToolMaterial("uselessToolMaterial", harvestLevel, maxUses, efficiency, damage, enchantability);
public static final ItemArmor.ArmorMaterial uselessArmorMaterial = EnumHelper.addArmorMaterial("uselessArmorMaterial", "useless_armor", maxUses, new int []{armorHelm,armorChest,armorLeg,armorBoot}, enchantability);

public static void init()
{
	useless_material = new Item().setUnlocalizedName("useless_material").setCreativeTab(JumCore.tabJUM);
	useless_sword = new ItemUselessSword(uselessToolMaterial).setUnlocalizedName("useless_sword").setCreativeTab(JumCore.tabJUM);
	useless_shovel = new ItemUselessShovel(uselessToolMaterial).setUnlocalizedName("useless_shovel").setCreativeTab(JumCore.tabJUM);
	useless_axe = new ItemUselessAxe(uselessToolMaterial).setUnlocalizedName("useless_axe").setCreativeTab(JumCore.tabJUM);
	useless_hoe = new ItemUselessHoe(uselessToolMaterial).setUnlocalizedName("useless_hoe").setCreativeTab(JumCore.tabJUM);
	useless_bro = new ItemUselessBro().setUnlocalizedName("useless_bro").setCreativeTab(JumCore.tabJUM);
	useless_pickaxe = new ItemUselessPickaxe(uselessToolMaterial).setUnlocalizedName("useless_pickaxe").setCreativeTab(JumCore.tabJUM);
	useless_food = new ItemFood(8, 2.0F, true).setUnlocalizedName("useless_food").setCreativeTab(JumCore.tabJUM);
	useless_helmet = new ItemUselessArmor(uselessArmorMaterial, 0, 0).setUnlocalizedName("useless_helmet").setCreativeTab(JumCore.tabJUM);
	useless_chestplate = new ItemUselessArmor(uselessArmorMaterial, 0, 1).setUnlocalizedName("useless_chestplate").setCreativeTab(JumCore.tabJUM);
	useless_leggings = new ItemUselessArmor(uselessArmorMaterial, 0, 2).setUnlocalizedName("useless_leggings").setCreativeTab(JumCore.tabJUM);
	useless_boots = new ItemUselessArmor(uselessArmorMaterial, 0, 3).setUnlocalizedName("useless_boots").setCreativeTab(JumCore.tabJUM);
	useless_multitool = new ItemUselessMultitool(uselessToolMaterial).setUnlocalizedName("useless_multitool").setCreativeTab(JumCore.tabJUM);
	useless_bow = new ItemUselessBow().setUnlocalizedName("useless_bow").setCreativeTab(JumCore.tabJUM);
	useless_arrow = new Item().setUnlocalizedName("useless_arrow").setCreativeTab(JumCore.tabJUM);
}

public static void register()
{
	GameRegistry.registerItem(useless_sword, useless_sword.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_material, useless_material.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_axe, useless_axe.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_shovel, useless_shovel.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_hoe, useless_hoe.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_bro, useless_bro.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_pickaxe, useless_pickaxe.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_food, useless_food.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_helmet, useless_helmet.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_chestplate, useless_chestplate.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_leggings, useless_leggings.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_boots, useless_boots.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_multitool, useless_multitool.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_bow, useless_bow.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(useless_arrow, useless_arrow.getUnlocalizedName().substring(5));
}

public static void registerRenders()
{
	registerRender(useless_sword);
	registerRender(useless_material);
	registerRender(useless_shovel);
	registerRender(useless_axe);
	registerRender(useless_hoe);
	registerRender(useless_bro);
	registerRender(useless_pickaxe);
	registerRender(useless_food);
	registerRender(useless_helmet);
	registerRender(useless_chestplate);
	registerRender(useless_leggings);
	registerRender(useless_boots);
	registerRender(useless_multitool);
	registerRender(useless_bow);
	registerRender(useless_arrow);
}

public static void registerRender(Item item)
{
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}
}

 

And here's the relevant part of the intialization:

	@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	config = new Configuration(event.getSuggestedConfigurationFile());
	UselessConfiguration.syncConfig();
	UselessItems.checks();
	UselessItems.init();
	UselessItems.register();
	UselessBlocks.init();
	UselessBlocks.register();
	UselessAchievements.loadAchievements();
	UselessAchievements.registerPage();
	FMLCommonHandler.instance().bus().register(new PlayerEvents());
}

@EventHandler
public void Init(FMLInitializationEvent event)
{
	proxy.registerRenders();
	UselessRecipes.register();
	UselessTileEntities.register();
	GameRegistry.registerWorldGenerator(new UselessGeneration(), 0);
	FMLCommonHandler.instance().bus().register(instance);
}

 

Thanks and sorry if I'm stupid as hell :P

Why are you reading this?

Link to comment
Share on other sites

I get a little fuzzy at times around the usage of final and static, but from what I see.  your list of material parameters will always be null the way you did that.

 

 

 

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

I get a little fuzzy at times around the usage of final and static, but from what I see.  your list of material parameters will always be null the way you did that.

So what I can do to fix the issue?

Why are you reading this?

Link to comment
Share on other sites

 

 

 

public static Item.ToolMaterial uselessToolMaterial;

public static ItemArmor.ArmorMaterial uselessArmorMaterial;

 

public static void init()

{

 

uselessToolMaterial = EnumHelper.addToolMaterial("uselessToolMaterial", harvestLevel, maxUses, efficiency, damage, enchantability);

uselessArmorMaterial = EnumHelper.addArmorMaterial("uselessArmorMaterial", "useless_armor", maxUses, new int []{armorHelm,armorChest,armorLeg,armorBoot}, enchantability);

 

 

useless_material = new Item().setUnlocalizedName("useless_material").setCreativeTab(JumCore.tabJUM);

 

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

 

 

 

public static Item.ToolMaterial uselessToolMaterial;

public static ItemArmor.ArmorMaterial uselessArmorMaterial;

 

public static void init()

{

 

uselessToolMaterial = EnumHelper.addToolMaterial("uselessToolMaterial", harvestLevel, maxUses, efficiency, damage, enchantability);

uselessArmorMaterial = EnumHelper.addArmorMaterial("uselessArmorMaterial", "useless_armor", maxUses, new int []{armorHelm,armorChest,armorLeg,armorBoot}, enchantability);

 

 

useless_material = new Item().setUnlocalizedName("useless_material").setCreativeTab(JumCore.tabJUM);

 

 

 

I understood my problem and your method is working perfectly.

Thanks! :D

Why are you reading this?

Link to comment
Share on other sites

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.