#Rendering overlay on mob effects

181 messages · Page 1 of 1 (latest)

waxen bay
#

Im trying to render screen overlays on mob effects, is it possible to do so?
i tried doing it like so:

ClientEvents.tick(event => {
    if (event.client.player.hasEffect("betterasfour:blood_gigante")){
        event.client.screen.renderTransparentBackground($GuiGraphics.MAX_GUI_Z)
    }
})```
but it can't render background of null now, 2 main things i wanna know are:
1. How do i make it not null
2. What are the GuiGraphics types and how do i get them
wicked yokeBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

waxen bay
#

even a vignette would suffice

hot niche
#

its null because if you dont have a screen up then your minecraft client's screen will be null.

#

so going through the screen is not the way unless you somehow register a dummy screen which I dont think is possible through current kubejs. what you might need to do is make a shader which is a whole 'nother process but is doable

#

for that you can check out visualjs which lets you do this

hot niche
#

so you may have to look into Overlays or wait for someone else who may have a better idea about it

waxen bay
#

Perhaps i need to register an overlay but i dont think thats a thing either

oblique owl
#

You definitely could do this with a shader, but i have no idea how to.

Instead I'd recommend registering a GuiLayer instead, it's what is used to render the hotbar, health and armor points.
-# StartupScript

let $RegisterGuiLayersEvent = Java.loadClass("net.neoforged.neoforge.client.event.RegisterGuiLayersEvent");
const OVERLAY_TEXTURE = ID.kjs("example_sprite")

NativeEvents.onEvent($RegisterGuiLayersEvent, event => {
    event.registerAboveAll(
        ID.kjs("custom_screen_overlay"), 
        (gui, delta) => global.drawCustomScreenOverlay(gui, delta)
    )
})

/**
 * @param {$GuiGraphics_} guiGraphics 
 * @param {$DeltaTracker_} deltaTracker 
 */
global.drawCustomScreenOverlay = (guiGraphics, deltaTracker) => {
    if (!Client.player || !Client.player.hasEffect("minecraft:poison")) return
    guiGraphics.blitSprite(OVERLAY_TEXTURE, 0, 0, guiGraphics.guiWidth(), guiGraphics.guiHeight())
}

Your texture has to be assets/kubejs/textures/gui/sprites/example_sprite.png in this case (see OVERLAY_TEXTURE declaration; the textures/gui/sprites/ part is required by mc)
Note that you might not want to use .registerAboveAll() because it draws over the hotbar. If so, just register above/below one of the vanilla layers. They render in this order: ```
camera_overlays, crosshair, hotbar, jump_meter, experience_bar, player_health, armor_level, food_level, vehicle_health, air_level, selected_item_name, spectator_tooltip, experience_level, effects, boss_overlay, sleep_overlay, demo_overlay, debug_overlay, scoreboard_sidebar, overlay_message, title, chat, tab_list, subtitle_overlay, saving_indicator

waxen bay
#

Wow ty for the effort in the answer i will try it out when i can

waxen bay
#

Hmm

#

im getting this error

#
[17:07:52] [ERROR] ! ScriptFile.java#71: java.lang.UnsupportedOperationException
[17:07:52] [ERROR] ! java.lang.UnsupportedOperationException
#

@oblique owl Is this for 1.21.1 neoforge?

#

I mean it should be considering the script

oblique owl
#

It is, yeah

#

that is odd

waxen bay
#

i only changed the declaration and the effect

hot niche
#

whats line 71?

waxen bay
#

i honestly have no idea

#

it doesn;t even get there

#
const OVERLAY_TEXTURE = ID.kjs("ice_cracks")

NativeEvents.onEvent($RegisterGuiLayersEvent, event => {
    event.registerAboveAll(
        ID.kjs("custom_screen_overlay"), 
        (gui, delta) => global.drawCustomScreenOverlay(gui, delta)
    )
})

/**
 * @param {$GuiGraphics_} guiGraphics 
 * @param {$DeltaTracker_} deltaTracker 
 */
global.drawCustomScreenOverlay = (guiGraphics, deltaTracker) => {
    if (!Client.player || !Client.player.hasEffect("betterasfour:blood_gigante")) return
    guiGraphics.blitSprite(OVERLAY_TEXTURE, 0, 0, guiGraphics.guiWidth(), guiGraphics.guiHeight())
}```
#

18 lines

hot niche
#

side note: this js if (!Client.player || !Client.player.hasEffect("minecraft:poison")) return
should be like this, surrounding both boolean checks in parenthases js if ((!Client.player || !Client.player.hasEffect("minecraft:poison"))) return
because of rhino

#

otherwise it will only ever check the first boolean and never the second even if the first passes

oblique owl
#

it might not even be necessary, i copied that from another script of mine where i actually ran into that issue

hot niche
#

yeah in this case its fine but just for future references

#

i should really set up a gnome macro for it because a lot of people do this and wonder why their return statement isnt working

waxen bay
#

xd

#

Im guilty of that

hot niche
#

lol i used to too

oblique owl
#

what the actual fuck

hot niche
#

what even

#

is this sorcery

waxen bay
#

Wait what

#

PigTurtle have you tried this on your own installation before?

#

I mean i bet you did but this issue seems like it should be universal

hot niche
#

wait did you put this in startup or client scripts

waxen bay
#

What was i supposed to...

#

where*

oblique owl
waxen bay
#

Is it a client or a startup script -./-

#

am i being dumb

oblique owl
#

It's startup

waxen bay
#

Ffs i should have listened to my guts

#

since it's registry

oblique owl
#

All NativeEvents calls are Startup

hot niche
#

lol

waxen bay
#

Hmm

hot niche
#

cause that would only happen if it was in client scripts

waxen bay
#

I have never used NativeEvents before

hot niche
#

native events are useable in other scripts i believe but this specific event should be in startup

waxen bay
#

they seems like they'd be the most usefull

hot niche
#

cause i think its some registry

oblique owl
#

but still the error being "java.lang.UnsupportedOperationException" is confusing me a lot
like is the problem that kube is modifying a private final Set<String>? and if so, wouldn't that error get thrown for literally every script?

waxen bay
#

o dam i just got attacked with the no textures screen

#

xD

#

I guess i did something wrong

#

It's definitely working just that im blind

hot niche
#

you have the texture in the correct folder?

waxen bay
#

Yep

#

Hmm

#

Wait

#

Does it matter what spacename?

#

Does it have to be kubeJS

#

ye i bet it does

hot niche
waxen bay
#

hmm

#

i still got it wrong

oblique owl
# waxen bay Does it have to be kubeJS

namespace depends on the ResourceLocation, you can either use ID.kjs("path") or ID.of("namespace", "path"). Wouldn't be surprised if there was also some wrapper to convert "namespace:path" strings to ResourceLocations, but i personally prefer using the kjs shorthands

waxen bay
#

curseforge\minecraft\Instances\True adventure neoforge 1.21.1\kubejs\assets\textures\gui\sprites\ice_cracks.png"

#

this is my current directory

#

o wait i seems correct or am i trippin

hot niche
#

whats the id youre going with rn

waxen bay
#

ice_cracks

hot niche
#

hmm

waxen bay
#

do i need to include .png?

hot niche
#

no

waxen bay
#

then something is off

hot niche
#

yeah youre doign it wrong

waxen bay
#

i needed to change the other .id?

hot niche
#

should be assets/kubejs/textures not assets/textures

waxen bay
#

O i see

hot niche
#

in your defence even i didnt see it til now lol

waxen bay
#

it's working now but ye i need to mess around with this cause now im blind again

#

at least it's the texture

hot niche
#

lol nice

waxen bay
#

are the 0,0 alpha controllers?

#

this should honestly be posted on player showcase i feel like many would find this helpful

#

i mean

hot niche
#

i was just about to say that cause i also might use it somewhere

waxen bay
#

example scripts

#

I want pig to post it, i mean they know it better and it's theirs >_>

#

btw Lio im putting your gorgeous addon to good use ty for that

hot niche
#

entityjs?

waxen bay
#

Yes

hot niche
#

nice

waxen bay
#

Would love to showcase some of its many uses so other would get ideas

oblique owl
#

In the process i seem to have broken the search function in my creative menu though, i really hope it isn't this script lol

waxen bay
#

Now i added the crosshair in the middle only because probe showed a difference between belowAll() and this method on the 2nd value

#

So i assumed it goes there

#

nevermind i got it

#

probeJS is just acting weird

#

was flipped

tawny notch
#

On 1.21.1, you can only set globals on Startup scripts (you get UnsupportedOperation if you dont)

#

Also, on 1.21.1 you can use NativeEvents on any script side

#

not just startup

hot niche
#

ah that makes sense then

hot niche
waxen bay
#

If i were to want to animate the overlay would it be wise to do it with schedule functions or is there a better way to do it via kubeJS?

waxen bay
#

I looked into json animation but im not sure how to register a json overlay in kubejs

oblique owl
#

if not, the second argument to the GuiLayer callback is something called a DeltaTracker. You'd want to use that to calculate what you want drawn.

waxen bay
#

hmm ye normal mcmeta didnt seem to work unless i did it wrong which it may just be that way

waxen bay
waxen bay
#

i also decided to console.log deltaTracker.getGameTimeDeltaTicks() and i get these results for some reason so i may not be understand this after all ``` 0.34
[11:42:10] [INFO] 0.06
[11:42:10] [INFO] 0.18
[11:42:10] [INFO] 0.16
[11:42:10] [INFO] 0.18
[11:42:10] [INFO] 0.16
[11:42:10] [INFO] 0.16
[11:42:10] [INFO] 0.18
[11:42:10] [INFO] 0.16
[11:42:10] [INFO] 0.18
[11:42:10] [INFO] 0.16
[11:42:10] [INFO] 0.18
[11:42:10] [INFO] 0.16
[11:42:10] [INFO] 0.18
[11:42:10] [INFO] 0.16
[11:42:10] [INFO] 0.18
[11:42:10] [INFO] 0.16

I also tried delta tracking the png with the mcmeta file but i get an error texture anyways
waxen bay
#

hmm nevermind the original method works

#

I just had the wrong file?

#

wrong png i guess

waxen bay
waxen bay
#

Now i just need to figure out how to do the gui positioning dynamic with the gui scale

oblique owl
waxen bay
#

Ye now im just trying to make the renderable coords keep the same positon with the gui scaling

oblique owl
#

Does the 0 -> width (100%) not work for you? in almost all other cases you would probably want to actually have gui scaling applied, not to disable it

#

but i suppose you can probably

const pose = guiGraphics.pose()
// enforce fixed scale
pose.pushPose()
const f = 1 / Client.options.guiScale().get()
guiGraphics.pose().scale(f, f, f)

// render calls

pose.popPose()
waxen bay
#

So what i was missing was the Client.options i didnt know that was a thing

#

I will try this when i can

waxen bay
oblique owl
#

Are you asking for how to anchor what you are drawing to a specific location then?

waxen bay
#

Yes

#

I read on the neoforged docs that you can use init method

#

But in kjs it's a bit different

oblique owl
#

you'd usually just use some_factor * guiGraphics.guiWidth() in that case, draw from that to it + n and you have something that always starts at the same spot on the screen but is a different size based on gui scale

waxen bay
#

Ye i did that in the beginning it's very confusing so i thought there must be a better way

#

But i guess it is one of the best ways

#

This whole support thread basically turned into a tutorial

#

Should def be a thread in the example scripts

#

PigTurtle do you have any like projects you made with kjs? You seem very knowledgeable

oblique owl
#

One Modpack, its been a really long while though

waxen bay
#

Hmm can i get the name?

oblique owl
#

I just recently started reading source code a lot more, kube is basically just more restricted java modding

waxen bay
#

Ye i realized that more now thanks to you

oblique owl
#

but it exists

waxen bay
#

That wasnt my plan anyway

#

Wtf

#

XD

#

The pfp and the name

#

Craz

oblique owl
#

not me lol, friend i've made the modpack with

#

gets worse when you look at his current discord name

waxen bay
#

I actually knew of this modpack already

#

Prety nice

#

Im also making a modpack but my ideas dont allow me to finish it or even come close

oblique owl
#

Well - We haven't updated CAE in about two years now. It can feel like a huge commitment.
if you do actually want to finish your modpack, I'd recommend writing down notes for what you are planning in something like a Todo list, and then picking out a point and actually finishing it before moving on to a different idea
That way you know you're getting something done and you can force yourself to not get (too) distracted

waxen bay
# oblique owl Well - We haven't updated CAE in about two years now. It can feel like a huge co...

I do have a list the problem is im a big fan of complex mechanics so everytime i do something new and learn from it, that something i just "finished" doing will get an upgrade considering i now have new options available and since i keep on adding to the mechanics and content i keep forcing myself to reshape a lot of what i did. For example i learnt of the possibility to register overlays via kjs thanks to you so that drove me back to a combat class i created like 1.5 months ago

#

My target gameplay is extremely out of my league right now, i started learning coding in general when i began about 3 months ago

#

But i should definitely learn to finish something properly first before moving on to the next

waxen bay
#

@oblique owl so i just tried this out but apparently the guiWidth and guiHeight methods do not give you actual integers

#

[INFO] int guiWidth() [dev.latvian.mods.rhino.NativeJavaMethod]
[23:24:48] [INFO] int guiHeight() [dev.latvian.mods.rhino.NativeJavaMethod]

#

So it doesn't seem to work in positioning

waxen bay
#

but i found a way to do it >_>

#

(1 / Client.options.guiScale().value) * 300, (1 / Client.options.guiScale().value) * 300

#

this for example

waxen bay
#

well technically you can do guiWidth().valueOf() to get a number but it's the same as using guiScale but even more confusing, since you get a big number

#

this also works as a scaling for the width and height of the png

#

(1 / Client.options.guiScale().value) * 128

#

If for example i want it to be 64x64 on the 2x guiScale

#

It will stay the same size for all scales this way

#

lmao but when it's put into auto gui it crashes because it is considered infinity -.-

#

well it's because auto gui scale counts as 0 and 1 / 0 is infinity but i have no idea how to deal with this

oblique owl
#

been a few days but I took another look and you should be able to get the scale from Client.window.guiScale, the GuiGraphics class gets it that way whenever it needs it.