Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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());
            }
        }
    }

 

  • Author

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. 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.