Jump to content

Recommended Posts

Posted

I made a custom cake. When i place it in the world the game crashes.

here is the crash:

 

  Reveal hidden contents

 

 

Here is the code for cheeseblock:

 

  Reveal hidden contents

 

 

And here for the item:

 

public class ItemCheeseCake extends Item{

private final Block block;

    public ItemCheeseCake(Block block, String unlocalname, String registryname)
    {
        this.block = block;
        this.setUnlocalizedName(unlocalname);
        this.setRegistryName(registryname);
        this.setMaxStackSize(1);
        setCreativeTab(Tem.itemstab);
    }

    public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();

        if (block == Blocks.SNOW_LAYER && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
        {
            facing = EnumFacing.UP;
        }
        else if (!block.isReplaceable(worldIn, pos))
        {
            pos = pos.offset(facing);
        }

        if (playerIn.canPlayerEdit(pos, facing, stack) && stack.stackSize != 0 && worldIn.canBlockBePlaced(this.block, pos, false, facing, (Entity)null, stack))
        {
            IBlockState iblockstate1 = this.block.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, 0, playerIn);

            if (!worldIn.setBlockState(pos, iblockstate1, 11))
            {
                return EnumActionResult.FAIL;
            }
            else
            {
                iblockstate1 = worldIn.getBlockState(pos);

                if (iblockstate1.getBlock() == this.block)
                {
                    ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack);
                    iblockstate1.getBlock().onBlockPlacedBy(worldIn, pos, iblockstate1, playerIn, stack);
                }

                SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, worldIn, pos, playerIn);
                worldIn.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                --stack.stackSize;
                return EnumActionResult.SUCCESS;
            }
        }
        else
        {
            return EnumActionResult.FAIL;
        }
    }
}

I can't see what's wrong

Posted

It looks like you passed a

null

Block

to

World#canBlockBePlaced

from

ItemCheeseCake#onItemUse

.

 

Side note: It looks like you've copy-pasted the vanilla cake code. Why not just use/extend the existing classes?

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.

Posted
  On 11/3/2016 at 1:40 PM, Choonster said:

It looks like you passed a

null

Block

to

World#canBlockBePlaced

from

ItemCheeseCake#onItemUse

.

 

Side note: It looks like you've copy-pasted the vanilla cake code. Why not just use/extend the existing classes?

Ow yes true, because i register items before blocks and the item needs to know wich block to use.

I'll try the extending way. I was not sure that would work properly.

But the main reason is i hate to do this:

.setfunction1.setfunction2.setfunction3.setfunction4.setfunction5

Posted
  On 11/3/2016 at 1:49 PM, winnetrie said:

Ow yes true, because i register items before blocks and the item needs to know wich block to use.

Block

s should be created and registered before

Item

s.

 

You should be using the new registry events,

RegistryEvent.Register<Block>

will be fired before

RegistryEvent.Register<Item>

.

 

  Quote

I'll try the extending way. I was not sure that would work properly.

But the main reason is i hate to do this:

.setfunction1.setfunction2.setfunction3.setfunction4.setfunction5

If you don't want to call a bunch of setter methods at the place of instantiation, move them to the constructor.

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.

Posted
  On 11/4/2016 at 3:38 PM, winnetrie said:

Where do i find this "new" registryEvent? What forge version is this?

How do i use it?

 

RegistryEvent

and

ModelRegistryEvent

were added in Forge 1.10.2-12.18.1.2092 (this commit).

 

I explain them here.

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.

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.