#Adding more modded weapon attributes via KubeJS?

52 messages · Page 1 of 1 (latest)

limber gulch
#

In short, since Better Combat adds new attack animations and hitboxes for specific weapon types, I've been trying to add parity with vanilla tools, as well as adding additional stats to tools with Pufferfish's Attributes, but I'm struggling because I'm not experienced with javascript let alone anything advanced with KubeJS.

Edit: found a solution regarding Better Combat's attack animations without KubeJS.

Any and all help would be greatly appreciated!

I've been using code from KonSola5 to modify tool stats like Attack Speed and Attack Damage, but I want to assign special stats from Pufferfish's AttributesI've tried:

  • I also don't know how to structure my code to call Pufferfish's Attributes and add them onto pre-existing tools, as it seems modifyAttributes and $Attributes function does not allow for non-vanilla attributes to be called, despite it being able to be filled in in VSC.

I'm still learning, and I want to learn more from the people here who are much more knowledgeable than me.

subtle cipherBOT
#

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

limber gulch
#

A portion of what I'm working with:

#

``const $Attributes = Java.loadClass("net.minecraft.world.entity.ai.attributes.Attributes");
const $WeaponType = Java.loadClass("handler$boo000$bettercombat$getAttributeValue_Inject(attribute: Internal.Attribute_, cir: Internal.CallbackInfoReturnable_<any>): void;"); //My attempt

ItemEvents.modification((event) => {
/**

  • @param {Internal.Item} item
  • @param {Internal.Attribute_} attribute
  • @param {number} value
    */

/**

  • @param {Internal.item} item
  • @param {Internal.WeaponAttributes_} type //My attempt
    */

function modifyAttribute(item, attribute, value) {
const attributeToModify = item.getAttributes(attribute).get(0);
item.removeAttribute(attribute, attributeToModify.id);
item.addAttribute(
attribute,
attributeToModify.id,
attributeToModify.name,
value,
attributeToModify.operation
);
}
function modifyType(item, type) {
const typeToModify = item.getType(type).get(0);
item.removeType(type, typeToModify.id);
item.addType(
type,
typeToModify.id,
typeToModify.name,
typeToModify.operation
);
}

//Flint Tools
event.modify("kubejs:flint_hatchet", (item) => {
item.maxDamage = 45;
item.digSpeed = 3;
modifyAttribute(item, $Attributes.ATTACK_DAMAGE, 4.5);
});
event.modify("kubejs:flint_pickaxe", (item) => {
item.maxDamage = 45;
item.digSpeed = 3;
modifyAttribute(item, $Attributes.ATTACK_DAMAGE, 4);
});``

limber gulch
#

Changing weapon attributes via KubeJS?

wide jungle
#

To format your code, put it between three backticks, with "js" after the first set:
```js
console.log("Hello, world!")
```

becomes:

console.log("Hello, world!")
#
const $WeaponType = Java.loadClass(
  'handler$boo000$bettercombat$getAttributeValue_Inject(attribute: Internal.Attribute_, cir: Internal.CallbackInfoReturnable_<any>): void;'
)

This is invalid, it looks like you pasted the dumped TS definition that ProbeJS generated into Java.loadClass(). No, that's not correct.
Java.loadClass can load Java classes. To load a class, you must provide a fully qualified class name.

Tip: Use IntelliSense (Ctrl + Space) inside the brackets to see completions.

#
/**
   * @param {Internal.Item} item
   * @param {Internal.Attribute_} attribute
   * @param {number} value
   */

This bit from my code is just type definitions for TypeScript to offer better completions - so the parameters aren't any. This does NOT change runtime behavior - it's only for editor convenience.

#
 function modifyType(item, type) {
    const typeToModify = item.getType(type).get(0);
    item.removeType(type, typeToModify.id);
    item.addType(
      type,
      typeToModify.id,
      typeToModify.name,
      typeToModify.operation
    );
  }

What is this for? And what mod would even add getType to Item?

#

Also:
$Attributes is NOT a function, it's a class, which houses all vanilla attributes.
You definitely CAN use modded attributes, but you have to use that mod's class which exposes its attributes.

wide jungle
#

As for example, I gave an Iron Pickaxe +3 Fortune from Pufferfish's Attributes:

const $AttributesMod = Java.loadClass('net.puffish.attributesmod.AttributesMod')

ItemEvents.modification(event => {
  const UUIDS = {
    FORTUNE: UUID.fromString("1e7e044b-e0d7-4caa-af46-ee9fabf3ec20")
  }

  /**
   * @param {Internal.Item} item
   * @param {Internal.UUID} uuid
   * @param {Internal.Attribute_} attribute
   * @param {number} value
   * @param {Internal.AttributeModifier$Operation_} operation
   */
  function addAttribute(item, uuid, attribute, value, operation) {
    item.addAttribute(
      attribute,
      uuid,
      "Attribute modification",
      value,
      operation
    )
  }

  event.modify('minecraft:iron_pickaxe', item => {
    addAttribute(item, UUIDS.FORTUNE, $AttributesMod.FORTUNE, 3, "addition")
  })
})
limber gulch
#

Omgggg thank you so much again 😭 Imma work on all this when I get back on my laptop.

limber gulch
#

Also, can I list multiple attributes under where it says js FORTUNE: UUID.fromString("1e7e044b-e0d7-4caa-af46-ee9fabf3ec20")?

wide jungle
#

Also, yeah - for each unique attribute, add a new UUID to the UUIDS object.

limber gulch
wide jungle
#

For new attributes - yes

limber gulch
#

ItemEvents.modification(event => {
  const UUIDS = {
    FORTUNE: UUID.fromString("1e7e044b-e0d7-4caa-af46-ee9fabf3ec20"),
    KNOCKBACK: UUID.fromString("cada926d-aa75-4a22-9b2b-c7953b0f770d"),
    ARMOR_SHRED: UUID.fromString("36cc0596-b4fd-4d1c-8711-d1c3a811628e")


  }

  /**
   * @param {Internal.Item} item
   * @param {Internal.UUID} uuid
   * @param {Internal.Attribute_} attribute
   * @param {number} value
   * @param {Internal.AttributeModifier$Operation_} operation
   */
  function addAttribute(item, uuid, attribute, value, operation) {
    item.addAttribute(
      attribute,
      uuid,
      "Attribute modification",
      value,
      operation
    )
  }

//Tools

//Flint Tools
event.modify('kubejs:flint_pickaxe', item => {
  addAttribute(item, UUIDS.ARMOR_SHRED, $AttributesMod.ARMOR_SHRED, 1, "addition")
})
//Golden Tools
  event.modify('minecraft:golden_pickaxe', item => {
    addAttribute(item, UUIDS.FORTUNE, $AttributesMod.FORTUNE, 2, "addition")
  })
  event.modify('minecraft:golden_shovel', item => {
    addAttribute(item, UUIDS.FORTUNE, $AttributesMod.FORTUNE, 2, "addition"),
    addAttribute(item, UUIDS.KNOCKBACK, $AttributesMod.KNOCKBACK, 1, "addition")
  })
})```
#

I also removed Quark before testing just to be safe, as it adds a passive Fortune/Looting II to all golden tools.

#

Is there something else I'm doing wrong?

wide jungle
#

Did at least the Flint Pickaxe got its attributes?

limber gulch
#

Nope

#

I even tried your example of an Iron Pick with Fortune +3 and it doesn't work

wide jungle
#

Weird

#

For me, it works fine

#

Try making a minimal instance with just KubeJS and Pufferfish's Attributes (and their dependencies) and try again, if that works it means that one of the mods is doing something unexpected

limber gulch
#

Perhaps it's because I put the 'addAttribute' script you gave me in a separate json file?

limber gulch
#

okay yeah, it seems another mod is conflicting with the pufferfish's attributes script

#

Regardless, I thank you for your help and information. Gonna pop a message here after closing the ticket once I find out what mod conflicts with this.

limber gulch
wide jungle
#

making another json file for adding pufferfish's attributes
What?
I don't know what do you mean, because I'm not that well versed in datapacks.
Or does another mod add such capability?

limber gulch
#

No no, so basically in my KubeJS startup script folder, I have an 'Item Modification' file, 'Item Attribute' file and an 'Item Registry' file.

  • 'Item Registry' is for adding new items into my modpack.
  • 'Item Modification' is used for changing the properties of items like stack size or attack damage.
  • 'Item Attribute' was what I was using to try and add Pufferfish's Attributes to items.
#

Both 'Item Modification' and 'Item Attribute' were both using ItemEvents.modification, but I put the code for adding Pufferfish's skills into 'Item Modification' instead of having it exist in its own javascript file and it worked.

#

No mods were causing the issues I was having, apparently.

#

(And i also deleted 'Item Attributes' from my startup script folder)

#

Also, I just realized that I mis-typed. I meant to say "Javascript file", not "Json".

#

Buuuut I mean it works now 😄

limber gulch
#

Just wanna re-open this to extend on what my original ticket was asking for help about:

My main asking point is: how would I go about adding weapon attributes from mods other than Pufferfish's skills? I've tried loading several different java classes, but none seem to fit for the mods I want to use.

#

Adding more modded weapon attributes via KubeJS?

#

Namely, I just want to know how the process works, like how it was solved for Pufferfish's skills. I want to add weapon attributes from mods like Apothic Attributes [attributelib], Tinker's, Oreganized, etc

novel moth
#

Since better combat is very popular you might find a kube js script balancing the range and attack speed in a modpack

limber gulch
#

Oh no, I don't mean weapon attributes for Better Combat, I mean like adding stats like Kinetic Damage [Oreganized], or Dodge Chance [Apothic Attributes]

#

One thing I will note is that I've found that for Oreganized specifically, I can allow an item to gain the mod's Kinetic Damage trait by adding a tag to it, but I want to change the value of it on a per-item basis.

limber gulch
#

Bumping this

limber gulch
#

Okay nevermind, because of a modpack that uses KubeJS, I found a piece of code that allows me to do what I was looking to do: item.addAttribute( "minecraft:generic.movement_speed", "27c72d42-c11e-404b-8577-0adf8e6c1863", "-5% Movement Speed", -0.05, "multiply_total" );