Jump to content

Inheriting from BlockPlanks Issue


Jack4096

Recommended Posts

It's line 36 in the class constructor that shows up as the error with the crash report, after it crashes before it finishes starting up, the line that says:

 

this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, MagicPlank.EnumType.MAGIC));

 

And this is the error message:

 

Caused by: java.lang.IllegalArgumentException: Cannot set property PropertyEnum{name=variant, clazz=class net.minecraft.block.BlockPlanks$EnumType, values=[oak, spruce, birch, jungle, acacia, dark_oak]} as it does not exist in BlockStateContainer{block=null, properties=[variant]}

 

package com.jack.tutorialmod.blocks;

import com.jack.tutorialmod.Main;
import com.jack.tutorialmod.util.IHasModel;

import net.minecraft.block.BlockPlanks;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;

public class MagicPlank extends BlockPlanks implements IHasModel {
    
    public static final PropertyEnum<MagicPlank.EnumType> VARIANT = PropertyEnum.<MagicPlank.EnumType>create("variant", MagicPlank.EnumType.class);

    public MagicPlank(String name)
    {
        super();
        
        setSoundType(SoundType.WOOD);
        setHardness(2.0F);
        setResistance(10.0F);
        setHarvestLevel("axe", 0);
        setUnlocalizedName(name);
        setRegistryName(name);
        this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, MagicPlank.EnumType.MAGIC));
        this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
    }

    /**
     * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
     * returns the metadata of the dropped item based on the old metadata of the block.
     */
    public int damageDropped(IBlockState state)
    {
        return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMetadata();
    }

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
    {
        for (MagicPlank.EnumType magicplank$enumtype : MagicPlank.EnumType.values())
        {
            items.add(new ItemStack(this, 1, magicplank$enumtype.getMetadata()));
        }
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(VARIANT, MagicPlank.EnumType.byMetadata(meta));
    }

    /**
     * Get the MapColor for this Block and the given BlockState
     */
    public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
        return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMapColor();
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        return ((MagicPlank.EnumType)state.getValue(VARIANT)).getMetadata();
    }

    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {VARIANT});
    }

    public static enum EnumType implements IStringSerializable
    {
        MAGIC(0, "magic", MapColor.BLUE),
        MAPLE(1, "maple", MapColor.RED),
        YEW(2, "yew", MapColor.YELLOW),
        REDWOOD(3, "redwood", MapColor.RED);

        private static final MagicPlank.EnumType[] META_LOOKUP = new MagicPlank.EnumType[values().length];
        private final int meta;
        private final String name;
        private final String unlocalizedName;
        /** The color that represents this entry on a map. */
        private final MapColor mapColor;

        private EnumType(int metaIn, String nameIn, MapColor mapColorIn)
        {
            this(metaIn, nameIn, nameIn, mapColorIn);
        }

        private EnumType(int metaIn, String nameIn, String unlocalizedNameIn, MapColor mapColorIn)
        {
            this.meta = metaIn;
            this.name = nameIn;
            this.unlocalizedName = unlocalizedNameIn;
            this.mapColor = mapColorIn;
        }

        public int getMetadata()
        {
            return this.meta;
        }

        /**
         * The color which represents this entry on a map.
         */
        public MapColor getMapColor()
        {
            return this.mapColor;
        }

        public String toString()
        {
            return this.name;
        }

        public static MagicPlank.EnumType byMetadata(int meta)
        {
            if (meta < 0 || meta >= META_LOOKUP.length)
            {
                meta = 0;
            }

            return META_LOOKUP[meta];
        }

        public String getName()
        {
            return this.name;
        }

        public String getUnlocalizedName()
        {
            return this.unlocalizedName;
        }

        static
        {
            for (MagicPlank.EnumType magicplank$enumtype : values())
            {
                META_LOOKUP[magicplank$enumtype.getMetadata()] = magicplank$enumtype;
            }
        }
    }
    
    @Override
    public void registerModels() {
        Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
    }
    
}

 

I'm sorry if this is a rookie mistake or something. I am experienced with Java, just not Minecraft Forge modding.

Edited by Jack4096
Forgot error message
Link to comment
Share on other sites

4 hours ago, Jack4096 said:

protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {VARIANT});
    }

Is this being properly overriden?

 

and how are you registering your block??

4 hours ago, Jack4096 said:

BlockStateContainer{block=null

Can you post your entire log using GitHub Gist or pastebin and your code as a github(or similar) repository?

  • Like 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

4 hours ago, Cadiboo said:

 

Thank you Cadiboo, putting @Override at the line over:

 

protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {VARIANT});
    }

 

fixed the crash on startup. Updated code:

 

 

public class BlockPlanksBase extends Block implements IHasModel
{
    public static final PropertyEnum<BlockPlanksBase.EnumType> VARIANT = PropertyEnum.<BlockPlanksBase.EnumType>create("variant", BlockPlanksBase.EnumType.class);

    public BlockPlanksBase(String name)
    {
        super(Material.WOOD);
        
        setUnlocalizedName(name);
        setRegistryName(name);
        
        ModBlocks.BLOCKS.add(this);
        ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
        
        this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
        this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlanksBase.EnumType.MAGIC));
    }

    /**
     * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
     * returns the metadata of the dropped item based on the old metadata of the block.
     */
    public int damageDropped(IBlockState state)
    {
        return ((BlockPlanksBase.EnumType)state.getValue(VARIANT)).getMetadata();
    }

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
    {
        for (BlockPlanksBase.EnumType blockplanksbase$enumtype : BlockPlanksBase.EnumType.values())
        {
            items.add(new ItemStack(this, 1, blockplanksbase$enumtype.getMetadata()));
        }
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(VARIANT, BlockPlanksBase.EnumType.byMetadata(meta));
    }

    /**
     * Get the MapColor for this Block and the given BlockState
     */
    public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
        return ((BlockPlanksBase.EnumType)state.getValue(VARIANT)).getMapColor();
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        return ((BlockPlanksBase.EnumType)state.getValue(VARIANT)).getMetadata();
    }
    
    @Override
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {VARIANT});
    }

    public static enum EnumType implements IStringSerializable
    {
        MAGIC(0, "magic", MapColor.SAND),
        MAPLE(1, "maple", MapColor.SAND),
        REDWOOD(2, "redwood", MapColor.SAND),
        YEW(3, "yew", MapColor.SAND);
        

        private static final BlockPlanksBase.EnumType[] META_LOOKUP = new BlockPlanksBase.EnumType[values().length];
        private final int meta;
        private final String name;
        private final String unlocalizedName;
        /** The color that represents this entry on a map. */
        private final MapColor mapColor;

        private EnumType(int metaIn, String nameIn, MapColor mapColorIn)
        {
            this(metaIn, nameIn, nameIn, mapColorIn);
        }

        private EnumType(int metaIn, String nameIn, String unlocalizedNameIn, MapColor mapColorIn)
        {
            this.meta = metaIn;
            this.name = nameIn;
            this.unlocalizedName = unlocalizedNameIn;
            this.mapColor = mapColorIn;
        }

        public int getMetadata()
        {
            return this.meta;
        }

        /**
         * The color which represents this entry on a map.
         */
        public MapColor getMapColor()
        {
            return this.mapColor;
        }

        public String toString()
        {
            return this.name;
        }

        public static BlockPlanksBase.EnumType byMetadata(int meta)
        {
            if (meta < 0 || meta >= META_LOOKUP.length)
            {
                meta = 0;
            }

            return META_LOOKUP[meta];
        }

        public String getName()
        {
            return this.name;
        }

        public String getUnlocalizedName()
        {
            return this.unlocalizedName;
        }

        static
        {
            for (BlockPlanksBase.EnumType blockplanksbase$enumtype : values())
            {
                META_LOOKUP[blockplanksbase$enumtype.getMetadata()] = blockplanksbase$enumtype;
            }
        }
        
    }
    
    @Override
    public void registerModels() {
        Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
    }
    
}

 

So yes, that fixed it. Thank you Cadiboo.

Edited by diesieben07
code formatting
Link to comment
Share on other sites

27 minutes ago, diesieben07 said:

This is impossible. Adding @Override never changes how your code behaves, except maybe making it not compile anymore in case you are not actually overriding.

It ONLY fixed the crash on startup, ONLY. It's still bugged. Sorry, I should have specified. But the crash on startup is fixed, I feel that I can do all the rest of the debugging on my own, and if I can't, I'll ask on this forum for help if I can't figure it out.

Link to comment
Share on other sites

1 minute ago, Jack4096 said:

It ONLY fixed the crash on startup, ONLY. It's still bugged. Sorry, I should have specified. But the crash on startup is fixed, I feel that I can do all the rest of the debugging on my own, and if I can't, I'll ask on this forum for help if I can't figure it out.

Use your IDE's auto-formatter function to automatically apply overrides etc.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

3 hours ago, diesieben07 said:

Again, it is impossible that adding @Override has achieved this. You have done something else.

I have to admit, I made all this post and comments late at night when very sleepy. So I truly honestly do not remember if I did anything else, sorry.

Link to comment
Share on other sites

On 10/10/2018 at 3:25 PM, Cadiboo said:

Can you post your entire log using GitHub Gist or pastebin and your code as a github(or similar) repository?

 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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



×
×
  • Create New...

Important Information

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