KubeJS (Old)

KubeJS (Old)

3M Downloads

Unable to register custom potions with Non-vanilla mob effects

TrkvonStpd1e11 opened this issue ยท 3 comments

commented

Minecraft Version

1.19.2

KubeJS Version

1902.6.2-build.59

Rhino Version

1902.2.2-build.284

Architectury Version

6.5.85

Forge/Fabric Version

Forge 43.3.5

Describe your issue

script&log.zip
Registering custom potions with modded or custom mob effects is not possible. You can only register custom potions with vanilla mob effects.

Crash report/logs

No response

commented

Still having this issue on 1.20.1
It keeps saying that my mob effect isn't registered despite it loading first and when loaded without the attempts to add a potion the effect is generated fine.

It's possible to even add potions with no effect, but the moment a potion that should have a effect is even tried it seems to collapse on itself.

I believe this is because kubejs avoids looking back on itself for things like recipes? So it can't look at its own mob effects?

commented

HUGE CORRECTOIN. YOU LITREALLY JUST FINISH BUILDING IT AND THEN PASS IT ON LIKE THIS:

const ThirstHelper = Java.loadClass('toughasnails.api.thirst.ThirstHelper');
const $PotionBuilder = Java.loadClass('dev.latvian.mods.kubejs.misc.PotionBuilder')

let lifebloodPotions = {
  mobeffect: `kubejs:lifeblood`,
  potion: `kubejs:lifeblood`,
  longPotion: `kubejs:long_lifeblood`,
  strongPotion: `kubejs:strong_lifeblood`
  }


StartupEvents.registry('mob_effect', event => {
  console.log('Registring effects');

  lifebloodPotions.mobeffect = event.create(lifebloodPotions.mobeffect)
  .color(0x00FF00)
  .beneficial()
  .effectTick((entity, lvl) => {
    // Ensure the event only executes once per second
    if (entity.age % 20 != 0 || !entity.isPlayer()) return;

    // Get the IThirst object for the player
    const thirst = ThirstHelper.getThirst(entity);

    // Add hydration to the player
    thirst.drink(1*lvl,1 * lvl);
  })
  
  .createObject();
});

StartupEvents.registry('potion', event => {
  console.log('Registring potions');

  // Create base potion effect.

  event.create(lifebloodPotions.potion).effect(lifebloodPotions.mobeffect, parseDuration("45s"), 0).createObject();
  /* 
  potionRegist(event, lifebloodPotions.mobeffect, lifebloodPotions.potion, "45s", 1);
  potionRegist(event, lifebloodPotions.mobeffect, lifebloodPotions.longPotion, "1m30s", 1);
  potionRegist(event, lifebloodPotions.mobeffect, lifebloodPotions.strongPotion, "22s", 2); */
});

function parseDuration(duration) {
  const regex = /^(\d+h)?(\d+m)?(\d+s)?$/;
  const match = duration.match(regex);
  if (!match) {
    throw new Error(`Invalid duration format: ${duration}`);
  }

  let hours = match[1] ? parseInt(match[1].slice(0, -1)) : 0;
  let minutes = match[2] ? parseInt(match[2].slice(0, -1)) : 0;
  let seconds = match[3] ? parseInt(match[3].slice(0, -1)) : 0;

  return (hours * 60 * 60 * 20) + (minutes * 60 * 20) + (seconds * 20);
}

/*
function potionRegist(e, effect, potion, duration, amplifier) {
  e.createCustom(potion, () => {
    return new $PotionBuilder(effect).effect(effect, parseDuration(duration-1), amplifier).createObject();
  })
}
*/```
commented

so if anyone is having this issue. DOWNLOAD PROBEJS. IT WOULD'VE SAID THE SAME THING

Image