Jump to content

[1.8.9][SOLVED] Spawning item when the block is placed


Recommended Posts

Posted

Help me solve this problem.

When I place my block, i want an item to spawn. I tryed this method but it isn't working.

 

@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    	if(!worldIn.isRemote) {
		float f = 0.7F;
        double d = worldIn.rand.nextFloat() * f + (1.0F - f) * 0.5D;
        double d1 = worldIn.rand.nextFloat() * f + (1.0F - f) * 0.2D + 0.6D;
        double d2 = worldIn.rand.nextFloat() * f + (1.0F - f) * 0.5D;
        EntityItem entityitem = new EntityItem(worldIn, hitX + d, hitY + d1, hitZ + d2, new ItemStack(Items.apple, 1));
        //entityitem.delayBeforeCanPickup = 5;
        worldIn.spawnEntityInWorld(entityitem);
	}
    	return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
}

 

 

anyone knows solution? Thanks

 

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

Posted

Thanks, it works now. One more question, i see that pick up delay int (EntityItem.delayBeforeCanPickup ) is now private, is there any substitute?

 

new code

 

 

@Override
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    	if(!world.isRemote) {
		EntityItem entityitem = new EntityItem(world, pos.getX(), pos.getY()+1, pos.getZ(), new ItemStack(Items.apple, 1));
        //entityitem.delayBeforeCanPickup = 5;
        world.spawnEntityInWorld(entityitem);
	}
    	return super.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, meta, placer);
}

 

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

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.