Jump to content

Spawning Projectile Through OnBlockActivated


Recommended Posts

I have a custom block that I want to spawn an arrow projectile on its front face every time a player right clicks said block while holding cobblestone. I've been digging around google and most people who wanted to achieve a similar effect seemed to have used the worldIn.spawnEntityInWorld(). I cannot, however, find said method in the world class, and judging from how the forum posts I've referenced are all 2yrs+ old, I'm guessing this method has been removed. Any ideas how I can achieve this in minecraft 1.12? 


This is the code for my custom block if it helps:

public class TrebuchetBlock extends BlockBase{

	public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
	public TrebuchetBlock(String name, Material material) {
		super(name, material);
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float side, float hitX, float hitY){
    	if(worldIn.isRemote) {
        	if(playerIn.getHeldItemMainhand().getItem().equals(Item.getItemFromBlock(Blocks.COBBLESTONE))) {
        		//Insert solution here
        		return true;
        		return true;
    		return false;
    protected BlockStateContainer createBlockState(){
        return new BlockStateContainer(this, new IProperty[] {FACING});

    public IBlockState withRotation(IBlockState state, Rotation rot){
        return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    public IBlockState withMirror(IBlockState state, Mirror mirrorIn){
        return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
    public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    public int getMetaFromState(IBlockState state){
        int i = 0;
        i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
        return i;
    public IBlockState getStateFromMeta(int meta){
        return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));


Link to comment
Share on other sites

9 minutes ago, Lumby said:


Its changed from that to World#spawnEntity

  • Thanks 1


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.

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.