Jump to content

[1.7.10] NPE on CreativeTab sorting using Comparators


nullcity

Recommended Posts

So I followed a tutorial displayed on here on how to organise a CreativeTab using Comparators and Item[] arrays.

The list is kept short and all for now, and I decided to run it just to get a glimpse on how the comparators will work out the list being displayed in the creative tab.

 

But I seem to be getting a NullPointerException...

I am guessing is because the custom creative tab file (NCTab.java) is trying to order items that have not been declared in the main class yet.

 

This is how mods main class works first before I show source code of both files.

1. Materials, CreativeTab, Blocks, and Items are initialised.

2. preInit(), custom code to check if mod is up to date and the CreativeTab gets some a parameter switched up [ ncTab.setNoScrollbar(); ]. Not going to have more stuff than what I already coded and I have a reasonable amount of space to disable the scroll bar. Then a world generator gets setup, fluid gets declared and registered (doesnt get registered later cause itll cause an NPE), Then blocks and items and tool get defined all in alphabetical order. (Blocks get ore defined first then their block). Next, GameRegistry registers the blocks, items, then tools. After that LanguageRegistry (I know I should not be using this anymore but I will replace it soon) adds the names for each block and item, then shapeless recipes are set up, then the shaped recipes, then the furnace recipes.

3. Init(), The events for buckets gets registered.

4. postInit(). outputs an "mod activated! message" showing the name and version, then a last check for update is done and logs one last time whether the mod is up to date or not.

 

Possible reasons for this NPE I think is either cause (going from most likely to least likely):

- All blocks and items should be declared in their proper class.

- I miscoded the Comparator when troubleshooting an error I got when following the text tutorial.

- The arrays are not setup properly as instead of using Array.asList(items...) I used Array.asList(new Item[]{items...}) as an alternative cause Array.asList(items...) gave a variable-type error.

 

Now here are the source files. Yes I am aware that I did squish in far too much code which is why I will now state that this mod is nowhere near even an 8th done. And yes I have been able to troubleshoot and fix every problem I have had (even with the fluid NPE) except for this one.

 

mod_NCElectromagnetism.java:

 

 

package mx.x10.nullcity.redstonemagnetism;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import scala.actors.threadpool.Arrays;

import com.google.common.base.Function;
import com.google.common.collect.Ordering;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStaticLiquid;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer.ItemRendererHelper;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;

import mx.x10.nullcity.ModUpdater;
import mx.x10.nullcity.redstonemagnetism.blocks.blockAluminium_ore;
import mx.x10.nullcity.redstonemagnetism.blocks.blockAluminium_pure;
import mx.x10.nullcity.redstonemagnetism.blocks.blockBrass_pure;
import mx.x10.nullcity.redstonemagnetism.blocks.blockChromite;
import mx.x10.nullcity.redstonemagnetism.blocks.blockChromium_pure;
import mx.x10.nullcity.redstonemagnetism.blocks.blockCobalt_ore;
import mx.x10.nullcity.redstonemagnetism.blocks.blockCobalt_pure;
import mx.x10.nullcity.redstonemagnetism.blocks.blockCopper_ore;
import mx.x10.nullcity.redstonemagnetism.blocks.blockIron_ferromagnetic;
import mx.x10.nullcity.redstonemagnetism.blocks.blockLiquido;
import mx.x10.nullcity.redstonemagnetism.blocks.blockLiquido_moviendo;
import mx.x10.nullcity.redstonemagnetism.blocks.blockMercury_fluid;
import mx.x10.nullcity.redstonemagnetism.blocks.blockNeodymium_ore;
import mx.x10.nullcity.redstonemagnetism.blocks.blockNeodymium_pure;
import mx.x10.nullcity.redstonemagnetism.blocks.blockNeodymium_tarnishing;
import mx.x10.nullcity.redstonemagnetism.blocks.blockNickel_ore;
import mx.x10.nullcity.redstonemagnetism.blocks.blockNickel_pure;
import mx.x10.nullcity.redstonemagnetism.blocks.blockPhosphorus_ore;
import mx.x10.nullcity.redstonemagnetism.blocks.blockTungsten_ore;
import mx.x10.nullcity.redstonemagnetism.blocks.blockTungsten_pure;
import mx.x10.nullcity.redstonemagnetism.blocks.blockZinc_ore;
import mx.x10.nullcity.redstonemagnetism.events.event_onBucketFill;
import mx.x10.nullcity.redstonemagnetism.generators.NCEOreGenerator;
import mx.x10.nullcity.redstonemagnetism.items.itemAluminium_bar;
import mx.x10.nullcity.redstonemagnetism.items.itemBucket_hg;
import mx.x10.nullcity.redstonemagnetism.items.itemBrass_bar;
import mx.x10.nullcity.redstonemagnetism.items.itemChromium_bar;
import mx.x10.nullcity.redstonemagnetism.items.itemCobalt_bar;
import mx.x10.nullcity.redstonemagnetism.items.itemCopper_bar;
import mx.x10.nullcity.redstonemagnetism.items.itemCuZnMix;
import mx.x10.nullcity.redstonemagnetism.items.itemMisc_chromitebits;
import mx.x10.nullcity.redstonemagnetism.items.itemMisc_pulidor;
import mx.x10.nullcity.redstonemagnetism.items.itemMisc_stonebits;
import mx.x10.nullcity.redstonemagnetism.items.itemNeodymium_bar;
import mx.x10.nullcity.redstonemagnetism.items.itemNickel_bar;
import mx.x10.nullcity.redstonemagnetism.items.itemTungsten_bar;
import mx.x10.nullcity.redstonemagnetism.items.itemZinc_bar;
import mx.x10.nullcity.redstonemagnetism.materials.materialCuZn;
import mx.x10.nullcity.redstonemagnetism.materials.materialHg;
import mx.x10.nullcity.redstonemagnetism.materials.materialP;
import mx.x10.nullcity.redstonemagnetism.materials.materialSpecialOre;
import mx.x10.nullcity.redstonemagnetism.tools.toolBrass_hoe;
import mx.x10.nullcity.redstonemagnetism.tools.toolBrass_pickaxe;
import mx.x10.nullcity.redstonemagnetism.tools.toolBrass_shovel;
import mx.x10.nullcity.redstonemagnetism.tools.toolBrass_sword;

@Mod(modid = mod_NCElectromagnetism.MODID, version = mod_NCElectromagnetism.VERSION)
public class mod_NCElectromagnetism
{
    public static final String MODID = "nc_redstonemagnetism";
    public static final String VERSION = "0.0.1_01a";
    
    protected static final ModUpdater mu	=	new ModUpdater();
    
    /* Generator Entities */
    public static IWorldGenerator NCEGenerator	=	new NCEOreGenerator();
    
    /* Materials */
    public static Material brass		=	new materialCuZn(MapColor.goldColor);
    public static Material mercury		=	new materialHg(MapColor.silverColor);
    public static Material phosphorus	=	new materialP(MapColor.redColor);
    public static Material specialOre	=	new materialSpecialOre(MapColor.stoneColor);
    
    /* mercury! */
    public static Fluid	fluid_hg;
    
    /* Blocks */
    public static Block blockAluminium_ore;
    public static Block blockAluminium_pure;
    public static Block blockBrass_pure;
    public static Block blockChromite;
    public static Block blockChromium_pure;
    public static Block	blockCobalt_ore;
    public static Block blockCobalt_pure;
    public static Block blockCopper_ore;
    public static Block	blockIron_ferromagnetic;
    public static Block	blockMercury_fluid;
    public static Block	blockNeodymium_pure;
    public static Block blockNeodymium_tarnishing;
    public static Block blockNeodymium_ore;
    public static Block blockNickel_ore;
    public static Block blockNickel_pure;
    public static Block blockPhosphorus_ore;
    public static Block	blockPulido;
    public static Block blockPulido_moving;
    public static Block blockTungsten_ore;
    public static Block blockTungsten_pure;
    public static Block	blockZinc_ore;
    
    /* Block-items (ingot) */
    public static Item	itemAluminium_bar;
    public static Item	itemBrass_bar;
    public static Item	itemChromium_bar;
    public static Item 	itemCobalt_bar;
    public static Item	itemCopper_bar;
    public static Item	itemNeodymium_bar;
    public static Item	itemNickel_bar;
    public static Item	itemTungsten_bar;
    public static Item	itemZinc_bar;
    
    /* Tools */
    public static final Item.ToolMaterial BRASS_ = EnumHelper.addToolMaterial("BRASS", 3, 780, 6.0F, 2.5F, 0);
    public static Item	toolBrass_hoe;
    public static Item	toolBrass_pickaxe;
    public static Item	toolBrass_shovel;
    public static Item	toolBrass_sword;
    
    /* Miscellaneous Items */
    public static Item	itemCobblestone_chunk;
    public static Item	itemChromite_bit;
    public static Item	itemStackedCuZn;
    
    /* Miscellaneous Tools */
    public static Item	hgContainer;
    public static Item	itemMisc_pulidor;
    
    /*public static CreativeTabs ncTab	=	new CreativeTabs("Redstonemagnetism")
    {
    	public Item getTabIconItem()
    	{
    		this.setNoScrollbar();
    		return Item.getItemFromBlock(mod_NCElectromagnetism.blockNeodymium_ore);
    	}
    };*/
    
    public static CreativeTabs ncTab	=	new NCTab(CreativeTabs.getNextID(), "Redstonemagnetism");
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent e)
    {
    	/* check for updates */
    	if(mu.isUpdated()	!=	1)
    	{
    		System.out.println("[Electromagnetism]: Your version is out of date!");
    	}
    	
    	/* add property for creative tab */
    	ncTab.setNoScrollbar();
    	
    	/* register the generators */
    	GameRegistry.registerWorldGenerator(NCEGenerator, 1);
    	
    	/* register fluid */
    	fluid_hg							=	new Fluid("fluid_hg");
    	fluid_hg.setBlock(blockMercury_fluid);
    	fluid_hg.setDensity(13600);			// 13.6 kg/m^3
    	// fluid_hg.setDensity(4250);		// 4.25 kg/m^3
    	fluid_hg.setGaseous(false);
    	fluid_hg.setLuminosity(4);
    	fluid_hg.setTemperature(273);
    	fluid_hg.setUnlocalizedName("fluid_hg");
    	fluid_hg.setViscosity(0);
    	
       	FluidRegistry.registerFluid(fluid_hg);
    	
    	/* register blocks */
    	blockAluminium_ore				=	new blockAluminium_ore(Material.rock);
    	blockAluminium_ore.setBlockName("aluminiumOre");
    	blockAluminium_ore.setHardness(3F);
    	blockAluminium_ore.setCreativeTab(ncTab);
    	blockAluminium_ore.setHarvestLevel("pickaxe", 2);
    	blockAluminium_ore.setBlockTextureName("nc_redstonemagnetism:aluminium_ore");
    	
    	blockAluminium_pure				=	new blockAluminium_pure(Material.iron);
    	blockAluminium_pure.setBlockName("pureAluminium");
    	blockAluminium_pure.setHardness(6F);
    	blockAluminium_pure.setCreativeTab(ncTab);
    	blockAluminium_pure.setHarvestLevel("pickaxe", 2);
    	blockAluminium_pure.setBlockTextureName("nc_redstonemagnetism:aluminium_pure");
    	
    	blockBrass_pure					=	new blockBrass_pure(brass);
    	blockBrass_pure.setBlockName("pureBrass");
    	blockBrass_pure.setHardness(8F);
    	blockBrass_pure.setHarvestLevel("pickaxe", 2);
    	blockBrass_pure.setCreativeTab(ncTab);
    	blockBrass_pure.setBlockTextureName("nc_redstonemagnetism:brass_pure");
    	
    	blockChromite					=	new blockChromite(Material.rock);
    	blockChromite.setBlockName("chromite");
    	blockChromite.setHardness(5F);
    	blockChromite.setCreativeTab(ncTab);
    	blockChromite.setHarvestLevel("pickaxe", 2);
    	blockChromite.setBlockTextureName("nc_redstonemagnetism:chromite");
    	
    	blockChromium_pure				=	new blockChromium_pure(Material.iron);
    	blockChromium_pure.setBlockName("pureChromium");
    	blockChromium_pure.setHardness(7F);
    	blockChromium_pure.setCreativeTab(ncTab);
    	blockChromium_pure.setHarvestLevel("pickaxe", 2);
    	blockChromium_pure.setBlockTextureName("nc_redstonemagnetism:chromium_pure");
    	
    	blockCobalt_ore					=	new blockCobalt_ore(Material.rock);
    	blockCobalt_ore.setBlockName("cobaltOre");
    	blockCobalt_ore.setHardness(6F);
    	blockCobalt_ore.setCreativeTab(ncTab);
    	blockCobalt_ore.setHarvestLevel("pickaxe", 2);
    	blockCobalt_ore.setBlockTextureName("nc_redstonemagnetism:cobalt_ore");
    	
    	blockCobalt_pure				=	new blockCobalt_pure(Material.iron);
    	blockCobalt_pure.setBlockName("pureCobalt");
    	blockCobalt_pure.setHardness(4F);
    	blockCobalt_pure.setCreativeTab(ncTab);
    	blockCobalt_pure.setHarvestLevel("pickaxe", 2);
    	blockCobalt_pure.setBlockTextureName("nc_redstonemagnetism:cobalt_pure");
    	
    	blockCopper_ore					=	new blockCopper_ore(Material.rock);
    	blockCopper_ore.setBlockName("copperOre");
    	blockCopper_ore.setHardness(4.5F);
    	blockCopper_ore.setCreativeTab(ncTab);
    	blockCopper_ore.setHarvestLevel("pickaxe", 2);
    	blockCopper_ore.setBlockTextureName("nc_redstonemagnetism:copper_ore");
    	
    	blockIron_ferromagnetic			=	new blockIron_ferromagnetic(Material.iron);
    	blockIron_ferromagnetic.setBlockName("ferroIron");
    	blockIron_ferromagnetic.setHardness(6F);
    	blockIron_ferromagnetic.setCreativeTab(ncTab);
    	blockIron_ferromagnetic.setHarvestLevel("pickaxe", 1);
    	blockIron_ferromagnetic.setBlockTextureName("minecraft:iron_block");
    	
    	blockMercury_fluid				=	new blockMercury_fluid(fluid_hg, this.mercury);
    	blockMercury_fluid.setBlockName("hgMercury");
    	blockMercury_fluid.setCreativeTab(ncTab);
    	
    	blockNeodymium_pure				=	new blockNeodymium_pure(Material.iron);
    	blockNeodymium_pure.setBlockName("pureNeodymium");
    	blockNeodymium_pure.setHardness(12F);
    	blockNeodymium_pure.setCreativeTab(ncTab);
    	blockNeodymium_pure.setHarvestLevel("pickaxe", 2);
    	blockNeodymium_pure.setBlockTextureName("nc_redstonemagnetism:neodymium_pure");
    	
    	blockNeodymium_tarnishing		=	new blockNeodymium_tarnishing(Material.iron);
    	blockNeodymium_tarnishing.setBlockName("tarnishedNeodymium");
    	blockNeodymium_tarnishing.setHardness(10.75F);
    	blockNeodymium_tarnishing.setLightLevel(0);
    	blockNeodymium_tarnishing.setCreativeTab(ncTab);
    	blockNeodymium_tarnishing.setHarvestLevel("pickaxe", 1);
    	blockNeodymium_tarnishing.setBlockTextureName("nc_redstonemagnetism:neodymium_pure");
    	
    	blockNeodymium_ore				=	new blockNeodymium_ore(Material.rock);
    	blockNeodymium_ore.setBlockName("neodymiumOre");
    	blockNeodymium_ore.setHardness(11.33F);
    	blockNeodymium_ore.setLightLevel(1);
    	blockNeodymium_ore.setCreativeTab(ncTab);
    	blockNeodymium_ore.setHarvestLevel("pickaxe", 2);
    	blockNeodymium_ore.setBlockTextureName("nc_redstonemagnetism:neodymium_ore");
    	
    	blockNickel_ore					=	new blockNickel_ore(Material.rock);
    	blockNickel_ore.setBlockName("nickelOre");
    	blockNickel_ore.setHardness(8F);
    	blockNickel_ore.setCreativeTab(ncTab);
    	blockNickel_ore.setHarvestLevel("pickaxe", 2);
    	blockNickel_ore.setBlockTextureName("nc_redstonemagnetism:nickel_ore");
    	
    	blockNickel_pure				=	new blockNickel_pure(Material.iron);
    	blockNickel_pure.setBlockName("pureNickel");
    	blockNickel_pure.setHardness(6.5F);
    	blockNickel_pure.setCreativeTab(ncTab);
    	blockNickel_pure.setHarvestLevel("pickaxe", 2);
    	blockNickel_pure.setBlockTextureName("nc_redstonemagnetism:nickel_pure");
    	
    	blockPhosphorus_ore				=	new blockPhosphorus_ore(this.phosphorus);
    	blockPhosphorus_ore.setBlockName("redPhosporus");
    	blockPhosphorus_ore.setHardness(12F);
    	blockPhosphorus_ore.setCreativeTab(ncTab);
    	blockPhosphorus_ore.setHarvestLevel("pickaxe", 2);
    	blockPhosphorus_ore.setBlockTextureName("nc_redstonemagnetism:phosphorus_ore");
    	
    	blockPulido						=	new blockLiquido(Material.water);
    	blockPulido.setHardness(100.0F);
    	blockPulido.setLightOpacity(2);
    	blockPulido.setBlockName("liquidPulido");
    	blockPulido.setBlockTextureName("minecraft:water");
    	
    	blockPulido_moving				=	new blockLiquido_moviendo(Material.water);
    	blockPulido_moving.setHardness(100.0F);
    	blockPulido_moving.setLightOpacity(2);
    	blockPulido_moving.setBlockName("liquidPulido_m");
    	blockPulido_moving.setBlockTextureName("minecraft:water");
    	
    	blockTungsten_ore				=	new blockTungsten_ore(Material.rock);
    	blockTungsten_ore.setBlockName("tungstenOre");
    	blockTungsten_ore.setHardness(5F);
    	blockTungsten_ore.setCreativeTab(ncTab);
    	blockTungsten_ore.setHarvestLevel("pickaxe", 2);
    	blockTungsten_ore.setBlockTextureName("nc_redstonemagnetism:tungsten_ore");
    	
    	blockTungsten_pure				=	new blockTungsten_pure(Material.iron);
    	blockTungsten_pure.setBlockName("pureTungsten");
    	blockTungsten_pure.setHardness(7.5F);
    	blockTungsten_pure.setCreativeTab(ncTab);
    	blockTungsten_pure.setHarvestLevel("pickaxe", 2);
    	blockTungsten_pure.setBlockTextureName("nc_redstonemagnetism:tungsten_pure");
    	
    	blockZinc_ore					=	new blockZinc_ore(specialOre);
    	blockZinc_ore.setBlockName("zincOre");
    	blockZinc_ore.setHardness(5.5F);
    	blockZinc_ore.setCreativeTab(ncTab);
    	blockZinc_ore.setHarvestLevel("pickaxe", 2);
    	blockZinc_ore.setBlockTextureName("nc_redstonemagnetism:cinc_ore");
    	
    	/* register items */
    	hgContainer						=	new itemBucket_hg(blockMercury_fluid);
    	hgContainer.setContainerItem(Items.bucket);
    	hgContainer.setCreativeTab(ncTab);
    	hgContainer.setTextureName("nc_redstonemagnetism:bucket_hg");
    	hgContainer.setUnlocalizedName("hgContainer_");
    	
    	itemCobblestone_chunk			=	new itemMisc_stonebits();
    	itemCobblestone_chunk.setTextureName("minecraft:iron_ingot");
    	itemCobblestone_chunk.setUnlocalizedName("cobblestone_c");
    	
    	itemChromite_bit				=	new itemMisc_chromitebits();
    	itemChromite_bit.setTextureName("minecraft:iron_ingot");
    	itemChromite_bit.setUnlocalizedName("chromite_c");
    	
    	itemStackedCuZn					=	new	itemCuZnMix();
    	itemStackedCuZn.setTextureName("nc_redstonemagnetism:brass_prealloy");
    	itemStackedCuZn.setUnlocalizedName("prebrass");
    	
    	/* register items */
    	itemMisc_pulidor				=	new itemMisc_pulidor();
    	itemMisc_pulidor.setTextureName("minecraft:iron_ingot");
    	itemMisc_pulidor.setUnlocalizedName("pulidor_t");
    	
    	/* register items */
    	itemAluminium_bar				=	new itemAluminium_bar();
    	itemAluminium_bar.setTextureName("nc_redstonemagnetism:aluminium_bar");
    	itemAluminium_bar.setUnlocalizedName("aluminiumBar");
    	
    	itemBrass_bar					=	new itemBrass_bar();
    	itemBrass_bar.setTextureName("nc_redstonemagnetism:brass_bar");
    	itemBrass_bar.setUnlocalizedName("brassBar");
    	
    	itemChromium_bar				=	new itemChromium_bar();
    	itemChromium_bar.setTextureName("nc_redstonemagnetism:chromium_bar");
    	itemChromium_bar.setUnlocalizedName("chromiumBar");
    	
    	itemCobalt_bar					=	new itemCobalt_bar();
    	itemCobalt_bar.setTextureName("nc_redstonemagnetism:cobalt_bar");
    	itemCobalt_bar.setUnlocalizedName("cobaltBar");
    	
    	itemCopper_bar					=	new itemCopper_bar();
    	itemCopper_bar.setTextureName("nc_redstonemagnetism:copper_bar");
    	itemCopper_bar.setUnlocalizedName("copperBar");
    	
    	itemNeodymium_bar				=	new itemNeodymium_bar();
    	itemNeodymium_bar.setTextureName("nc_redstonemagnetism:neodymium_bar");
    	itemNeodymium_bar.setUnlocalizedName("neodymiumBar");
    	
    	itemNickel_bar					=	new itemNickel_bar();
    	itemNickel_bar.setTextureName("nc_redstonemagnetism:nickel_bar");
    	itemNickel_bar.setUnlocalizedName("nickelBar");
    	
    	itemTungsten_bar				=	new itemTungsten_bar();
    	itemTungsten_bar.setTextureName("nc_redstonemagnetism:tungsten_bar");
    	itemTungsten_bar.setUnlocalizedName("tungstenBar");
    	
    	itemZinc_bar					=	new itemZinc_bar();
    	itemZinc_bar.setTextureName("nc_redstonemagnetism:cinc_bar");
    	itemZinc_bar.setUnlocalizedName("zincBar");
    	
    	/* register tools */
    	toolBrass_hoe					=	new toolBrass_hoe(BRASS_);
    	toolBrass_hoe.setTextureName("nc_redstonemagnetism:brass_hoe");
    	toolBrass_hoe.setUnlocalizedName("brass_hoe");
    	
    	toolBrass_pickaxe				=	new toolBrass_pickaxe(BRASS_);
    	toolBrass_pickaxe.setTextureName("nc_redstonemagnetism:brass_pickaxe");
    	toolBrass_pickaxe.setUnlocalizedName("brass_pickaxe");
    	
    	toolBrass_shovel				=	new toolBrass_shovel(BRASS_);
    	toolBrass_shovel.setTextureName("nc_redstonemagnetism:brass_spade");
    	toolBrass_shovel.setUnlocalizedName("brass_spade");
    	
    	toolBrass_sword					=	new toolBrass_sword(BRASS_);
    	toolBrass_sword.setTextureName("nc_redstonemagnetism:brass_sword");
    	toolBrass_sword.setUnlocalizedName("brass_sword");
    	
    	/* process stuff */
    	
    	GameRegistry.registerBlock(blockAluminium_pure,			"pureAluminium");
    	GameRegistry.registerBlock(blockBrass_pure,				"pureBrass");
    	GameRegistry.registerBlock(blockChromite,				"chromite");
    	GameRegistry.registerBlock(blockChromium_pure,			"pureChromium");
    	GameRegistry.registerBlock(blockCobalt_pure,			"pureCobalt");
    	GameRegistry.registerBlock(blockIron_ferromagnetic, 	"ferroIron");
    	GameRegistry.registerBlock(blockMercury_fluid,			"hgMercury");
    	GameRegistry.registerBlock(blockNeodymium_pure,			"pureNeodymium");
    	GameRegistry.registerBlock(blockNeodymium_tarnishing,	"tarnishedNeodymium");
    	GameRegistry.registerBlock(blockNickel_pure,			"pureNickel");
    	GameRegistry.registerBlock(blockPulido,					"liquidPulido");
    	GameRegistry.registerBlock(blockPulido_moving,			"liquidPulido_m");
    	GameRegistry.registerBlock(blockTungsten_pure,			"pureTungsten");
    	
    	GameRegistry.registerBlock(blockAluminium_ore,			"aluminiumOre");
    	GameRegistry.registerBlock(blockCobalt_ore,				"cobaltOre");
    	GameRegistry.registerBlock(blockCopper_ore,				"copperOre");
    	GameRegistry.registerBlock(blockNeodymium_ore,			"neodymiumOre");
    	GameRegistry.registerBlock(blockNickel_ore,				"nickelOre");
    	GameRegistry.registerBlock(blockPhosphorus_ore,			"redPhosphorus");
    	GameRegistry.registerBlock(blockTungsten_ore,			"tungstenOre");
    	GameRegistry.registerBlock(blockZinc_ore,				"zincOre");
    	
    	GameRegistry.registerItem(itemAluminium_bar,			"aluminiumBar");
    	GameRegistry.registerItem(itemBrass_bar,				"brassBar");
    	GameRegistry.registerItem(itemChromium_bar,				"chromiumBar");
    	GameRegistry.registerItem(itemCobalt_bar,				"cobaltBar");
    	GameRegistry.registerItem(itemCopper_bar,				"copperBar");
    	GameRegistry.registerItem(itemStackedCuZn,				"prebrass");
    	GameRegistry.registerItem(itemNeodymium_bar,			"neodymiumBar");
    	GameRegistry.registerItem(itemNickel_bar,				"nickelBar");
    	GameRegistry.registerItem(itemTungsten_bar,				"tungstenBar");
    	GameRegistry.registerItem(itemZinc_bar,					"zincBar");
    	
    	GameRegistry.registerItem(hgContainer,					"hgContainer_");
    	
    	GameRegistry.registerItem(toolBrass_hoe,				"brass_hoe");
    	GameRegistry.registerItem(toolBrass_pickaxe,			"brass_pickaxe");
    	GameRegistry.registerItem(toolBrass_shovel,				"brass_spade");
    	GameRegistry.registerItem(toolBrass_sword,				"brass_sword");
    	
    	/*
    	GameRegistry.registerItem(itemCobblestone_chunk,		"cobblestone_c");
    	GameRegistry.registerItem(itemChromite_bit,				"chromite_c");
    	GameRegistry.registerItem(itemMisc_pulidor,				"pulidor_t");
    	*/
    	
    	FluidContainerRegistry.registerFluidContainer(fluid_hg, new ItemStack(hgContainer), new ItemStack(Items.bucket));
    	
    	/* language */
    	/*
    	 * @TODO: Add Mexican Spanish + Use New Language System
    	 */
    	LanguageRegistry.addName(blockMercury_fluid,			"Mercury");
    	
    	LanguageRegistry.addName(blockAluminium_pure,			"Aluminium");
    	LanguageRegistry.addName(blockBrass_pure,				"Brass");
    	LanguageRegistry.addName(blockChromite,					"Chromite");
    	LanguageRegistry.addName(blockChromium_pure,			"Chromium");
    	LanguageRegistry.addName(blockCobalt_pure,				"Cobalt");
    	LanguageRegistry.addName(blockIron_ferromagnetic,		"Ferroiron");
    	LanguageRegistry.addName(blockMercury_fluid,			"Mercury");
    	LanguageRegistry.addName(blockNeodymium_pure,			"Neodymium");
    	LanguageRegistry.addName(blockNeodymium_tarnishing,		"Neodymium (Tarnished)");
    	LanguageRegistry.addName(blockNickel_pure,				"Nickel");
    	LanguageRegistry.addName(blockTungsten_pure,			"Tungsten");
    	LanguageRegistry.addName(blockPulido,					"Pulido para metal");
    	LanguageRegistry.addName(blockPulido_moving,			"Pulido para metal");
    	
    	LanguageRegistry.addName(blockAluminium_ore,			"Aluminium Ore");
    	LanguageRegistry.addName(blockCobalt_ore,				"Cobalt Ore");
    	LanguageRegistry.addName(blockCopper_ore,				"Copper Ore");
    	LanguageRegistry.addName(blockNeodymium_ore,			"Neodymium Ore");
    	LanguageRegistry.addName(blockNickel_ore,				"Nickel Ore");
    	LanguageRegistry.addName(blockPhosphorus_ore,			"Red Phosphorus");
    	LanguageRegistry.addName(blockTungsten_ore, 			"Tungsten Ore");
    	LanguageRegistry.addName(blockZinc_ore,					"Zinc Ore");
    	
    	LanguageRegistry.addName(itemAluminium_bar,				"Aluminium Bar");
    	LanguageRegistry.addName(itemBrass_bar,					"Brass Bar");
    	LanguageRegistry.addName(itemChromium_bar,				"Chromium Bar");
    	LanguageRegistry.addName(itemCobalt_bar,				"Cobalt Bar");
    	LanguageRegistry.addName(itemCopper_bar,				"Copper Bar");
    	LanguageRegistry.addName(itemStackedCuZn,				"Cu + Zn Stack");
    	LanguageRegistry.addName(itemNeodymium_bar,				"Neodymium Bar");
    	LanguageRegistry.addName(itemNickel_bar,				"Nickel Bar");
    	LanguageRegistry.addName(itemTungsten_bar,				"Tungsten Bar");
    	LanguageRegistry.addName(itemZinc_bar,					"Zinc Bar");
    	
    	LanguageRegistry.addName(hgContainer,					"Mercury Bucket");
    	LanguageRegistry.addName(toolBrass_hoe,					"Brass Hoe");
    	LanguageRegistry.addName(toolBrass_pickaxe,				"Brass Pickaxe");
    	LanguageRegistry.addName(toolBrass_shovel,				"Brass Shovel");
    	LanguageRegistry.addName(toolBrass_sword,				"Brass Sword");
    	/*
    	LanguageRegistry.addName(itemCobblestone_chunk,			"Cobblestone Chunk");
    	LanguageRegistry.addName(itemChromite_bit,				"Chromite Piece");
    	LanguageRegistry.addName(itemMisc_pulidor,				"Metal Polisher");
    	*/
    	
    	/* shapeless recipes */
    	GameRegistry.addShapelessRecipe(new ItemStack(Blocks.iron_block, 1),	new ItemStack(blockIron_ferromagnetic));
    	GameRegistry.addShapelessRecipe(new ItemStack(itemCobblestone_chunk,9), new ItemStack(Blocks.cobblestone));
    	
    	GameRegistry.addShapelessRecipe(new ItemStack(itemAluminium_bar, 9),	new ItemStack(blockAluminium_pure));
    	GameRegistry.addShapelessRecipe(new ItemStack(itemBrass_bar, 9),		new ItemStack(blockBrass_pure));
    	GameRegistry.addShapelessRecipe(new ItemStack(itemChromium_bar, ,		new ItemStack(blockChromium_pure));
    	GameRegistry.addShapelessRecipe(new ItemStack(itemCobalt_bar, ,		new ItemStack(blockCobalt_pure));
    	GameRegistry.addShapelessRecipe(new ItemStack(itemNeodymium_bar, ,	new ItemStack(blockNeodymium_pure));
    	GameRegistry.addShapelessRecipe(new ItemStack(itemNickel_bar, ,		new ItemStack(blockNickel_pure));
    	GameRegistry.addShapelessRecipe(new ItemStack(itemTungsten_bar, ,		new ItemStack(blockTungsten_pure));
    	
    	/* crafting recipes */
    	GameRegistry.addRecipe(new ItemStack(Blocks.cobblestone),		"xxx", "xxx", "xxx",
    	        'x', itemCobblestone_chunk);
    	GameRegistry.addRecipe(new ItemStack(blockAluminium_pure),		"xxx", "xxx", "xxx",
    	        'x', itemAluminium_bar);
    	GameRegistry.addRecipe(new ItemStack(blockBrass_pure),			"xxx", "xxx", "xxx",
    	        'x', itemBrass_bar);
    	GameRegistry.addRecipe(new ItemStack(blockChromium_pure),		"xxx", "xyx", "xxx",
    	        'x', itemChromium_bar, 'y', blockChromite);
    	GameRegistry.addRecipe(new ItemStack(blockCobalt_pure),			"xxx", "x x", "xxx",
    	        'x', itemCobalt_bar);
    	GameRegistry.addRecipe(new ItemStack(blockIron_ferromagnetic), 	"x  ", "y  ", "   ",
    	        'x', Blocks.iron_block, 'y', Items.compass);
    	GameRegistry.addRecipe(new ItemStack(blockNeodymium_pure), 		"xxx", "xyx", "xxx",
    	        'x', itemNeodymium_bar, 'y', Items.compass);
    	GameRegistry.addRecipe(new ItemStack(blockNickel_pure), 		"xxx", "x x", "xxx",
    	        'x', itemNickel_bar);
    	GameRegistry.addRecipe(new ItemStack(blockTungsten_pure), 		"xxx", "x x", "xxx",
    	        'x', itemTungsten_bar);
    	
    	GameRegistry.addRecipe(new ItemStack(itemStackedCuZn), 			"x  ", "y  ", "   ",
    	        'x', itemCopper_bar, 'y', itemZinc_bar);
    	GameRegistry.addRecipe(new ItemStack(itemStackedCuZn), 			"y  ", "x  ", "   ",
    	        'x', itemCopper_bar, 'y', itemZinc_bar);
    	
    	GameRegistry.addRecipe(new ItemStack(toolBrass_hoe), 			"xx "," y "," y ",
    			'x', itemBrass_bar, 'y', Items.stick);
    	GameRegistry.addRecipe(new ItemStack(toolBrass_pickaxe), 		"xxx"," y "," y ",
    			'x', itemBrass_bar, 'y', Items.stick);
    	GameRegistry.addRecipe(new ItemStack(toolBrass_shovel), 		" x "," y "," y ",
    			'x', itemBrass_bar, 'y', Items.stick);
    	GameRegistry.addRecipe(new ItemStack(toolBrass_sword), 			" x "," x "," y ",
    			'x', itemBrass_bar, 'y', Items.stick);
    	
    	/* furnace recipes */
    	GameRegistry.addSmelting(blockAluminium_ore,	new ItemStack(itemNickel_bar, 1),		0.5f);
    	GameRegistry.addSmelting(blockChromite, 		new ItemStack(itemChromium_bar, 1), 	0.5f);
    	GameRegistry.addSmelting(blockCobalt_ore, 		new ItemStack(itemCobalt_bar, 2),		0.5f);
    	GameRegistry.addSmelting(blockCopper_ore, 		new ItemStack(itemCopper_bar, 1),		0.5f);
    	GameRegistry.addSmelting(blockNeodymium_ore,	new ItemStack(itemNeodymium_bar, 1),	0.5f);
    	GameRegistry.addSmelting(blockNickel_ore, 		new ItemStack(itemNickel_bar, 1), 		0.5f);
    	GameRegistry.addSmelting(blockTungsten_ore, 	new ItemStack(itemTungsten_bar, 2), 	0.1f);
    	GameRegistry.addSmelting(blockZinc_ore,			new ItemStack(itemZinc_bar, 1), 		0.5f);
    	
    	GameRegistry.addSmelting(itemStackedCuZn,		new ItemStack(itemBrass_bar, 1), 		0.5f);
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
    	MinecraftForge.EVENT_BUS.register(event_onBucketFill.INSTANCE);
    }
    
    @EventHandler
    public void postInit(FMLPostInitializationEvent e)
    {
    	System.out.println("[Electromagnetism]: NullCity Electromagnetism Mod Activated!");
    	System.out.println("[Electromagnetism]: version: " + VERSION);
    	
    	if(mu.isUpdated()	!=	1)
    	{
    		System.out.println("[Electromagnetism]: Last warning, this version is out of date!");
    	}
    }
}

 

 

 

NCTab.java:

 

 

package mx.x10.nullcity.redstonemagnetism;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import scala.actors.threadpool.Arrays;

import com.google.common.base.Function;
import com.google.common.collect.Ordering;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

import mx.x10.nullcity.redstonemagnetism.mod_NCElectromagnetism;

public class NCTab extends CreativeTabs
{
    public static List<Item>  ncTab_order	=	Arrays.asList(new Item[]
    		{
    		mod_NCElectromagnetism.toolBrass_hoe,
    		mod_NCElectromagnetism.toolBrass_pickaxe,
    		mod_NCElectromagnetism.toolBrass_shovel,
    		mod_NCElectromagnetism.toolBrass_sword
    		}
    );
    
    public static Comparator<ItemStack> c = Ordering.explicit(ncTab_order).onResultOf(new Function<ItemStack, Item>(){
        @Override
        public Item apply(ItemStack input)
        {
            return input.getItem();
        }
    });

public NCTab(int i, String s) {
	super(i, s);
}

@Override
public void displayAllReleventItems(List l)
{
	Collections.sort(l, c);
}

public Item getTabIconItem()
{
	this.setNoScrollbar();
	return Item.getItemFromBlock(mod_NCElectromagnetism.blockNeodymium_ore);
}
}

 

 

 

Any help is appreciated and thanks!

AMD A8-5550M Quadcore (Turbo'd to 3.1 GHz)

AMD Radeon HD 8550G

8 GB RAM 1600 MHz (2 x 4 GB)

750 GB HDD @ 5400rpm

Focusrite 2i2 USB Audio Interface

------

Not bad for a laptop! Even on heavy load doesnt go over 65C! (most laptops go 75 - 80C)

Link to comment
Share on other sites

You want to put initializing code in the constructor of the creative tab, so it's clearer when that code gets called.

 

For example, it's better to have this line of code inside the constructor instead of

getTabIconItem()

:

this.setNoScrollbar();

 

The static list initializer should also be in the constructor, and you should call that constructor AFTER you registered all your items. You must set the creative tab of the items after you call the constructor (can be inside the constructor) so that the creative tab of the items aren't null. Your constructor should look something like this then:

public NCTab(int i, String s) {
    super(i, s);
    this.setNoScrollbar();
    List<Item> ncTab_order = Arrays.asList(new Item[]{
        item1.setCreativeTab(this),
        item2.setCreativeTab(this),
        ...
    });
}

 

 

As a sidenote, I'm failing to see the use for sorting the items in the creative tab like this. Items and blocks get added in the order you register them in, so you can just register them in the order you want instead of doing complex things like sorting and using comparators.

Link to comment
Share on other sites

Actually, I forgot to mention this but I already fixed it by initialising the items before the CreativeTab gets initialised and I fixed up the NCTab.java structure because all I did was just copy and paste it from main class to another class.

 

And I no longer have the NPE! So turns out it was cause I registered the items and blocks after the creative tab, but thanks for pointing out I had the setNoScrollbar(); there. i didnt even notice that!

 

PS: The items and blocks DO NOT get ordered in the way they registered them. I already initalised and registered ores first, then blocks, then ingots, then tools and I had a pickaxe right next to an ore and the rest of the tool set for brass as the last 3 slots. Which is why I decided to see if there was a method then saw a text tutorial that was on this forum and tried following it

 

EDIT: Turns out LanguageRegistry also effects the order in how the items are placed in the CreativeTab. So by registered in alphabetical and by type (blocks, items, tools, misc). Now its all ordered!

AMD A8-5550M Quadcore (Turbo'd to 3.1 GHz)

AMD Radeon HD 8550G

8 GB RAM 1600 MHz (2 x 4 GB)

750 GB HDD @ 5400rpm

Focusrite 2i2 USB Audio Interface

------

Not bad for a laptop! Even on heavy load doesnt go over 65C! (most laptops go 75 - 80C)

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.