-
Notifications
You must be signed in to change notification settings - Fork 433
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
base: 1.19.4
Are you sure you want to change the base?
Add BEFORE_SPAWN
event
#2975
Conversation
...tity-events-v1/src/main/java/net/fabricmc/fabric/api/entity/event/v1/ServerPlayerEvents.java
Outdated
Show resolved
Hide resolved
...tity-events-v1/src/main/java/net/fabricmc/fabric/api/entity/event/v1/ServerPlayerEvents.java
Outdated
Show resolved
Hide resolved
...ntity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/PlayerManagerMixin.java
Outdated
Show resolved
Hide resolved
...ntity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/PlayerManagerMixin.java
Outdated
Show resolved
Hide resolved
@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(); | ||
} |
There was a problem hiding this comment.
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) -> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
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:
I have tested it on
1.19.4
and1.19.3
, but it should work with most previous versions.