Since the constructor is private and you can't modify the class, you have a few potential workarounds:
Option 1: Use Reflection (Most Direct)
public static final DeferredRegister<BlockStateProviderType<?>> BSPT = DeferredRegister.create(BuiltInRegistries.BLOCKSTATE_PROVIDER_TYPE, Main.MOD_ID);
public static final Supplier<BlockStateProviderType<SupplementNoiseProvider>> SUPPLEMENT_NOISE_PROVIDER = BSPT.register("supplement_noise_provider", () -> {
try {
Constructor<BlockStateProviderType> constructor = BlockStateProviderType.class.getDeclaredConstructor(MapCodec.class);
constructor.setAccessible(true);
return constructor.newInstance(SupplementNoiseProvider.CODEC);
} catch (Exception e) {
throw new RuntimeException("Failed to create BlockStateProviderType", e);
}
});
Option 2: Use Access Transformers (Cleaner but requires setup)
Create an access transformer file (usually src/main/resources/META-INF/accesstransformer.cfg):
public net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProviderType <init>(Lcom/mojang/serialization/MapCodec;)V
Then add this to your build.gradle:
minecraft {
accessTransformers {
file('src/main/resources/META-INF/accesstransformer.cfg')
}
}
After setting up the access transformer, your original code should work as intended.
Option 3: Mixin (If you're using Mixins)
@Mixin(BlockStateProviderType.class)
public class BlockStateProviderTypeMixin {
@Shadow
@Final
private MapCodec<?> codec;
// Make constructor accessible through a static method
public static <P extends BlockStateProvider> BlockStateProviderType<P> create(MapCodec<P> codec) {
return new BlockStateProviderType<>(codec);
}
}
Recommendation: Access transformers (Option 2) are the cleanest approach for Forge modding, as they're designed specifically for this purpose and don't have the runtime overhead of reflection. Reflection (Option 1) works immediately without additional setup but is less elegant.