Jump to content

AnvilUpdateEvents don't fire if the middle slot is empty


leod

Recommended Posts

Line 149 in RepairContainer.java (in 1.15.2, I don't know about 1.16) checks whether the middle slot in the anvil GUI is empty, and only if it isn't the onAnvilChange ForgeHook is called, which makes is making it pretty impossible for me to implement anvil recipes that don't need an item in the center. I've had to resort to making a coremod to implement this, but I don't think it should be that way.

 

The relevant lines look like this:

if (!itemstack2.isEmpty()) {
    if (!ForgeHooks.onAnvilChange(this, itemstack, itemstack2, this.outputSlot, this.repairedItemName, j)) {
        return;
    }

I don't think much of anything would break if the ForgeHook was to be moved in front of the first line to allow events to be sent with empty center slots.

 

If you're wondering why I would want to do what I'm doing, it's a flavor thing for the mod I'm working on and also lets me make it cost XP to get the output item, to keep it out of the early game.

Link to comment
Share on other sites

I’m pretty sure that the anvil is supposed to work that way (with a center item, since the anvil combines the two).

If you want a crafting method that turns one item into another at the cost of experience, you should make a custom crafting block instead.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

I don't think I should have to create a custom crafting block when the anvil fulfills exactly what I need and the restriction is purely a technical one. You can already rename Items in it without a center item present, so it's not like the anvil is hardcoded to never do anything at all without a center item.

Link to comment
Share on other sites

On 7/5/2020 at 10:21 PM, leod said:

I don't think I should have to create a custom crafting block when the anvil fulfills exactly what I need

It doesn't fulfill your need, since it doesn't update when the middle item changes.

 

I would say that since anvil is almost never used without a middle item (renaming is its own case), it would bring extra fuss (unnecessary event subscriber calls) to fire the event subscriber when the middle item changes. It can be made to do stuff without a center item, but it shouldn't design-wise IMO.

However you could propose a PR and see what others think.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.