#How to make a block open a form

1 messages · Page 1 of 1 (latest)

mossy basalt
#

I'm searching for a method to make a block open a form when the player interacts with it without any item on hand, i already managed to do that with getBlockFromViewDirection, but it doesn't work as i expected on mobile devices, so i need another method. If anyone could help me, i would be grateful

high ore
#

its not possible currently but if you're okay with players requiring an item on their hand to click on a block then we can implement that

#

or if you are using a custom block

mossy basalt
stuck jewel
#

Just run /scriptevent in a command in a block event

high ore
mossy basalt
#

you can only get either sourceEntity or sourceBlock

mossy basalt
stuck jewel
#

for the scriptevent

mossy basalt
# stuck jewel event?
system.events.scriptEventReceive.subscribe((eventData)=>{
    const player = eventData.sourceEntity
    const block = eventData.sourceBlock;
    const blockLocation = block.location;

    const { x, y, z } = blockLocation
    
    if (eventData.id == "way:open_form") {
        try {
            if (block.hasTag('ender_altar') && block.hasTag('active') == true && !player.isSneaking) {
                ender_altarScreen(player, player.dimension.id, player.level, x, y, z)
            }
        } catch { }
    }
})```
mossy basalt
stuck jewel
#

you cant get both the block and the player

mossy basalt
mossy basalt
#

why?

stuck jewel
#

idk either

mossy basalt
#

i was using getViewBlockDirection

stuck jewel
#

two events

mossy basalt
# stuck jewel two events

like this?

system.events.scriptEventReceive.subscribe((eventData) => {
    const player = eventData.sourceEntity
    if (eventData.id == "way:open_form") {
        system.events.scriptEventReceive.subscribe((eventData) => {
            const block = eventData.sourceBlock;
            const blockLocation = block.location;

            const { x, y, z } = blockLocation

            if (eventData.id == "way:open_form2") {
                try {
                    if (block.hasTag('ender_altar') && block.hasTag('active') == true && !player.isSneaking) {
                        ender_altarScreen(player, player.dimension.id, player.level, x, y, z)
                    }
                } catch { }
            }
        })
    }
})```
stuck jewel
#

maby you might unsubscribe the secound one but you have trigger the event for the block and the player

stuck jewel
# mossy basalt how can i do that?
{
    "events": {
        "test": {
            "run_command": {
                "command": [
                    "scriptevent"
                ],
                "target": "other"
            },
            "trigger": {
                "event": "block"
            }
        },
        "block": {
            "run_command": {
                "command": [
                    "scriptevent"
                ],
                "target": "self"
            }
        }
    }
}```
mossy basalt
#

oh

#

thanks

mossy basalt
stuck jewel
#

player then block yes

mossy basalt
mossy basalt
stuck jewel
# mossy basalt oh

but ```js
const callback = (eventData) => {
const block = eventData.sourceBlock;
const blockLocation = block.location;

        const { x, y, z } = blockLocation

        if (eventData.id == "way:open_form2") {
            try {
                if (block.hasTag('ender_altar') && block.hasTag('active') == true && !player.isSneaking) {
                    ender_altarScreen(player, player.dimension.id, player.level, x, y, z)
                }
            } catch { }
        }

system.events.scriptEventReceive.unsubscribe(callback);
};
system.events.scriptEventReceive.subscribe(callback);

mossy basalt
# stuck jewel but ```js const callback = (eventData) => { const block = eventData....

like this?

system.events.scriptEventReceive.subscribe((eventData) => {
    const player = eventData.sourceEntity
    if (eventData.id == "way:open_form") {
        const callback = (eventData) => {
            const block = eventData.sourceBlock;
            const blockLocation = block.location;
        
            const { x, y, z } = blockLocation
        
            if (eventData.id == "way:open_form2") {
                try {
                    if (block.hasTag('ender_altar') && block.hasTag('active') == true && !player.isSneaking) {
                        ender_altarScreen(player, player.dimension.id, player.level, x, y, z)
                    }
                } catch { }
            }
        system.events.scriptEventReceive.unsubscribe(callback);
        };
        system.events.scriptEventReceive.subscribe(callback);
    }
})```
#

still getting this error but it seens to work normally

mossy basalt