Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let vanilla try to handle Container interactions before checking for item handlers #1787

Open
wants to merge 3 commits into
base: 1.21.x
Choose a base branch
from

Conversation

Technici4n
Copy link
Member

@Technici4n Technici4n commented Dec 18, 2024

Move our IItemHandler interaction hooks after vanilla checks for Container interactions. This gives vanilla control over interactions with Containers. Fixes #1750. Fixes #1770. (Did not test the latter but I assume it gets fixed).
As a side effect, this greatly simplifies our hooks since we don't need to handle vanilla edge cases such as hopper - hopper interactions having special interactions when it comes to cooldowns.

Breaking change

Modders need to be careful that their Containers will be interacted with as Containers before an item handler is even attempted to be found. I'd suggest not implementing Container directly on block entities to avoid this problem. Nevertheless, this counts as a breaking change.

Lookup order

From highest priority to lowest priority: Container block > IItemHandler block > Container entity > IItemHandler entity.

@neoforged-automation neoforged-automation bot added bug A bug or error 1.21.4 Targeted at Minecraft 1.21.4 labels Dec 18, 2024
@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Dec 18, 2024

  • Publish PR to GitHub Packages

Last commit published: 5cea5dce44481ed60c264df1f03d01d2132b3e96.

PR Publishing

The artifacts published by this PR:

Repository Declaration

In order to use the artifacts published by the PR, add the following repository to your buildscript:

repositories {
    maven {
        name 'Maven for PR #1787' // https://github.com/neoforged/NeoForge/pull/1787
        url 'https://prmaven.neoforged.net/NeoForge/pr1787'
        content {
            includeModule('net.neoforged', 'neoforge')
            includeModule('net.neoforged', 'testframework')
        }
    }
}

MDK installation

In order to setup a MDK using the latest PR version, run the following commands in a terminal.
The script works on both *nix and Windows as long as you have the JDK bin folder on the path.
The script will clone the MDK in a folder named NeoForge-pr1787.
On Powershell you will need to remove the -L flag from the curl invocation.

mkdir NeoForge-pr1787
cd NeoForge-pr1787
curl -L https://prmaven.neoforged.net/NeoForge/pr1787/net/neoforged/neoforge/21.4.46-beta-pr-1787-fix-vanilla-inv-hooks/mdk-pr1787.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip

To test a production environment, you can download the installer from here.

@neoforged-compatibility-checks
Copy link

neoforged-compatibility-checks bot commented Dec 19, 2024

@Technici4n, this PR introduces breaking changes.
Fortunately, this project is currently accepting breaking changes, but if they are not intentional, please revert them.
Last checked commit: 5cea5dce44481ed60c264df1f03d01d2132b3e96.

neoforge (:neoforge)

  • net/neoforged/neoforge/items/VanillaInventoryCodeHooks
    • dropperInsertHook(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/DispenserBlockEntity;ILnet/minecraft/world/item/ItemStack;)Z: ❗ API method was removed
    • insertHook(Lnet/minecraft/world/level/block/entity/HopperBlockEntity;)Z: ❗ API method was removed
    • insertCrafterOutput(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/CrafterBlockEntity;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/item/ItemStack;: ❗ API method was removed
    • extractHook(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/level/block/entity/Hopper;)Ljava/lang/Boolean;: ❗ API method was removed

@2No2Name
Copy link

Confirmed to fix #1750
Also the measurements for #1770
(1671 for vanilla, 1201 for Neo w/o fix, 1805 for Neo w/ fix) posted on discord suggest that this PR fixes #1770 as well.

@sciwhiz12
Copy link
Member

Currently, Container entities are preferred over IItemHandler blocks. What do people think about that?

Current order: Container block > Container entity > IItemHandler block > IItemHandler entity.

I think that it would be preferable to check in this order: Container block > IItemHandler block > Container entity > IItemHandler entity.

How difficult would that be to implement? I can see what you mean by that being preferrable -- ensuring that blocks are always checked before entities in either case -- but I wonder how the impl. look like if you have to interweave the item handler check between container blocks and entities.

@Technici4n
Copy link
Member Author

I managed to implement it locally and am planning to update the PR tomorrow.

@Technici4n
Copy link
Member Author

PR updated with a more modder-friendly lookup order. 😄 @sciwhiz12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.4 Targeted at Minecraft 1.21.4 bug A bug or error
Projects
None yet
3 participants