#custom bow / ranged weapon

542 messages · Page 1 of 1 (latest)

frosty plume
#

how would iu go about making a custom ranged weapon that uses its own ammo type, and or customise most aspects, from looking at a different post

const $bowItem = Java.loadClass('net.minecraft.world.item.BowItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')
StartupEvents.registry('item', event => {
    event.create('dart_chute', () => new $bowItem(new $ItemProperties().defaultDurability(23)))
})
```dont work, either because BowItem isnt a thing or some other random thing
warm bronzeBOT
#

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

sly stone
#

what does the log say

frosty plume
#

it crashes on startup

#

getting screenshotr

#

idk how i would go about creating a new item with all the same properties as a bow but with its own ammo from scratch

#

and idk how to copy an item using the above method, as it broke

idle portalBOT
#

[Quote ➤](#1098163110747050055 message) this is how you do it

StartupEvents.registry('item', event => {
    const $SandPaperItem = Java.loadClass('com.simibubi.create.content.curiosities.tools.SandPaperItem')
    const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')

    event.custom('diamond_sandpaper', new $SandPaperItem(new $ItemProperties().defaultDurability(2000)))
})

You need to get the items class for the first import, which requires some code diving

sly stone
#

wait

frosty plume
#

thats where i got the code from in the first place

idle portalBOT
#

[Quote ➤](#1149564801891192962 message) I'm getting around to learning how to use Java.loadClass and I can at least say that my brain is now some sort of sludge that was fried on the highest setting. I was able to at least get to this point by scavenging this discord for anything and I found this post #1098163110747050055 messagewhich helped me initially create the bow but I am now lost.
I know next to nothing about java

StartupEvents.registry('item', event => {
    const $BowItem = Java.loadClass(`net.minecraft.world.item.BowItem`)
    const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')

    event.custom('custom_bow', new $BowItem(new $ItemProperties().defaultDurability(500)))
})
sly stone
#

yeah but you used it incorrectly

frosty plume
#

ok, howso

sly stone
#

you need to use event.custom()

#

and dont need an arrow function

#

So this

const $bowItem = Java.loadClass('net.minecraft.world.item.BowItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')
StartupEvents.registry('item', event => {
    event.custom('dart_chute', new $bowItem(new $ItemProperties().defaultDurability(23)))
})
frosty plume
#

ah

#

lemme try

frosty plume
# idle portal

that still leaves modeling which i read about in the same quote post

idle portalBOT
frosty plume
#

and ammo

#

so it wont use regular arrows as that kinda defeats the purpose of a custom ranged weapon

#

item works, just with wrong ammo, no model and not in kubejs tab

#

but the other post had a fix for the tab thing

sleek wigeon
#

isnt it createcustom?

midnight topaz
#

it is

#

custom is legacy, and not recommended to use

#

you should use createCustom instead

sleek wigeon
#

i thought so

frosty plume
#

legacy?

sleek wigeon
#

in other words its outdated

frosty plume
#

but it works?

sleek wigeon
#

sure but how well is the real question

frosty plume
#

changed it

#

ah ok

#

now how to prevent it using arrows and make a custom item[s] to use instead

sleek wigeon
frosty plume
#

optional poison status effect like tipped arrows

sleek wigeon
#

mine works like a regular bow

frosty plume
#

same

sleek wigeon
#
const $BowItem = Java.loadClass('net.minecraft.world.item.BowItem')
const $Properties = Java.loadClass('net.minecraft.world.item.Item$Properties')
const $Tab = Java.loadClass('net.minecraft.world.item.CreativeModeTab')

let bow_props = new $Properties().tab($Tab.TAB_MISC)

let customBow

StartupEvents.registry('item', items => {
    customBow = items.createCustom("modid:custom_bow", () => new $BowItem(bow_props))
})```
#

nice

#

make sure you add it to a tab like this as well

frosty plume
#
const $bowItem = Java.loadClass('net.minecraft.world.item.BowItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')

const $kubejs = Java.loadClass('dev.latvian.mods.kubejs.KubeJS')
StartupEvents.registry('item', event => {
    event.createCustom('dart_chute', new $bowItem(new $ItemProperties().tab($kubejs.tab).defaultDurability(23)))
})
#

its in a tab currently, firable and has the same enchants a bow does

sleek wigeon
#

oh fr?

#

fair enough

#

so whats the issue

#

oh custom arrows?hmmm

frosty plume
#

still need a way to:
custom ammo / prevent arrows from being used
change sound, projectile texture and model

#

yes

#

thats the main reason for this ticket

#

custom ranged weapon + ammo

#

nope

#

changing event.custom to event.createCustom breaks it

#

adding the () => back makes it work??

#

ye

#

either ```js
event.createCustom('dart_chute', () => new $bowItem(new $ItemProperties().tab($kubejs.tab).defaultDurability(23)))

or ```js
event.custom('dart_chute', new $bowItem(new $ItemProperties().tab($kubejs.tab).defaultDurability(23)))
```
sleek wigeon
#

with createcustom you need the callback function

frosty plume
#

alr

#

ammo how?

#

and making sure regular + tipped arrows cant be fired from it

sleek wigeon
#

might need to extend the class to do that this way

#

which currently rhino does not do

#

lats working on a new javascript engine called ichor which can extend classes i believe

#

though im sure you could somehow mimic this in some weird way with other events

frosty plume
#

how tho

#

am almost a complete beginner

#

to kubejs and js/java/json

sleek wigeon
#

im trying something

#

dont get your hopes up tho

frosty plume
#

iwont [began playing a diff game]

sleek wigeon
#

lol

frosty plume
#

it would be neat to create a custom texture / sound for said projectile
but if ammo is the least possible i'd be happi

#

if not im gonna have to make a simpler recipe for poison arrows, just use them and model the ranged weapon / blowpipe

#

its [although not preferred] atleast an option

sleek wigeon
#

this is a startup script going off the forge LivingGetProjectileEvent which basically changes the itemstack used depending on the item used to fire it

ForgeEvents.onEvent('net.minecraftforge.event.entity.living.LivingGetProjectileEvent', event => {
    global.projectile(event);
});
/**
 * 
 * @param {Internal.LivingGetProjectileEvent} event 
 */
global.projectile = event => {
    // Check if the entity is a living entity
    if (event.entity.living) {
        const livingEntity = event.entity;

        // Check if the projectile is being requested by a specific weapon (modify this condition as needed)
        if (event.projectileWeaponItemStack.id == 'minecraft:bow') {
            event.setProjectileItemStack('minecraft:spectral_arrow')
        }
    }
};``` you can modify anything in that global function and run /kubejs reload startup_scripts to reload it without having to restart the entire game
#

as long as youve loaded it up at least once

frosty plume
#

wait so, whats this for

#

effect?

sleek wigeon
#

you would replace 'minecraft:bow' with your custom bow name

sleek wigeon
#

wym whats this for

frosty plume
#

what does this do?

sleek wigeon
#

uh

midnight topaz
sleek wigeon
#

lol hey don

sleek wigeon
#

tabby you wanted to use different arrows by default with your custom bow correct?

frosty plume
#

no

sleek wigeon
frosty plume
#

well

#

partly

#

to use a different custom item as ammo

#

INSTEAD of arrows

sleek wigeon
#

well yeah

#

you would then just replace 'minecraft:spectral_arrow' with your custom item

#

thats the whole point of this

frosty plume
#

ah ok

#

brain fog

sleek wigeon
#

💀

#

all g

frosty plume
#

💀 ikr

#

so this would consume said item?

#

im gonna have to test that one

sleek wigeon
#

let me ask a question just so i understand what youre trying to do a little bit better here

#

do you want it to default to firing a custom projectile, or do you only want it to be able to fire certain projectiles(like the potato gun)

frosty plume
#
/**
 * 
 * @param {Internal.LivingGetProjectileEvent} event 
 */
``` is this part useful?
#

-new to js- am assuming its a comment

sleek wigeon
#

if you have probejs it supplies information on what methods are available

frosty plume
#

ah ok

#

no probejs though ive heard of it

sleek wigeon
#

you should def get it

#

its a lifesaver

#

??tutori

#

woops

#

??tutorial

idle portalBOT
sleek wigeon
#

watch the first one skip to 30 seconds in

midnight topaz
sleek wigeon
#

it explains how to install it(45 seconds to explain)

sleek wigeon
frosty plume
#

is useful but requires aditional programs to work

sleek wigeon
#

you mean..

frosty plume
#

like a non notepad++ editor

sleek wigeon
#

youre not using vsc?

frosty plume
#

no 💀

sleek wigeon
#

breh

frosty plume
#

notepad++ baby!

sleek wigeon
#

notepad++ is so bad for js

midnight topaz
#

breh

sleek wigeon
#

get vsc

midnight topaz
#

??editor

idle portalBOT
# midnight topaz ??editor

If you're working with KubeJS scripts, config files, or similar things, we generally recommend using an actual IDE rather than just Notepad++ and its various siblings.
In a lot of cases, it can help you find errors in your code faster and also gives you neat features like syntax highlighting, automatic formatting, etc!
We recommend Visual Studio Code, since it's lightweight(-ish) and works very well with JavaScript files out-of-the-box.

midnight topaz
#

please

sleek wigeon
#

sooo much better, especially if youre serious about coding

frosty plume
#

m maybe

sleek wigeon
#

in any case

frosty plume
#

btw curious code question

midnight topaz
sleek wigeon
idle portalBOT
#

[Quote ➤](#1183093106384576602 message) do you want it to default to firing a custom projectile, or do you only want it to be able to fire certain projectiles(like the potato gun)

frosty plume
#
ForgeEvents.onEvent('net.minecraftforge.event.entity.living.LivingGetProjectileEvent', event => {
    global.projectile(event);
});
#

and below that

global.projectile = event => {
sleek wigeon
#

yeah thats a global function usage

frosty plume
#

is there a reason the bottom doesnt go in the top function

sleek wigeon
#

yes

frosty plume
#

ellaborate [ifyouwant]

sleek wigeon
#
ForgeEvents.onEvent('net.minecraftforge.event.entity.living.LivingGetProjectileEvent', event => {
   //anything in here requires a full game restart
});```
#

global functions can be used across script types however and lets us run /kubejs reload startup_scripts

midnight topaz
#

that's called "the global trick"™️

sleek wigeon
#

she still hasnt answered my question btw

midnight topaz
idle portalBOT
#

[Quote ➤](#1183093106384576602 message) do you want it to default to firing a custom projectile, or do you only want it to be able to fire certain projectiles(like the potato gun)

midnight topaz
#

@frosty plume heh

sleek wigeon
#

we'll see if it works a third time

midnight topaz
#

as they say, third time's the charm

sleek wigeon
#

lmao

frosty plume
sleek wigeon
#

you

#

breh

midnight topaz
frosty plume
#

sorry did not see that

frosty plume
sleek wigeon
#

ah ok then this script is the right one then

#

oh mb

#

she*

#

hmm as for consuming the itemstack ill look into that

frosty plume
#

now if this only fires spectral arrows, the script works and thats another one off the list

sleek wigeon
#

should

frosty plume
#

consuming itemstack yeah but also

#

if i were to make a custom arrow item

sleek wigeon
#

shouldnt matter if you have other projectiles in your inv

frosty plume
#

how make the projectile texture

sleek wigeon
#

you probably want to do it the same way vanilla did

frosty plume
#

its able to use a regular arrow

#
const $bowItem = Java.loadClass('net.minecraft.world.item.BowItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')

const $kubejs = Java.loadClass('dev.latvian.mods.kubejs.KubeJS')
StartupEvents.registry('item', event => {
    event.createCustom('dart_chute', () => new $bowItem(new $ItemProperties().tab($kubejs.tab).defaultDurability(23)))
})

ForgeEvents.onEvent('net.minecraftforge.event.entity.living.LivingGetProjectileEvent', event => {
    global.projectile(event)
})
global.projectile = event => {
    if (event.entity.living) {
        const livingEntity = event.entity
        if (event.projectileWeaponItemStack.id == 'kubejs: dart_chute') {
            event.setProjectileItemStack('minecraft:spectral_arrow')
        }
    }
}
#

the whole script thusfar

#

wait

#

theres a space in there

sleek wigeon
#

was gonna say lol

frosty plume
#

ok so it fires spectral arrows

#

but even without them in your inventory

sleek wigeon
#

yeah

frosty plume
#

which is a "consume item" problem

sleek wigeon
#

like i said imma look into it

frosty plume
#

as it dont check if theres such items in your inventory, let alone deduct from a stack

#

alr

#

been a great help sofar man

sleek wigeon
#

np lol, always glad to figure things like this out

frosty plume
#

ok problem

#

im gonna send log

#

but sometimes it doesnt fire an arrow

#

and spamming it crashes the ganme

idle portalBOT
#

Paste version of message.txt from @frosty plume

frosty plume
#

2100 lines of error

#

somewhere something went bad

sleek wigeon
#

hmm

#

yeah im working on the null check as well on my end

frosty plume
#

im gonna try get the model to work

#

just with some random bamboo textures to see IF the model changes / renders

#

if that somehow all works, making a custom texture but thats longtermgoals[tm]

#

this sadly doesnt work according to that website

{
  "parent": "minecraft:item/generated",
  "textures": {
    "layer0": "kubejs:item/bamboo_singleleaf"
  },
  "overrides": [
    {
      "predicate": {
        "pulling": 1
      },
      "model": "kubejs:item/dart_chute_pulling_0"
    },
    {
      "predicate": {
        "pulling": 1,
        "pull": 0.65
      },
      "model": "kubejs:item/dart_chute_pulling_0"
    },
    {
      "predicate": {
        "pulling": 1,
        "pull": 0.9
      },
      "model": "kubejs:item/dart_chute_pulling_0"
    }
  ]
}
#

pulling_0 being

{
  "parent": "kubejs:item/dart_chute",
  "textures": {
    "layer0": "kubejs:item/dart_chute_pulling_0"
  }
}

sleek wigeon
#

you need the other 3 .json models as well

#

oh you have them hmmm

frosty plume
#

they're the same file

#

just to test if it would even change but it doesnt

#

doesnt display missing texture so thats not a fault of texture misnaming

#

it just shows the first texture but pulling it back

#

gonna try it with just 1

#

the crashing issue is purely when underdrawing the bow i think

#

issue might be in the item creation not being able to bear overrides

#

"some"

frosty plume
sleek wigeon
#

i fixed that null bug btw

#

im working on getting it to only shoot the specified item, gonna be a sec but i think it's possible

frosty plume
#

nice

#

the model is also borke

#

some other person also had this problem

sleek wigeon
#

though theres a couple things to note

kind cape
sleek wigeon
#
ForgeEvents.onEvent('net.minecraftforge.event.entity.living.LivingGetProjectileEvent', event => {
    global.projectile(event);
});

/**
 * @param {Internal.LivingGetProjectileEvent} event 
 */
global.projectile = event => {
    if (event.entity.level.clientSide) return
    if (event.projectileWeaponItemStack.id != 'minecraft:bow') return
    event.setProjectileItemStack('minecraft:spectral_arrow')

};
ForgeEvents.onEvent('net.minecraftforge.event.entity.player.ArrowLooseEvent', event => {
    global.shoot(event)
})
/**
 * 
 * @param {Internal.ArrowLooseEvent} event 
 */
global.shoot = event => {
    if (event.entity.level.clientSide) return
    if (event.bow.id != 'minecraft:bow') return
    let entity = event.entity;
    let maxSlots = 41;
    for (let slotIndex = 0; slotIndex < maxSlots; slotIndex++) {
        let slot = entity.getSlot(slotIndex);
        let itemStack = slot.get();

        if (!itemStack.count <= 0) {
            // Access the item ID directly
            let itemId = itemStack.id;
            if (itemId === 'minecraft:spectral_arrow') {
                itemStack.count--
                return
            }
        }

    }
    event.setCanceled(true)
}```
Here we have to utilize 2 forge events, one to change the projectile of your weapon to your custom projectile item (here we're using spectral arrows and a normal bow as examples) and one to cancel the arrowloose forge event if you dont have the right arrow in your inventory. The arrow loose event also acts as a trigger to decrease the stack of the arrow by 1 when the bow shoots
#

this is one big startup script

frosty plume
#

gonna test it

sleek wigeon
#

the only issue is client desync when you have normal arrows in your inventory and it cancels the event
though im sure you could maybe open up another ticket and someone will know how to fix that

#

makes it look like youre using normal arrows when youre not, til you update it in your inv that is

frosty plume
#

hmm odd

sleek wigeon
#

is it working for you?

frosty plume
#

testing now

sleek wigeon
#

besides the client desync?

frosty plume
#

i hope that client desync gets fixers

#

does the client desync occur when having 0 items?

sleek wigeon
#

aight, i would open up a ticket labeled "client desync in forge event" for someone who knows about the subject to see

#

nah

frosty plume
#

alr

#

if this works

#

-new ticket
-texture+model for arrow entity and just item
-the model for bow / texture being broken

#

there is probably a way around that issue

#

as in creative mode it also deletes items and wont work if none are present

#

it also draws the bow

#

maybe somehow check for item BEFORE it even draws bow

#

that sounds very dumb

#

E

#

idont think this is a "next ticket" issue

#

it ties in with it not working in creative mode

#

nope it straight up crashed with normal arrows

#

in creative mode

idle portalBOT
#

Paste version of latest.log from @frosty plume

frosty plume
#
const $bowItem = Java.loadClass('net.minecraft.world.item.BowItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')

const $kubejs = Java.loadClass('dev.latvian.mods.kubejs.KubeJS')
StartupEvents.registry('item', event => {
    event.createCustom('dart_chute', () => new $bowItem(new $ItemProperties().tab($kubejs.tab).defaultDurability(23)))
})

ForgeEvents.onEvent('net.minecraftforge.event.entity.living.LivingGetProjectileEvent', event => {
    global.projectile(event)
});    ForgeEvents.onEvent('net.minecraftforge.event.entity.player.ArrowLooseEvent', event => {
        global.shoot(event)
})
global.projectile = event => {
    if (event.entity.level.clientSide) return
    if (event.projectileWeaponItemStack.id == 'kubejs:dart_chute') return
    event.setProjectileItemStack('minecraft:spectral_arrow')
}
global.shoot = event => {
    if (event.entity.level.clientSide) return
    if (event.bow.id != 'kubejs:dart_chute') return
    
    let entity = event.entity
    let maxSlots = 41
    for (let slotIndex = 0; slotIndex < maxSlots; slotIndex++) {
        let slot = entity.getSlot(slotIndex)
        let itemStack = slot.get()

        if (!itemStack.count <= 0) {
            // Access the item ID directly
            let itemId = itemStack.id
            if (itemId === 'minecraft:spectral_arrow') {
                itemStack.count--
                return
            }
        }

    }
    event.setCanceled(true)
}

#

dont mind the cursed arranging of code

#

its very late, thanks forall the help thusfar

#

if you find a fix, tomorrow, somewhere next week
for it crashing / not working in ccreative / just straight up ghost animation with no arrows

#

lmk

sleek wigeon
#

hmm odd its not crashing for me, ill have to test your code out tomorrow

#

did you restart the full game?

sleek wigeon
sleek wigeon
# frosty plume it also draws the bow

to avoid this just put this in both a client event script as well as a server event script ```js
ItemEvents.rightClicked('minecraft:bow', event => {

let entity = event.entity;
let maxSlots = 41;
for (let slotIndex = 0; slotIndex < maxSlots; slotIndex++) {
    let slot = entity.getSlot(slotIndex);
    let itemStack = slot.get();

    if (!itemStack.count <= 0) {
        // Access the item ID directly
        let itemId = itemStack.id;
        if (itemId === 'minecraft:spectral_arrow') {
            return
        }
    }
}
event.cancel()

})``` this prevents it from drawing the bow if you dont have the correct arrows in your inventory

#

the desync issue is probably just as simple(though i must be missing something here)

frosty plume
sleek wigeon
#

ah kk

#

ill test your script out tomorrow then

sleek wigeon
#

@frosty plume your first issue i see is youre returning if youre weilding the correct weapon which is not what i sent up there

idle portalBOT
#

[Quote ➤](#1183093106384576602 message) ```js
ForgeEvents.onEvent('net.minecraftforge.event.entity.living.LivingGetProjectileEvent', event => {
global.projectile(event);
});

/**

  • @param {Internal.LivingGetProjectileEvent} event
    */
    global.projectile = event => {
    if (event.entity.level.clientSide) return
    if (event.projectileWeaponItemStack.id != 'minecraft:bow') return
    event.setProjectileItemStack('minecraft:spectral_arrow')

};
ForgeEvents.onEvent('net.minecraftforge.event.entity.player.ArrowLooseEvent', event => {
global.shoot(event)
})
/**
*

  • @param {Internal.ArrowLooseEvent} event
    */
    global.shoot = event => {
    if (event.entity.level.clientSide) return
    if (event.bow.id != 'minecraft:bow') return
    let entity = event.entity;
    let maxSlots = 41;
    for (let slotIndex = 0; slotIndex < maxSlots; slotIndex++) {
    let slot = entity.getSlot(slotIndex);
    let itemStack = slot.get();

     if (!itemStack.count <= 0) {
         // Access the item ID directly
         let itemId = itemStack.id;
         if (itemId === 'minecraft:spectral_arrow') {
             itemStack.count--
             return
         }
     }
    

    }
    event.setCanceled(true)
    }```
    Here we have to utilize 2 forge events, one to change the projectile of your weapon to your custom projectile item (here we're using spectral arrows and a normal bow as examples) and one to cancel the arrowloose forge event if you dont have the right arrow in your inventory. The arrow loose event also acts as a trigger to decrease the stack of the arrow by 1 when the bow shoots

sleek wigeon
#
if (event.projectileWeaponItemStack.id != 'kubejs:dart_chute') return``` should be this
frosty plume
#

Will change once fully awake

sleek wigeon
#

ill keep testing to see if i can recreate the crash

#

np

#

doesnt look like im crashing thus far

frosty plume
#

Nice

#

Does adding it to both server AND startup fix visual bug?

#

Like firing both when no arrow And wrong arrow

#

Drawing*

sleek wigeon
#

you mean the forge events?

#

or the ItemEvents.rightclicked

frosty plume
#

ok am back, what exactly needs to be re-added to the file

#

i fixed the != part

sleek wigeon
#

you wanna add that script to both client and server

#

this will prevent you from pulling the bow if you dont have the correct ammo

#

then it should work

frosty plume
#

holup

#

client and sertver?

#

theres startup and server

sleek wigeon
#

mhmm

#

uh

#

no

frosty plume
#

oh holdon

sleek wigeon
#

you see this item right click event?

idle portalBOT
#

[Quote ➤](#1183093106384576602 message) to avoid this just put this in both a client event script as well as a server event script ```js
ItemEvents.rightClicked('minecraft:bow', event => {

let entity = event.entity;
let maxSlots = 41;
for (let slotIndex = 0; slotIndex < maxSlots; slotIndex++) {
    let slot = entity.getSlot(slotIndex);
    let itemStack = slot.get();

    if (!itemStack.count <= 0) {
        // Access the item ID directly
        let itemId = itemStack.id;
        if (itemId === 'minecraft:spectral_arrow') {
            return
        }
    }
}
event.cancel()

})``` this prevents it from drawing the bow if you dont have the correct arrows in your inventory

frosty plume
#

i see

sleek wigeon
#

put it in kubejs>client_scripts and kubejs>server_scripts

frosty plume
#

ah ok

#

wil ldo

sleek wigeon
#

if it crashes again lemme know and send your latest.logs

#

it wasnt crashing for me as far as i've tested

frosty plume
#
ItemEvents.rightClicked('kubejs:dart_chute', event => {

    let entity = event.entity
    let maxSlots = 41
    for (let slotIndex = 0; slotIndex < maxSlots; slotIndex++) {
        let slot = entity.getSlot(slotIndex)
        let itemStack = slot.get()

        if (!itemStack.count <= 0) {
            let itemId = itemStack.id
            if (itemId === 'minecraft:spectral_arrow') {
                return
            }
        }
    }
    event.cancel()
})

``` both client and server have this
#

startup has:

#
const $bowItem = Java.loadClass('net.minecraft.world.item.BowItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')

const $kubejs = Java.loadClass('dev.latvian.mods.kubejs.KubeJS')
StartupEvents.registry('item', event => {
    event.createCustom('dart_chute', () => new $bowItem(new $ItemProperties().tab($kubejs.tab).defaultDurability(23)))
})

ForgeEvents.onEvent('net.minecraftforge.event.entity.living.LivingGetProjectileEvent', event => {
    global.projectile(event)
});    ForgeEvents.onEvent('net.minecraftforge.event.entity.player.ArrowLooseEvent', event => {
        global.shoot(event)
})
global.projectile = event => {
    if (event.entity.level.clientSide) return
    if (event.projectileWeaponItemStack.id != 'kubejs:dart_chute') return
    event.setProjectileItemStack('minecraft:spectral_arrow')
}
global.shoot = event => {
    if (event.entity.level.clientSide) return
    if (event.bow.id != 'kubejs:dart_chute') return
    
    let entity = event.entity
    let maxSlots = 41
    for (let slotIndex = 0; slotIndex < maxSlots; slotIndex++) {
        let slot = entity.getSlot(slotIndex)
        let itemStack = slot.get()

        if (!itemStack.count <= 0) {
            // Access the item ID directly
            let itemId = itemStack.id
            if (itemId === 'minecraft:spectral_arrow') {
                itemStack.count--
                return
            }
        }

    }
    event.setCanceled(true)
}


sleek wigeon
#

yes

#

keep in mind if you do end up registering a new type of arrow item it has to be a projectile

#

i tried firing non projectiles and it didnt work

frosty plume
#

ok so

#

it didnt fire without arrows / regular arrows

#

BUT

#

when firing the spectral arrow it crashed, getting log now

sleek wigeon
#

kk

frosty plume
idle portalBOT
#

Paste version of latest.log from @frosty plume

frosty plume
#

i posted scripts above

sleek wigeon
#

also send the startup_scripts log

frosty plume
#

startup scripts log whats that

sleek wigeon
#

??kjslogs

idle portalBOT
# sleek wigeon ??kjslogs

You can find your KubeJS startup log in /minecraft/logs/kubejs/startup.log.
If you are on 1.18 or below it will be called startup.txt.
Please send it if asked, as it contains helpful information.

frosty plume
idle portalBOT
#

Paste version of startup.log from @frosty plume

sleek wigeon
#

also whats your kubejs version

#

nvm it says there

frosty plume
#

ìt doenst draw atleast

#

thats a start

#

like what you're doing atm is 100% what i needed

sleek wigeon
frosty plume
#

bow + custom ammo

#

just it crashes and model file is borke

sleek wigeon
#

the weird part is it doesnt crash for me

frosty plume
#

nasa

sleek wigeon
#

lemme copy this exact code again

frosty plume
#

yes

#

the top one was in server/client, bottom in startup

#

i defo mistyped something in startup or smthn

sleek wigeon
#

while im doing that i want you to update kubejs

frosty plume
#

ue

#

to which version

sleek wigeon
#

latest

#

build 45

frosty plume
#

send download

#

or link

sleek wigeon
#

you use curseforge?

frosty plume
#

no

sleek wigeon
#

what you use

frosty plume
#

idk

sleek wigeon
#

nothing?

frosty plume
#

any link people send

sleek wigeon
#

i mean your launcher

#

you just have a forge profile setup or something?

frosty plume
#

prismlauncher for this

sleek wigeon
#

ah

frosty plume
#

someone sent a pack

#

like as a zip sent a whole pack

sleek wigeon
#

youre not able to update on prism?

frosty plume
#

i feel like the issue is the startup script

#

idk

#

which version is latest kubejs

frosty plume
#

ima go search on modrinth

sleek wigeon
#

or that

#

we're about to find out

frosty plume
#

wha

#

type the version you want me to download

#

am skeptical of curseforge

sleek wigeon
#

breh

#

build 45

#

1.19

#

kubejs

frosty plume
#

am on 1.19.2 btw

sleek wigeon
#

same here

#

also its not crashing for me

#

im gonna try your build which is 42

frosty plume
#

kk

sleek wigeon
#

also you dont need to use curse launcher just download

frosty plume
#

check startup script i sent to be sure

sleek wigeon
sleek wigeon
frosty plume
#

kk

sleek wigeon
#

testing build 42 now

frosty plume
#

installed, updated

sleek wigeon
#

if it works here then what i suggest you start a new prism instance with only kubejs installed and try the script there

frosty plume
#

i hope some of my older scripts dont break

#

or the person who made the pack's scripts

frosty plume
#

too much work for a script

sleek wigeon
frosty plume
#

i can send some over if any are broken

#

they should all work

#

the bow without items: dont fire = correct

sleek wigeon
#

then i would temporarily remove every other script besides this one

frosty plume
#

with arrow doesnt fire either which is good

#

btw maybe add a creative mode exception

#

since yk

sleek wigeon
#

and make sure that script is the only thing kubejs is running and test it

#

works fine in creative too

frosty plume
#

yep same

#

in /cr it consumes the arrow tho

#

script works perfectly now thanks

sleek wigeon
#

whats your inventory look like

#

oh its working now?

#

maybe the update worked then

frosty plume
#

this is on a world with many a test items / prior playthrough

#

before firing:

#

after firing once

#

bow is next to the arrow the little green thing

#

it works

sleek wigeon
#

nice

frosty plume
#

just gotta add creative mode unlimited arrow exception

#

then only projectile item / texture and model files

#

and everything will work

#

nice

#

oh no

#

i found an error

#

spamming it breaks it

sleek wigeon
#

oh?

#

ah lemme test

frosty plume
#

like the arrows dont fire

#

click 0.1 seconds and dont hold it

sleek wigeon
#

oh

frosty plume
#

just tap oit

sleek wigeon
#

ah good catch

#

lemme fix that

frosty plume
#

so there needs to be a checkk to see IIF it actually fired

#

THEN delete the item

#

and a creative mode bypass of no need for an item

#

if creative mode (just heccing fire)

#

how do i mark a new item as projectile btw

#

lemme check documentation

sleek wigeon
#

Startup Script:

global.shoot = event => {
    if (event.entity.level.clientSide) return
    if (event.bow.id != 'kubejs:dart_chute') return

    let entity = event.entity
    let maxSlots = 41
    for (let slotIndex = 0; slotIndex < maxSlots; slotIndex++) {
        let slot = entity.getSlot(slotIndex)
        let itemStack = slot.get()

        if (!itemStack.count <= 0) {
            // Access the item ID directly
            let itemId = itemStack.id
            if (itemId === 'minecraft:spectral_arrow') {
                if (event.charge <= 2 || event.entity.isCreative()) return
                itemStack.count--
                return
            }
        }

    }
    if (!entity.isCreative()) {
        event.setCanceled(true)
    }
}```
Server/Client Script:```js
ItemEvents.rightClicked('kubejs:dart_chute', event => {

    let entity = event.entity
    let maxSlots = 41
    for (let slotIndex = 0; slotIndex < maxSlots; slotIndex++) {
        let slot = entity.getSlot(slotIndex)
        let itemStack = slot.get()

        if (!itemStack.count <= 0) {
            let itemId = itemStack.id
            if (itemId === 'minecraft:spectral_arrow') {
                return
            }
        }
    }
    if (!event.player.isCreative()) {
        event.cancel()
    }
})```
#

change your global to that

sleek wigeon
frosty plume
#

that doesnt accomodate creative mode but does for the glitch?

sleek wigeon
#

anything 3 and above fires the arrow

#

yea

#

as for the creative thing thats easy, sec

#
if (event.charge <= 2 || event.entity.isCreative()) return```
#

there edited it

#

shouldnt consume in creative anymore

frosty plume
#

wait

sleek wigeon
#

?

frosty plume
#

you are makiing it not consume in creative

sleek wigeon
#

yeah thats what you wanted right

frosty plume
#

but does it still then fire an arrow if NONE are present

sleek wigeon
#

hmm

#

true, sec

frosty plume
#

should being in creative bypass the entire check for arrows

sleek wigeon
#

ill add that as well

frosty plume
#

im not good at js

#

but ive got logical thinking and pickyness from here to 東京

idle portalBOT
#

Paste version of latest.log from @frosty plume

frosty plume
idle portalBOT
#

Paste version of startup.log from @frosty plume

frosty plume
#

when in /cr and firing it crashed

#

you sure the extra line makes sure it doenst consume arrow, AND doesnt fire / cancels event

sleek wigeon
#

whats /cr

frosty plume
#

/gamemode creative

#

creative mode

#

i use shorthand /cr

sleek wigeon
#

ah

#

hmm sec

sleek wigeon
#

also are you running /kubejs reload startup_scripts /kubejs reload client_scripts and /kubejs reload server_scripts?

#

or you just /reload ing?

frosty plume
#

im hard resetting minecraft

#

quit game, restartup

#

to make sure its fresh each time

#

ive got a new beefy computer, with beefy ram and cpu

sleek wigeon
#

uh

frosty plume
#

modded loads in 20 seconds

sleek wigeon
#

you dont have to do that

#

since we're running a global event you can just do /kubejs reload startup_scripts

#

instant reload

frosty plume
#

im using to having to wait 15 minutes for minecraft to load fully when modded

#

20 seconds is fine

sleek wigeon
#

1 second is better tho

frosty plume
#

but it didnt work before tho

sleek wigeon
#

what

#

/kubejs reload startup_scripts?

frosty plume
#

like i once did /kubejs reload startuo_scripts

#

and it just didnt work

sleek wigeon
#

well now itll work

frosty plume
#

ok so

sleek wigeon
#

it wont work if you dont use global functions

frosty plume
#

in creative it behaves exacly like a bow

sleek wigeon
#

oh hmm

frosty plume
#

doesnt consume arrows (good

sleek wigeon
#

what

frosty plume
#

can be spammed without breaking

#

in creative gamemode 0

sleek wigeon
#

how many scripts do you have in your kubejs folders

#

a lot?

frosty plume
#

wait

#

it works well

#

lemme test /survival

sleek wigeon
#

im lost

frosty plume
#

in creative mode: doesnt consume arrows for 0 reason, can be spammed without crashing, works fine

#

in survival mode: ddoesnt crash either, doesnt consume arrows when spammed, works fine

#

it works perfectly

#

doesnt draw back when no arrows are present

#

it just works perfectly now

#

now the projectile

#

gonna try find which tag im suppose to give it

sleek wigeon
frosty plume
#

gonna close this for now and make a new ticket for the projectile/model files being borke

#

but im gonna paste the code for anyone wanting a bow

#
const $bowItem = Java.loadClass('net.minecraft.world.item.BowItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')

const $kubejs = Java.loadClass('dev.latvian.mods.kubejs.KubeJS')
StartupEvents.registry('item', event => {
    event.createCustom('YOUR_BOW_HERE', () => new $bowItem(new $ItemProperties().tab($kubejs.tab).defaultDurability(23)))
})


ForgeEvents.onEvent('net.minecraftforge.event.entity.living.LivingGetProjectileEvent', event => {
    global.projectile(event)});    ForgeEvents.onEvent('net.minecraftforge.event.entity.player.ArrowLooseEvent', event => {
        global.shoot(event)
})

global.projectile = event => {
    if (event.entity.level.clientSide) return
    if (event.projectileWeaponItemStack.id != 'kubejs:YOUR_BOW_HERE') return
    event.setProjectileItemStack('minecraft:spectral_arrow')
}

global.shoot = event => {
    if (event.entity.level.clientSide) return
    if (event.bow.id != 'kubejs:YOUR_BOW_HERE') return

    let entity = event.entity
    let maxSlots = 41
    for (let slotIndex = 0; slotIndex < maxSlots; slotIndex++) {
        let slot = entity.getSlot(slotIndex)
        let itemStack = slot.get()

        if (!itemStack.count <= 0) {
            let itemId = itemStack.id
            if (itemId === 'minecraft:spectral_arrow') {
                if (event.charge <= 2 || event.entity.isCreative()) return
                itemStack.count--
                return
            }
        }

    }
    if (!entity.isCreative()) {
        event.setCanceled(true)
    }
}
#

in startup events

#
ItemEvents.rightClicked('kubejs:YOUR_BOW_HERE', event => {

    let entity = event.entity
    let maxSlots = 41
    for (let slotIndex = 0; slotIndex < maxSlots; slotIndex++) {
        let slot = entity.getSlot(slotIndex)
        let itemStack = slot.get()

        if (!itemStack.count <= 0) {
            let itemId = itemStack.id
            if (itemId === 'minecraft:spectral_arrow') {
                return
            }
        }
    }
    if (!event.player.isCreative()) {
        event.cancel()
    }
})
#

in both client and server events

#

scripts*

#

this makes a bow-like item, that fires spectral arrows [replace with custom projectile if aplicable], fires infinitely in creative mode, can be spammed without client-server desync

#

and doesnt use regular arrows accidentally