JamCoreModding / right-click-harvest

Right click crops to harvest them - with style.
MIT License
14 stars 11 forks source link

Add support for Cocoa Beans and other random changes #1

Closed Fourmisain closed 3 years ago

Fourmisain commented 3 years ago

I really liked the implementation of your mod and the only thing that I felt was missing is support for Cocoa Beans, so I added it!

I also changed a few other things:

Fourmisain commented 3 years ago

P.S. The true motivation behind removing RightClickInit was the logger stuff:

Instead of something like

    public static void log(Level level, String message){
        LOGGER.log(level, "["+MOD_NAME+"] " + message);
    }

a logger should be given an appropriate name like Logger LOGGER = LogManager.getLogger("rightclickharvest"); and simply called via LOGGER.log(level, message) (or LOGGER.info etc). If you want to concatenate a string and print an exception you can do that too: LOGGER.log(level, message, "this is concatenated", exceptionToBePrinted);

One advantage of this is performance. In the above log method, the strings are always concatenated, even if they are never printed due to the log level, while the latter will only do this if necessary.

So how do you see the name of the logger? That's the kinda ugly part, but I find it oh so worth it. You need a custom log4j2.xml configuration file and need to start the game with -Dlog4j.configurationFile=log4j2.xml (when putting the file in the minecraft instance base directory, else /path/to/log4j2.xml).

Here's the default log4j2.xml file Minecraft uses (up to 1.16.5, I don't think it changed in 1.17).

There you can set exactly which data is logged in what format (and where to), e.g. if you use a pattern layout like <PatternLayout pattern="[%d{HH:mm:ss}] [%level/%t] [%logger] %msg%n" /> it'll print something like

[16:58:15] [INFO/main] [rightclickharvest] actual message

You can enable debug logging for specific loggers by adding <Logger name="loggername" level="debug"></Logger> above the <Root ...> logger, or change the root logger - which can be very interesting because you'll see tons of MC internals (which you can then filter for, once you know the logger names).

Debug logging can also be enabled programmatically, we used that for Falling Leaves to enable it via a config switch.

It's also possible to suppress certain loggers (e.g. when they spam your server log).

I can tell you a little more about this if you're interested.

Jamalam360 commented 3 years ago

Thanks, I'll merge and release this tomorrow. Only reason I had that class was because I generated the project with GeneratorFabricMod