#Giving an effect in relation to a block and item

184 messages · Page 1 of 1 (latest)

spice linden
#

i have a block which i want to be radioactive, already created the effect but now i want to apply it in a few different situations.
#1 When the player is near the radioactive block (2-3 block radius)
#2 When the player is within a block of the radioactive block or When the player mines the block
#3 When the item is in the inventory of the player it should constantly give the effect

i already did the second point quite fast but idk how to get started with the other ones

onEvent("block.break", event => {
    if (event.block.id == "forgedingears:neutrum_ore")
    {
        event.player.potionEffects.add('kubejs:radiation', 40, 2, false, true)
    }
})
idle sapphireBOT
#

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

cyan panther
#

for third:

onEvent("player.tick", event => {
  if(event.player.age % 20 != 0) return
  if(event.player.inventory.find("forgedingears:neutrum_ore") == -1) return
  event.player.potionEffects.add('kubejs:radiation', 21, 2, false, true)
})
#

I wouldn't recommend doing first as it would probably be quite laggy (scanning 200 - 343 blocks every 20 ticks for each player)

full solar
hybrid dockBOT
#

[Quote ➤](#1166308080317907014 message) js PlayerEvents.tick(event => { const {player,server,player:{username}} = event if(!(player.age % 20 == 0)) return if (player.persistentData.canaccessnetherportal == 1) return if (player.block.id == 'minecraft:nether_portal') { player.block.set('air') player.displayClientMessage(Component.of('The forces of the universe deny your impudence').bold().red(), true) }else if (player.block.west == 'minecraft:nether_portal'){ player.block.west.set('air') player.displayClientMessage(Component.of('The forces of the universe deny your impudence').bold().red(), true) }else if (player.block.east == 'minecraft:nether_portal'){ player.block.east.set('air') player.displayClientMessage(Component.of('The forces of the universe deny your impudence').bold().red(), true) }else if (player.block.north == 'minecraft:nether_portal'){ player.block.north.set('air') player.displayClientMessage(Component.of('The forces of the universe deny your impudence').bold().red(), true) }else if (player.block.south == 'minecraft:nether_portal'){ player.block.south.set('air') player.displayClientMessage(Component.of('The forces of the universe deny your impudence').bold().red(), true) } }) PlayerEvents.advancement(event => { if(event.advancement.id().toString() == "minecraft:story/mine_diamond") { event.player.persistentData.canaccessnetherportal = 1 } })

full solar
#

destroys the nether portal block if you dont have access to the nether through persistent data yet

cyan panther
#

yeah this isn't really usable in this case

full solar
#

how so

full solar
cyan panther
#

you can't scale this up in any way

full solar
#

you can

#

sec

cyan panther
#

good luck making a 800+ line script then

#

with manually setting each cord

#

also the performance question still applies

full solar
#

who said itd be 800 lines

cyan panther
#

if you need to scan 200+ blocks that's like 400 lines and 200 positions to set manually, sorry counted incorrectly

full solar
#

not 200 block radiusdespair

cyan panther
#

that's 200+ blocks

#

but in all directions

#

you need to scan

full solar
#

what

cyan panther
#

use basic maths

full solar
#

3x3x3 != 200

cyan panther
#

also radius

full solar
#

thats included in 3x3x3

cyan panther
#

that's atleast 7x7x7

full solar
#

we're talking about 3-4 blocks

#

not 7

cyan panther
#

yeah but 3 in each direction

full solar
#

yeah, 3x3x3

cyan panther
#

that's what radius means

#

3 in each direction

#
  • the player pos
#

gives 7x7x7

full solar
#

hmm

#

youre right

#

crap

#

mb

#

ok so heres what we'll do then

#

we set up the block as a block entity where we can run server ticks

#

if its a block entity then we can have it give people the effect when they're nearby

cyan panther
#

this is 1.18

full solar
#

no

#

what

cyan panther
#

yes

full solar
#

no

hybrid dockBOT
#
lat

[Quote ➤](#future-vision message) ## kubejs I'm working on adding custom BlockEntities to KubeJS!
And custom screens/menus. It's still WIP, and only for 1.20.1, but you will be able to do stuff like this:
https://i.latvian.dev/pc/2023-09-11_22.18.55.mp4

Code used for demo:

StartupEvents.registry('block', event => {
    event.create('machine_block').soundType('netherite_block').blockEntity(entityInfo => {
        entityInfo.inventory(9, 4) // create inventory to 9x4 / 36 slots
        entityInfo.rightClickOpensInventory() // Right-clicking on entity opens its inventory

        entityInfo.clientTick(12, 0, entity => { // Tick on client side only. 12, 0 = every 12 ticks with offset 0 (tick % 12 == 0)
            entity.level.addParticle('minecraft:campfire_cosy_smoke', true, entity.x + 0.5, entity.y + 1.05, entity.z + 0.5, 0, 0.3, 0)
        })

        entityInfo.serverTick(20, 0, entity => { // Tick on server side only
            entity.inventory.insertItem('minecraft:apple', false)
        })
    })
})
full solar
#

we must be thinking of different things

#

oh wait i coulda sworn lat backported this to 18

#

crap i just realized you meant the post was 1.18

cyan panther
#

yeah

full solar
#

dang

#

hmm

cyan panther
#

we would need to spawn a entity

#

ignore that

full solar
#

i mean its possible

cyan panther
#

it wouldn't work, as the block is worldgened

full solar
#

yeah true

cyan panther
#

you could do it with scanning the blocks, but it could impact performance on high amounts of players, so idk if that's a great idea

#

if it wouldn't worldgen it would be so much easier and more performent

full solar
#

this is one of those year old questions from others trying to make custom fluids play the lava sound i just realized

#

it might be doable on 1.19 with block entities but 1.18 im not sure if itd honestly be worth it

#

unless someone can figure out a non laggy way of detecting if a player is near a block

full solar
#

idk

cyan panther
#

that's probably worse in performance that kube

full solar
#

you think so?

#

i mean its checking a box of blocks, this is done regularly in mods like world edit

#

on a MUCH bigger scale

#

tho ive never messed with it so maybe its different

cyan panther
#

that command wouldn't work as you would need to place a test template somewhere

full solar
#

you can have it adjacent to yourself with ~5 ~5 ~5 for example

#

the issue is i have no idea how it works lol

cyan panther
#

the first two coordinate sets mark an area that is going to be tested the last coordinate set marks a second area with the same size as the first, and then those get checked

#

so it scans double the blocks

#
  • you need to have a template somewhere
full solar
#

hmm

cyan panther
spice linden
#

it doesnt have to be as huge as 7x7x7

#

it can also be 5x5x5

#

or smaller maybe

full solar
#

well what he means is that detecting all the blocks in a 1 block radius around you is 27 checks

#

think of a 3x3x3 cube

#

its only 1 block out from you

cyan panther
#

yeah that wouldn't be a problem performance whise

full solar
#

i was confused at first too

cyan panther
#

but it only runs if you stand directly in front (pretty much)

full solar
#

yea

#

could easily make it so if youre standing on the block then it triggers

spice linden
#

what about something like this

#

or is it not possible on 1.18

full solar
#

hmm

#

thats detecting entities, not sure about block radius

hybrid dockBOT
#

Adds Forge's Capability system integration for KubeJS. With PowerfulJS, you can retrieve, attach capabilities supported for ItemStacks, Block Entities and so on!

Mod by @fossil temple


full solar
#

oof 1.19 only

#

what about skulk sensors

#

maybe could remake one of those

cyan panther
#

this would be the script for looping over each block. Though check with higher values aswell (if you use r = 2 try r = 6, for r = 3, try r = 7 for the performance impact with around 20 players or try even higher values)

onEvent("player.tick", event => {
  if(event.player.age % 20 != 0) return
  let radius = 1
  let px = event.player.block.x
  let py = event.player.block.y
  let pz = event.player.block.z
  for(let x = -radius; x <= radius; x++){
    for(let y = -radius; y <= radius; y++){
      for(let z = -radius; z <= radius; z++){
        if(event.player.level.getBlock(new BlockPos(px + x, py + y, pz + z)).id != "forgedingears:neutrum_ore") continue
        event.player.potionEffects.add('kubejs:radiation', 21, 2, false, true)
        return
      }
    }
  }
})
cyan panther
#

This will probably result in better average performance as it's more likely that a given block is below you then on the side / above you

onEvent("player.tick", event => {
  if(event.player.age % 20 != 0) return
  let radius = 1
  let px = event.player.block.x
  let py = event.player.block.y
  let pz = event.player.block.z
  for(let y = -radius; y <= radius; y++){
    for(let x = -radius; x <= radius; x++){
      for(let z = -radius; z <= radius; z++){
        if(event.player.level.getBlock(new BlockPos(px + x, py + y, pz + z)).id != "forgedingears:neutrum_ore") continue
        event.player.potionEffects.add('kubejs:radiation', 21, 2, false, true)
        return
      }
    }
  }
})
spice linden
#

its not working i think

#

is this effect too impactful on performance?

#

if so ill just not use it and setup other ways to make the ore hard to obtain

#

ill try to make the inventory one

full solar
#

send logs, looks like it should work

frank tangle
#

I will try something and measure performance

spice linden
hybrid dockBOT
#

Paste version of message.txt from @spice linden

frank tangle
#

so this is 1.18 right?

spice linden
#

if it's too impactful on performance then mining and picking the item up/having it in ur inventory is fine

#

ye 1.18

frank tangle
#

it is 3 radius

#

looking each second

spice linden
#

is it too impactful on performance?

#

would using it on a server be a bad idea

frank tangle
#

you can see at player status how long it is taking

#

I will change to something absurd like 30 radius, just to test

#

yeah it takes like 5-80ms for absurd like 30 radius
which is not recommended, but for 3 radius is very light, you can test yourself

full solar
#

doesnt look too impactful to me

frank tangle
#
onEvent("player.tick",event => {
  let player = event.player
  if (player.ticksExisted % 20 != 0) return
  let radioactiveBlockPos = BlockPos.findClosestMatch(player.block.pos, 3, 3, pos => event.level.getBlock(pos).hasTag("forge:radioactive"))
  radioactiveBlockPos.ifPresent(() => player.potionEffects.add("wither",200))
})

onEvent("block.tags", event => {
  event.add("forge:radioactive", ["minecraft:iron_ore", "minecraft:diamond_ore"])
})
full solar
#

tho you also have to take into account multiplayer

full solar
frank tangle
#

always has been.png

full solar
#

fair enough

#

if its searching every second then its probably fine if it isnt too large of an area tbh

spice linden
#

works great

#

what about the item giving the effect if it's in the inventory

frank tangle
#

didn't @full solar provide that?

spice linden
#

oh i didnt see mb

full solar
#

i contributed my moral support thus far

spice linden
#

it isnt working

full solar
#

try doing this js if(event.player.inventory.find("forgedingears:neutrum_ore") <= 0) return

frank tangle
#
onEvent("player.tick",event => {
  let player = event.player
  if (player.ticksExisted % 20 != 0) return
  let radioactiveBlockPos = BlockPos.findClosestMatch(player.block.pos, 3, 3, pos => event.level.getBlock(pos).hasTag("forge:radioactive"))
  radioactiveBlockPos.ifPresent(() => player.potionEffects.add("wither",200))
  if (player.inventory.find("#forge:radioactive") > -1) player.potionEffects.add("wither",200)
})

onEvent("block.tags", event => {
  event.add("forge:radioactive", ["minecraft:iron_ore", "minecraft:diamond_ore"])
})

onEvent("item.tags", event => {
  event.add("forge:radioactive", ["minecraft:iron_ore", "minecraft:diamond_ore"])
})
full solar
#

or that

#

tho > -1?

#

im assuming he tested it so i guess it works

frank tangle
#

I did test, -1 is when it is not found

full solar
#

fair enough

#

im used to doing <= 0

#

nice

spice linden
#

yea its working great

frank tangle
spice linden
frank tangle
#

check your block tags

#

i didn't change anything about blocks

#

send YOUR script

spice linden
#

yea idk what i messed up but it works now

full solar
#

probably needed to reload tags maybe

spice linden
#

Is there a way to not apply this effect if the player is wearing full tconstruct cobalt armor which is embellished(modifier that’s nbt data too im pretty sure) by a certain material, to reduce the radiation levels

frank tangle
#

everything is possible when you believe

hybrid dockBOT
#

[Quote ➤](#1152944634067165285 message) ```js
let tick = 0
let rad = NaN
onEvent('player.tick', event => {
const { player } = event
if(tick % 5 == 0) {rad = player.fullNBT.ForgeCaps["enlightened_end:player_variables"].radiation}
if (player.mainHandItem == 'compass' || player.offHandItem == 'compass') player.paint({ radiation: { text: Radiation: ${rad} rads, visible: true } })
else player.paint({ radiation: { visible: false } })

if (player.headArmorItem == 'thermal:hazmat_helmet'
    && player.chestArmorItem == 'thermal:hazmat_chestplate'
    && player.legsArmorItem == 'thermal:hazmat_leggings'
    && player.feetArmorItem == 'thermal:hazmat_boots') {
    player.getPotionEffects().add('enlightened_end:radiation_resistance', 10, 255, false, false)
}
tick++

})

onEvent('player.logged_in', event => {
const { player, server } = event
player.paint({
radiation: {
type: 'text',
text: 'Radiation',
scale: 1,
x: -4,
y: -4,
alignX: 'right',
alignY: 'bottom',
draw: 'ingame',
visible: false
}
})
})

Nobody helped 😦 but i fiex it lol. I defined variable outside the scope and updated it every 5 ticks inside the ticking event.
spice linden
#

Would it be something similar to this?

spice linden
#

well i got it somewhat work, i have no clue how to check if it has the "tconstruct:embellishment":"forgedingears:element_zero" nbt.

item id of the embellished armor piece:
Item.of('tconstruct:plate_helmet', '{Damage:0,tic_broken:0b,tic_modifiers:[{level:1s,name:"tconstruct:embellishment"}],tic_persistent_data:{abilities:1,defense:5,"tconstruct:embellishment":"forgedingears:element_zero",upgrades:2},tic_stats:{"tconstruct:armor":2.0f,"tconstruct:armor_toughness":2.0f,"tconstruct:durability":440.0f,"tconstruct:knockback_resistance":0.05f},tic_upgrades:[{level:1s,name:"tconstruct:embellishment"}]}')

onEvent("player.tick",event => {
    let player = event.player
    if (player.headArmorItem == 'tconstruct:plate_helmet' && player.chestArmorItem == 'tconstruct:plate_chestplate' && player.legsArmorItem == 'tconstruct:plate_leggings' && player.feetArmorItem == 'tconstruct:plate_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)
  })

also if it would be possible making it so the armor reduces the effect give to only level 1

full solar
# spice linden well i got it somewhat work, i have no clue how to check if it has the "tconstru...

try something like this js onEvent("player.tick",event => { let player = event.player if (player.headArmorItem.nbt.contains('forgedingears:element_zero') && player.chestArmorItem.nbt.contains('forgedingears:element_zero') && player.legsArmorItem.nbt.contains('forgedingears:element_zero') && player.feetArmorItem.nbt.contains('forgedingears:element_zero')) 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) })

spice linden
#

Alr ill take a look at it tmrrw had no time today

spice linden
full solar
#

hmm

#

do /kubejs hand and send the item.of info here

#

for all the armor pieces

#

the ones that have forgedingears:element_zero

spice linden
#

Item.of('tconstruct:plate_helmet', '{Damage:0,tic_broken:0b,tic_modifiers:[{level:1s,name:"tconstruct:embellishment"}],tic_persistent_data:{abilities:1,defense:5,"tconstruct:embellishment":"forgedingears:element_zero",upgrades:2},tic_stats:{"tconstruct:armor":2.0f,"tconstruct:armor_toughness":2.0f,"tconstruct:durability":440.0f,"tconstruct:knockback_resistance":0.05f},tic_upgrades:[{level:1s,name:"tconstruct:embellishment"}]}')

Item.of('tconstruct:plate_chestplate', '{Damage:0,tic_broken:0b,tic_modifiers:[{level:1s,name:"tconstruct:embellishment"}],tic_multipliers:{"tconstruct:attack_damage":0.4f},tic_persistent_data:{abilities:1,defense:5,"tconstruct:embellishment":"forgedingears:element_zero",upgrades:1},tic_stats:{"tconstruct:armor":6.5f,"tconstruct:armor_toughness":2.0f,"tconstruct:attack_damage":0.0f,"tconstruct:durability":640.0f,"tconstruct:knockback_resistance":0.05f},tic_upgrades:[{level:1s,name:"tconstruct:embellishment"}]}')

Item.of('tconstruct:plate_leggings', '{Damage:0,tic_broken:0b,tic_modifiers:[{level:1s,name:"tconstruct:embellishment"}],tic_persistent_data:{abilities:1,defense:5,"tconstruct:embellishment":"forgedingears:element_zero",upgrades:1},tic_stats:{"tconstruct:armor":5.5f,"tconstruct:armor_toughness":2.0f,"tconstruct:durability":520.0f,"tconstruct:knockback_resistance":0.05f},tic_upgrades:[{level:1s,name:"tconstruct:embellishment"}]}')

Item.of('tconstruct:plate_boots', '{Damage:0,tic_broken:0b,tic_modifiers:[{level:1s,name:"tconstruct:embellishment"}],tic_persistent_data:{abilities:1,defense:5,"tconstruct:embellishment":"forgedingears:element_zero",upgrades:1},tic_stats:{"tconstruct:armor":2.0f,"tconstruct:armor_toughness":2.0f,"tconstruct:durability":400.0f,"tconstruct:knockback_resistance":0.05f},tic_upgrades:[{level:1s,name:"tconstruct:embellishment"}]}')

spice linden
full solar
#

hmmm

#

sec

spice linden
full solar
#

heres my github from where i was detecting nbt on armor

#
PlayerEvents.tick(event => {
  let helmetslot = event.player.getItemBySlot(5)
  let chestslot = event.player.getItemBySlot(4)
  let legslot = event.player.getItemBySlot(3)
  let bootslot = event.player.getItemBySlot(2)
  let item = event.player.getHeldItem('main_hand')
  let air = event.player.getMainHandItem().id == 'minecraft:air'
  let pData = event.player.persistentData
  let test = (helmetslot) => event.player.tell(helmetslot)
  let tell = (string) => event.player.tell(string)
  //test(helmetslot)
  
  
  if(pData.timer == 0 || pData.timer == 5 || pData.timer == 10 || pData.timer == 15 || pData.timer == 20) {
    
  
    if (helmetslot.hasNBT() && helmetslot.nbt.Helmet) {``` though this was 1.19
#

see if theres getitembyslot

spice linden
#

idk ive tried everything i could nothing is working

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)
  })
full solar
spice linden
#

ight ill close this one thanks