Skip to content

Commit 05a60af

Browse files
committed
feat: add "lobby_player_yaw" config setting
Controls player facing when initially spawning in lobby, and also teleporting back to lobby.
1 parent 736dab1 commit 05a60af

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

common/src/main/java/dev/ftb/mods/ftbteambases/config/ServerConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public interface ServerConfig {
4141
.comment("Position at which new players spawn. Only used if the lobby structure comes from a pregenerated region!");
4242
StringValue LOBBY_DIMENSION = LOBBY.addString("lobby_dimension", "minecraft:overworld")
4343
.comment("Dimension ID of the level in which the lobby is created. This *must* be a static pre-existing dimension, not a dynamically created one! New players will be automatically teleported to this dimension the first time they connect to the server. This setting should be defined in default config so the server has it before any levels are created - do NOT modify this on existing worlds!");
44+
DoubleValue LOBBY_PLAYER_YAW = LOBBY.addDouble("lobby_player_yaw", 0.0, 0.0, 360.0)
45+
.comment("Player Y-axis rotation when initially spawning in, or returning to, the lobby. (0 = south, 90 = west, 180 = north, 270 = east)");
4446

4547
SNBTConfig WORLDGEN = CONFIG.addGroup("worldgen");
4648
EnumValue<ChunkGenerators> CHUNK_GENERATOR = WORLDGEN.addEnum("chunk_generator", ChunkGenerators.NAME_MAP)
@@ -62,7 +64,7 @@ public interface ServerConfig {
6264
BooleanValue ALLOW_NETHER_PORTALS = NETHER.addBoolean("allow_nether_portals", true)
6365
.comment("When set to true, nether portals may be constructed in team dimensions");
6466
BooleanValue TEAM_SPECIFIC_NETHER_ENTRY_POINT = NETHER.addBoolean("team_specific_nether_entry_point", true)
65-
.comment("If true, then players going to the Nether via Nether Portal will be sent to a team-specific position in the Nether");
67+
.comment("If true, then players going to the Nether via Nether Portal will be sent to a random (but deterministic for the team) position in the Nether");
6668

6769
static Optional<ResourceLocation> lobbyLocation() {
6870
if (LOBBY_STRUCTURE_LOCATION.get().isEmpty()) {

common/src/main/java/dev/ftb/mods/ftbteambases/data/bases/BaseInstanceManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public Optional<LiveBaseDetails> getBaseForTeam(Team team) {
264264

265265
public boolean teleportToLobby(ServerPlayer serverPlayer) {
266266
ResourceKey<Level> destLevel = ServerConfig.lobbyDimension().orElse(Level.OVERWORLD);
267-
return DimensionUtils.teleport(serverPlayer, destLevel, lobbySpawnPos);
267+
return DimensionUtils.teleport(serverPlayer, destLevel, lobbySpawnPos, ServerConfig.LOBBY_PLAYER_YAW.get().floatValue());
268268
}
269269

270270
public void deleteAndArchive(MinecraftServer server, Team team) {

common/src/main/java/dev/ftb/mods/ftbteambases/util/DimensionUtils.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
3333
import net.minecraft.world.phys.Vec3;
3434
import org.jetbrains.annotations.NotNull;
35+
import org.jetbrains.annotations.Nullable;
3536

3637
import java.util.Objects;
3738
import java.util.Optional;
@@ -104,15 +105,19 @@ public static Stream<Holder<StructureSet>> possibleStructures(HolderLookup<Struc
104105
).orElse(Stream.of());
105106
}
106107

107-
public static boolean teleport(ServerPlayer player, ResourceKey<Level> key, BlockPos destPos) {
108+
public static boolean teleport(ServerPlayer player, ResourceKey<Level> key, @Nullable BlockPos destPos) {
109+
return teleport(player, key, destPos, player.getYRot());
110+
}
111+
112+
public static boolean teleport(ServerPlayer player, ResourceKey<Level> key, @Nullable BlockPos destPos, float yRot) {
108113
ServerLevel level = player.server.getLevel(key);
109114

110115
if (level != null) {
111-
if (key.equals(Level.OVERWORLD)) {
116+
if (key.equals(ServerConfig.lobbyDimension().orElse(Level.OVERWORLD))) {
112117
BlockPos lobbySpawnPos = BaseInstanceManager.get(player.server).getLobbySpawnPos();
113118
BlockPos pos = Objects.requireNonNullElse(destPos, lobbySpawnPos);
114119

115-
doTeleport(player, level, pos);
120+
doTeleport(player, level, pos, yRot);
116121
} else {
117122
Vec3 vec;
118123
if (destPos == null) {
@@ -129,7 +134,7 @@ public static boolean teleport(ServerPlayer player, ResourceKey<Level> key, Bloc
129134
vec = Vec3.atCenterOf(destPos);
130135
}
131136

132-
doTeleport(player, level, BlockPos.containing(vec.x, vec.y, vec.z));
137+
doTeleport(player, level, BlockPos.containing(vec.x, vec.y, vec.z), yRot);
133138
}
134139
return true;
135140
} else {
@@ -138,11 +143,11 @@ public static boolean teleport(ServerPlayer player, ResourceKey<Level> key, Bloc
138143
}
139144
}
140145

141-
private static void doTeleport(ServerPlayer player, ServerLevel level, BlockPos pos) {
146+
private static void doTeleport(ServerPlayer player, ServerLevel level, BlockPos pos, float yRot) {
142147
ChunkPos chunkpos = new ChunkPos(pos);
143148
level.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkpos, 1, player.getId());
144149
player.stopRiding();
145-
player.teleportTo(level, pos.getX() + .5D, pos.getY() + .01D, pos.getZ() + .5D, player.getYRot(), player.getXRot());
150+
player.teleportTo(level, pos.getX() + .5D, pos.getY() + .01D, pos.getZ() + .5D, yRot, player.getXRot());
146151

147152
FTBTeamBases.LOGGER.debug("teleported {} to {} in {}", player.getGameProfile().getName(), pos, level.dimension().location());
148153
}

0 commit comments

Comments
 (0)