#matchMainHand / check item or armor for mobs LootJS
212 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
bumperoo
I'd also love to know!
just a bump!
If it only should work for specific items you can try this
.matchEntity(entity => {
entity.matchSlot(EquipmentSlot.MAINHAND, "item")
})
If you want to do this for any item you could take a look at the apply callback and at the function it provides https://github.com/AlmostReliable/lootjs/wiki/1.20.1#lootcontextjs
if you get the entity you can probably check for the equipped items
would this apply to a lootjs script? js LootJS.modifiers((event) => { event.matchEntity(entity => { entity.matchSlot(EquipmentSlot.MAINHAND, "simplyswords:soulstealer") .addEntityLootModifier("minecraft:piglin_brute").addLoot(LootEntry.of("simplyswords:soulstealer").when((c) => c.randomChance(1.0))) })} ) like so?
not like that no, You always need the .addEntityLootModifier first. You also had your brackets incorrectly for the .matchEntity callback, otherwise I've structure the code a little better
LootJS.modifiers((event) => {
event
.addEntityLootModifier("minecraft:piglin_brute")
.matchEntity(entity => {
entity.matchSlot(EquipmentSlot.MAINHAND, "simplyswords:soulstealer")
})
.addLoot(LootEntry.of("simplyswords:soulstealer").when((c) => c.randomChance(1.0)))
})
ahh I see okay makes sense ill give it a shot
I'm getting Error in 'LootJS.modifiers': ReferenceError: "EquipmentSlot" is not defined.
const $EquipmentSlot = Java.loadClass("net.minecraft.world.entity.EquipmentSlot")
LootJS.modifiers((event) => {
event
.addEntityLootModifier("minecraft:piglin_brute")
.matchEntity(entity => {
entity.matchSlot($EquipmentSlot.MAINHAND, "simplyswords:soulstealer")
})
.addLoot(LootEntry.of("simplyswords:soulstealer").when((c) => c.randomChance(1.0)))
})
try this
the thing that confuses me is that the code I had before was documented like this https://github.com/AlmostReliable/lootjs/wiki/1.18.2#equipment-slots in 1.18.2, but basically nothing changed that shouldn't have made this work (or it just didn't work in 1.18.2 aswell)
I suspected that it may be because this applied to a previous version, I'm this checking now
Yeah I know, but I couldn't find any code in base KubeJS or LootJS that added this EquipmentSlot
hmm sometimes they drop two
const $EquipmentSlot = Java.loadClass("net.minecraft.world.entity.EquipmentSlot")
LootJS.modifiers((event) => {
event.addEntityLootModifier("minecraft:piglin_brute")
.matchEntity(entity => {entity.matchSlot($EquipmentSlot.MAINHAND, "simplyswords:soulstealer")})
.addLoot(LootEntry.of("simplyswords:soulstealer").when((c) => c.randomChance(0.5)))})```
is the random chance value messing it up?
okay so what I think is happening, is that the script already causes the sword to drop, but the addloot causes an additional one to drop
actually no that isn't whats happening
Generally mobs have a chance to drop equipment
this is happening roughly 50% of the time (like the random chance), additionally, the mob didnt drop the sword at all prior to adding this script
I gotta do something for like 45 mins just so you think I didnt disappear, thank you for the help so far brb
did some more testing and yes ```js
.addLoot(LootEntry.of("simplyswords:soulstealer").when((c) => c.randomChance(1.0)))``` drops 2
im not in the condition to read or understand all this rn but
I would really love to
Couls you pls dm me later with a short explanation?
It still doesn't really work yet 😢
Oh..
just a bump
At this point normally most of the people that are helping have already taken a look at it and didn't have a solution, this is pretty normal
just a waiting game
so where did u stuck, what is a problem
The weapon is dropped, however it drops 2 @honest breach
why u need adding this weapon drop, when it will drop even without this script?
u just wanna change dropping chance or what?
yes, and also in my testing it does not drop without a script
just remove drop before adding loot with different chance
I don't have the means to remove the drop, it will either drop 2, or not drop 2
i mean, if u remove weapon drop before adding new one, u will get only one weapon
if it works as i think 
Would you be able to provide an example of this?
const $EquipmentSlot = Java.loadClass("net.minecraft.world.entity.EquipmentSlot")
LootJS.modifiers((event) => {
event.addEntityLootModifier("minecraft:piglin_brute")
.matchEntity(entity => {entity.matchSlot($EquipmentSlot.MAINHAND, "simplyswords:soulstealer")})
.removeLoot("simplyswords:soulstealer")
.addLoot(LootEntry.of("simplyswords:soulstealer").when((c) => c.randomChance(0.5)))})
try this
okay, ill have to check it out tomorrow, ill get back to you
Okay, same situation, it has a %50 chance of dropping one and a %50 chance of dropping two
no idea 
idk how to do it with lootjs, but i have a regular kubejs server script in which i changed item drops from skeletons and pigmans. guess you can modify it to suit your needs
EntityEvents.spawned(event => {
const entity = event.entity
if (entity.type === "minecraft:skeleton" || entity.type === "minecraft:zombified_piglin") {
const equipment = entity.getEquipment()
if (equipment) {
equipment.mainHandDropChance = 0
equipment.offHandDropChance = 0
}
}
})
Thank you I'm looking into it now
EntityEvents.spawned(event => {
let entity = event.entity
if (entity.type === "minecraft:piglin_brute" || entity.type === "takesapillage:legioner" || entity.type === "paradise_lost:envoy" || entity.type === "minecraft:wither_skeleton" || entity.type === "monsterplus:spectral_skeleton")
{
const equipment = entity.getEquipment()
if (equipment === "simplyswords:soulstealer" || equipment === "simplyswords:arcanethyst" || equipment === "simplyswords:dormant_relic" || equipment === "simplyswords:emberslash" || equipment === "simplyswords:soulpyre") {
equipment.mainHandDropChance = 1
}
}
})``` Unfortunately the following code does nothing for me, and the mobs don't drop their items. Is this a 1.20.1 script?
yep
So this should work? And the listed enemies should drop the listed items %100 of the time if they're holding it?
yep, everything seems to be working fine for me
So, I didn't see any results, I don't know what the issue is
For the script you said worked, except they dropped 2, did you try adding a count?
.addLoot(LootEntry.of("simplyswords:soulstealer", 1).when((c) => c.randomChance(1.0)))
I suspect it might not fix it, but worth a shot
You are a saint. It fixed it
How simple was that
Happy it worked!
No wait I totally lied 🥲
It didn't lol
Just got lucky
Haha, okay, I suspected it may not
I don't even understand what could be going wrong
Is it possible to write a script that deletes an item if you pick up 2 withing x amount of ticks?
Can you post the entire LootJS.modifiers block?
or makes it so 2 cant exist as drops
const $EquipmentSlot = Java.loadClass("net.minecraft.world.entity.EquipmentSlot")
LootJS.modifiers((event) => {
event.addEntityLootModifier("minecraft:piglin_brute")
.matchEntity(entity => {entity.matchSlot($EquipmentSlot.MAINHAND, "simplyswords:soulstealer")})
.removeLoot("simplyswords:soulstealer")
.addLoot(LootEntry.of("simplyswords:soulstealer", 1).when((c) => c.randomChance(0.5)))})
it seems like it drops 1 sword %33 percent of the time, nothing %33 of the time and the remaining 2 swords
give me a sec and I'll explain why, sorry, in a match lol
dont sweat it thank
s
So basically it's running the script twice, so you have a few different possible outputs, right?
0, 0
0, 1,
1, 0,
1, 1
So it's roughly 50% chance to get 1, 25% to get 0, and 25% to get 1
okay got it
The thing is, I don't know why it's running it twice, and I've run into something like this in KubeJS, but not LootJS
sounds like a bug
simplyswords:soulstealer isn't already in its loot table, right?
Just asking because you have .removeLoot("simplysword:soulstealer")
EntityEvents.spawned(event => {
let entity = event.entity
//minecraft:piglin_brute
if (entity.type == "minecraft:piglin_brute" && Math.random() < 0.52) {
entity.setItemSlot(0, "simplyswords:soulstealer")
entity.setItemSlot(1, "shieldexp:netherite_shield")
entity.setItemSlot(4, "minecraft:netherite_chestplate")
entity.setItemSlot(2, "minecraft:netherite_boots")
}``` The only other entry with it. I've tested this and unlike how spawns normally drop weapons, this is not the case
that was just a precaution that didnt work
Kk, give me a couple minutes to think this through
Okay, I'm not familiar with loading classes, but can you try this? And then I have a couple more ideas
LootJS.modifiers((event) => {
event.addEntityLootModifier("minecraft:piglin_brute")
.matchEntity(entity => {entity.matchSlot($EquipmentSlot.MAINHAND, "simplyswords:soulstealer")})
.addWeightedLoot(
[0,1], [
Item.of("simplysword:soulstealer").withChance(100)]);
})```
0, 1 means it can drop 0 or 1, with a chance of 100%, and I removed the removeLoot, my hope is that will work
Okay I'll give it a crack, thank you!
I have a few more ideas of how to tackle this if that doesn't work
was that a typo 'witchchance'?
yes, haha
yep
okay SO, the script doesn't do anything, however, I've noticed that it's dropping normally at the 1/8 chance. Unfortunately, the rest of the mobs equipment is dropping, which isn't that great. Even when using it like such:
LootJS.modifiers((event) => {
event.addEntityLootModifier("minecraft:piglin_brute")
.matchEntity(entity => {entity.matchSlot($EquipmentSlot.MAINHAND, "simplyswords:soulstealer")})
.removeLoot("minecraft:netherite_chestplate")
.removeLoot("shieldexp:netherite_shield")
.removeLoot("minecraft:netherite_boots")
.addWeightedLoot(
[0,1], [
Item.of("simplysword:soulstealer").withChance(100)])});```
so with and without the script its the same
it drops all items though, which is not the goal
because the brute has armor on
so the removeloot doesn't work in that script
But the one I gave you, it just doesn't do anything, or it still drops twice sometimes?
It doesn't do anything
Same thing as if I just completely deleted it
Hmmm, okay re-add the .removeLoot and see what happens
with js }) const $EquipmentSlot = Java.loadClass("net.minecraft.world.entity.EquipmentSlot") LootJS.modifiers((event) => { event.addEntityLootModifier("minecraft:piglin_brute") .removeLoot("minecraft:netherite_chestplate") .removeLoot("shieldexp:netherite_shield") .removeLoot("minecraft:netherite_boots")});
still drops armor
No I mean to mine
Like this?
or just one item removed?
Oops, okay, so first, I made a type on the second simplyswords
LootJS.modifiers((event) => {
event.addEntityLootModifier("minecraft:piglin_brute")
.matchEntity(entity => {entity.matchSlot($EquipmentSlot.MAINHAND, "simplyswords:soulstealer")})
.addWeightedLoot(
[0,1], [
Item.of("simplyswords:soulstealer").withChance(100)]);
})```
this caused them to drop 2 sometimes 😢
Kk, that's what I suspected, let's try one more thing, but I need a few minutes to type it out lol
no worries my man I appreciate it
Okay, this is a hail mary, but worth a shot, lol
LootJS.modifiers((event) => {
const whenSword = LootEntry.of("simplyswords:soulstealer", 1).when((c) =>
c.matchEntity(entity => {entity.matchSlot($EquipmentSlot.MAINHAND, "simplyswords:soulstealer")})
event.addEntityLootModifier("minecraft:piglin_brute")
.addAlternativesLoot(whenSword);
})```
uhh
typo lol
Okay, there we go lmao
If that doesn't work, it basically confirms the issue, that the entire script is running two times
getting an error for the event
what line?
second from the last
red underline
is it defined?
actually, it may be redundant
event shouldn't be throwing an exception; the const whenSword is being defined, and then even.addEntityLootModifier is calling the standard loot table
what exactly does the error message say?
Ope, you're right, for the .when()
oh, for that error, try adding a semicolon after the const, so like
LootJS.modifiers((event) => {
const whenSword = LootEntry.of("simplyswords:soulstealer", 1).when((c) =>
c.matchEntity(entity => {entity.matchSlot($EquipmentSlot.MAINHAND, "simplyswords:soulstealer")}));
event.addEntityLootModifier("minecraft:piglin_brute")
.addAlternativesLoot(whenSword);
})```
Okay, that's still data, that means it is running two times regardless of how we try to add it
why have they done this
crazy question but how did you learn so much of KubeJS despite being new on the Discord
- I'm an autodidact and have taught myself VB.NET and C#.NET in the past, 2) I'm a natural troubleshooter, 3) I'm relying heavily on the documentation and use an LLM to help me analyze and understand code I'm not familiar with
what documentation? Surely you dont mean latviadev?
yep, lol
also whats llm lol
chatgpt, deepseek
I don't have them write code for me, but I use them to understand if I don't recognize the code
hmm okay fair enough
So let's start extremely basic to see if it repeats at the base level; just try this and see if it still sometimes drops 2:
event.addEntityLootModifier("minecraft:piglin_brute")
.addLoot("simplyswords:soulstealer");
})```
Interesting... what if you just do "minecraft:diamond_sword"? Basically I'm trying to isolate the element that's causing the double drop
srry doing a bit more testing
all good
Okay, now try a different mob, so like
event.addEntityLootModifier("minecraft:cow")
.addLoot("simplyswords:soulstealer");
})```
still dropping two??
Okay, then last step would be trying no script whatsoever and seeing what happens
well no
wait, nevermind
We already know it's that the script is running twice, we don't need to do that lmao
ummmm
Okay so its firing all my loot scripts twice for some reason
are you able to throw your entire .js somewhere so I can see the entire doc?
Paste version of loot.js from @bright holly
Sorry, a lot to look through; this is in server_scripts, right?
In general I would keep separate js files by function, but that's just my own organizational imperative, haha
If I did that you have no idea how many files I'd have
Okay, so let's test something really quick; can you test out limpets and see if they ever drop 3 or 4 soul dust?
I'll take a look, I just deleted all scripts so I'll copy them back in after I check something
I'm going to relaunch, but I deleted all server scripts except for this single entry and it still drops double```js
LootJS.modifiers((event) => {
event.addEntityLootModifier([
"cataclysm:coralssus"
])
.addLoot(
LootEntry.of(Item.of('irons_spellbooks:scroll', '{ISB_Spells:{data:[{id:"traveloptics:coral_barrage",index:0,level:1,locked:1b}],maxSpells:1,mustEquip:0b,spellWheel:0b}}').weakNBT()).when((c) => c.randomChance(1.0))
);
});
well, at least we know the issue isn't with your scripts themselves, lol
still got client and startups tho
those are next
okay still happens when I relaunch
So when you remove every script except for the single call, it still drops double?
checking that right now, I just removed startup and client scripts
yep still drops 2
I have only a single script
this
looks like there may be a mod config
that sucks
Well it's about time I go to bed so I'll give it a crack later
alrighty, you might, unfortunately, have to start checking individual mods 🙁
thank you for all your help tho
it was mob AI tweaks
good riddance lol
final script to prevent armor drops ```js
let patchedEntities = [
'minecraft:piglin_brute'
]
EntityEvents.spawned(event => {
let ent = event.entity
if (!ent || !ent.isLiving()) return
if (!patchedEntities.includes(ent.type)) return
let dim = ent.level.dimension
let x = ent.x, y = ent.y, z = ent.z
event.server.scheduleInTicks(1, () => {
event.server.runCommandSilent(execute in ${dim} positioned ${x} ${y} ${z} run data merge entity @e[type=${ent.type},distance=..0.5,limit=1,sort=nearest] {ArmorDropChances:[0.0f,0.0f,0.0f,0.0f],HandDropChances:[0.0f,0.0f]})
})
})
const $EquipmentSlot = Java.loadClass("net.minecraft.world.entity.EquipmentSlot")
LootJS.modifiers((event) => {
event.addEntityLootModifier("minecraft:piglin_brute").matchEntity(entity => {entity.matchSlot($EquipmentSlot.MAINHAND, "simplyswords:soulstealer")}).addLoot(LootEntry.of("simplyswords:soulstealer").when((c) => c.randomChance(1.0)));
```
well, I'm glad you got it 😅