#fix up nether access script
160 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
Paste version of nethergate.js from @shell ferry
so ya... regardless of the achivment done or not, players can enter the nehter if they find a portal already lit.
and on Servers... they appear more and more. not sure how to rectify that , or even if its possible to.
i dont think that script does what you think it should do
also the formatting is almost unreadable 
player.block is the block the player is standing on, to start with
Hey I never made this. Lol someone from here shared it. And Ive been using it
Suppose to gate nether access by achievement
I got an achievement for killing warden. Then u get access. But without killing warden u can still access if portal already lit . But portal loses its portal after
[➤](#1166308080317907014 message)
PlayerEvents.tick(event => {
const {player,server,player:{username}} = event
if(!(player.age % 20 == 0)) return
if (player.persistentData.canaccessnetherportal == 1) return
if (player.block.id == 'minecraft:nether_portal') {
player.block.set('air')
player.displayClientMessage(Component.of('The forces of the universe deny your impudence').bold().red(), true)
}else if (player.block.west == 'minecraft:nether_portal'){
player.block.west.set('air')
player.displayClientMessage(Component.of('The forces of the universe deny your impudence').bold().red(), true)
}else if (player.block.east == 'minecraft:nether_portal'){
player.block.east.set('air')
player.displayClientMessage(Component.of('The forces of the universe deny your impudence').bold().red(), true)
}else if (player.block.north == 'minecraft:nether_portal'){
player.block.north.set('air')
player.displayClientMessage(Component.of('The forces of the universe deny your impudence').bold().red(), true)
}else if (player.block.south == 'minecraft:nether_portal'){
player.block.south.set('air')
player.displayClientMessage(Component.of('The forces of the universe deny your impudence').bold().red(), true)
}
})
PlayerEvents.advancement(event => {
if(event.advancement.id().toString() == "minecraft:story/mine_diamond") {
event.player.persistentData.canaccessnetherportal = 1
}
})```
@rain knoll what is this travesty 
oh thats been revised long ago 
sec
PlayerEvents.tick(event => {
const { player, player: { block, block: { id, south, west, north, east } } } = event;
if (!(player.age % 20 == 0) || player.isCreative() || player.isSpectator()) return;
const destroyPortalAndDisplayMessage = (targetBlock) => {
targetBlock.set('air');
player.displayClientMessage(Component.of(`It looks like a mysterious force prevents entry.. I'll have to find another way.`).bold().green(), true);
};
switch (true) {
case id === 'minecraft:nether_portal':
destroyPortalAndDisplayMessage(block);
break;
case west === 'minecraft:nether_portal':
destroyPortalAndDisplayMessage(west);
break;
case east === 'minecraft:nether_portal':
destroyPortalAndDisplayMessage(east);
break;
case north === 'minecraft:nether_portal':
destroyPortalAndDisplayMessage(north);
break;
case south === 'minecraft:nether_portal':
destroyPortalAndDisplayMessage(south);
break;
default:
break;
}
});``` try this
wait what do you mean by already lit, it shouldnt matter if its lit already or not, it should break regardless if they dont have the acheivement
do you have a mod that insta teles them like if they were in creative mode or something?
Hey @shell ferry do you need to destroy the portal or just stop the player from going through if they aren't allowed Nether Access yet?
he wants to stop the player from going to the nether i think
im looking into morejs teleport event rn
I'm gating access. Don't need to be destroyed. Don't really care if it do either lol
Why not just do this?
\server_scripts\player_dim.js
global.dimChangeEvent = event => {
let player = event.getEntity();
let targetDimension = event.dimension.location();
let server = player.getServer();
if (targetDimension == 'minecraft:the_nether') {
if (!player.stages.has('nether_access')) {
player.statusMessage = Text.of("The portal doesn't seem to work...");
server.schedule(2*1000, ()=> player.statusMessage = Text.of("You have not unlocked the ability to use this portal, you must kill the warden first!"));
return event.setCanceled(true);
} else {
event.setCanceled(false);
}
}
}```
what event does this use?
And:
startup_scripts\player_dim.js
ForgeEvents.onEvent("net.minecraftforge.event.entity.EntityTravelToDimensionEvent", (event) => {
global.dimChangeEvent(event);
});
It works flawlessly in 1.20.1
yeah thats probably cleaner than the one i sent over
To break it down simply...
Player tries to enter the portal, the target dimension is checked, if it's the nether they aren't allowed to travel and get a message.
I use this in my pack to block access to any dimension that isn't unlocked
Then just add the gamestage to the player and they can enter
So once the warden is killed, give them nether_access
also you can just do js event.dimension == 'minecraft:the_nether' i believe
You're welcome to try, but rhino makes assumptions and tries to turn it into a resource so instead of fighting it I used the resource key instead
sorry what
LOL

If you use the namespace dimension string like that, you'll get an error in the log about an invalid resource location.
Rhino or Kube does something dumb with namespaced dimension strings and turns it into the resource key, so if you do a string compare like that, it fails. I instead used the actual ResourceKey that it was expecting to avoid having to cast to string and compare that way.
all I know is what I provided above works perfectly for me. ¯_(ツ)_/¯
I don't get paid to write code, no professional training, I'm a Server Admin, this is just a hobby 🙂
ah yes its js event.dimension.location()
returns the resourcelocation instead of the key
this way you dont need to parse to string and read from it
so better performance(marginally) as well
but yeah wouldnt make a huge diff
Sure, feel free to update what I did with a working example for the OP to use 🙂
I haven't tested your proposed change, so I don't want to insist it works.
I am now too
it used to be event.dimension in 1.19 but 1.20 i think added the .location() aspect
in normal kubejs events its event.player.dimension with no need for .location()
probably why not many people know about it

Ok, yeah that's cleaner and works
Updated above
Thanks @rain knoll I learned something today 🙂
same same
just wanted to put it in file format. i believe these are the end result to work for 1.20.1 forge. tested and confirmed working in my modpack. 🙂 thanks you guys.
Paste version of player_dim.js, player_dim.js from @shell ferry
happy to help
Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue! This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.
Do you have any other questions regarding your issue? Feel free to ask!
Note: You generally should create a new post for unrelated issues.
Ticket re-opened!
Paste version of crash-2024-02-26_12.24.08-server.txt from @shell ferry
@steel furnace the fun starts. lol im not sure how common this crash wlil happen... and even if it can be avoided using this method?
Uhh
Did something else go through the portal? Might need to do an entity check I guess
Yep, I get that error when a sheep goes through the portal. Hold on, let me get a fix
Yep, I can reproduce, hold on a sec
why not just return early if the entity isnt a player?
if (!player.isPlayer()) return```

global.dimChangeEvent = event => {
if (! event.getEntity().player) return;```
That works for me
do you even need the else block with the event.setCanceled(false);? Isn't that a redundant default?
probably not
I like to overcomplicate things sometimes
over-engineered is a way of life
probably also don't need to return event.setCancelled(true) and can just cancel it.
global.dimChangeEvent = event => {
if (!event.getEntity().player) return;
let player = event.getEntity();
let targetDimension = event.dimension.location();
let server = player.getServer();
if (targetDimension == 'minecraft:the_nether') {
if (!player.stages.has('nether_access')) {
player.statusMessage = Text.of("The portal doesn't seem to work...");
server.schedule(2 * 1000, () => player.statusMessage = Text.of("You have not unlocked the ability to use this portal!"));
event.setCanceled(true);
}
}
}```
A little cleaner 🙂 Works for all dimensions
I'd directly add the event.dimension.location() into the if tbh
it's only used once anyway
and I might merge the 2 ifs into one using a boolean and
yup, of course if you are using it somewhere else don't do that
There's no real performance gain from any of that, it just shrinks the code more. I like to keep things a bit more readable.
It's why I use event and not e
global.dimChangeEvent = event => {
if (!event.getEntity().player) return;
let player = event.getEntity();
let server = player.getServer();
if (event.dimension.location() == 'minecraft:the_nether' && !player.stages.has('nether_access') {
player.statusMessage = Text.of("The portal doesn't seem to work...");
server.schedule(2 * 1000, () => player.statusMessage = Text.of("You have not unlocked the ability to use this portal!"));
event.setCanceled(true);
}
}
I'm not trying to save 8bytes of code to take up less lines and whitespace
I use event too but I prefer single line ifs
I find indents hard to follow
so I reduce indents
but otherwise I don't try reduce stuff
You're not contributing anything useful though, just rewriting my code to your preference.
I was trying to help with code organisation
But that's a preference
the removing of the variable wasn't, that was to make it clearer
The OP didn't ask for help making the code take up less lines, space or fit a coding style
they can still choose either, I just wanted to offer an alternative solution ¯_(ツ)_/¯
They asked for a solution, I provided one and then you come in trying to shrink it and format it differently without changing the functionality.
It's not an alternative solution
no need to get heated I'm jsut trying to help make stuff more readable
okay alternative formatting then
however you want to phrase it
You offer great ideas in other threads, I'm not challenging your skills, but what you are doing here is just annoying
how is helping formatting annoying (even if it's subjective)? Plus if you disagree just state it, no need to attack what I'm doing
just going to repost both lots of the code so it can be seen and isnt buried by this tangent
global.dimChangeEvent = event => {
if (!event.getEntity().player) return;
let player = event.getEntity();
let targetDimension = event.dimension.location();
let server = player.getServer();
if (targetDimension == 'minecraft:the_nether') {
if (!player.stages.has('nether_access')) {
player.statusMessage = Text.of("The portal doesn't seem to work...");
server.schedule(2 * 1000, () => player.statusMessage = Text.of("You have not unlocked the ability to use this portal!"));
event.setCanceled(true);
}
}
or
global.dimChangeEvent = event => {
if (!event.getEntity().player) return;
let player = event.getEntity();
let server = player.getServer();
if (event.dimension.location() == 'minecraft:the_nether' && !player.stages.has('nether_access') {
player.statusMessage = Text.of("The portal doesn't seem to work...");
server.schedule(2 * 1000, () => player.statusMessage = Text.of("You have not unlocked the ability to use this portal!"));
event.setCanceled(true);
}
}
both should do the same thing, the bottom is just more compact
global.dimChangeEvent = event => {
const {entity:{player,server,statusMessage,stages},dimension} = event
if (!player) return;
if (dimension.location() == 'minecraft:the_nether' && !stages.has('nether_access')) {
statusMessage = Text.of("The portal doesn't seem to work...");
server.schedule(2 * 1000, () => statusMessage = Text.of("You have not unlocked the ability to use this portal!"));
event.setCanceled(true);
}
}``` 
much appricated guys hahaha been a thrill to read lol
using this as a test... it works but no text on screen. weird.

It's cuz he dropped player. from player.statusMessage
see, shortening code and making it less readable for the noobs isn't always the best way
player is entity though
let player = event.getEntity();
and we're going off the entity

You aren't using statusMessage though, it's just an unused variable.
My code may have had nested if statements and used more lines to get things done but for someone that is a novice or noob coder, it was easier to read and actually worked 😛
should be used
but it's not sending to the player
yes
thats what this is js const {entity:{statusMessage}} = event
I don't think it's working the way you think it should though
uh
would you say this would be the correct way then? js let statusMessage = event.entity.statusMessage
Yeah, I would think so, I'd have to test to see if it works the same way.
ok, its the same as this just so you know
which means its not the issue here
I've found that things don't always work the way you'd expect
Mine works for me, so I'm keeping what I've got. I like where your head's at with assigning those variables off the event like that but it's breaking something.
I have to agree with darklotus on this one. His script does all that is intended and easy to read and manipulate. Works as intended.

ok why does this work js global.dimChangeEvent = event => { const { entity, entity: { player, server, stages }, dimension } = event if (!player) return if (dimension.location() == 'minecraft:the_nether' && !stages.has('nether_access')) { entity.statusMessage = Text.of("The portal doesn't seem to work..."); server.schedule(2 * 1000, () => entity.statusMessage = Text.of("You have not unlocked the ability to use this portal!")); event.setCanceled(true); } }
yeah i mean either one should work
??closeticket
Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue! This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.
Do you have any other questions regarding your issue? Feel free to ask!
Note: You generally should create a new post for unrelated issues.
