#Creating Custom items with abilities

19 messages · Page 1 of 1 (latest)

small anvil
#

I used kubejs to make custom items, the example ill use is a shield
using pmmo players will get these items as a sort of "class"

The shield specifically is meant to give resistance while held, and have a right click + shift right click active abilities.

im stuck at the potion effect though as it is always max rank and falls off after 7 seconds.

ebon magnetBOT
#

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

cunning orioleBOT
#

🗒️ Send the code! 🗒️

You may have an issue with a KubeJS script and you explain it to the best of your ability yet without the actual code in question we have very little to go off of in trying to assist you.

small anvil
# cunning oriole ## 🗒️ Send the code! 🗒️ You may have an issue with a KubeJS script and you exp...

// ⛨ Warrior Passive: Resistance while holding Warrior Shield
const SHIELD_ID = 'kubejs:warrior_shield'
const EFFECT_ID = 'minecraft:resistance'

ForgeEvents.onEvent("net.minecraftforge.event.TickEvent$ServerTickEvent", event => {
  if (event.phase.toString() !== 'END') return

  Utils.server.getPlayerList().players.forEach(player => {
    const item = player.mainHandItem?.id ?? ''
    const hasEffect = player.hasEffect(EFFECT_ID)

    if (item === SHIELD_ID && !hasEffect) {
      player.potionEffects.add(EFFECT_ID, 600, 0, false, false) // Resistance I
    }

    if (item !== SHIELD_ID && hasEffect) {
      player.removeEffect(EFFECT_ID)
    }
  })
})

#

sorry for forgetting that part

#

i really have just been trial and erroring lines because i dont know what its supposed to look like 😦

#

// kubejs/startup_scripts/warrior_shield.js

onEvent('item.registry', event => {
  event.create('warrior_shield')
    .displayName('§6Warrior’s Shield')
    .texture('minecraft:item/shield') // Placeholder texture
    .maxStackSize(1)
    .unstackable()
})

this is the item

small anvil
#

onEvent('player.tick', event => {
  const player = event.player
  const heldItem = player.mainHandItem


  if (heldItem.id == 'kubejs:warrior_shield') {

    player.potionEffects.add('minecraft:resistance', 40, 0, false, false)
  }
})

ive brought it down to this so its working now but if u have any tips or things i can look for when doing beam and aoe abilities that would be great

small anvil
#

or even abilities in general, i cant seem to get my right click to detect. im trying to have it just send a chat message when i right click with the item equipped just to test

small anvil
#

Update ;

I have right click and shift right click working now
My big issues are making an offensive ability (a shield slam or a beam that does a burn)

Is there any example script someone could provide for 1.18.2 mc pls and ty

small anvil
#

onEvent('block.right_click', event => {
  const player = event.player
  const item = player.mainHandItem

  if (player.level.isClientSide) return
  if (!item || item.id != 'kubejs:warrior_shield') return

  if (player.isCrouching()) {
    player.tell("🧎 Detected crouching (via isCrouching())")
  } else {
    player.tell("🚶 Not crouching (via isCrouching())")
  }
})


onEvent('player.tick', event => {
  const player = event.player
  const heldItem = player.mainHandItem


  if (heldItem.id == 'kubejs:warrior_shield') {

    player.potionEffects.add('minecraft:resistance', 40, 0, false, false)
  }
})

this is everything i currently have working.

the goal from here is to create;

Target enemies directly (damage, control)

Target allies directly
(Healing, buffs)

Create a deployable
(Aoe heal, damage, control)

Have a skill shot
(Fireball ish, splash potion of healing ish)

Have a beam from a player
(Healing, damage)

oh and MAYBE summons (maybe using abilities that exist from other mods?)

Any examples that would help figure out any of these would be awesome thank u 🙂

next moon
#

so for the rightclick thing, you want to use the itemrightclick, not block

#

item.right_click

#

for the tick event, you dont want it to run 20 times a second, thats gonna be very laggy
do something like this instead

onEvent('player.tick', e => {
  if (e.player.age % 40 != 0) return
  if (e.player.mainHandItem.id != 'kubejs:warrior_shield') return
  e.player.potionEffects.add('minecraft:resistance', 60, 0, false, false)
})

which will apply a 3 second buff every 2 seconds

#

to get an entity youre looking at, you can use rayTrace()
rightclick with a stick to test this

onEvent('item.right_click', e => {
  if (e.item.id != 'minecraft:stick') return
  result = e.player.rayTrace(50) // distance
  if (result.entity) e.player.tell(result.entity.type)
  if (result.block) e.player.tell(result.block.id)
})
#

also FYI you can reload using /kubejs reload server_scripts
no need for /reload

small anvil
next moon
#

what happens when you go close to the mobs, i might have a theory on why its not working

small anvil
#

oh sorry i didnt see this, its the same though if im close, it just registers the block that i would be seeing if they didnt exist