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

Hello guys,

 

I'm working on a Minecraft mod which will add certain blocks and items. I was adding a new block when I came across this error, "ItemBlock cannot be resolved to a type." My code is the following:

 

 

 

package maxgaming3648.vanillaextension;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import maxgaming3648.vanillaextension.lists.BlockList;
import maxgaming3648.vanillaextension.lists.ItemList;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Mod("vanillaextension")
public class VanillaExtension {
    
    public static VanillaExtension instance;
    public static final String modid = "vanillaextension";
    private static final Logger logger = LogManager.getLogger(modid);
    
    public static final ItemGroup miscellaneous = new MiscellaneousItemGroup();
    public static final ItemGroup buildingblocks = new BuildingBlocksItemGroup();
    
    public VanillaExtension() {
        
        instance = this;
        
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientRegistries);
        
        MinecraftForge.EVENT_BUS.register(this);

    }
    
    private void setup(final FMLCommonSetupEvent event) {
        
        logger.info("Setup method registered.");
        
    }
    
    private void clientRegistries(final FMLClientSetupEvent event) {
        
        logger.info("clientRegistries method registered.");
        
    }
    
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        
        @SubscribeEvent
        public static void registerItems(final RegistryEvent.Register<Item> event) {
            
            event.getRegistry().registerAll(
            
                    // Items
                    
                    ItemList.ruby = new Item(new Item.Properties().group(miscellaneous)).setRegistryName(location("ruby")),
                    
                    // Blocks
                    
                    ItemList.ruby_block = new ItemBlock(BlockList.ruby_block, new Item.Properties().group(buildingblocks))
            
            );
            
            logger.info("Items registered.");
            
        }
        
        @SubscribeEvent
        public static void registerBlocks(final RegistryEvent.Register<Block> event) {
            
            event.getRegistry().registerAll(
            
                    BlockList.ruby_block = new Block(Block.Properties.create(Material.IRON).hardnessAndResistance(5.0f, 30.0f).sound(SoundType.METAL)).setRegistryName(location("ruby_block"))
            
            );
            
            logger.info("Items registered.");
            
        }
        
        private static ResourceLocation location(String name) {
            
            return new ResourceLocation(modid, name);
            
        }
        
    }

}
 

 

 

I tried manually importing "net.minecraft.item.Itemblock", but it just said "The import net.minecraft.item.ItemBlock cannot be resolved." What can I do to fix the problem?

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.