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

Use fake level for JEI #10304

Open
wants to merge 6 commits into
base: version/main
Choose a base branch
from
Open

Use fake level for JEI #10304

wants to merge 6 commits into from

Conversation

uecasm
Copy link
Contributor

@uecasm uecasm commented Oct 3, 2024

Closes #10302 (once ported)

Changes proposed in this pull request

  • Use a fake level when creating citizens for JEI

Testing

  • Yes I tested this before submitting it.
  • I also did a multiplayer test.

Review please (should port)

Thodor12
Thodor12 previously approved these changes Oct 3, 2024
Copy link
Member

@Nightenom Nightenom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is technically breaking change logic-wise in latest fakelevel backport, so please update
Use singleblockfakelevel, probably with blockstate of air
Don't forget to override getRealLevel as redirect to mc.instance.level

Nightenom
Nightenom previously approved these changes Oct 4, 2024
Raycoms
Raycoms previously approved these changes Oct 4, 2024
Nightenom
Nightenom previously approved these changes Oct 4, 2024
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why onlyin? dont think we should use that in 1.21

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paranoia, mostly. Since it's using client-only classes it must not be loaded in the server jar. Though that should be the case even without this, it seems safer to make it explicit.

@pietro-lopes
Copy link

Please, check how you are instancing this LivingEntity if you would need to use a fake level here too.

private final LivingEntity requiredEntity;

This is where it starts:

final ClientLevel level = Objects.requireNonNull(Minecraft.getInstance().level);

@uecasm uecasm dismissed stale reviews from Nightenom and Raycoms via ab4275e October 6, 2024 05:49
@uecasm
Copy link
Contributor Author

uecasm commented Oct 6, 2024

Please, check how you are instancing this LivingEntity if you would need to use a fake level here too.

Good catch, thanks.

src/main/resources/META-INF/accesstransformer.cfg Outdated Show resolved Hide resolved
@Nightenom
Copy link
Member

Hmm, out of scope of this PR: but why do we pass instantiated entity in the first place?

@uecasm
Copy link
Contributor Author

uecasm commented Oct 7, 2024

Because (a) that's what the entity renderer wants in order to draw an entity, and (b) other places need to query various instance methods that only exist on the instantiated entity.

@pietro-lopes
Copy link

Honestly, if possible, I prefer WeakReference instead of cached by magic number 2 minutes

@uecasm
Copy link
Contributor Author

uecasm commented Oct 8, 2024

Minecraft GCs all the time, so a WeakReference is almost identical to not caching it at all. And entities are not sufficiently lightweight for that to seem justifiable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory Leak of Client Level
6 participants