I’m mid-way though writing a Minecraft 1.18.2 mod (Forge 40.1.80). As this is the first Minecraft mod I am writing, I’m not too experienced in the field and have no idea what is causing this issue. When I try running the code I get this error (4 times): java: no suitable constructor found for Block(net.minecraft.world.level.block.state.BlockBehaviour.Properties). Any help would be greatly appreciated. The error appears here: "() -> new Block(ORE_PROPERTIES <-Here"
package com.example.factorytechv0_1.startup;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.openjdk.nashorn.internal.ir.Block;
public class Registration {
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create((ResourceLocation) ForgeRegistries.BLOCKS, "factorytechv0_1");
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "factorytechv0_1");
public static void init() {
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
}
public static final BlockBehaviour.Properties ORE_PROPERTIES = BlockBehaviour.Properties.of(Material.STONE).strength(2f);
public static final Item.Properties ITEM_PROPERTIES = new Item.Properties().tab(ModSetup.ITEM_GROUP);
public static final RegistryObject<Block> CHROME_ORE_OVERWORLD = BLOCKS.register("chrome_ore_overworld", () -> new Block(ORE_PROPERTIES));
public static final RegistryObject<Item> CHROME_ORE_OVERWORLD_ITEM = fromBlock(CHROME_ORE_OVERWORLD);
public static final RegistryObject<Block> CHROME_ORE_DEEPSLATE = BLOCKS.register("chrome_ore_deepslate", () -> new Block(ORE_PROPERTIES));
public static final RegistryObject<Item> CHROME_ORE_DEEPSLATE_ITEM = fromBlock(CHROME_ORE_DEEPSLATE);
public static final RegistryObject<Block> HAFNIUM_ORE_NETHER = BLOCKS.register("hafnium_ore_nether", () -> new Block(ORE_PROPERTIES));
public static final RegistryObject<Item> HAFNIUM_ORE_NETHER_ITEM = fromBlock(HAFNIUM_ORE_NETHER);
public static final RegistryObject<Block> TECHNETIUM_ORE_END = BLOCKS.register("technetium_ore_end", () -> new Block(ORE_PROPERTIES));
public static final RegistryObject<Item> TECHNETIUM_ORE_END_ITEM = fromBlock(TECHNETIUM_ORE_END);
public static <B extends Block> RegistryObject<Item> fromBlock(RegistryObject<B> block)
{
return ITEMS.register(block.getId().getPath(), () -> new BlockItem(block.get(), ITEM_PROPERTIES));
}
}
Here is the main initialisation file for the mod (if needed)
package com.example.factorytechv0_1;
import com.example.factorytechv0_1.startup.ClientSetup;
import com.example.factorytechv0_1.startup.ModSetup;
import com.example.factorytechv0_1.startup.Registration;
import com.mojang.logging.LogUtils;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.slf4j.Logger;
// The value here should match an entry in the META-INF/mods.toml file
@Mod("factorytechv0_1")
public class factorytechv0_1 {
// Directly reference a slf4j logger
private static final Logger LOGGER = LogUtils.getLogger();
public factorytechv0_1() {
// Register the deferred reg
Registration.init();
// Register the setup method for Modloading
IEventBus modbus = FMLJavaModLoadingContext.get().getModEventBus();
modbus.addListener(ModSetup::init);
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> modbus.addListener(ClientSetup::init));
}
}
I think you might have the wrong import, perhaps intellij/eclipse suggested the wrong one for you.
import org.openjdk.nashorn.internal.ir.Block
This import looks weird, please remove it and replace it with something starting with net.minecraft.world.item
.