#Optimal Time Check

25 messages · Page 1 of 1 (latest)

quaint snow
#

Hey there! Total noob here, just downloaded KubeJS today and it's been blowing my mind. I was only able to find one existing post related to my question, however, it was for an older version: https://discord.com/channels/303440391124942858/1137609364841168959

I was wondering if there was a way to sort of mimic item behavior, for context, in my modpack I've got like 6 different hammers all for different furniture mods, I'd like to unify them but I'm not sure if that's possible.

celest pollenBOT
#

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

thick mulch
#

what does those hammers do

#

use as ingredient?

#

open a gui?

#

use on a block?

quaint snow
thick mulch
#

so thats the use of hammer?

#

im not sure if im getting it right, it does something to the item itself?

quaint snow
thick mulch
#

they only change the block that belongs to their mod?

quaint snow
#

Yes, I'm trying to unify them though, one hammer to change it all

thick mulch
dense canopyBOT
#

[➤](#1302909605105500170 message)
Startup script, requires EntityJS.
Auto plant on fall, should be performant since slow things are executed in different tick.

const BushBlock = Java.loadClass('net.minecraft.world.level.block.BushBlock')
const BlockHitResult = Java.loadClass('net.minecraft.world.phys.BlockHitResult');
function auto_plant(entity) { //only triggers on item fall
    if(entity.level.isClientSide()) return;
    const {item} = entity, {item: {block}} = item;
    if(!block || !(block instanceof BushBlock)) return; //if it's block item, if the block is plant

    const {server} = entity;
    server.scheduleInTicks(Utils.random.nextInt(0, 3), () => { //random delay to avoid lag in extreme cases
        const player = server.players.getFirst();
        if(!player) return;
        const use_result = item.useOn(
            new UseOnContext(
                player, 'main_hand',
                new BlockHitResult(
                    null, 'up',
                    entity.block.pos, false
                )
            )
        );
        if(use_result != 'CONSUME') return; //despawn item entity on success plant
        entity.discard();
        entity.playSound('block.grass.place', 0.3, 1.06);
    })
}

EntityJSEvents.modifyEntity(e => {
    e.modify('minecraft:item', modifyBuilder => modifyBuilder.onFall(context => auto_plant(context.entity)))
})
thick mulch
#

since i dont have, and wont have those mods installed, i cant test script for you

#
  1. use block right clicked event
  2. check if event.item is your custom hammer
  3. check event.block.id.split(':')[0] aka the mod name, and use Item.of('hammer id').useOn()
quaint snow
#

I will give that a go asap 🫡

quaint snow
#

no dice :[

quaint snow
#

Unrelated to the previous question, would this be the most optimal way to run something every 20 minutes? ```let tick = 0;

ServerEvents.tick((e) => {
tick += 1(tick == 24000) && console.log("20 minutes has passed");
});

#

Optimal Time Check

thick mulch
#

if you change the title, other people wont be able to get the answer for previous question

#

dont do that

#

searching is important in this channel

#

if you feel your question is solved, close the ticket

dense canopyBOT
#

Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue!
This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.

Do you have any other questions regarding your issue? Feel free to ask!
Note: You should generally create a new post for unrelated issues.