CraftTweaker

CraftTweaker

186M Downloads

enchantments can be deleted, how?

Zarcog24 opened this issue ยท 4 comments

commented

Describe the feature you'd like

I would like to remove some enchantments from my mod pack that are very overpowered but I haven't found how to do it anywhere

Describe alternatives you've considered

No response

Additional context

No response

Minecraft version

1.19

Modloader

Forge

commented

You cannot fully remove enchantments from the game, the best you can do is use a PlayerTickEvent to loop over the player's inventory, check each item if they have the enchantment and then remove it from the item, but this is not an ideal solution, and may be confusing to players.

commented

Interesting, tell me more. A PlayerTickEvent loop might be literally the only solution to my issue on 1.16.5 modded, I want to remove a very specific overpowered enchantment from a mod but it's effectively a hardcoded enchantment(no option to disable it) and I'd rather not remove an entire mod due to one stupid thing it has.

commented

You can try this, it is untested though

import crafttweaker.api.event.tick.MCPlayerTickEvent;

CTEventManager.register<MCPlayerTickEvent>((event) => {
    if event.start {
        return;
    }
    val player = event.player;
    // Run every 10 ticks
    if player.world.gameTime % 10 == 0 {
        val inventory = player.inventory;
        // Get all stacks in the player's inventory that is enchanted and has the enchantment
        val stacks = inventory.getStacks(stack => stack.isEnchanted && stack.getEnchantmentLevel(<enchantment:minecraft:riptide>) > 0);
        for stack in stacks {
            // Remove the enchantment
            stack.mutable().removeEnchantment(<enchantment:minecraft:riptide>);
        }
    }
});
commented

Well, I tried it, it sadly does not work(I know it was untested, but just confirming it doesn't work).

Gives the error "No such symbol: CTEventManager\nPossible imports:\ncrafttweaker.api.events.CTEventManager"

Edit: I did try adding "import crafttweaker.api.events.CTEventManager" with the same error as a result.

Edit 2: Okay I forgot a ; after "import crafttweaker.api.events.CTEventManager" like a dummy, but now the error is switched to expecting a ; on line 2 despite there being one?

Edit 3: Disregard everything, I had to restart the client entirely for the script to work, but it works.

I guess my only option is to remove the mod entirely from my pack, which is sad cause it's a nether farming mod that I liked.