#Hooking up another mod to make a custom item

313 messages · Page 1 of 1 (latest)

uneven edge
fresh hillBOT
#

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

uneven edge
#

Hooking up another mod to make a custom item

rapid ibex
#

probably spamming JavaAdapter to override the methods to create your own item

#

take a look at my script I did for custom armors variants #1473465876534657024

uneven edge
#

kinda lost here tbh

rapid ibex
rapid ibex
#

I mean that's it

cerulean mica
#

The Backported Spears do it in a really jank way

rapid ibex
#

nvm I do see a register spear static function

#

You could try that out

cerulean mica
#

Yeah

#

But watch out! The code is using Yarn mappings, not official Mojang mappings!

#

KubeJS uses and resolves Mojang mappings

uneven edge
cerulean mica
#

It's just you can't just copy-paste the code and expect it to work

uneven edge
#

As a person who just getting along with Java and JavaScript it seems that this task is out of my reach

#

ok this mod already have some integrations

#

not with mod I use tho

rapid ibex
#

nah it's not hard to translate mappings

#

just use a translator

#

and some of them you can already guess

cerulean mica
#

This is really helpful

rapid ibex
#

I was going to suggest linkie but their translator has been down for a while now

mint vortex
#

I'm also actually interested in doing this, as well. The furthest I've gotten so far is finding a handful of potential Java.loadClass entries with arg0 as $Tier,3 other numerical entries and $Item.Internal (If memory serves) Don't know how else to progress, though.

rapid ibex
#

there shouldn't be any issues because it's a public static

mint vortex
#

``let Spear = Java.loadClass('com.spearsplus.item.SpearItem')
let Trident = Java.loadClass('net.minecraft.world.item.TridentItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')
const $TEST = Java.loadClass('dev.latvian.mods.kubejs.item.ItemBuilder')
const $Tier = Java.loadClass('net.minecraft.world.item.Tiers')

StartupEvents.registry('item', event => {
event.create('electrum_spear', Spear).displayName("Electrum Spear").tier("diamond")
}) ``

rapid ibex
#

where are you calling the register spear function?

mint vortex
#

I could be trying to call it wrong, but this is what I've attempted so far

#

These are the only ones available through ProbeJs:

rapid ibex
#

ProbeJS doesn't dump all the classes and can't dump some

mint vortex
#

dang..

rapid ibex
#

don't blindly trust probejs

#

trust the source code more

mint vortex
#

the reason I was trying to call that bit of code is because of this part within that .class file:

#

I assumed it was the key to registering a new spear item, but I'm unsure at this point.

rapid ibex
mint vortex
#

I have something more cohesive, but there's one entry that confuses me:

#

The only bit in the source code that I can see that refrences 'settings' is this: Item.Properties settings

cerulean mica
#

Load the Item$Properties class and pass an instance of it to the parameter

mint vortex
#

like this?

cerulean mica
#

new Item$Properties()

#

You want to pass in an instance, not a class

#

Also, after you construct it, you can chain some methods to set up the item properties

#

Like, make it stack to 1:

new $ItemProperties().stacksTo(1)
mint vortex
cerulean mica
#

No

mint vortex
#

What passes it as an instance? I'm only aware of let and class.

rapid ibex
#

new

cerulean mica
#

Using Java.loadClass, you get a reference to a class - an object, that can construct derived objects called instances by using new on the class and passing in constructor parameters.

const $ItemProperties = Java.loadClass("net.minecraft.world.item.Item$Properties")

Item.Properties has no parameters for its constructor, so no parameters passed.

const properties = new $ItemProperties()

Here, properties is an instance of the Item.Properties class.
And that's what you want to pass in.

#

Think of a class as a "car factory" and instances as "cars"

mint vortex
#

Duly noted

mint vortex
#

YESSSS finally got it working, albeit untextured.

cerulean mica
#

Then give your item a texture and a model

mint vortex
#

Yea, I figured.

#

I was more worried about making it acutally exist first lol

cerulean mica
#

Normally, KubeJS does give your item a model automatically, but if you create an item with createCustom you have to add a model manually

mint vortex
cerulean mica
#

Resourcepack - yes

mint vortex
#

gotcha

cerulean mica
#

Lucky for you, assets folder inside the kubejs folder is a global resource pack

uneven edge
#

oh wait you are on Spear+?

mint vortex
#

Sorry, just woke up. Lemme get you the code.

mint vortex
# uneven edge Can you pass the code please? 🙏
  const itemProperties = new $ItemProperties

let spear = Java.loadClass('com.notunanancyowen.spears.items.SpearItem')

let $KubeJSItemTier = Java.loadClass('dev.latvian.mods.kubejs.item.MutableToolTier')
let $ItemTier = Java.loadClass('net.minecraft.world.item.Tiers')

  const Brass = new $KubeJSItemTier('brass')
  const Steel = new $KubeJSItemTier('steel')

const spearRegistry = (
                        name, tier, swingAnimationTicks, chargeDamageMultiplier, ChargeDelay, 
                        maxDurationForDismount, minSpeedForDismount, maxDurationForChargeKnockback, minSpeedForChargeKnockback,
                        maxDurationForChargeDamage, minRelativeSpeedForChargeDamage, hitSound, attackSound, 
                        useSound, settings
                      ) => {

StartupEvents.registry('item', event => {
    event.createCustom(name, () => new spear(
      /*material*/                          tier, //Use $ItemTier for vanilla tiers, $KubeJSItemTier for custom tiers
      /*swingAnimationTicks*/               swingAnimationTicks,
      /*chargeDamageMultiplier*/            chargeDamageMultiplier,
      /*ChargeDelay(s)*/                    ChargeDelay,
      /*maxDurationForDismount(s)*/         maxDurationForDismount,
      /*minSpeedForDismount*/               minSpeedForDismount,
      /*maxDurationForChargeKnockback(s)*/  maxDurationForChargeKnockback,
      /*minSpeedForChargeKnockback*/        minSpeedForChargeKnockback,
      /*maxDurationForChargeDamage(s)*/     maxDurationForChargeDamage,
      /*minRelativeSpeedForChargeDamage*/   minRelativeSpeedForChargeDamage,
      /*hitSound*/                          hitSound,
      /*attackSound*/                       attackSound,
      /*useSound*/                          useSound,
      /*settings*/                          settings //based off of Item$Properties, create a new one with data attached
    ))
})
}```
#

It does include some custom tiers I made for my own project, so please ignore that. Also, I'm using "Backported Spears" since that's what this topic was originally about.

#

And since I condensed this registry into a constant, you can just type in spearRegistry(... and just fill in the fields with values that match what you want your spear to be like.

daring glenBOT
#

You can write your code in a codeblock by typing it between the codeblock delimiters:
Note that these are backticks, not apostrophes

```js :arrow_left:

ServerEvents.recipes(event => {
event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})

``` :arrow_left:

This example will look like this:

ServerEvents.recipes(event => {
  event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})
cerulean mica
#

Use three backticks, not one

uneven edge
mint vortex
cerulean mica
#

Also insert js after first set

#

For syntax highlighting

mint vortex
uneven edge
cerulean mica
#

Yes, unless you want to reuse vanilla tiers

mint vortex
uneven edge
#

For example, in my modpack I need to make spears for every Aether material

#

I need to assign them to Aether tiers?

cerulean mica
#

Find the class in the Aether mod that has tiers, and load that class

uneven edge
cerulean mica
#

Not quite

#

Look through the Aether source code

uneven edge
mint vortex
#

I'd also reccomend installing WinRaR if you haven't already.

uneven edge
#

But i'm scouting through their github

#

maybe it will be easier to make KubeJS tiers at this point

mint vortex
uneven edge
#

I have so much materials to do spears for

#

16, to be exact

#

From different mods, so, it will be far easier to make KubeJS tiers from all of them, plus, it will hook nicely with Harvest Level Tweaker

mint vortex
#

Just keep in mind that if certain materials have passive benefits, like Electrum from Oreganized, you'll have to find a way to add those traits manually.

#

I'll update this thread if I get the model working 100%

uneven edge
mint vortex
rapid ibex
#

Please drop the working script in #1048591172165189632 when you guys get it to work

mint vortex
#

I'm pretty stumped as to how to apply my spear's texture file to the model since this is being created through createCustom :/ It seems no matter where I put it, the spear remains untextured, but the model loads in just fine.

cerulean mica
mint vortex
#

Are you asking if it's a .png file?

cerulean mica
#

No

#

A model JSON

mint vortex
#

Ohhhh that. The model's file is located at kubejs/assets/kubejs/models/item/steel_spear.json

cerulean mica
#

And its contents are... ?

#

(paste the contents here)

mint vortex
daring glenBOT
#

Paste version of steel_spear.json from @mint vortex

mint vortex
#

Nevermind, I finally got it working

#

You gave me the idea to look into the model's json file lol. It worked!

#

The only other issue that I have is that the inventory icon is just the spear model itself, but other than that it works just fine.

rapid ibex
#

you can override that with a texture pack

#

that is default behavior unless specificed otherwise

cerulean mica
mint vortex
uneven edge
#

@mint vortex You are the best, holy, I owe you now 🙏

#

Closing the ticket!

fresh hillBOT
#

Ticket re-opened!

uneven edge
#

nvm I need some additional help LOL

stoic fossil
mint vortex
uneven edge
#

I'm kinda lost with them

mint vortex
#

Soooo have you created one yet?

#

I'm using Blockbench for mine.

uneven edge
#

Can you pass .bbmodel of your model?

mint vortex
#

I just learned recently that you can actually drag a .png of your sprite into blockbench!

#

It'll automatically create a model based on the sprite.

#

Also, for Java, you'll need your model to be exported as a .json file.

mint vortex
#

IDK MAN

#

I was shocked as soon as I saw that was a thing.

uneven edge
mint vortex
#

Nope! But you will need to pose it for left hand, right hand, item frames, and dropped items.

#

Though I think you may be able to bypass some of that by setting the parent to minecraft:item/held

uneven edge
#

I will go insane to make it for 16 spears

daring glenBOT
#

Paste version of steel_spear_model.json from @mint vortex

mint vortex
#

You will have to create a sprite for it though.

mint vortex
#

I made mine 32 x 32

#

There is a little bit of wonkiness when the spears charge animation gets exhausted, as it moves up and away instead of down and out of view.

uneven edge
mint vortex
#

Other than that, it should function just fine.

mint vortex
uneven edge
mint vortex
#

Steel spear

#

Unfortunately, since you can't modify spears' stats atm like you can with tools and armor, its damage is going to default to whatever tier you set it to if memory serves.

#

Since my steel, brass, lead and silver spears all have a base attack damage of 3.

#

So at the moment, the only way you can influence their damage is by changing their charge damage multiplier. The jab attack will still only deal 3 damage regarless.

mint vortex
#

yeah

#

It's the second number after "material" when adding in a new spear.

#

Like i said, it has no effect on base damage, but only the "jousting" damage.

uneven edge
#

But hold on what's the problem with setting up custom damage?

#

It acts like a melee, no?

#

Why you can't change the damage controls in tiers?

uneven edge
mint vortex
#

Yeahhh I haven't been able to figure out how to have it display as a different sprite other than the model itself despair

uneven edge
mint vortex
#

Only info I'm working with is from a dump of 1.20.1:

uneven edge
mint vortex
#

And from 1.21.11, there's 3 separate .json files for a single spear entry; the spear, its held-in-hand file, and a general "spear-in-hand" file

uneven edge
#

From the mod itself

mint vortex
#

I'm assuming that's from the- yep

#

I tried that already

uneven edge
#

What's wrong with it then?

#

oh I can see what actually

mint vortex
#

something to do with "spears: in_gui"

#

since the spears we're making are from kubejs, not spears

uneven edge
#

And we need to hook it to the script

#

somehow

#

And it will work

mint vortex
#

yep

#

that's the working theory anyway

#

So unless there's a different way to do that same exact function in the .json file, I'm stumped.

#

I'm currently browsing 1.21.11 assets regarding spears, so I might find something there.

#

Okay so now the item's gui sprite is correct, but not the held model

mint vortex
#

No matter what I do, it seems like it'll only display one texture or the other...

uneven edge
#

We need to figure out what class is rendering the spear in GUI

daring glenBOT
#

[➤](#1445468987394887800 message)
In KJS 1.20.1,

  • attackDamage setter on Item in the callback is broken (game doesn't launch),
  • attackSpeed setter on Item adds a completely new attribute, that's why it doesn't look right.

So that's why you need to use addAttribute instead to modify those.

Credit: @still furnace:
<#1407522304543559810 message>
-# There you can see that the implicit conversion of a string representing an attribute to an Attribute is also possible.

Please note:

Attribute modification is only possible on classes that implement ModifiableItemKJS, that is:

  • ArmorItem,
  • SwordItem,
  • DiggerItem,
  • TridentItem
  • and any classes extending one of above classes.
const $Attributes = Java.loadClass("net.minecraft.world.entity.ai.attributes.Attributes");

ItemEvents.modification((event) => {
  /**
   * @param {Internal.Item} item
   * @param {Internal.Attribute_} attribute
   * @param {number} value
   */
  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
    );
  }
  
  event.modify("minecraft:iron_pickaxe", (item) => {
    item.maxDamage = 2813;
    item.digSpeed = 12;
    modifyAttribute(item, $Attributes.ATTACK_DAMAGE, 5);
    modifyAttribute(item, $Attributes.ATTACK_SPEED, -2.8);
  });
});
uneven edge
#

Isn't that we are looking for?

#

For attack attribute?

mint vortex
#

already have that script and it didn't work

#

That's the main issue; Backported Spears' spears items, and by extension the new KubeJS spears are deemed as "unsupported"

#

I don't know whether it's because their attack damage isn't directly stated when building one or whatever, but it doesn't work 🤷‍♂️

#

Even with trying to add stats through item.addAttribute doesn't work for the same reason.

#

I'm starting to think maybe it's because the backported spears' IDs are minecraft:///spear instead of backported_spears:///spears. Maybe it messes with how the item is registered?

mint vortex
cerulean mica
# mint vortex

The spear most likely doesn't implement the ModifiableItemKJS interface

#

Which is injected into SwordItem, ArmorItem, DiggerItem and TridentItem

rapid ibex
#

you'll probably need to check how they implement attributes values for the "spear"s when registered

mint vortex
#

Buuuuut I'm kinda stumped as to what to do either way.

rapid ibex
#

because you mentioned something about all the spears have the same attribute values

mint vortex
#

I think it's because of the custom tiers I made. I made another test_spear with vanilla minecraft's wood tier and it set that item's attack damage to 1 as it should.

rapid ibex
#

and it worked?

mint vortex
#

Yea, but I'm assuming its durability went down to that of the wooden spear, as well.

#

Lemme double-check

#

Okay, this is weird as heck... The wooden spear has a durability of 59, but the test_spear has a durability of 250.

#

A netherite spear has a durability of 2031, but the steel spear also still has only 250 durability, when it should have 215.

cerulean mica
#

I think that's because custom tiers are broken in general in KubeJS

mint vortex
#

Honestly I wouldn't be upset about that if it werent for the fact that we currently can't modify their stats until this is resolved.

rapid ibex
#

I mean you could do this. Remove their attribute tooltips and replace it with your own

#

then on the LivingHurtEvent modify the damage

mint vortex
#

Remove their attribute tooltips?

rapid ibex
#

yes

#

someone made a script

#

and I think I posted that in #1474144029435367576

#

or maybe not. but it is in this server

mint vortex
#

I did find something regarding Alembic, if that's what you're talking about.

rapid ibex
mint vortex
#

So basically, you want me to remove the stats from the spears and replace them? Just making sure I'm understanding.

rapid ibex
#

hide the attribute stats and replace them with the tooltips you want

#

IF thats how you want to work around attributes not working correctly

mint vortex
#

Let me see if it works

rapid ibex
#

it should work since the example script works with everything

mint vortex
#

So...... I removed attack damage and attack speed, but that doesn't seem like it did anything.

#
    "minecraft:generic.attack_damage",
    "minecraft:generic.attack_speed"
];```
#

that's the only part I modified, I made the whole script as its own file in the startup script folder, and nothing seemed to change.

rapid ibex
#

It should remove the attribute tooltip not the actual values

mint vortex
#

So is it purely visual?

rapid ibex
#

yes ...

mint vortex
#

oh.....

rapid ibex
mint vortex
#

Ohhhhhh now I get what you were trying to say

#

I'm gonna see if I can get Alembic to change anything instead.

#

Unless something else pops up that we can try.

mint vortex
#

I'm also trying to see if I can add onto my current script to try and do something with it.

rapid ibex
#

I dont think any normal attribute modifcation is possible

mint vortex
#

The funny thing is that with Alembic, the damage of the spears indirectly changed due to that mod adding resistances and weaknesses to damage types. Not what I'm looking for, just a happy accident.

mint vortex
#

Also, it seems like installing Alembic messes with the charge damage code, as it's the same as the jab damage.

mint vortex
#

Just a theory, but if we could somehow classify those spears as an item type that's supported by KubeJS like SwordItem or TridentItem, I wonder if it could also be modified..?

rapid ibex
#

there is no somehow

#

you can't cast item types I think in KubeJS

mint vortex
#

Oop-

mint vortex
#

I suppose another solution would be just to make an addon that supports the spears as an item type in the KubeJS item builder...

cerulean mica
cerulean mica
# rapid ibex you can't cast item types I think in KubeJS

Even in Java you couldn't if the wasn't already extending/modifying the class.
Java ensures type safety, but there are some unsafe casts in Java:

  • unchecked upcasts (TridentItem) item
  • cast to Object ("any" type), then to anything (ModifiableItemKJS) (Object) item, this is actually seen in mixins where you have to sometimes bypass the type safety
uneven edge
#

@mint vortex This script can help us to make custom stab damage

#

It needs to be modified tho

uneven edge
#

@mint vortex ok here is the solution for the hotbar sprite render

uneven edge
#

THE CUSTOM SPEAR SCRIPT CAN BE FINISHED

mint vortex
#

At least the script is useful for changing the damage of usually unmodifiable items/weapons.

mint vortex
mint vortex
mint vortex
daring glenBOT
#

Paste version of crash-2026-02-23_09.58.48-client.txt from @mint vortex

mint vortex
#

Okay, it's not crashing now, but it doesn't work...

#

The model itself is fine, but the gui part is still just the model and not the given sprite

rapid ibex
#

just search up a spartan weaponry texture pack

#

as far as I'm aware there are only two that modify the texture in gui

#

waccyy fantasia texture tweaks and icedmi's spartan weaponry

stoic fossil
wooden flower
uneven edge
#

bump heh

mint vortex
#

You know, I did find a way to still technically add onto these spears without modifying their item attributes heh

#

Basically, I essentially coded in a very basic "Apply status on hit" mechanic and applied it to anything that had a specific tag.

#

Specifically, I added the ability for "holy-type" weapons to inflict only undead enemies with Slowed III from Iron's Spells.

#

Just posting my thoughts here, but maybe I can use that same script to either change the damage value of specific items only when it hits an entity, since we can already control almost all the basic stats of spears.

rapid ibex
#

probably a good idea

mint vortex
#

Wonderful development, ladies and gentlemen! I've found a way to modify the base damage of the custom spears!!

mint vortex
uneven edge
mint vortex
#

Oh?

#

Does it allow for the spears to be registered as a modifiable item through KubeJS or smth?

uneven edge
mint vortex
mint vortex
#

Ohhhhhh nice!

fiery quiver
#

what is going on in this thread? 300+ messages and the original problem is still not fixed? ;o

rapid ibex
#

nah it should be fixed now