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 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;
    }

 

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.