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

Added target level to teleport events #1531

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

Conversation

HenryLoenwind
Copy link
Contributor

Implements #1526

Added the target level to EntityTeleportEvent (and its sub-events). Changing it is supported where the teleporting code already supports it, although this feature could need some additional testing.

I decided to carry around a Level instead of a ServerLevel because the event wasn't confined to the server side before, even though it pretty much is a server-side-only functionality. Forcing a ServerLevel would be breaking for mods that fire the event for their own teleporting on both sides. Changing this in the next breaking phase may be desirable.

Adding this without breaking the old constructors adds a potential for mod incompatibility between mods that do dimension teleporting and fire the event with the old constructors and mods that handle the events and read/write the target level. This sadly is unavoidable when adding fields to an event that is fired by mods. I added a warning to the javadoc to reduce the risk.

@neoforged-pr-publishing
Copy link

  • Publish PR to GitHub Packages

@HenryLoenwind
Copy link
Contributor Author

Any opinions on the "api-ness" of those 3 fields? In my eyes, them being protected was a mistake (they have unrestricted getters and setters) and nobody should access them directly.

@sciwhiz12 sciwhiz12 added enhancement New (or improvement to existing) feature or request 1.21.1 Targeted at Minecraft 1.21.1 labels Sep 10, 2024
Comment on lines 871 to 872
@ApiStatus.Internal
public static EntityTeleportEvent.EnderPearl onEnderPearlLand(ServerPlayer entity, double targetX, double targetY, double targetZ, ThrownEnderpearl pearlEntity, float attackDamage, HitResult hitResult) {
EntityTeleportEvent.EnderPearl event = new EntityTeleportEvent.EnderPearl(entity, targetX, targetY, targetZ, pearlEntity, attackDamage, hitResult);
public static EntityTeleportEvent.EnderPearl onEnderPearlLand(ServerPlayer entity, GlobalVec3 target, ThrownEnderpearl pearlEntity, float attackDamage, HitResult hitResult) {
Copy link
Member

Choose a reason for hiding this comment

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

While it wasn't done by this PR, this method being internal whilst the other methods of its family are not internal strikes me as odd, and an inconsistency.

We should look into why this specific method is internal, and whether to remove its annotation or apply the same to the rest.

We should also factor in here the decision to mark as internal the constructor of those classes; I think we could leave those constructors unmarked and these marked as internal, but I'm not fully sure yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a look at that and decided to leave it as-is because this one is fired from a very specific vanilla entity and I can see event subscribers assuming it is the only one that can fire it.

And adding Internal to the others would be breaking, so it's off-limits at the moment.

src/main/java/net/neoforged/neoforge/event/EventHooks.java Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.1 Targeted at Minecraft 1.21.1 enhancement New (or improvement to existing) feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EntityTeleportEvent has no way to tell which dimension target will be teleported to
2 participants