#Hooking up another mod to make a custom item
313 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
Hooking up another mod to make a custom item
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
Basically, I need to search for all classes that Backported Spears have for Type, Resource Location and Properties, then I am creating a custom item, that hooked up to the existed model and overriding it using JavaAdapter?
kinda lost here tbh
not exactly see if you can extend their SpearItem and see if it has a constructor for materials and what not
Elaborate
I mean that's it
The Backported Spears do it in a really jank way
Because they create their spears using an inline anonymous class that extends ToolItem:
https://github.com/Unknowneth/Backported-Spears/blob/ccf8b121c201f01cd04960b9d98710157f0e7cb3/common/src/main/java/com/notunanancyowen/spears/Spears.java#L215

Yeah
But watch out! The code is using Yarn mappings, not official Mojang mappings!
KubeJS uses and resolves Mojang mappings
Ok that means it is impossible?
No
It's just you can't just copy-paste the code and expect it to work
That makes things worse 
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
nah it's not hard to translate mappings
just use a translator
and some of them you can already guess
I was going to suggest linkie but their translator has been down for a while now
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.
Just call this function and see what happens
there shouldn't be any issues because it's a public static
So, I attemped to call it during item creation and this is what happens:
``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")
}) ``
where are you calling the register spear function?
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:
ProbeJS doesn't dump all the classes and can't dump some
dang..
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.
try this and see what happens
wait, I think I see the problem. I was using a different Spears backport mod, Spears +. Just installed the one I believe you're using in this case.
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
https://www.curseforge.com/minecraft/mc-mods/spears-spears-plus
Hooray, ARR with no source code
Load the Item$Properties class and pass an instance of it to the parameter
like this?
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)
Just to make sure, I'd add instance in place of class, right?
No
What passes it as an instance? I'm only aware of let and class.
new
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"
Duly noted
YESSSS finally got it working, albeit untextured.
Then give your item a texture and a model
Normally, KubeJS does give your item a model automatically, but if you create an item with createCustom you have to add a model manually
Since we're using createCustom, would the model and inventory sprite have to be added via a datapack?
Resourcepack - yes
gotcha
Lucky for you, assets folder inside the kubejs folder is a global resource pack
Can you pass the code please? 🙏
oh wait you are on Spear+?
Sorry, just woke up. Lemme get you the code.
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.
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)
})
Use three backticks, not one
So, it IS working properly, right?
Whoops, I keep using two lol. Thanks.
Yes, and I'm still trying to get the spear model working properly. It's working mostly right, but textures aren't loading and the inventory icon is the spear model itself.
I see...
To make them work in your code I need to create a tier for each material type?
Yes, unless you want to reuse vanilla tiers
If you want to make a tier that isn't a vanilla tier yea
For example, in my modpack I need to make spears for every Aether material
I need to assign them to Aether tiers?
Find the class in the Aether mod that has tiers, and load that class
let $ItemTierAether = Java.loadClass('aether.class')?
Easier said than done 
I actually use a program that lets me view .class files. Lemme see what it's called.
I'd also reccomend installing WinRaR if you haven't already.
ofc I have lol
But i'm scouting through their github
maybe it will be easier to make KubeJS tiers at this point
JD-GUI?
IntelliJ IDEA
Yeah, I'm thinking that making custom tiers will benefit
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
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%
yeah, Enderum from Majrusz's Progressive Difficulty have passive benefits, but for armor only
oreganzied uses attributes
Really? Because the only way I've been able to add its Kinetic Damage attribute is through item tags. Unless that's what you mean?
Please drop the working script in #1048591172165189632 when you guys get it to work
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.
What texture is your model referencing?
Are you asking if it's a .png file?
Ohhhh that. The model's file is located at kubejs/assets/kubejs/models/item/steel_spear.json
Paste version of steel_spear.json from @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.
you can override that with a texture pack
that is default behavior unless specificed otherwise
You can change that in the model as well
If anyone can help with making unsupported item types allow for their item attributes to be modified, I would like to kindly redirect you to my help ticket: https://discordapp.com/channels/303440391124942858/1474525293271056484
Ticket re-opened!
nvm I need some additional help LOL
No you can directly change the attributes
Whatcha need help with?
That's where I stuck - how? 
Can you pass .bbmodel of your model?
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.
Since WHEN 
Ok, I need to test it out. I suppose I need to re-create the animation itself or?..
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
for the love of please send me a template for this 🙏
I will go insane to make it for 16 spears
Paste version of steel_spear_model.json from @mint vortex
You will have to create a sprite for it though.
ofc
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.
Same here
Other than that, it should function just fine.
Oh hell yeah
Skystone spear 
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.
In the script itself?
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.
Gotcha
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?
And I see the problem number 2: hotbar render
Yeahhh I haven't been able to figure out how to have it display as a different sprite other than the model itself 

How it renders model in hotbar even?
Only info I'm working with is from a dump of 1.20.1:
hold on I might have an idea
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
From the mod itself
something to do with "spears: in_gui"
since the spears we're making are from kubejs, not spears
I guess it is from the mod itself
And we need to hook it to the script
somehow
And it will work
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
No matter what I do, it seems like it'll only display one texture or the other...



We need to figure out what class is rendering the spear in GUI
#1445468987394887800 message
@mint vortex
[➤](#1445468987394887800 message)
In KJS 1.20.1,
attackDamagesetter onItemin the callback is broken (game doesn't launch),attackSpeedsetter onItemadds 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);
});
});
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?
Okay, I'm getting somewhere; I just tried to add attack damage and extra jumps to a stick and it also gave the same error. I think this problem has to do something with how the item is registered, or what is declared when creating the item.
🤔
The spear most likely doesn't implement the ModifiableItemKJS interface
Which is injected into SwordItem, ArmorItem, DiggerItem and TridentItem
you'll probably need to check how they implement attributes values for the "spear"s when registered
Yeah, I'm trying to mess around with those to see if I can do something with it.
Buuuuut I'm kinda stumped as to what to do either way.
Then might have a place where they pull default values to assign to the spears
because you mentioned something about all the spears have the same attribute values
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.
and it worked?
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.
I think that's because custom tiers are broken in general in KubeJS
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.
I mean you could do this. Remove their attribute tooltips and replace it with your own
then on the LivingHurtEvent modify the damage
Remove their attribute tooltips?
yes
someone made a script
and I think I posted that in #1474144029435367576
or maybe not. but it is in this server
I did find something regarding Alembic, if that's what you're talking about.
nah I'll find it give me a moment if this is the method you really want to do
So basically, you want me to remove the stats from the spears and replace them? Just making sure I'm understanding.
hide the attribute stats and replace them with the tooltips you want
IF thats how you want to work around attributes not working correctly
Let me see if it works
it should work since the example script works with everything
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.
It should remove the attribute tooltip not the actual values
So is it purely visual?
yes ...
oh.....
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.
I'm also trying to see if I can add onto my current script to try and do something with it.
I dont think any normal attribute modifcation is possible
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.
OKAY, so I did find one workaround regarding durability. You can set the custom spear's durability in the itemProperties section by typing itemProperties.defaultDurability(...)
Also, it seems like installing Alembic messes with the charge damage code, as it's the same as the jab damage.
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..?
Oop-
I suppose another solution would be just to make an addon that supports the spears as an item type in the KubeJS item builder...

Or inject the ModifiableItemKJS interface into them, but still - that requires a mixin, so a mod
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
@mint vortex This script can help us to make custom stab damage
It needs to be modified tho
Okay, good news and bad news. Good news! That script functions as intended. Bad news #1: The spear's jousting attack is also set to the value you put in. Bad news #2: That script doesn't (currently?) function with Better Combat.
At least the script is useful for changing the damage of usually unmodifiable items/weapons.
The ironic part is that installing Better Combat actually fixes the jab attack's double damage bug

When trying to load the game with these changes, the game crashes before getting to the main menu ;w;

Paste version of crash-2026-02-23_09.58.48-client.txt from @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
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
I have this too with some of the weapons in spartan weaponry it's Soo annoying
lol that title
bump 
You know, I did find a way to still technically add onto these spears without modifying their item attributes 
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.
probably a good idea
🔥
Wonderful development, ladies and gentlemen! I've found a way to modify the base damage of the custom spears!!
Just wanna ping you real quick regarding this.
Omg, I commissioned a mod in desperation 
Oh?
Does it allow for the spears to be registered as a modifiable item through KubeJS or smth?
I just asked to add spears and gloves I need

What kinda gloves we talking about? Like, slapping gloves? Accessories?
aether gloves
Ohhhhhh nice!
what is going on in this thread? 300+ messages and the original problem is still not fixed? ;o
nah it should be fixed now