Jump to content

Crash on placing MagicLog when inheriting from BlockLog


Jack4096

Recommended Posts

The line stating the error from the crash report:

 

java.lang.IllegalArgumentException: Cannot set property PropertyEnum{name=axis, clazz=class com.jack.tutorialmod.blocks.MagicLog$EnumAxis, values=[x, y, z, none]} as it does not exist in BlockStateContainer{block=tm:magic_log, properties=[axis]}

 

I am attempting to have class MagicLog extends (inherit from) BlockLog class. The game crashes when I place MagicLog. It has a texture and is named properly when it is in my character's hand, although for some reason it is all the bark texture. Here's my code:

 

public class MagicLog extends BlockLog implements IHasModel {
    
    public static final PropertyEnum<MagicLog.EnumAxis> LOG_AXIS = PropertyEnum.<MagicLog.EnumAxis>create("axis", MagicLog.EnumAxis.class);

    public MagicLog(String name)
    {
        super();
        
        setUnlocalizedName(name);
        setRegistryName(name);
        
        ModBlocks.BLOCKS.add(this);
        ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
    }

    /**
     * Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
     */
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
    {
        int i = 4;
        int j = 5;

        if (worldIn.isAreaLoaded(pos.add(-5, -5, -5), pos.add(5, 5, 5)))
        {
            for (BlockPos blockpos : BlockPos.getAllInBox(pos.add(-4, -4, -4), pos.add(4, 4, 4)))
            {
                IBlockState iblockstate = worldIn.getBlockState(blockpos);

                if (iblockstate.getBlock().isLeaves(iblockstate, worldIn, blockpos))
                {
                    iblockstate.getBlock().beginLeavesDecay(iblockstate, worldIn, blockpos);
                }
            }
        }
    }

    /**
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
     * IBlockstate
     */
    public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
        return this.getStateFromMeta(meta).withProperty(LOG_AXIS, MagicLog.EnumAxis.fromFacingAxis(facing.getAxis()));
    }

    /**
     * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
     * blockstate.
     */
    public IBlockState withRotation(IBlockState state, Rotation rot)
    {
        switch (rot)
        {
            case COUNTERCLOCKWISE_90:
            case CLOCKWISE_90:

                switch ((MagicLog.EnumAxis)state.getValue(LOG_AXIS))
                {
                    case X:
                        return state.withProperty(LOG_AXIS, MagicLog.EnumAxis.Z);
                    case Z:
                        return state.withProperty(LOG_AXIS, MagicLog.EnumAxis.X);
                    default:
                        return state;
                }

            default:
                return state;
        }
    }

    @Override public boolean canSustainLeaves(IBlockState state, net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; }
    @Override public boolean isWood(net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; }

    public static enum EnumAxis implements IStringSerializable
    {
        X("x"),
        Y("y"),
        Z("z"),
        NONE("none");

        private final String name;

        private EnumAxis(String name)
        {
            this.name = name;
        }

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

        public static MagicLog.EnumAxis fromFacingAxis(EnumFacing.Axis axis)
        {
            switch (axis)
            {
                case X:
                    return X;
                case Y:
                    return Y;
                case Z:
                    return Z;
                default:
                    return NONE;
            }
        }

        public String getName()
        {
            return this.name;
        }
    }
    
    @Override
    public void registerModels() {
        Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
    }
    
}

 

If you need more information on the error to help solve it, please do ask if it will help. I should also mention that I do not know how to make it so that the block does not have all the same texture (The MagicLog's bark texture) on all sides of the block. It would be appreciated if someone explained how to give it the top of the block's texture (The non-bark part that shows the inside of the wood, like on a vanilla log) on the top of the block.

Link to comment
Share on other sites

14 minutes ago, Jack4096 said:

If you need more information on the error to help solve it, please do ask if it will help. 

Does BlockLog override the createBlockState method, and if it does does it add the AXIS property to the BlockStateContainer? If neither is true you need to do so.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

37 minutes ago, Animefan8888 said:

Does BlockLog override the createBlockState method, and if it does does it add the AXIS property to the BlockStateContainer? If neither is true you need to do so.

So Anime fan, I added this to the code:

 

@Override
    protected BlockStateContainer createBlockState() {
        return super.createBlockState();
    }

 

So this is the code now:

 

public class MagicLog extends BlockLog implements IHasModel {
    
    public static final PropertyEnum<MagicLog.EnumAxis> LOG_AXIS = PropertyEnum.<MagicLog.EnumAxis>create("axis", MagicLog.EnumAxis.class);

    public MagicLog(String name)
    {
        super();
        
        setUnlocalizedName(name);
        setRegistryName(name);
        
        ModBlocks.BLOCKS.add(this);
        ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
    }
    
    @Override
    protected BlockStateContainer createBlockState() {
        return super.createBlockState();
    }

    /**
     * Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
     */
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
    {
        int i = 4;
        int j = 5;

        if (worldIn.isAreaLoaded(pos.add(-5, -5, -5), pos.add(5, 5, 5)))
        {
            for (BlockPos blockpos : BlockPos.getAllInBox(pos.add(-4, -4, -4), pos.add(4, 4, 4)))
            {
                IBlockState iblockstate = worldIn.getBlockState(blockpos);

                if (iblockstate.getBlock().isLeaves(iblockstate, worldIn, blockpos))
                {
                    iblockstate.getBlock().beginLeavesDecay(iblockstate, worldIn, blockpos);
                }
            }
        }
    }

    /**
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
     * IBlockstate
     */
    public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
        return this.getStateFromMeta(meta).withProperty(LOG_AXIS, MagicLog.EnumAxis.fromFacingAxis(facing.getAxis()));
    }

    /**
     * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
     * blockstate.
     */
    public IBlockState withRotation(IBlockState state, Rotation rot)
    {
        switch (rot)
        {
            case COUNTERCLOCKWISE_90:
            case CLOCKWISE_90:

                switch ((MagicLog.EnumAxis)state.getValue(LOG_AXIS))
                {
                    case X:
                        return state.withProperty(LOG_AXIS, MagicLog.EnumAxis.Z);
                    case Z:
                        return state.withProperty(LOG_AXIS, MagicLog.EnumAxis.X);
                    default:
                        return state;
                }

            default:
                return state;
        }
    }

    @Override public boolean canSustainLeaves(IBlockState state, net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; }
    @Override public boolean isWood(net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; }

    public static enum EnumAxis implements IStringSerializable
    {
        X("x"),
        Y("y"),
        Z("z"),
        NONE("none");

        private final String name;

        private EnumAxis(String name)
        {
            this.name = name;
        }

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

        public static MagicLog.EnumAxis fromFacingAxis(EnumFacing.Axis axis)
        {
            switch (axis)
            {
                case X:
                    return X;
                case Y:
                    return Y;
                case Z:
                    return Z;
                default:
                    return NONE;
            }
        }

        public String getName()
        {
            return this.name;
        }
    }
    
    @Override
    public void registerModels() {
        Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
    }
    
}

 

And it gives this error in the crash report, after crashing on startup:

 

java.lang.IllegalArgumentException: Cannot set property PropertyEnum{name=axis, clazz=class com.jack.tutorialmod.blocks.MagicLog$EnumAxis, values=[x, y, z, none]} as it does not exist in BlockStateContainer{block=tm:magic_log, properties=[axis]}

 

I don't know how to get past this error, but you said something about adding the AXIS property to the BlockStateContainer. I just don't know how to add it, I tried to figure it out, but I couldn't figure it out. Help is appreciated.

Link to comment
Share on other sites

1 hour ago, Jack4096 said:

I don't know how to get past this error, but you said something about adding the AXIS property to the BlockStateContainer. I just don't know how to add it, I tried to figure it out, but I couldn't figure it out. Help is appreciated.

Create a new instance of a BlockStateContainer that has a PropertyEnum of the type EnumFacing.Axis.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 hour ago, Jack4096 said:

Sorry, I tried to figure out how to do that and didn't succeed in figuring out how, so could you please explain further?

If you look in BlockLog1(I think that is the name) you can look at what they did.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.



×
×
  • Create New...

Important Information

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