#Radiation Poisoning Effect

182 messages · Page 1 of 1 (latest)

hard parrot
#

Startup Script:

const $DamageSource = Java.loadClass(`net.minecraft.world.damagesource.DamageSource`)

/** Register effects */
StartupEvents.registry('mob_effect', event => {
    // Register radiation effect
    event.create('radiation')
        // Change the name to be "Radiation", in green
        .displayName(Component.green("Radiation"))
        // Set a tick event to apply the action
        .effectTick((entity, lvl) => global.radiationEffect(entity, lvl))
        // Set the color of the effect
        .color(Color.GREEN)
        // Set whether the effect is harmful
        .harmful();
})

/**
 * Applies the radiation effect.
 * Damages the entity (likely player) with 2 HP (1 hearts) per 10 ticks.
 *
 * @param {Internal.Entity} entity The entity to apply the effect to
 * @param {number} lvl The level of the effect
 */
global.radiationEffect = (entity, lvl) => {
    // Create damage source
    let damagesource = new $DamageSource('radiation')
    // Check if the global is run on the client. If so, return
    if (entity.level.clientSide) return;
    // Damage based on level 
    entity.attack(damagesource, lvl + 1);
}```
Client Script:
```js
/** Add language entries */
ClientEvents.lang('en_us', (e) => {
    // Effect / Radiation
    e.add("death.attack.radiation", "%1$s died in a horrible way");
})```

You can add an icon to go along with the effect by just dropping an 18px by 18px image over in ``kubejs/assets/kubejs/mob_effect/radiation.png`` - words of wisdom by @modest current 
Credit to @sullen roost and @carmine wyvern

@oak saffron 's 1.18 version here in: [#1170471805148999751 message](/guild/303440391124942858/thread/1170471805148999751/p/1170471805148999751/#msg-1170696177126223922)

@fleet ferry 's 1.20 Successful Port here:
[#1183085911974608977 message](/guild/303440391124942858/thread/1183085911974608977/p/1183085911974608977/#msg-1183419350519132200)
grizzled craneBOT
#

Paste version of en_us.json from @hard parrot

sullen roost
#

I did another thing

plush kettle
#

you can constuct the damage source and save it to a var outside of the event which will minorly improve performance cause your not making a new one each time

sullen roost
#

idk how I didn't consider that

sullen roost
#

please never use var in js. use let or const.

hard parrot
#

he just said use var

sullen roost
#

well yeah, a variable

hard parrot
#

also i suggested doing it as a const outside of the codeblock but you didnt hear me

sullen roost
#

but not the var keyword

hard parrot
#

smh my head

#

it is done happy

sullen roost
#

yes heh

hard parrot
sullen roost
hard parrot
sullen roost
hard parrot
plush kettle
gloomy terrace
#

Why an entity damage source?

modest current
#

How would I apply this effect?

plush kettle
#

/effect add @s kubejs:radiation

modest current
#

Should I make a support ticket for this?

plush kettle
#

after you read the script type this belongs in, yes make a support ticket

carmine wyvern
#

neat is a mod by vazkii

sullen roost
#

~~okay shut the fuck u-~~

#

/j

lunar summit
#

wouldn't the script in it's current form error saying that entity is not defined?

hard parrot
#

also is the script in startup scripts

#

try the script now, i guess putting the const outside the function breaks it

lunar summit
#

probably

#

as I pointed out, it would probably error saying that entity is not defined

hard parrot
#

right

#

which it did

#

good to know

hard parrot
modest current
# hard parrot are you on 1.19 and did you already do at least 1 full game restart?

Yeah it was the full game restart. Thanks. I assumed that it'd work if I closed my single player instance and opened it back up once again. But that was not the case.

Can confirm that this works for 1.20.1 as well though!

Oh also may wanna add that you can add an icon to go along with the effect by just dropping an 18px by 18px image over in kubejs/assets/kubejs/mob_effect/effect_name.png (I think that's the path, I'm not at my PC rn.)

sullen roost
#

we discussed this in vc, but then kinda forgot it

hard parrot
modest current
grizzled craneBOT
carmine wyvern
#

mojank

lofty zinc
#

is there anyway to add a heart texture change to it like with the wither effect?

hard parrot
lofty zinc
#

would be pretty neat

plush kettle
#

probably not easily

hard parrot
#

would that require the js paint?

plush kettle
#

and/or cancelling the existing heart renderer with forge events

hard parrot
#

true

#

is there a forge event for it?

plush kettle
hard parrot
#

i see

ancient leaf
#

How do you protect against this? Radiation is great, but what's the counter?

hard parrot
ancient leaf
#

Well yes, just was wondering if there was an example hazmat to go with it?

hard parrot
grizzled craneBOT
#

[Quote ➤](#1171855437835022406 message) i have this script here which applies radiation to a player when they get near a certain distance, i tried but didnt find a way on how to make it nbt specific, only working version is with item ids

onEvent("player.tick",event => {
    let player = event.player
    if (player.ticksExisted % 20 != 0) return
    if (player.headArmorItem == 'tconstruct:slime_helmet' && player.chestArmorItem == 'tconstruct:slime_chestplate' && player.legsArmorItem == 'tconstruct:slime_leggings' && player.feetArmorItem == 'tconstruct:slime_boots') return
    let radioactiveBlockPos = BlockPos.findClosestMatch(player.block.pos, 3, 3, pos => event.level.getBlock(pos).hasTag("forgedingears:radioactive"))
    radioactiveBlockPos.ifPresent(() => player.potionEffects.add('kubejs:radiation', 21, 2, false, true))
    if (player.inventory.find("#forgedingears:radioactive") > -1) player.potionEffects.add('kubejs:radiation', 201, 3, false, true)
  })
hard parrot
#

though his got complicated though you could clear the effect if you have a certain set of armor on (or prevent it)

ancient leaf
#

I guess the application spot would be better place to check for armor, and radaway could remove like milk

velvet ice
desert viper
#

This is actually very useful for a food item that I'm currently working on

oak saffron
hard parrot
#

assets>kubejs>textures>mob_effect>radiation.png

#

also make sure its 18x18 not 16x16

hard parrot
#

btw for whoever wants the radiation png i made here you go heh

desert viper
#

thank you

dark scroll
hard parrot
dark scroll
#

here is my radiation png

hard parrot
#

ill look into that

#

probably just need to change the damage type

dark scroll
#

should I provide a video?

#

ok

hard parrot
#

nah i know what youre talking about

dark scroll
#

also when I tried saving the world while I had the effect, it gave these errors

fleet ferry
#

update to latest Rhino

dark scroll
fleet ferry
#

oh Lat didn't release yet

it is build 282+

#

you may download yourself from #mod-updates

#

the build 282

dark scroll
#

thanks

hard parrot
#

all i did was change the global function so thats all you need to overwrite

dark scroll
#

Thank you very much!

hard parrot
#

actually crap now the death message isnt working?

#

hold on im gonna have to open up a ticket for this

fleet ferry
hard parrot
fleet ferry
#

why you broke stuff

hard parrot
#

ikr

fleet ferry
#

@hard parrot oh you were using entity damage source lol

hard parrot
#

yeah lmao

fleet ferry
#

it assumed a player hit you

hard parrot
#

fair enough

#

good to know, gonna edit the script now

fleet ferry
#

hence why it has knockback

hard parrot
hard parrot
chilly ruin
#

there is a way to specify how much damage per x ticks??

sullen roost
hard parrot
#

and i dont type my code like that, not my style

sullen roost
hard parrot
sullen roost
#

shorter cod

hard parrot
hard parrot
#

when it makes 0 difference at all lul

sullen roost
#

no it does

#

obv

chilly ruin
hard parrot
#

thats the damage thats dealt per attack

#

here we're going off the level of the effect + 1

hard parrot
chilly ruin
#

but what about the cooldowns btwen each attack?

#

in ticks

hard parrot
#

you can check what we did in the 1.20 version where you change the invulnerability time of the player depending on the damage source

#

should be pretty much the same thing in 1.19

chilly ruin
#

dude pls, im new here and not expert on coding just lnow some things and im building a lil project

#

i just need to set a cooldown in ticks

hard parrot
#

uh

chilly ruin
#

im having headshakes with this since 2 hours ago

hard parrot
#

click on #unkown

chilly ruin
chilly ruin
hard parrot
#

then scroll down and its right here

worn prairie
#

I've copied the scripts for 1.20 and I'm attempting to run it, however it's not applying any effect, and outputting

[14:34:55] [Server thread/ERROR] [KubeJS Startup/]: radiation.js#17: Error while ticking mob effect kubejs:radiation for entity JetPoweredSheep: TypeError: Cannot call property level in object ServerPlayer['JetPoweredSheep'/2, l='ServerLevel[aeugh]', x=6.48, y=-58.00, z=-5.80]. It is not a function, it is "object".```
in the logs each tick. The scripts should all be in the right place, but I can't work out what the problem is.
It seems the problem is with the line ```    const damageSource = getDamageSource(entity.level(), "kubejs:radiation");``` but I'm not familiar enough with js to work it out
hard parrot
#

in later 1.20 versions level() is remapped to just level

#

so just remove the parentheses call

worn prairie
#

ah sweet thanks!

shrewd coyote
#

if i just want to add a damage type with no effect would this be how i would do it?

const $DamageSource = Java.loadClass(`net.minecraft.world.damagesource.DamageSource`)


/**
 * Applies the radiation effect.
 * Damages the entity (likely player) with 2 HP (1 hearts) per 10 ticks.
 *
 * @param {Internal.Entity} entity The entity to apply the effect to
 * @param {number} lvl The level of the effect
 */
global.soulLeech = (entity, lvl) => {
    // Create damage source
    let damagesource = new $DamageSource('soul_leech')
    // Check if the global is run on the client. If so, return
    if (entity.level.clientSide) return;
    // Damage based on level 
    entity.attack(damagesource, lvl + 1);
}
#

i need it for my origin

#

ig ill just

#

??tias

grizzled craneBOT
shrewd coyote
#

ig not

hard parrot
#

i think youll wanna take a look at the 1.20 version of it

#

in 1.20 things changed for damage source registries

shrewd coyote
#

alr

#

where is that?

hard parrot
#

should be a link at the bottom of the post

barren fjord
#

i dont seem to be taking damage when i give myself the effect

hard parrot
#

change level() to level

barren fjord
#

hmm nope didnt seem to work

#

youre saying change it to this correct:

StartupEvents.registry('mob_effect', event => {
    // Register radiation effect
    event.create('mantle:radiation_sickness')
        // Change the name to be "Radiation", in green
        .displayName("Radiation Sickness")
        // Set a tick event to apply the action
        .effectTick((entity, lvl) => global.radiationEffect(entity, lvl))
        // Set the color of the effect
        .color(Color.GREEN)
        // Set whether the effect is harmful
        .harmful();
})
const $ResourceKey = Java.loadClass("net.minecraft.resources.ResourceKey")
const DAMAGE_TYPE = $ResourceKey.createRegistryKey("damage_type")
global.radiationEffect = (entity, lvl) => {
    // Create damage source
    const damageSource = getDamageSource(entity.level, "mantle:radiation_sickness");
    // Check if the global is run on the client. If so, return
    if (entity.level.clientSide) return;
    // Damage based on level 
    entity.attack(damageSource, (lvl - 0.2) + 1);
}
function getDamageSource(/** @type {Internal.Level}*/ level, /** @type {Internal.DamageType_}*/ damageType) {
    const resourceKey = $ResourceKey.create(DAMAGE_TYPE, Utils.id(damageType))
    const holder = level.registryAccess().registryOrThrow(DAMAGE_TYPE).getHolderOrThrow(resourceKey)
    return new DamageSource(holder)
}```
#

entity.level instead of entity.level()

#

for both instances

hard parrot
#

all instances yea

barren fjord
#

its just 2 there though right

hard parrot
#

that was remapped in an update to stay consistent with earlier versions

barren fjord
#

can you see anything else that would be going wrong then?

hard parrot
#

if its still not working then please open up a support ticket posting the server logs and script

#

do not @ me though because i am going to bed pepelaugh