#Error computing listener using ForgeEvents

122 messages · Page 1 of 1 (latest)

spark goblet
#

In startup_scripts

const $TackleBox = Java.loadClass("com.teammetallurgy.aquaculture.inventory.container.TackleBoxContainer");

ForgeEvents.onEvent($TackleBox, event => {
    global.removeFishingRod(event)
})

global.removeFishingRod = event => {
    let player = event.entity;
    if (/.+aquaculture:bobber.+/.test(event.removed.nbt)) {
        player.data.ftbquests.addProgress('71D0A3B6667D834E', 1)
    }
}

Source: https://github.com/TeamMetallurgy/Aquaculture/blob/AQ2-1.20.2/src/main/java/com/teammetallurgy/aquaculture/inventory/container/slot/SlotFishingRod.java

stuck canopyBOT
#

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

spark goblet
#

Am trying to detect if the item which is being removed has this item in their NBT

low glacier
#

that's.....not an event

hollow hatch
#

Das a container xd

#

The class names are important :P

spark goblet
hollow hatch
#

Look at the name

polar raft
#

only forge events can be used in the forgeevents event

#

this is not a forge event, matter fact it has nothing to do with forge events

polar raft
spark goblet
#

No, I just wanted to detect the nbt of a customized fishing rod removed out of the output

polar raft
#

what output

#

elaborate please

spark goblet
#

the box has a output

polar raft
#

ah i see

#

that might be tricky

hollow hatch
#

highly unlikely that is an event

polar raft
#

you're trying to remove fishing rods from being outputs or something?

hollow hatch
#

use the inventory changed event maybe

spark goblet
#

i can make a screenshot of the tackleboxes' gui

polar raft
#

that would help

#

i think i understand what you're trying to do now, you want to add an ftb quest for people to add tackle to the fishing rod

#

yeah like lex said thats most definately not an event though maybe using the inventory changed event you can listen to see if they gain a fishing rod with the nbt

spark goblet
#

this is a screenshot I was able to find from public sources (top right, fishing rod)

polar raft
#

its funny cause this actually might be possible

#

definately doable though im a little busy doing some other stuff atm to do some testing though if someone else wants to delve into it you basically can get the container from the containerscreen event and detect if the screen event is one of these and then if it is then you can do stuff, mainly the draggingItem or lastquickmoved method ect

spark goblet
#

I was wondering if clientsided would work on servers too

#
const $ContainerScreen = Java.loadClass("net.minecraftforge.client.event.ContainerScreenEvent");

ForgeEvents.onEvent($ContainerScreen, event => {
    global.removeFishingRod(event)
})

global.removeFishingRod = event => {
    let player = event.entity;
    if (/.+aquaculture:bobber.+/.test(event.draggingItem.nbt)) {
        player.data.ftbquests.addProgress('71D0A3B6667D834E', 1)
    }
}

something like this, I assume

polar raft
#

its a startup script so it on both client and server

#

no

#

again forge events only

#

if they dont have net.minecraftforge at the beginning of the path you can automatically rule the class out as not a forge event

#

eh i guess i have some time

#

sec

spark goblet
#

changed the event

#

I've seen a lot users use loadClass in there server_scripts too

low glacier
#

too bad the inventorylistener in kubejs wasn't a lil more general, would be cool to be able to just add a slot listener to any menu

polar raft
spark goblet
#

Ok, so Im guessing it's because of this sussy part TackleBoxContainer extends AbstractContainerMenu

polar raft
#

(not with the forgeevent binding though)

#

instead of loading the class you need to put the string

#
ForgeEvents.onEvent("net.minecraftforge.client.event.ContainerScreenEvent", event => {
    global.screenEvent(event)
})```
spark goblet
#

Does the reason for not loading the class first have to do with it being client-sided

low glacier
#

no, the onEvent handler will do if for you, it's an unnecessary extra step

polar raft
#

ok so i have this so far where it detects what the player is carrying```js
Java.loadClass("net.minecraftforge.client.event.ContainerScreenEvent")
ForgeEvents.onEvent("net.minecraftforge.client.event.ContainerScreenEvent", event => {
global.screenEvent(event)
})
let TackleBoxScreen = Java.loadClass("com.teammetallurgy.aquaculture.client.gui.screen.TackleBoxScreen")
/**
*

  • @param {Internal.ContainerScreenEvent} event
    */
    global.screenEvent = event => {
    const { containerScreen } = event
    try {
    if (containerScreen instanceof TackleBoxScreen) {
    if (containerScreen.menu.getCarried().id == "aquaculture:diamond_fishing_rod") {
    console.log("carrying rod")
    }
    }
    } catch (error) {
    console.log(error)
    }
    }```
#

and it only fires if the screen is the tackle box screen

polar raft
#

mainly log lastQuickMoved

spark goblet
#

what will the @param do?

polar raft
#

thats for probejs

#

put this in startup scripts and then ingame run /probejs dump and you should get some methods from the abstractcontainerscreen class in the global event

#

its not need but very helpful

spark goblet
#

Do I have to get ProbeJS for this?

polar raft
#

also you'll wanna run everything throgh event.containerScreen.menu because the menu is your current menu, for example js console.log(event.containerScreen.menu.lastQuickMoved)

polar raft
spark goblet
#

Will /kjs reload startup_scripts work if I want to add something below console log

polar raft
#

it will reload anything in the global function

#

so even the try catch

#

its recommended to keep all your code inside those try brackets though because as you may already know, startup scripts will crash your game if it errors

spark goblet
#

so then I must have gotten something wrong with editing your code

global.screenEvent = event => {
    const { containerScreen, entity } = event
    try {
        if (containerScreen instanceof TackleBoxScreen) {
            if (/.+aquaculture:bobber.+/.test(containerScreen.menu.getCarried().nbt))
                entity.data.ftbquests.addProgress('71D0A3B6667D834E', 1)
        }
    } catch (error) {
        console.log(error)
    }
}
polar raft
#

uh i would test that regex method in an item right click event to make sure it works first of all

#

oh you're missing a bracket

#

no nvm

#

yeah test it out in ItemEvents.rightClicked

spark goblet
#

So that try + catch is like having a dummy test the car crash before you do

polar raft
#

exactly! heh

#

though some errors it will not work on, cause rhino is weird like that

spark goblet
#
ItemEvents.rightClicked(event => {
    if (/.+aquaculture:bobber.+/.test(event.item.nbt)) {
        event.player.potionEffects.add('reliquary:flight', 20*300, 0, true, false);
    }
})

right click event worked fine

polar raft
#
console.log(containerScreen.menu.getCarried().nbt)```
#

just be careful cause it spams the logs

#

also theres no entity

#

i dont think

#

which is probably the issue

spark goblet
#
[INFO] {Damage:0,Inventory:{Items:[{Count:1b,Slot:0,id:"aquaculture:double_hook"},{Count:1b,Slot:1,id:"aquaculture:worm",tag:{Damage:0}},{Count:1b,Slot:2,id:"aquaculture:fishing_line"},{Count:1b,Slot:3,id:"aquaculture:bobber"}],Size:4}} [net.minecraft.nbt.CompoundTag]
[INFO] TypeError: Cannot read property "data" from undefined [dev.latvian.mods.rhino.NativeError]
#

okay, so entity is the issue

polar raft
#

thought so

#

do js containerScreen.minecraft.player @spark goblet

spark goblet
#

Successful

polar raft
spark goblet
#

This whole thread was quite helpful

polar raft
#

very good

#

you might also want to account for lastQuickMoved

#

incase they shift click it out

#

doesnt have to be a complicated check since you cant really control whether or not they put in an already crafted item in and take it back out hmmm

spark goblet
#

Did you use getCarried instead of draggingItem?

polar raft
#

yea

#

why

#

i think they both are pretty much the same right

spark goblet
#

I can find that method on the forge site (getCarried)

polar raft
#

yeah its not on the forge site for some reason

#

actually its not on the site because its not a method off of the container screen

#

its a method off of menu

#

containerScreen.menu

#

right here

spark goblet
#

Cannot find function lastQuickMoved in object com.teammetallurgy.aquaculture.inventory.container.TackleBoxContainer@3c952e82. [dev.latvian.mods.rhino.NativeError]

#
if (/.+aquaculture:bobber.+/.test(containerScreen.menu.getCarried().nbt) || 
                /.+aquaculture:bobber.+/.test(containerScreen.menu.quickMoveStack(containerScreen.minecraft.player, 1).nbt)) {
                containerScreen.minecraft.player.data.ftbquests.addProgress('71D0A3B6667D834E', 1)
            }
polar raft
#

thats a method off the containerScreen

spark goblet
#

Also tried using

if (/.+aquaculture:bobber.+/.test(containerScreen.menu.getCarried().nbt) || 
                /.+aquaculture:bobber.+/.test(containerScreen.menu.lastQuickMoved().nbt)) {
                containerScreen.minecraft.player.data.ftbquests.addProgress('71D0A3B6667D834E', 1)
            }

[INFO] TypeError: Cannot find function lastQuickMoved in object com.teammetallurgy.aquaculture.inventory.container.TackleBoxContainer@2243b2b0. [dev.latvian.mods.rhino.NativeError]

#

eventhough this worked

if (/.+aquaculture:bobber.+/.test(containerScreen.menu.getCarried().nbt) || 
                /.+aquaculture:bobber.+/.test(containerScreen.menu.quickMoveStack(containerScreen.minecraft.player, 0).nbt)) {
                containerScreen.minecraft.player.data.ftbquests.addProgress('71D0A3B6667D834E', 1)
            }

it duped a bunch of rods (if there was already a rod in the slot)

#

could be due to some desync bug

polar raft
spark goblet
polar raft
#

yeah thats an abstract method

#

not something to use as an itemstack to determine a boolean

#

though im not really seeing anything else so hmmm

#

oh its lastQuickMoved not lastQuickMoved() @spark goblet

#

try this, if it doesnt work then idk

#

its a variable not a method

spark goblet
#

[INFO] TypeError: Cannot read property "nbt" from undefined [dev.latvian.mods.rhino.NativeError]

/.+aquaculture:bobber.+/.test(containerScreen.menu.lastQuickMoved.nbt)
polar raft
#

yeah i guess lastquickmoved is undefined always for some reason despair