Hey all, I need some help getting a tile entity to register properly. I am following McJty's modding tutorial for making a GUI and inventory that can be found on his wiki. I noticed he is using ITileEntityProvider instead of overriding createTileEntity and hasTileEntity so I've modified my code to do so. However, when trying to launch the game, I get the following error in CommonProxy on registering the ItemBlock: java.lang.NullPointerException: null
at com.petersx34.rfutilities.proxy.CommonProxy.registerItems(CommonProxy.java:60) ~[CommonProxy.class:?]
Any guidance on this would be much appreciated. I have been struggling with it for the better half of the day.
Block Code
public class SmartCrafterBlock extends Block {
public static final int GUI_ID = 1;
public SmartCrafterBlock() {
super(Material.WOOD);
setUnlocalizedName(RFUtilities.MODID + ".smartcrafterblock");
setRegistryName("smartcrafterblock");
setCreativeTab(CreativeTabs.MISC);
}
@SideOnly(Side.CLIENT)
public void initModel() {
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new SmartCrafterTileEntity();
}
@Override
public boolean hasTileEntity(IBlockState state) {
return true;
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
}
TileEntity te = world.getTileEntity(pos);
if (!(te instanceof SmartCrafterTileEntity)) {
return false;
}
player.openGui(RFUtilities.instance, GUI_ID, world, pos.getX(), pos.getY(), pos.getZ());
return true;
}
}
ModBlocks
public class ModBlocks {
@GameRegistry.ObjectHolder("rfutilities:smartcrafterblock")
public static SmartCrafterBlock smartCrafterBlock;
@SideOnly(Side.CLIENT)
public static void initModels() {
smartCrafterBlock.initModel();
}
@SideOnly(Side.CLIENT)
public static void initItemModels() {
}
}
CommonProxy
@Mod.EventBusSubscriber
public class CommonProxy{
public static Configuration config;
public void preInit(FMLPreInitializationEvent e) {
File directory = e.getModConfigurationDirectory();
config = new Configuration(new File(directory.getPath(), "rfutilities.cfg"));
Config.readConfig();
}
public void init(FMLInitializationEvent e) {
NetworkRegistry.INSTANCE.registerGuiHandler(RFUtilities.instance, new GuiProxy());
}
public void postInit(FMLPostInitializationEvent e) {
if (config.hasChanged()) {
config.save();
}
}
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event) {
event.getRegistry().register(new SmartCrafterBlock());
GameRegistry.registerTileEntity(SmartCrafterTileEntity.class, RFUtilities.MODID + "_smartcrafterblock");
}
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) {
event.getRegistry().register(new ItemLightningBoots());
event.getRegistry().register(new ItemBlock(ModBlocks.smartCrafterBlock).setRegistryName(ModBlocks.smartCrafterBlock.getRegistryName()));
}
}