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

Move certain events to the newly introduced ServerPlayerEvent #1153

Closed

Conversation

Spinoscythe
Copy link
Contributor

@Spinoscythe Spinoscythe commented Jun 20, 2024

Some modders in the community noticed that some PlayerEvent events, like PlayerEvent.PlayerLoggedInEvent, only ever pass in a ServerPlayer instance. However, since PlayerEvent is a Player type, you have to cast the player back to ServerPlayer.

It would be worth switching to a <? extends Player> generic type for player events, but we don't support generic events anymore. So this seems the most ideal.

Some modders = @LeScooter. ty for the idea :)
Also @Technici4n approves this idea.
image

@neoforged-pr-publishing
Copy link

  • Publish PR to GitHub Packages

@Spinoscythe Spinoscythe marked this pull request as ready for review June 20, 2024 19:18
@sciwhiz12 sciwhiz12 added cleanup Change that isn't an enhancement or a bug fix breaking change Breaks binary compatibility 1.21 Targeted at Minecraft 1.21 labels Jun 21, 2024
@sciwhiz12 sciwhiz12 added this to the 1.21 Stable Release milestone Jun 21, 2024
@Shadows-of-Fire
Copy link
Contributor

This change doesn't really make sense. If we're going to make breaking changes to these events, they should be moved to their own individual files. There isn't any reason for ServerPlayerEvent to exist.

@Spinoscythe
Copy link
Contributor Author

This change doesn't really make sense. If we're going to make breaking changes to these events, they should be moved to their own individual files. There isn't any reason for ServerPlayerEvent to exist.

I think having ServerPlayerEvent saves time from casting getEntity in every event to ServerPlayer

@neoforged-compatibility-checks
Copy link

neoforged-compatibility-checks bot commented Jun 24, 2024

@Spinoscythe, 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: 288e628cf04d3d30572cd5df12fa6c4fc6b675a0.

Compatibility checks

neoforge (:neoforge)

  • net/neoforged/neoforge/event/entity/player/PlayerEvent$PlayerLoggedInEvent
    • ❗ API class no longer exists
  • net/neoforged/neoforge/event/entity/player/PlayerEvent$PlayerRespawnEvent
    • ❗ API class no longer exists
  • net/neoforged/neoforge/event/entity/player/AdvancementEvent$AdvancementProgressEvent
    • <init>(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/advancements/AdvancementHolder;Lnet/minecraft/advancements/AdvancementProgress;Ljava/lang/String;Lnet/neoforged/neoforge/event/entity/player/AdvancementEvent$AdvancementProgressEvent$ProgressType;)V: ❗ API method was removed
  • net/neoforged/neoforge/event/entity/player/PlayerEvent$PlayerLoggedOutEvent
    • ❗ API class no longer exists
  • net/neoforged/neoforge/event/entity/player/PlayerContainerEvent$Close
    • <init>(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/inventory/AbstractContainerMenu;)V: ❗ API method was removed
  • net/neoforged/neoforge/event/entity/player/PlayerSetSpawnEvent
    • <init>(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/core/BlockPos;Z)V: ❗ API method was removed
  • net/neoforged/neoforge/event/entity/player/PlayerEvent$PlayerChangeGameModeEvent
    • ❗ API class no longer exists
  • net/neoforged/neoforge/event/entity/player/PlayerContainerEvent
    • ❗ Class was made abstract
    • <init>(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/inventory/AbstractContainerMenu;)V: ❗ API method was removed
  • net/neoforged/neoforge/event/entity/player/PlayerContainerEvent$Open
    • <init>(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/inventory/AbstractContainerMenu;)V: ❗ API method was removed
  • net/neoforged/neoforge/event/entity/player/PlayerEvent$PlayerChangedDimensionEvent
    • ❗ API class no longer exists
  • net/neoforged/neoforge/event/entity/player/AdvancementEvent
    • <init>(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/advancements/AdvancementHolder;)V: ❗ API method was removed
  • net/neoforged/neoforge/common/NeoForgeEventHandler
    • playerLogin(Lnet/neoforged/neoforge/event/entity/player/PlayerEvent$PlayerLoggedInEvent;)V: ⚠ API method was removed
  • net/neoforged/neoforge/common/CommonHooks
    • onChangeGameType(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/GameType;Lnet/minecraft/world/level/GameType;)Lnet/minecraft/world/level/GameType;: ❗ API method was removed
  • net/neoforged/neoforge/event/EventHooks
    • onAdvancementProgressedEvent(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/advancements/AdvancementHolder;Lnet/minecraft/advancements/AdvancementProgress;Ljava/lang/String;Lnet/neoforged/neoforge/event/entity/player/AdvancementEvent$AdvancementProgressEvent$ProgressType;)V: ⚠ API method was removed
    • onAdvancementEarnedEvent(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/advancements/AdvancementHolder;)V: ⚠ API method was removed
    • onPlayerSpawnSet(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/core/BlockPos;Z)Z: ❗ API method was removed
    • firePlayerChangedDimensionEvent(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/resources/ResourceKey;)V: ❗ API method was removed
    • firePlayerLoggedIn(Lnet/minecraft/world/entity/player/Player;)V: ❗ API method was removed
    • firePlayerLoggedOut(Lnet/minecraft/world/entity/player/Player;)V: ❗ API method was removed
  • net/neoforged/neoforge/event/entity/player/AdvancementEvent$AdvancementEarnEvent
    • <init>(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/advancements/AdvancementHolder;)V: ❗ API method was removed

@Caltinor
Copy link
Contributor

Caltinor commented Jul 1, 2024

This change doesn't really make sense. If we're going to make breaking changes to these events, they should be moved to their own individual files. There isn't any reason for ServerPlayerEvent to exist.

I think having ServerPlayerEvent saves time from casting getEntity in every event to ServerPlayer

I noticed a code format difference. In subclasses of LivingEvent which return a specific entity type (namely PlayerEvent and AnimalTameEvent), they each take the specific entity class for their event class name (Player and Animal respectively), pass that into super but also store it locally and pass it back via the getEntity override.

public class ExampleEntityEvent extends LivingEvent {
  private final ExampleEntity example;
  
  public ExampleEntityEvent(ExampleEntity example) {
    super(example);
    this.example = example;
  }

  @Override
  public ExampleEntity getEntity() {return example;}
}

This implementation in contrast just casts the super invocation. Whether this or the other classes change, I think we should be consistent.

@TelepathicGrunt
Copy link
Contributor

When you can, please implement Caltinor's suggestion. It would remove the need for the casting in the server player events

@Caltinor
Copy link
Contributor

Caltinor commented Jul 7, 2024

I think this c7cf777 is the opposite of what @TelepathicGrunt wanted. They wanted to remove the casts, from how I read it.

@TelepathicGrunt
Copy link
Contributor

Yeah. Less casting. Not more

@Shadows-of-Fire
Copy link
Contributor

Per a conversation in the NF discord:

Introducing a generic to EntityEvent allows us to streamline more than just the server player events:
We'd be able to drop LivingEvent, ItemEvent, and PlayerEvent just by having that generic there. We introduce some redundancy where we may end up having EntityEvent<Entity> (which would be a nontrivial number of cases), but there's also a benefit: Authors of events that are children of EntityEvent<T> should now be thinking about what the correct T is for the situation (so we don't end up with events that are too lenient as we have now).

Based on that, this PR is not something we want to proceed with at this time, and the refactor triggered by switching to EntityEvent<T> is large enough it warrants its own new PR.

@Spinoscythe Spinoscythe deleted the enhancement/serverplayer-event branch July 7, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21 Targeted at Minecraft 1.21 breaking change Breaks binary compatibility cleanup Change that isn't an enhancement or a bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants