#How does EntityPredicate work in LootJS?

20 messages · Page 1 of 1 (latest)

barren nacelle
#

Currently trying to create Music Disc functionality similar to Vanilla, where a music disc is dropped when a Skeleton deals the killing blow on a certain mob (in this case, a Zombie). I found the syntax I need but clicking the EntityPredicate link leads to an empty WIP page. As such I am stumped at what exactly the syntax is requesting.

My current code is attached as an image.

humble joltBOT
#

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

barren nacelle
#

Realized the reason the line itself was erroring was because I was missing a parentheses. However, now it is giving this error in game

#

[ERROR] ! …rhino.EvaluatorException: Java class "com.almostreliable.lootjs.loot.Predicates" has no public instance field or method named "entity". (server_scripts:music_disc_loot.js#101)```
#

Here is the current code

 event
    .getLootTable("minecraft:entities/zombie")
    .firstPool()
    .addEntry(LootEntry.of("kubejs:music_disc_14_revamped").matchAttacker(Predicates.entity("minecraft:skeleton")))
barren nacelle
#

@slow panther Would it be possible to get a list of EntityPredicates for 1.21? I've been trying to reverse engineer the 1.20 documentation here and not had any luck.

slow panther
#

Will Update the wiki

#

You should be able to pass in a json like you would do in datapacks

#

Will give u some screenshot of the Minecraft code when I'm at my pc

barren nacelle
#

Sounds good

slow panther
#

past me actually made an example script lol

#

Internal MC code (Sorry for this kek )

public record EntityPredicate(Optional<EntityTypePredicate> entityType, Optional<DistancePredicate> distanceToPlayer, Optional<MovementPredicate> movement, LocationWrapper location, Optional<MobEffectsPredicate> effects, Optional<NbtPredicate> nbt, Optional<EntityFlagsPredicate> flags, Optional<EntityEquipmentPredicate> equipment, Optional<EntitySubPredicate> subPredicate, Optional<Integer> periodicTick, Optional<EntityPredicate> vehicle, Optional<EntityPredicate> passenger, Optional<EntityPredicate> targetedEntity, Optional<String> team, Optional<SlotsPredicate> slots) {

}
#

if you need some explanation of something lemme know, feel free to ping me in this thread

barren nacelle
#

Thank you so much! Referencing the resources you provided I was finally able to get it working

#

In case anyone is trying to do something similar in the future and are stumped, here is the final functioning code

event
    .getLootTable("minecraft:entities/zombie")
    .createPool()    
    .addEntry(LootEntry.of("kubejs:music_disc_14_revamped").matchAttacker({entityType: "minecraft:skeleton"}).withWeight(6))
})```
barren nacelle
#

@slow panther Okay this may be a fairly obvious fix but in the situation of these and the ones I added as drops for bosses where I just did .addEntry instead of .addEntry(LootEntry.of) I noticed the discs are being fully rolled in the loot tables so it's currently a chance of rolling provided you meet the conditions. What would I need to do to ensure they drop each time the condition is met (Using the above example, every time a Skeleton kills a zombie it will drop the music disc, no matter what)

slow panther
#

use createPool instead of firstPool. Then the entry it put into another pool and each pool is rolled on its own in minecraft

barren nacelle
#

That seemed to work. Thank you once again