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

Add BEFORE_SPAWN event #2975

Open
wants to merge 4 commits into
base: 1.19.4
Choose a base branch
from
Open

Add BEFORE_SPAWN event #2975

wants to merge 4 commits into from

Conversation

Digifox03
Copy link

This pull request adds a new event invoked before a player is spawned (i.e. when opening a single-player world or joining a server).
Some use cases are:

  • Detecting when a player is about to spawn.
  • Overriding where a player initially spawns.
  • Changing a player's initial data before the server sends it to the client.

I have tested it on 1.19.4 and 1.19.3, but it should work with most previous versions.

Comment on lines +47 to +55
@ModifyVariable(method = "onPlayerConnect", ordinal = 1, at = @At(value = "INVOKE", target = "net/minecraft/server/network/ServerPlayerEntity.setWorld(Lnet/minecraft/server/world/ServerWorld;)V", shift = At.Shift.AFTER))
private ServerWorld fixServerWorld(ServerWorld world, ClientConnection connection, ServerPlayerEntity player) {
return player.getWorld();
}

@ModifyVariable(method = "onPlayerConnect", ordinal = 0, at = @At(value = "INVOKE", target = "net/minecraft/server/network/ServerPlayerEntity.setWorld(Lnet/minecraft/server/world/ServerWorld;)V", shift = At.Shift.AFTER))
private RegistryKey<World> fixRegistryKey(RegistryKey<World> world, ClientConnection connection, ServerPlayerEntity player) {
return player.getWorld().getRegistryKey();
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? Some comments might be useful.

* <p>Note: this event is not called when a player is respawned.
* For that purpose, {@link ServerPlayerEvents#COPY_FROM} should be used.
*/
public static final Event<BeforeSpawn> BEFORE_SPAWN = EventFactory.createArrayBacked(BeforeSpawn.class, callbacks -> (player) -> {
Copy link
Member

Choose a reason for hiding this comment

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

BEFORE_JOIN_SERVER maybe a better name? Also dont want to confuse it with ServerPlayConnectionEvents.JOIN

If anyone has any suggestions please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

BEFORE_FIRST_SPAWN is also an option because I think it's about the first spawn in a World?

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.

4 participants