Jump to content

[1.9.4] [SOLVED] PropertyEnum NullPointerException


Bektor

Recommended Posts

Hi,

 

I've got a huge problem when creating my own leaves block with a property enum which stores all types of leaves and woods.

It always results into a NullPointerException and I don't know what's wrong.

 

Here the crash:

 

java.lang.NullPointerException: Initializing game
at net.minecraft.block.state.BlockStateContainer.validateProperty(BlockStateContainer.java:101)
at net.minecraft.block.state.BlockStateContainer.<init>(BlockStateContainer.java:75)
at net.minecraft.block.state.BlockStateContainer.<init>(BlockStateContainer.java:60)
at minecraftplaye.primevalforest.common.blocks.core.BlockBaseLeaves.createBlockState(BlockBaseLeaves.java:216)
at net.minecraft.block.Block.<init>(Block.java:272)
at net.minecraft.block.Block.<init>(Block.java:281)
at net.minecraft.block.BlockLeaves.<init>(BlockLeaves.java:30)
at minecraftplaye.primevalforest.common.blocks.core.BlockBaseLeaves.<init>(BlockBaseLeaves.java:49)
at minecraftplaye.primevalforest.common.blocks.BlockLeaves.<init>(BlockLeaves.java:13)
at minecraftplaye.primevalforest.common.core.ModBlocks.init(ModBlocks.java:30)
at minecraftplaye.primevalforest.PrimevalForest.preinit(PrimevalForest.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:568)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:228)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:587)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:475)
at net.minecraft.client.Minecraft.run(Minecraft.java:384)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
at net.minecraft.block.state.BlockStateContainer.validateProperty(BlockStateContainer.java:101)
at net.minecraft.block.state.BlockStateContainer.<init>(BlockStateContainer.java:75)
at net.minecraft.block.state.BlockStateContainer.<init>(BlockStateContainer.java:60)
at minecraftplaye.primevalforest.common.blocks.core.BlockBaseLeaves.createBlockState(BlockBaseLeaves.java:216)
at net.minecraft.block.Block.<init>(Block.java:272)
at net.minecraft.block.Block.<init>(Block.java:281)
at net.minecraft.block.BlockLeaves.<init>(BlockLeaves.java:30)
at minecraftplaye.primevalforest.common.blocks.core.BlockBaseLeaves.<init>(BlockBaseLeaves.java:49)
at minecraftplaye.primevalforest.common.blocks.BlockLeaves.<init>(BlockLeaves.java:13)
at minecraftplaye.primevalforest.common.core.ModBlocks.init(ModBlocks.java:30)
at minecraftplaye.primevalforest.PrimevalForest.preinit(PrimevalForest.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:568)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:228)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:587)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:475)

-- Initialization --
Details:
Stacktrace:
at net.minecraft.client.Minecraft.run(Minecraft.java:384)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)

 

 

Besides: I'm using Forge 1.9.4 with Java 8.

 

BlockLeaves.java

package minecraftplaye.primevalforest.common.blocks;

import minecraftplaye.primevalforest.api.types.WoodType;
import minecraftplaye.primevalforest.common.blocks.core.BlockBaseLeaves;

import net.minecraft.block.properties.PropertyEnum;

public class BlockLeaves extends BlockBaseLeaves {
    
    public static PropertyEnum<WoodType> META_PROPERTY = PropertyEnum.create("wood", WoodType.class/*, Arrays.copyOfRange(WoodType.values(), 0, 0)*/);
    
    public BlockLeaves() {
        super(META_PROPERTY);
    }
}

 

Block Base Leaves (the lines and methods marked in the crash log and the constructor):

public abstract class BlockBaseLeaves extends BlockLeaves implements IShearable {

    protected final PropertyEnum<WoodType> META_PROP;
    
    public BlockBaseLeaves(PropertyEnum<WoodType> META_PROPERTY) {
        super();
        this.META_PROP = META_PROPERTY;
        
        this.setLightOpacity(1);
        this.setTickRandomly(true);
        this.setTickRandomly(true);
        this.setSoundType(SoundType.PLANT);
        this.setCreativeTab(ModCreativeTabs.primevalTab);
    }

 

The complete stuff is in the order of the crash log:

    @Override
    protected BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, new IProperty[] {META_PROP});
    }

 

    public BlockBaseLeaves(PropertyEnum<WoodType> META_PROPERTY) {
        super();

 

Here are all methods which have something to do with the meta data:

    @Override
    protected BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, new IProperty[] {META_PROP});
    }
    
    @Override
    public IBlockState getStateFromMeta(int meta) {
        return this.getDefaultState().withProperty(META_PROP, WoodType.getTypeFromID(meta));
    }
    
    @Override
    public int getMetaFromState(IBlockState state) {
        return ((WoodType) state.getValue(META_PROP)).getID();
    }
    
    @Override
    public EnumType getWoodType(int meta) {
        return null;
    }

    @Override
    public int damageDropped(IBlockState state) {
        return ((WoodType) state.getValue(META_PROP)).getID();
    }

 

My WoodType enum is currently filled with just 2 values:

public enum WoodType implements IStringSerializable {
    
    // ID, name, Modulus of Rupture, Dried Weight
    Oak(0, "oak", 47.f),
    TEST(1, "test", 35.f);

    private final float driedWeight;
    
    private WoodType(int ID, String name, float driedWeight) {
        this.ID = ID;
        this.name = name;
        this.driedWeight = driedWeight / 10;
    }

    public static WoodType getTypeFromID(int ID) {
        for(int i = 0; i < WoodType.values().length; i++) {
            if(WoodType.values()[i].getID() == ID)
                return WoodType.values()[i];
        }
        
        return null;
    }

 

There are also getters for all values of the class.

 

I hope someone can help me with this. ;)

 

Thx in advance.

Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

Your property fields have to be static, otherwise they are not initialized yet when createBlockState is called, since createBlockState is called from the super constructor, but field initializers are run after that.

So there is no way to just have one property field which will be set for each block?

Because I don't like the idea of having to have them static, because when I have 32 wood types I need 2 classes and then I would need all the code in methods like updateTick() which can get large again.... and I'm not the fan of C&P code from class A to B.

 

I mean, it was the main idea behind making the class abstract that I don't need to copy over my fast leave decay stuff to all classes because it requires the block metadata, so the property field to work.

Developer of Primeval Forest.

Link to comment
Share on other sites

If each subclass stores its property in a static field (and initialises it there), the base class can have an abstract method that returns the property and the subclasses can override it to return their property. You can call this method from

createBlockState

.

 

BlockSlab

does this for its variant property.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.

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...

×   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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When i try to launch Minecraft Java 1.20.1 forge with mods (82 mods),on start it loaded all mods,but at end Java just crashed.  p.s i allocated 8GB ram for minecraft and i didn't runned another instance.Log file pp.s I use ATlauncher   Environment: Organising filesystem [24/04/2024 23:40:08 PM] ATLauncher Version: 3.4.36.3 [11ae0b2334c236e93ee8128de980952b2a1b8900] [24/04/2024 23:40:08 PM] App Arguments: ["--install-method=aur","--no-launcher-update"] [24/04/2024 23:40:08 PM] JVM Arguments: ["-Dawt.useSystemAAFontSettings=on","-Dswing.aatext=true"] [24/04/2024 23:40:08 PM] Java Version: Java 22 (22) [24/04/2024 23:40:08 PM] Java Path: /usr/lib/jvm/java-22-openjdk [24/04/2024 23:40:08 PM] 64 Bit Java: true [24/04/2024 23:40:08 PM] RAM Available: 14931MB [24/04/2024 23:40:08 PM] Launcher Directory: **USERSDIR** [24/04/2024 23:40:08 PM] GPU: IvyBridge GT2 [HD Graphics 4000] (Intel Corporation (0x8086)) unknown 256MB VRAM [24/04/2024 23:40:08 PM] CPU: Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz 4 cores/8 threads [24/04/2024 23:40:08 PM] Operating System: EndeavourOS (unknown (unknown) build 6.8.7-arch1-1) [24/04/2024 23:40:08 PM] Bitness: 64 [24/04/2024 23:40:08 PM] Uptime: 15889 [24/04/2024 23:40:08 PM] Manufacturer: GNU/Linux
    • If you have nvidia graphics, don't touch your amd drivers, otherwise it might fix it but keep running on integrated graphics, which will result in terrible performance. For nvidia graphics, you need to tell windows and nvidia control panel that anything Minecraft related (the launcher, java, etc...) should prefer high performance graphics so that it actually uses your nvidia gpu
    • In the ever-evolving landscape of technology, the rise of cryptocurrencies and digital assets has introduced both unparalleled opportunities and unprecedented challenges. As these digital currencies become increasingly prevalent, so too does the risk of theft and loss. Yet, amidst the complexity and uncertainty, there exists a beacon of hope: ADRIAN LAMO HACKER. Technology has indeed become more sophisticated and enhanced, presenting new challenges in the realm of asset recovery. However, just as any other currency can be stolen or lost, crypto and digital assets are not beyond redemption. With the right expertise and guidance, recovery is possible and achievable. Contact ADRIAN LAMO HACKER via the website: https://adrianlamohackpro.online/ , a trusted, honest, and certified agency specializing in the retrieval of stolen or lost digital assets. In my own experience, I found myself in dire straits after falling victim to cybercriminals who absconded with a significant portion of my crypto holdings. It was a daunting situation, but I refused to succumb to despair. Upon engaging ADRIAN LAMO HACKER, their professionalism, and integrity immediately struck me, as an unwavering commitment to their clients. They deeply understand blockchain technology and utilize advanced methodologies to trace and recover lost or stolen funds. Their approach is meticulous, their expertise unparalleled, and their results speak for themselves. In a matter of days, ADRIAN LAMO HACKER successfully traced and recovered over 90% of my stolen funds, a feat I once believed to be unattainable. Their fees were fair and transparent, and communication throughout the process was nothing short of excellent. They kept me informed every step of the way, providing reassurance and guidance when I needed it most. For anyone who has fallen victim to crypto theft or loss, I wholeheartedly recommend ADRIAN LAMO HACKER. They are not just experts in their field; they are guardians of justice in the digital realm. With their assistance, you can reclaim what's rightfully yours and emerge stronger than ever before. So, if you find yourself grappling with the devastation of lost or stolen digital assets, don't despair. Reach out to ADRIAN LAMO HACKER via website: https://adrianlamohackpro.online/  / Telegram: @ADRIANLAMOHACKERTECH and let them guide you toward a brighter tomorrow.
  • Topics

×
×
  • Create New...

Important Information

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