Jump to content

1.7.10 Configuration Tutorial [SOLVED]


Eractnod

Recommended Posts

I am looking for some tutorials on how to setup a config file.  In particular, I need a config file where a user will enter blocks that should not be used to make an elevator shaft.  Config would be like minecraft:gold_block; minecraft:diamond_block; modid:mod_block.  These values would then be compared to a slot itemstack and if match, set isItemValid(ItemStack stack) to false.

My config file at present looks like this, with the console output added.

# Configuration file

general {
    S:disallowedblocks=minecraft:gold_block;minecraft:iron_block;minecraft:emerald_block;minecraft:redstone_block

}
minecraft:gold_block
minecraft:iron_block
minecraft:emerald_block
minecraft:redstone_block

To read the file in, I have

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

 	Config.load();
 		String bandBlocks = Config.get(Configuration.CATEGORY_GENERAL,"disallowBlocks", "").getString();
 		EVarInit.bandBlocksArray = bandBlocks.split(";");

 		for(int i = 0; i < EVarInit.bandBlocksArray.length; i++){
 			System.out.println(EVarInit.bandBlocksArray[i]);
 		}

 		if (Config.hasChanged()){
 			Config.save();
 		}

 

Where I am running into a problem is comparing the string EVarInit.bandBlockArray with an ItemStack.

 

EDIT: Solution

No changes made to the config portion.  Here is the code in the isItemValid method

 @Override
    public boolean isItemValid(ItemStack itemStack)
    {
    	if (itemStack.getItem() instanceof ItemBlock){
    		if (itemStack != null){
    			String str = Item.itemRegistry.getNameForObject(itemStack.getItem());
    			if(itemStack.getHasSubtypes()) str = str + " " + itemStack.getItemDamage();
    			if(itemStack.hasTagCompound()){
    				str = str + " " + itemStack.stackTagCompound.toString();
    			}
    			for(int ii = 0; ii < EVarInit.bandBlocksArray.length; ii++){ 
    				if (str.equals(EVarInit.bandBlocksArray[ii])){
    					return false;
    				}
    			}
    	
    			//Hardcode in the removal of diamond block and diamond ore
    			if (itemStack.getItem() == new ItemStack(Blocks.diamond_block).getItem() || itemStack.getItem() == new ItemStack(Blocks.diamond_ore).getItem()){

        		return false;
        	}
    		return true;
    		}
    	}
    	return false;
    }

 

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.