Skip to content

Commit

Permalink
Add PlayerOffer.accept overload that sets a rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Jun 23, 2024
1 parent d2172b6 commit 07f5845
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public GameProfile profile() {
}

@Override
public PlayerOfferResult.Accept accept(ServerWorld world, Vec3d position) {
return new Accept(world, position);
public PlayerOfferResult.Accept accept(ServerWorld world, Vec3d position, float yaw, float pitch) {
return new Accept(world, position, yaw, pitch);
}

@Override
Expand All @@ -30,12 +30,16 @@ public PlayerOfferResult.Reject reject(Text reason) {
public static class Accept implements PlayerOfferResult.Accept {
private final ServerWorld world;
private final Vec3d position;
private final float yaw;
private final float pitch;

private final List<Consumer<ServerPlayerEntity>> thenRun = new ArrayList<>();

Accept(ServerWorld world, Vec3d position) {
Accept(ServerWorld world, Vec3d position, float yaw, float pitch) {
this.world = world;
this.position = position;
this.yaw = yaw;
this.pitch = pitch;
}

@Override
Expand All @@ -46,7 +50,7 @@ public Accept thenRun(Consumer<ServerPlayerEntity> consumer) {

public ServerWorld applyJoin(ServerPlayerEntity player) {
player.changeGameMode(GameMode.SURVIVAL);
player.refreshPositionAndAngles(this.position.x, this.position.y, this.position.z, 0.0F, 0.0F);
player.refreshPositionAndAngles(this.position.x, this.position.y, this.position.z, this.yaw, this.pitch);

for (Consumer<ServerPlayerEntity> consumer : this.thenRun) {
consumer.accept(player);
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/xyz/nucleoid/plasmid/game/player/PlayerOffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;

import java.util.UUID;
import java.util.function.Consumer;

/**
* Represents a request for a {@link ServerPlayerEntity} to join a {@link GameSpace}.
Expand Down Expand Up @@ -48,10 +49,27 @@ default String playerName() {
*
* @param world the world that the player should be teleported to when accepted
* @param position the position that the player should be teleported to when accepted
* @param yaw the 'yaw' angle that the player should be teleported to when accepted
* @param pitch the 'pitch' angle that the player should be teleported to when accepted
* @return an "accept" offer result
* @see PlayerOfferResult.Accept#thenRun(java.util.function.Consumer)
* @see PlayerOfferResult.Accept#thenRun(Consumer)
*/
PlayerOfferResult.Accept accept(ServerWorld world, Vec3d position);
PlayerOfferResult.Accept accept(ServerWorld world, Vec3d position, float yaw, float pitch);

/**
* Returns an offer result that accepts this player offer and allows the player into this {@link GameSpace}.
* <p>
* This function does not do anything on its own, but its result must be returned within a
* {@link GamePlayerEvents#OFFER} listener.
*
* @param world the world that the player should be teleported to when accepted
* @param position the position that the player should be teleported to when accepted
* @return an "accept" offer result
* @see PlayerOfferResult.Accept#thenRun(Consumer)
*/
default PlayerOfferResult.Accept accept(ServerWorld world, Vec3d position) {
return this.accept(world, position, 0.0f, 0.0f);
}

/**
* Returns an offer result that rejects this player offer and does not allow the player into this {@link GameSpace}.
Expand Down

0 comments on commit 07f5845

Please sign in to comment.