#[Port] Script 1.19.2 to 1.18.2

60 messages · Page 1 of 1 (latest)

languid meteor
#
ForgeEvents.onEvent('net.minecraftforge.event.entity.living.LivingChangeTargetEvent', event => {
    //set the global changetarget function into here and restart your game once
    global.changetarget(event)
})

/**
 * 
 * @param {Internal.LivingChangeTargetEvent} event 
 */
global.changetarget = event => {
    //since this is a global event you can run /kubejs reload startup_scripts to reload whatever is in here without
    //restarting the entire game!
    let { entity, entity: { persistentData } } = event
    let { originalTarget, newTarget } = event
    //returning if the original target is not a player
    if (newTarget.id == "hordes:zombie_player")
    {
        event.setCanceled(true)
    }
}

Hi people, I wonder does ForgeEvents.onEvent do they exists in 1.18.2 as well? I found a script that I needed but it only exists in 1.19.2, so wondering those syntax is there a way to convert them or anyone could help out?

Essentially I want all the mobs ignore the zombie player because of a bug I am trying to fix.

high hazelBOT
#

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

languid meteor
#

[Port] Script 1.19.2 to 1.18.2

covert prism
#

try this ```js
onForgeEvent('net.minecraftforge.event.entity.living.LivingChangeTargetEvent', event => {
//set the global changetarget function into here and restart your game once
global.changetarget(event)
})

/**
*

  • @param {Internal.LivingChangeTargetEvent} event
    */
    global.changetarget = event => {
    //since this is a global event you can run /kubejs reload startup_scripts to reload whatever is in here without
    //restarting the entire game!
    let { entity, entity: { persistentData }, originalTarget, newTarget } = event
    if (newTarget.type == "hordes:zombie_player") {
    event.setCanceled(true)
    }
    }```
#

also its js newTarget.type not id

languid meteor
#

omg you're the script creator! Thanks for replying! I'll try it out real quick

covert prism
#

yeah np 😄

languid meteor
#

hmm seems like forge event doesn't exist on 1.18.2?

covert prism
#

it goes in startup scripts

languid meteor
#

ah ok

covert prism
#

and the first time loading it youll have to restart the entire client

languid meteor
#

yup, doing it for the dedicated server to test

#

hmm encountered a crash
[11:33:51] [Server thread/ERROR] [ne.mi.ev.EventBus/EVENTBUS]: Exception caught during firing event: TypeError: Cannot read property "type" from null (startup_scripts:mutation_sickness_check.js#17)

And it also doesn't seem to ignore that specific entity

#

maybe it wasn't the change target event??

covert prism
#

the target is null

#

so you'll have to add a null check

languid meteor
#

essentially what happens currently is
there's some mobs in mutationcraft they're automatically hostile to every single zombie related mobs, and I am trying to make them invisible for them so they don't target them

#

lemme try again

covert prism
#
if (newTarget != null && newTarget.type == "hordes:zombie_player") {
        event.setCanceled(true)
    }```
languid meteor
#

with the null check

#

hmm nope they still targeting him

#

is there a separate event that functions differently from ChangeTarget? I am not sure if it's tryign to change target or is there a specific event that makes them spot the enemy and "target" them

covert prism
#

try this js global.changetarget = event => { //since this is a global event you can run /kubejs reload startup_scripts to reload whatever is in here without //restarting the entire game! let { entity, entity: { persistentData }, originalTarget, newTarget } = event if (!entity.type.toString().includes("mutationcraft:")) return if (newTarget == null) return if (newTarget.type == "hordes:zombie_player") { event.setNewTarget(null) } }

languid meteor
#

oh that's brilliant, instead of cancelling the event you redirected it back to null

#

let me try that

covert prism
#

if that doesnt work then console.log(newTarget.type) for me

languid meteor
#

oof it straight out crashed

#

[11:40:49] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
net.minecraft.ReportedException: Ticking entity

covert prism
#

send the full latest logs

languid meteor
jaunty archBOT
#

Paste version of crash-2024-03-14_11.40.49-server.txt from @languid meteor

languid meteor
#

assuming includes doesn't exist in 1.18.2 yet?

covert prism
#

sec

languid meteor
#

only beyond 1.19.2

languid meteor
#

hmm strange

#

global.changetarget = event => {
    //since this is a global event you can run /kubejs reload startup_scripts to reload whatever is in here without
    //restarting the entire game!
    let { entity, entity: { persistentData }, originalTarget, newTarget } = event
    console.log("Entity: " + entity.type.toString())

    if (!entity.type.toString().includes("mutationcraft:")) return
    if (newTarget == null) return
    console.log("Entity Type: " + newTarget.type)

    if (newTarget.type == "hordes:zombie_player") {
        console.log("Zombie: " + newTarget.type)
        event.setNewTarget(null)
    }
}
#

this is the current code

#

but it didn't reach below entity type or the zombie player check

#

looks like its constantly null

#

the zombie player log shows up I assume during they got attacked and switch target

covert prism
#

yeah im workin on it rn, just booted up an instance

#

1.18 is weird with its entity methods despair

languid meteor
#

I agree, but can't afford to upgrade to 1.19.2 because the modpack is in 1.18.2 and it's large haha

#

could it be this? onLivingSetAttackTarget

#

or maybe the mod itself is buggy because its made from mcreator

covert prism
#

this works js global.changetarget = event => { //since this is a global event you can run /kubejs reload startup_scripts to reload whatever is in here without //restarting the entire game! let { entity, entity: { persistentData }, originalTarget, newTarget } = event if (!entity.getType().toString().includes('entity.mutationcraft')) return if (newTarget == null) return if (newTarget.type.toString().includes("hordes.zombie_player")) { event.setNewTarget(null) } }

#

though you'll have to change it from minecraft.zombie to hordes.zombie_player

#

not to be confused with hordes**:**zombie

languid meteor
#

ah, that make sense

#

omg it works

#

thank you so much!!

#

you're my life savior

#

❤️

#

final script for anyone who want to change mob aggro or invisible for a certain mob

onForgeEvent('net.minecraftforge.event.entity.living.LivingChangeTargetEvent', event => {
    //set the global changetarget function into here and restart your game once
    global.changetarget(event)
})

/**
 * 
 * @param {Internal.LivingChangeTargetEvent} event 
 */
global.changetarget = event => {
    //since this is a global event you can run /kubejs reload startup_scripts to reload whatever is in here without
    //restarting the entire game!
    let { entity, entity: { persistentData }, originalTarget, newTarget } = event
    if (!entity.type.toString().includes("entity.mutationcraft")) return
    if (newTarget == null) return
    if (newTarget.type.toString().includes("entity.hordes")) {
        event.setNewTarget(null)
    }
}