Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.spongepowered.api.Sponge;
import org.spongepowered.api.world.SerializationBehavior;
import org.spongepowered.common.SpongeCommon;
import org.spongepowered.common.bridge.world.level.border.WorldBorderBridge;
import org.spongepowered.common.world.server.SpongeServerLevelData;
import org.spongepowered.common.world.server.SpongeWorldManager;

Expand Down Expand Up @@ -127,6 +128,15 @@ public interface ServerLevelDataBridge {
return Optional.empty();
}

default @Nullable WorldBorderBridge bridge$worldBorder() {
final ServerLevel level = this.bridge$level();
if (level != null) {
return (WorldBorderBridge) level.getWorldBorder();
}

return null;
}

default void bridge$triggerViewDistanceLogic() {
final ServerLevel level = this.bridge$level();
if (level != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.spongepowered.api.entity.living.player.gamemode.GameMode;
import org.spongepowered.api.world.SerializationBehavior;
import org.spongepowered.api.world.WorldType;
import org.spongepowered.api.world.border.WorldBorder;
import org.spongepowered.api.world.difficulty.Difficulty;
import org.spongepowered.api.world.generation.config.WorldGenerationConfig;
import org.spongepowered.api.world.server.WorldArchetype;
Expand Down Expand Up @@ -78,8 +77,6 @@ public static void register(final DataProviderRegistrator registrator) {
.get(ServerLevelData::isAllowCommands)
.create(Keys.INITIALIZED)
.get(ServerLevelData::isInitialized)
.create(Keys.WORLD_BORDER)
.get(h -> (WorldBorder) (Object) h.getLegacyWorldBorderSettings().orElse(null))
.create(Keys.WEATHER)
.get(SpongeWeather::of)
.set(SpongeWeather::apply)
Expand All @@ -100,6 +97,8 @@ public static void register(final DataProviderRegistrator registrator) {
.get(ServerLevelDataBridge::bridge$loadOnStartup)
.create(Keys.WORLD_ARCHETYPE_TYPE)
.get(h -> (WorldArchetypeType) (Object) h.bridge$levelStem())
.create(Keys.WORLD_BORDER)
.get(h -> h.bridge$worldBorder().bridge$asImmutable())
.asMutable(PrimaryLevelData.class)
.create(Keys.WORLD_DIFFICULTY)
.set((h, v) -> h.setDifficulty((net.minecraft.world.Difficulty) (Object) v))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ private ServerLevel createLevel(

// Ensure that the world border is registered.
levelData.getLegacyWorldBorderSettings().ifPresent(world.getWorldBorder()::applySettings);
levelData.setLegacyWorldBorderSettings(Optional.empty());
PlatformHooks.INSTANCE.getWorldHooks().postLoadWorld(world);
return world;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Optional<ServerLocation> findSafeLocation(ServerLocation location, int he

private Stream<Vector3i> getBlockLocations(ServerLocation worldLocation, int height, int width) {
// We don't want to warp outside of the world border, so we want to check that we're within it.
final WorldBorder.Settings worldBorder = (WorldBorder.Settings) (Object) worldLocation.world().properties().worldBorder();
final WorldBorder.Settings worldBorder = (WorldBorder.Settings) (Object) worldLocation.world().border();
final double radius = worldBorder.size() / 2.0D;
int worldBorderMinX = GenericMath.floor(worldBorder.centerX() - radius);
int worldBorderMinZ = GenericMath.floor(worldBorder.centerZ() - radius);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public WorldBorder setBorder(final WorldBorder border) {
if (worldBorder == null) {
return (WorldBorder) (Object) net.minecraft.world.level.border.WorldBorder.Settings.DEFAULT;
}
this.serverLevelData.setLegacyWorldBorderSettings(Optional.of((net.minecraft.world.level.border.WorldBorder.Settings) (Object) border));

return worldBorder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.JukeboxBlockEntity;
import net.minecraft.world.level.block.entity.TickingBlockEntity;
import net.minecraft.world.level.border.WorldBorder;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.dimension.end.EndDragonFight;
Expand Down Expand Up @@ -375,9 +374,7 @@ public abstract class ServerLevelMixin extends LevelMixin implements ServerLevel
if (behavior != SerializationBehavior.NONE) {
original.call(self, flush);

// per-world WorldInfo/WorldBorder/BossBars
final var border = this.getWorldBorder();
levelData.setLegacyWorldBorderSettings(Optional.of(new WorldBorder.Settings(border)));
// per-world WorldInfo/BossBars
if (levelData instanceof WorldData worldData) {
worldData.setCustomBossEvents(this.bridge$getBossBarManager().save(SpongeCommon.server().registryAccess()));
this.bridge$getLevelSave().saveDataTag(SpongeCommon.server().registryAccess(), worldData, this.shadow$dimension() == Level.OVERWORLD ? SpongeCommon.server().getPlayerList().getSingleplayerData() : null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public <T> T readSpongeMapData(
DataUtil.syncTagToData(dch);
dch.data$setCompound(null);
}
return null;
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.world.border;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.world.DefaultWorldKeys;
import org.spongepowered.api.world.border.WorldBorder;
import org.spongepowered.api.world.server.ServerWorld;

public class WorldBorderTest {

@Test
public void testBorderIsApplied() {
final ServerWorld world = Sponge.server().worldManager().world(DefaultWorldKeys.DEFAULT).get();
final WorldBorder worldBorder = world.border();
final WorldBorder border = WorldBorder.builder().center(1, 1).initialDiameter(1).build();

try {
world.setBorder(border);

Assertions.assertEquals(border, world.border());
} finally {
world.setBorder(worldBorder);
}
}

@Test
public void testBorderIsWorldSpecific() {
final ServerWorld world = Sponge.server().worldManager().world(DefaultWorldKeys.DEFAULT).get();
final ServerWorld nether = Sponge.server().worldManager().world(DefaultWorldKeys.THE_NETHER).get();

final WorldBorder worldBorder = world.border();
final WorldBorder worldBorderNether = nether.border();

final WorldBorder border = WorldBorder.builder().center(1, 1).initialDiameter(1).build();
final WorldBorder netherBorder = WorldBorder.builder().center(2, 2).initialDiameter(2).build();

try {
world.setBorder(border);
nether.setBorder(netherBorder);

Assertions.assertEquals(border, world.border());
Assertions.assertEquals(netherBorder, nether.border());
} finally {
world.setBorder(worldBorder);
nether.setBorder(worldBorderNether);
}
}

}
Loading