Posted June 13, 20205 yr 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.
June 13, 20205 yr 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.
June 13, 20205 yr 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.)
June 14, 20205 yr 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.