public final class ModItems
{
// 1: This shouldn't be in a class called ModItems
// 2: You shouldn't be using this method, thats why its depreciated, you should be using the registry events
@SuppressWarnings("deprecation")
private static <T extends Entity> EntityType<T> register(String key, EntityType.Builder<T> builder) {
return Registry.register(Registry.ENTITY_TYPE, key, builder.build(key));
}
public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, Main.MODID);
// This shouldn't be in a class called ModItems
//public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = new DeferredRegister<>(ForgeRegistries.ENTITIES, Main.MODID);
// 1: This shouldn't be in a class called ModItems
// 2: You shouldn't use static initialisers
// 3: You shouldn't register stuff statically
// You should create and register your objects inside the registry events
public static final EntityType<UnicornEntity> UNICORN = register("unicorn_entity", EntityType.Builder.create(UnicornEntity::new, EntityClassification.AMBIENT).size(0.5F, 0.9F));
// This is correct - it's how you should be doing your registration, but it shouldn't be in a class called ModItems
//public static final RegistryObject<EntityType<UnicornEntity>> UNICORN = ENTITY_TYPES.register("unicorn_entity", () -> EntityType.Builder.create(UnicornEntity::new, EntityClassification.AMBIENT).build(null));
public static final RegistryObject<Item> RAINBOW_INGOT = ITEMS.register("rainbow_ingot",() -> new Item(new Item.Properties().group(ModItemGroups.RAINBOW_MOD_GROUP)));
public static final RegistryObject<Item> UNICORN_ENTITY_EGG = ITEMS.register("unicorn_entity_egg", () -> new SpawnEggItem(UNICORN, 0xf0f0f0, 0xdf51f5, new Item.Properties().group(ModItemGroups.RAINBOW_MOD_GROUP)));
}
You should remove entity related stuff from your ModItems class and make a new class like so:
public final class ModEntityTypes {
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = new DeferredRegister<>(ForgeRegistries.ENTITIES, Main.MODID);
public static final RegistryObject<EntityType<UnicornEntity>> UNICORN = ENTITY_TYPES.register("unicorn", () -> EntityType.Builder.create(UnicornEntity::new, EntityClassification.AMBIENT).size(0.5F, 0.9F).build(null));
}
and register your DeferredRegister in your mods constructor like this.