#how to make alloyed guns drop shell casings when fired

6 messages · Page 1 of 1 (latest)

carmine wadi
#

is it possible to make CGM / Alloyed Guns have a chance to drop their respective shell casing when fired? if so, where's a good place to start?

lucid atlasBOT
#

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

last barn
#

well, to start, here's a script i made previously...

const $ForgeRegistries = java('net.minecraftforge.registries.ForgeRegistries')
onEvent('entity.death', event => {
    const { entity, source, level } = event
    if (!entity.isLiving() || !entity.isMonster()) return
    const actual = source.actual
    if (!actual) return
    if (actual.type != 'minecraft:player') return
    let player = actual
    /**
     * @param {Internal.ItemStack} item
     * @returns {Internal.GunItem}
     */
    function getModifiedGun(item) {
        return item.getItem().getModifiedGun(item)
    }
    let modifiedGun = getModifiedGun(player.getMainHandItem())
    let ammo = $ForgeRegistries.ITEMS.getValue(modifiedGun.getProjectile().getItem())
    if (ammo != null) {
        let i = level.createEntity('item')
        i.item = Item.of(ammo.id, Utils.random.nextInt(10, 20))
        i.setPos(entity.x, entity.y, entity.z)
        let random = Math.random() * 2
        if (random < 1) random = Math.random() * -0.2
        else random = Math.random() * 0.2
        i.setMotion(random, random, random)
        i.spawn()
    }
})

...that I just converted to 1.18.2 and it gets the gun you used to kill something to drop ammo

#

you can use this part:

    /**
     * @param {Internal.ItemStack} item
     * @returns {Internal.GunItem}
     */
    function getModifiedGun(item) {
        return item.getItem().getModifiedGun(item)
    }
    let modifiedGun = getModifiedGun(player.getMainHandItem())
    let ammo = $ForgeRegistries.ITEMS.getValue(modifiedGun.getProjectile().getItem())

to get the ammo item from the gun

carmine wadi
#

thanks tho