CraftTweaker

CraftTweaker

151M Downloads

[1.20.1] Anvil Bug?

Looodon opened this issue ยท 3 comments

commented

Issue description

I tried to disable the anvil from giving the trident any enchantments and failed even after three people on the discord reviewed and said it should have worked. No one is able to stop the item from getting an enchantment from a book on the anvil. I tried it with only 1) crafttweaker, 2) jeitweaker, and 3) jei installed.

Steps to reproduce

No response

Script used

https://pastebin.com/8rnvCxPR

The crafttweaker.log file

https://pastebin.com/tcKKXSiF

Minecraft version

1.20.1

Modloader

Forge

Modloader version

47.3.7

CraftTweaker version

14.0.43

Other relevant information

No response

The latest.log file

https://pastebin.com/ELChDq2i

commented

The AnvilUpdateEvent is cancelable, despite what the docs say, so the following will work:

import crafttweaker.forge.api.event.tick.PlayerTickEvent;

events.register<crafttweaker.forge.api.event.anvil.AnvilUpdateEvent>((event) => {
    if <item:minecraft:trident>.matches(event.left) {
            event.cancel();
        }
    }
);

I am working on updating the docs, but I do not have an ETA on when it will be done.

commented

hey, I tried the code. It prevented the Trident from getting any enchantments, but if let's say there was a diamond sword with an enchanted book and I swapped out the sword with a Trident it duplicates the sword.

Screen Shot (2024-09-09 15_38_27)

commented

That would be a bug with Forge then, we don't have any special handling for events, writing that same event exactly like that in a mod would result in the same thing happening.

While not a good solution, you can do this instead:

import crafttweaker.forge.api.event.tick.PlayerTickEvent;

events.register<crafttweaker.forge.api.event.anvil.AnvilUpdateEvent>((event) => {
    if <item:minecraft:trident>.matches(event.left) {
            event.output = event.left;
        }
    }
);

however that will still consume the book, but it won't get any enchantments.