#how to make alloyed guns drop shell casings when fired
6 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
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
it doesn't seem to work with alloyed guns
thanks tho