Jump to content

Creating an instance of block


Recommended Posts

So I'm trying to create an instance of Block

static {
        Block funnyUselessBlockWithNoPurpose = new Block(BlockBehaviour.Properties.of(Material.AIR));


I don't want to register it in block registry or use it anywhere else, only need this temporary to measure a few things. However it fails with "Registry is already frozen".

Shouldn't block register when I actually call `BLOCKS.register(name, block);`?



java.lang.reflect.InvocationTargetException: null
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?]
	at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?]
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.19.3-44.1.4.jar%23187!/:?]
	at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.3-44.1.4.jar%23190!/:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?]
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?]
	at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?]
	at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?]
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?]
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?]
Caused by: java.lang.ExceptionInInitializerError
	at ****.mod1.<init>(mod1.java:26) ~[%23191!/:?]
	... 14 more
Caused by: java.lang.IllegalStateException: Registry is already frozen
	at net.minecraftforge.registries.NamespacedWrapper.validateWrite(NamespacedWrapper.java:264) ~[forge-1.19.3-44.1.4_mapped_official_1.19.3-recomp.jar%23185%23192!/:?]
	at net.minecraftforge.registries.NamespacedWrapper.createIntrusiveHolder(NamespacedWrapper.java:358) ~[forge-1.19.3-44.1.4_mapped_official_1.19.3-recomp.jar%23185%23192!/:?]
	at net.minecraft.world.level.block.Block.<init>(Block.java:67) ~[forge-1.19.3-44.1.4_mapped_official_1.19.3-recomp.jar%23186!/:?]
	at ****.modBlocks.<clinit>(modBlocks.java:42) ~[%23191!/:?]
	at ****.<init>(mod1.java:26) ~[%23191!/:?]
	... 14 more



Edited by A_A
Link to comment
Share on other sites

No, I was measuring execution time for a method in my custom block 10000 (A-B testing) times and I was too lazy to wait for Minecraft to load up for every change. Looking at Minecraft code they can do it but with forge in place, it seems register somehow gets called via code injected into block init (probably to register vanilla blocks?).

Link to comment
Share on other sites

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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.