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.