Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Spawning entity when block is hit


Recommended Posts

Hello, I am going through a minecraft mod course, and I have been tasked with creating an event, but struggling to complete this. I have only started the course the past few days so I am not familiar with a lot of the code needed. I am wanting to spawn a sheep when a specific modded block is hit with a specific item, but I can not figure out how to spawn the sheep. I originally wanted the sheep to spawn at the blocks location, but I have read that blocks do not keep their position data, so i had to change it to the players location, but I just can't figure out the spawning part.

From the code, you can see that I am trying to use addEntity, I am not sure if this is the correct way, as I have also seen spawn being used. But I am lost at what the arguments should be for SheepEntity(). 

Also if anyone could point me in the direction to be able to read about these functions etc, it would be appreciated. I have used the docs here, but found not many things are covered (maybe I am using it wrong)

 

@SubscribeEvent
    public void onCopperBlockAppleHit(BlockEvent.BreakEvent event)
    {

        Block block = event.getState().getBlock();
        PlayerEntity player = event.getPlayer();

        World world = player.getEntityWorld();


        if(event.getPlayer().getHeldItemMainhand().getItem() == ModItems.COPPER_APPLE.get())
        {
            if(block == ModBlocks.COPPER_BLOCK.get())
            {
                //world.addEntity(new SheepEntity(world, player.getPosX(), player.getPosY(), player.getPosZ()
                //       new SheepEntity())



                String msg = TextFormatting.YELLOW + "Spawned entity!";
                player.sendMessage(new StringTextComponent(msg), player.getUniqueID());
            }
        }
    }

 

Link to post
Share on other sites

Hello, thank you for the answers, but I am still having trouble. I have managed to use the getPos for the block. But struggling with the spawn. I find no spawn function to use. Ive tried going into the Entity class and I do not see anything there either. Could you please show me how this would be used. 

Link to post
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.

Guest
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 Privacy Policy.