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

I'm brand new to Forge and Minecraft modding, never done anything like this before.

 

As a test, I wanted to just print a message when the player clicks a dirt block. I created a simple block class:

 

public class BlockLogger extends Block {
    private static final Logger LOGGER = LogManager.getLogger();

    public BlockLogger(Properties properties) {
        super(properties);
    }

    @Override
    public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
        if (!worldIn.isRemote()) {
            LOGGER.warn("Clicked!");
            player.sendMessage(new StringTextComponent("Clicked!"));
        }
        return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
    }
}

 

I registered the block in the root class of my mod with the following:

 

Registry.register(Registry.BLOCK, "dirt", new BlockLogger(Block.Properties.create(Material.EARTH, MaterialColor.DIRT).hardnessAndResistance(0.5F).sound(SoundType.GROUND)));

 

Running this, if I right-click the block with an open hand or a tool, I get two "Clicked!" messages. If I right-click the block with another place-able block, I get only one message like I expect. This behavior persists regardless of whether or not I call the parent's onBlockActivated method, but that's not surprising, it doesn't seem that the parent does anything other than returning PASS.

 

What's going on here? I don't suspect a client / server issue since it does work with a place-able block. Have I registered it wrong? Is this just entirely the wrong way to do this? Or is this intended behavior?

 

Thanks.

 

 

1 hour ago, TechnoSam said:

Hand handIn

The player has two hands.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Oh wow, I didn't even think about that. Thanks a bunch!

 

I added the hand to the chat message so I could investigate what was going on. It seems like it triggers once for each hand in almost all scenarios. It triggers with only the main hand when right clicking with a block in the main hand. With a block in the off hand, it still triggers once for each hand. I can't manage to get only off hand.

 

What's the logic there? If I place a block from my off hand, wouldn't I want to only get one event? It seems like that makes it impossible to build an action that happens only when clicking with the off hand. (Not that I want to do that, I'm just trying to understand how the system works.)

The main hand is checked. If something happens with the item or block as a result of the main hand (ItemActionResult.SUCCESS), the off hand is not checked.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.