#How to create custom portals with PortalJS

321 messages Β· Page 1 of 1 (latest)

twilit egret
#

With the following code with the PortalJS mod:

PortalEvents.register(event => {
    event.create()
        .frameBlock("minecraft:glowstone")
        .lightWithWater()
        .setDestination("minecraft:the_nether")
})
graceful quartz
#

sick

twilit egret
dense current
#

very cool

#

now make it generate dimensions at runtime

nova bear
#

would be cooler if you could replace or remove existing portals

twilit egret
#

true

nocturne pewter
#

Can portalJS change the color of the portals? I couldn't pull that off with just hooking into the API

twilit egret
#

Yes you can with .tint(r, g, b) and with .tint(0x[hex code])

nocturne pewter
#

MMM I tried that back with the API, but it always gave me back the black/gray portal

twilit egret
#

With PortalJS?

#

Doing .tint(255, 255, 255) makes it white

vernal wing
#

I hava a idea

#

Portal to Alfheim but only implements it with kubejs

Feed The Beast Wiki

The Portal to Alfheim is a multiblock structure added by Botania. It allows the player to exchange certain blocks and items. Unlike most portals, the Portal to Alfheim cannot be travelled through; if the player were to stand in it, it would not teleport them anywhere.
If the portal runs out of Mana, or a part of the structure is broken, the Port...

dense current
#

honestly wouldnt be that hard

twilit egret
#

I did not know Botany did that 😭

dense current
#

@vernal wing that isnt even a portal. that could be done in "vanilla" kjs

twilit egret
#

How to create custom portals with PortalJS

#

Unlike most portals, the Portal to Alfheim cannot be travelled through; if the player were to stand in it, it would not teleport them anywhere.
You can do this with

.beforeTeleportation(entity => return ShouldTP.CANCEL)
vernal wing
vernal wing
#

This is a cool addon

dense current
#

hmm, yeah that would be possible

dense current
vernal wing
#

This mod has been made public on curseforge!

twilit egret
#

You can do

.beforeTeleportation(entity => {
  // your code here
  return ShouldTP.CANCEL
})
vernal wing
untold archBOT
#

Paste version of mclo.gs/mfMtbUp from @vernal wing

vernal wing
#

ah crash

untold archBOT
#

Paste version of latest-snippet.log from @vernal wing

twilit egret
#

ahhh that's why

#

apparently I do really need a blank mixin json

#

@vernal wing uploading patch

twilit egret
#

@vernal wing download the new one

#

Plans for next update or something

  • .onRandomTick(context => {...}) Like how the nether portal spawns randomlly
  • "replace or remove existing portals" - @dense current
  • Generate dimension at runtime 😭
dense current
#

nd what about generating dimensions at runtime :HMMM:

twilit egret
#

why

#

😭

dense current
#

BE CAUSE

#

its cool

twilit egret
#

How would I even do that??

dense current
#

and i need it for my project

#

like this or something

twilit egret
#

throw an item in the portal

dense current
#

but with kjs implementation

twilit egret
#

Hm

#

I'll see what I can do

twilit egret
#

Ohhhh idea maybe

#

where in order to light the portal, you would need to have blocks around the portal, where you could do .canIgnite(levelOrSomething => {}) and you would have to have stuff fullfilled before it can be ignited

#

just an idea

grand robin
#

Damn. 1.21. Great work regardless. This is really cool.

twilit egret
#

thanks :D

grand robin
#

One thing that would be nice is if there were some built in functionality to just try igniting a portal of a certain type at a position. Because as it is now, It seems like if I wanted to do something like, For example, Throwing an experience bottle at the frame of the portal to ignite it, That would not be possible. Similarly, A Twilight Forest style portal opening where you toss an item through the structure would also not be possible.

dense current
twilit egret
twilit egret
#

Going to include infiniverse API into the mod

twilit egret
dense current
#

Hahahahhaha

#

I love you

twilit egret
#

Should I include it or just package it with it?

#

Meaning like you need to have it downloaded

#

or I just include it...

#

hm

dense current
#

Package it

#

So it's easier

#

May need to check their license

twilit egret
#

they said it's fine

#

Asked in neoforge server lol

dense current
#

Aight

twilit egret
#

.generate()?

dense current
#

Hmmm, in the link to dimension

#

Maybe in there do custom(name)

#

And maybe some other params

#

Like biome

#

Or sum

#

Or, .generatecustom(name)

twilit egret
#

You can specify custom dimensions

dense current
#

And then inside of the .linkto(namefrombefore)

dense current
twilit egret
#

.setDestination("minecraft:the_nether")

dense current
#

Yeah

twilit egret
#

so it could be like

.setDestination("thing")
.preGenerate()

or something

dense current
#
.generateCustom(id,biome,otherParametersYouWantToAdd)
.setDestination(id)
#

That's what I would say

twilit egret
#

Ohhh that's what you mean

#

like that one mc april fools

dense current
#

Well kind kf

#

But allow for void dimensions

#

Please

#

So where it would be

.generateCustom(test_void, "minecraft:void")
.setDestination(test_void)
twilit egret
#

what would test_void be?

#

string?

twilit egret
dense current
#

Yeah

#

Just something along those lines

twilit egret
#

ye

dense current
#

Wait, on cf it is

#

Not on MR tho

livid oar
twilit egret
#

yeah right here in the orignal mod

dense current
#

@twilit egret when can I expect the patch with infiniverseAPI?

twilit egret
#

Once I figure out how to create the entire system of generation and such 😭

dense current
#

Oke

livid oar
# twilit egret yeah right here in the orignal mod

Thanks! I was just curious because when I used the custom portal API + custom portal builder on 1.20, there is no nausea at all. So its unclear whether you are actually teleporting or not when you step into the portalπŸ₯²

twilit egret
#

I may or may not backport it to 1.20.1 once I get more featurees in

livid oar
#

That would be amazing, but I can understand if its tough to backport. Either way, thanks for making an add-on for easier custom portals with KubeJS πŸ™

twilit egret
#

I want to scream rn

#

having the random tick method is casuing so many errors

#

I hate registries

twilit egret
#

It was in the 200's some hours ago 😭

graceful quartz
#

sick

#

it's an extremely cool mod tbh

vernal wing
# twilit egret <@467532880625664000> download the new one
const ItemEntity = Java.loadClass("net.minecraft.world.entity.item.ItemEntity");

global.recipes = global.recipes || {};
global.recipes.portal = [
  ["#c:raw_materials/gold", "2x minecraft:gold_ingot"],
  ["#c:raw_materials/iron", "2x minecraft:iron_ingot"],
  ["#c:raw_materials/copper", "2x minecraft:copper_ingot"],
];

PortalEvents.register((event) => {
  event
    .create()
    .frameBlock("minecraft:cherry_log")
    .lightWithItem("minecraft:wheat_seeds")
    .forcedSize(4, 5)
    .tint(Color.LIME_DYE.rgb())
    .beforeTeleportation((/**@type {$Entity_}*/ entity) => {
      if (!(entity instanceof ItemEntity)) return;

      const item = entity.item;
      for (let [ingredient, output] of global.recipes.portal) {
        if (Ingredient.of(ingredient).test(item)) {
          entity.item = Item.of(output);
          break;
        }
      }
      return ShouldTP.CANCEL;
    });
});
vernal wing
untold archBOT
#

Paste version of mclo.gs/bUGFPRS from @vernal wing

vernal wing
#

I understand, I didn't install CustomPortalAPI, and this mod is not required in mods.toml

#

No, he is in mods.toml, but he does not detect it

#

hmm

#

I found the problem

nocturne pewter
#

pepethink should i put PortalJS in Oceanblock and move away from the reflection method we have been using

vernal wing
#

hmm

#

.lightWithItem("minecraft:wheat_seeds") not work

#

Or do items need any characteristics?

twilit egret
nocturne pewter
#

I might look into it later today, if I get the time for it... Mainly the colored portals is what I was missing

twilit egret
#

Well you have the r, g, b and the 0xFFFFFF way (the color code hex edition)

twilit egret
#

I have released the 1.0.2 patch:

Fix the TOML to prevent mod crashes from unknown classes when a mod is not installed

twilit egret
#

CustomPortalParticle... hmmm I would so need to add this

vernal wing
#

@twilit egret I have an idea

#

Let us register a Block of the CustomPortalBlock type for use in customPortalBlock

twilit egret
#

That IS what I want to do

#

funnily enougth

vernal wing
#

yoo

twilit egret
#

But I need to fix an issue with setting a custom portal block in the builder of the api 😭

#

They have to extend CustomPortalBlock for the API to accept it, and when I try to do this.builder.customPortalBlock(() -> new PJSPortalBlock(randomConsumer));, I get registry errors

#

Common setup event? NAHHH
Registry event? NAHHH

#

Registry already frozen!!!
or
some concurrent error

#

Is it not registering my block???

#

OHHHHHH

#

THAT'S WHYYYY

#

I WAS REGISTERING IT WRONG THE ENTIRE TIME 😭

#

THE BLOCK NEVER EXISTED

#
public static final DeferredBlock<PJSPortalBlock> PORTAL_BLOCK = DeferredBlock.createBlock(ResourceLocation.fromNamespaceAndPath(PortalJS.MODID, "portal_block"));

I do not know how this was not causing any errors because THAT is WRONG

#
public static final DeferredBlock<PJSPortalBlock> PORTAL_BLOCK = BLOCKS.register("portal_block", registryName -> new PJSPortalBlock(null));

IS the correct way

twilit egret
forest river
#

Would be awesome if you could disable portal creation with this

vernal wing
twilit egret
#

Idea accepted

twilit egret
#

I think PortalJS is the new famous mod for me as of yesterday

twilit egret
#

good idea

#

So would

PortalEvents.onPortalSpawn(event => {
   if (event.frame == "minecraft:obsidian") {
      event.cancel()
    }
})

I will see how I can replace the stuff

forest river
#

Have been looking for so many mods to disable portals

#

and this will help me a ton!

twilit egret
#

It will be in server scripts

forest river
#

Nice!

twilit egret
#

cancel anybody?

graceful quartz
#

peak

twilit egret
#

almost done with it, need to fix a bug

#

(obisdian correct, glowstone not)

twilit egret
twilit egret
#

reopen this discord

twilit egret
#
vernal wing
twilit egret
#

oh yeah

#

... none of these

#

how do I make it public...

vernal wing
#

just create an issue?

twilit egret
#

aha

#

just need to move it to portaljs

vernal wing
#

link a project

twilit egret
#

there it is

vernal wing
#

Also, Github Projects can be displayed in multiple ways, including Trello-like card formats

#

like this

twilit egret
#

there we go!

#

thanks!

vernal wing
twilit egret
#

Anybody want random tick events???

#

I got it working!!

dense current
#

You go!

twilit egret
#

I was doing a thing wrong which caused it

#

fixed

#

now to figure out how to get it to summon a thing

dense current
twilit egret
#

ah

#

trying to summon an item frame as @pure wave said one day

twilit egret
#

Anyone want to test 1.1.0?

forest river
#

I haven't been keeping up but have the Cancel Portal function to disable portal creation been released yet?

twilit egret
forest river
#

XD

nocturne pewter
#

Stop slacking peepoSlam

forest river
twilit egret
forest river
#

So will it be added in?

vernal wing
untold archBOT
#

Paste version of mclo.gs/h6H4bly from @vernal wing

twilit egret
vernal wing
#

nah

#

But when I set returnDim, I still get the same error

twilit egret
#

@nocturne pewter Portal colors are fixed on the latest API version to let you know

nocturne pewter
#

i shal gib it a try later today

twilit egret
#

alright

twilit egret
#

I need to change the errors

#

where portal JS would say "Hey, you did not set X"

#

Ohhhh

#

I see what you mean now

#
PortalEvents.register(event => {
    event.create()
        .frameBlock("minecraft:infested_cobblestone")
        .setDestination("minecraft:the_end")
        .returnDim("minecraft:the_nether")
        .tint(0xFFAAFF)
})

works fine

nocturne pewter
#

does it?

nocturne pewter
twilit egret
twilit egret
#

New feature: Shows you errors for incorrect portal registration. (Messages will be changed to tell more info)

#

one mixin later you can now see what portal block is erroring

#

if there is no frame block, it will just be null

#

ORRR "No frame block set"

twilit egret
#

muahaha errors

pure wave
#

is it gonna error if you dont have any of those set?

#

i'd just.. set defaults

#

or are those only gonna fire if they try to set a non-registered block as a frame cause if so nvm then

twilit egret
#

I just took the Portal API errors, and just kube'd it

pure wave
#

when they un cancel it how will they re light the end portal?

#

i think its impossible cause ender eye right click only runs the code if the blockstate isnt already a filled end portal frame lol

twilit egret
#

Updating the wiki rn

twilit egret
pure wave
#

its some helper method i forget which one tho

twilit egret
# pure wave

I have a mixin on the blockPatternMatch#getFrontTopLeft

#
@Inject(method = "useOn", at= @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/pattern/BlockPattern$BlockPatternMatch;getFrontTopLeft()Lnet/minecraft/core/BlockPos;"), cancellable = true)
private void portalCreationInjection(@NotNull UseOnContext context, CallbackInfoReturnable<InteractionResult> cir) {
    BlockPos blockpos = context.getClickedPos();
    CreatedPortalEvent event = new CreatedPortalEvent(context.getLevel(), blockpos, Blocks.END_PORTAL_FRAME, true);
    ModLoader.postEvent(event);
    if (event.isCanceled()) {
        cir.setReturnValue(InteractionResult.CONSUME);
    }
 }
#

but that does the strange thing

pure wave
#

i dont think this even needs a mixin, just get the level from your event context and cancel it by default if the block shape matches an end portal frame

twilit egret
#

The end portal does not post an event

pure wave
#

hmm

#

youll have to do it on forge item right click then

twilit egret
#

The nether portal is the one portal that posts an event on the portal event thingy

pure wave
#

or ig mixin to the "HEAD" or invoke of the ender pearl item right click tho forge event right click is what i'd do personally

pure wave
twilit egret
#

working on the wiki rn

#

suggestions?

twilit egret
#

You can use potions to light portals

#

fun fact

twilit egret
#

started working on portaljs again

#

That class is for on item use

#

So I can do BiHolder<? super Item, Consumer<? super Item>> or however it would go

#

so I can do consumer.accept(the item on the left)

#

and such

wide thorn
#

1.20.1 backport when?

twilit egret
#

I'm working on it 😭

wide thorn
#

i was forced to use that cursed script that was posted recently lol

livid oar
#

How goes the porting? πŸ‘€

wide thorn
polar fossil
#

am I stupid? my portal doesn't light up. I've written;

PortalEvents.register(event => {
event.create()
.frameBlock("minecraft:glowstone") // required
.lightWithWater()
.setDestination("minecraft:the_nether") // required
.forcedSize(4, 5)
})

polar fossil
#

I guess I was stupid, I should've guessed that it didn't count the corners

untold archBOT
#

You can write your code in a codeblock by typing it between the codeblock delimiters:
Note that these are backticks, not apostrophes

```js :arrow_left:

ServerEvents.recipes(event => {
event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})

``` :arrow_left:

This example will look like this:

ServerEvents.recipes(event => {
  event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})
forest river
untold archBOT
#

Paste version of crash-2025-08-24_19.53.37-server.txt from @forest river

forest river
#

got you a crash report

twilit egret
#

oh no

#

Annnnd it is a mixin error with my mod

#

What is the code your using?

forest river
#

Haven't even started using it

#

ONly had it in my pack

#

🀣

#

I wanted to use it in future to remove portals if that was a thing

twilit egret
#

oh 😭

forest river
#

haha

#

Have fun

#

Oh and did you add functionality to remove a portal from working completely yet?

twilit egret
#

You can disable the nether and end portal

#

The vanilla ones

forest river
#

What about modded ones?

twilit egret
#

Mods have their own way of making portals 😭

forest river
#

Dang

forest river
#

You fixed shit yet`?

forest river
#

@twilit egret another one It lags like crazy when I try make a portal with this script

PortalEvents.onPortalSpawn(event => {
   if (event.frame == "minecraft:obsidian") {
      event.cancel()
    }
})```

it stops it sure but lags then it crashed me when I used Fire charge
untold archBOT
#

Paste version of crash-2025-08-25_09.36.41-server.txt from @forest river

forest river
#

New snapshot

twilit egret
#

What about end portals

forest river
#

Nope

#

sadly

forest river
#

then yes same issue

#

🀣

twilit egret
#

About the snapshot, but okay 😭