TeamJM / journeymap

JourneyMap mod for Minecraft
http://journeymap.info
122 stars 10 forks source link

[Feature Request]: Add hooks to API enabling addons to selectively toggle visibility of overlay elements #640

Open Endgineer opened 9 months ago

Endgineer commented 9 months ago

Describe the new feature.

It would be nice to have the option to only show certain elements of the overall JourneyMap overlay IFF a player has certain items (might be from external mods, ideally specified by modid:itemid through configs) in their inventory (preferably should also check curio slots, which would also be a request to support curios in this feature).

For example, I hope to be able to do the following:

Images

No response

mysticdrew commented 9 months ago

Sorry, this is not something I will add to journeymap itself. However, it may be something that I could add hooks into the API for other mods to implement. Like GameStages or another specific addon.

Also note, journeymap for mc 1.18.x is no longer in development. Only 1.20.1+ versions.

Endgineer commented 9 months ago

Yeah, I was wondering if this was out of scope and I guess it is. Understandable.

Though the API hooks would probably be nice; giving the community the ability to create addons for JourneyMap controlling when certain elements of the overlay are shown/hidden, I mean.

Apologies about the version; it's been a while. It makes sense that 1.18 would be abandoned by lots of mods by now.

mysticdrew commented 9 months ago

Someone just sent me some KubeJS scripts for disabling the minimap. This could also be used for what you want, KubeJS is a mod that you can use to modify other mods by using a javascript. client_script.js

onEvent('client.tick', e => {
    if (e.level.time % 5 == 0.0) { // we could have this be more or less frequent if we wanted
    if (Client.player && Client.player.stages.has('journeymap')) {
        //global.JMmanager.setMiniMapEnabled(true);
        // If this is toggled, mini map will always be active
    }
    else {
        global.JMmanager.setMiniMapEnabled(false);
        global.JMwaypoints.getAll().forEach(point => {
            point.setEnable(false);
            point.setDirty();
        })
    }}
})

startup_script.js

const $JMFS = java('journeymap.client.ui.fullscreen.Fullscreen')
const $JMWE = java('journeymap.client.ui.waypoint.WaypointEditor')
const $JMWM = java('journeymap.client.ui.waypoint.WaypointManager')

console.info('Limiting Journeymap...')
onEvent('client.logged_in', e => {
    const $JMM = java('journeymap.client.ui.UIManager')
    const $JMW = java('journeymap.client.waypoint.WaypointStore')

    global.JMmanager = $JMM.INSTANCE
    global.JMwaypoints = $JMW.INSTANCE

    if (Client.player && !Client.player.stages.has('journeymap')) {
    global.JMmanager.setMiniMapEnabled(false); // No mini map for u :(

    global.JMwaypoints.getAll().forEach(point => {
        point.setEnable(false); // This makes waypoints invisible since they can still be shared/created on death
        point.setDirty(); // We need this to force a refresh of waypoints so that they're hidden
    })
}})

onForgeEvent('net.minecraftforge.client.event.ScreenOpenEvent', e => {
        // We check for e.screen and Client.player otherwise we get an error during startup when neither exist yet
    if (e.screen && Client.player && !Client.player.stages.has('journeymap')) {
        if (e.screen instanceof $JMFS || e.screen instanceof $JMWE || e.screen instanceof $JMWM) e.setCanceled(true);
}})

If you want to attempt to modify this for your needs, come into our discord and I help you with the hooks in JM that are needed to disable/enable JM things.

Endgineer commented 9 months ago

Had no clue this was possible. I probably wont do this anytime soon, but when I decide to, I'll be sure to pass by. Thanks!

Can I close this issue?

mysticdrew commented 9 months ago

No, let's leave it open to remind to add hooks for things in our api.