-
Notifications
You must be signed in to change notification settings - Fork 1
Enchantment Filtering
LLytho edited this page May 16, 2023
·
1 revision
With MoreJS 1.19-0.1 you are now able to filter Enchantments. This means you can prevent certain enchantments from being applied to an item.
This event gets called when a villager offers an enchanted book trade. Keep in mind that this event only filters potential enchantments. Adding an enchantment does not mean it will be 100% applied to the item.
MoreJSEvents.filterEnchantedBookTrade((event) => {
// Remove the given enchantment
event.remove("minecraft:unbreaking");
// Add the given enchantment
event.add("minecraft:unbreaking");
event.printEnchantments(); // Simple debug function to print all enchantments
/**
* More stuff:
* event.getEnchantments(); // Returns a list of all potential enchantments
* event.getRandom(); // Returns a random source
* event.isVillager(); // Returns true if the source is a villager
* event.isWanderer(); // Returns true if the source is a wandering trader
* event.getEntity(); // Returns the villager that offers the trade
*/
});
For enchantment tables, entity items and other stuff, we need a second event. This event is different to the first one as we don't use the simple enchantment here. Instead we have EnchantmentInstance
's which contains the level and the enchantment directly. Keep this in mind when working with this event.
MoreJSEvents.filterAvailableEnchantments((event) => {
// Remove the given enchantment
event.remove("minecraft:unbreaking");
/**
* Add the given enchantment. The level will be calculated base on the power level:
* -> enchantment min cost < power level < enchantment max cost = enchantment level
*
*/
event.add("minecraft:unbreaking");
// But we can also set the level manually
event.addWithLevel("minecraft:unbreaking", 3);
event.printEnchantmentInstances(); // Simple debug function to print all enchantments with level
/**
* More stuff:
* event.getEnchantmentInstances(); // Returns a list of all potential enchantments with level
* event.getItem(); // Returns the item that will be enchanted
* event.getPowerLevel(); // Returns the power level to apply enchantments later on. E.g for enchantment tables
*/
});