Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/api-10' into api-11
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Dec 7, 2023
2 parents d6b6988 + 86fc1c9 commit 2445188
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;
Expand All @@ -44,4 +45,5 @@ public interface ChunkMapAccessor {

@Invoker("getChunks") Iterable<ChunkHolder> invoker$getChunks();

@Accessor("level") ServerLevel accessor$level();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.border.WorldBorder;
import net.minecraft.world.level.dimension.DimensionType;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.data.type.SkinPart;
Expand Down Expand Up @@ -110,4 +111,7 @@ public interface ServerPlayerBridge extends ServerPlayerEntityHealthScaleBridge

void bridge$setGameModeNoEvent(final GameType gameType);

@Nullable WorldBorder bridge$getWorldBorder();

void bridge$replaceWorldBorder(final @Nullable WorldBorder border);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public interface TrackedContainerBridge {

boolean bridge$capturePossible();

void bridge$detectAndSendChanges(boolean captureOnly);
void bridge$detectAndSendChanges(boolean capture, boolean synchronize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public static void handleCursorRestore(final Player player, final Transaction<It
}
final ItemStack cursor = ItemStackUtil.fromSnapshotToNative(cursorSnap);
player.containerMenu.setCarried(cursor);
player.containerMenu.setRemoteCarried(cursor);
if (player instanceof net.minecraft.server.level.ServerPlayer) {
((net.minecraft.server.level.ServerPlayer) player).connection.send(new ClientboundContainerSetSlotPacket(-1, player.containerMenu.getStateId(), -1, cursor));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,14 @@ public Collection<net.minecraft.world.scores.Objective> getObjectives() {

public static final class Builder implements Objective.Builder {

private static final int MAX_NAME_LENGTH = 16;
private @Nullable String name;
private @Nullable Component displayName;
private @Nullable Criterion criterion;
private @Nullable ObjectiveDisplayMode objectiveDisplayMode;

@Override
public Objective.Builder name(final String name) {
Objects.requireNonNull(name);
if (org.spongepowered.common.scoreboard.SpongeObjective.Builder.MAX_NAME_LENGTH < name.length()) {
throw new IllegalStateException(String.format("name '%s' is too long: %s characters over limit of %s",
name, org.spongepowered.common.scoreboard.SpongeObjective.Builder.MAX_NAME_LENGTH - name.length(), org.spongepowered.common.scoreboard.SpongeObjective.Builder.MAX_NAME_LENGTH));
}
this.name = name;
this.name = Objects.requireNonNull(name);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.spongepowered.common.accessor.world.scores.ScoreAccessor;
import org.spongepowered.common.bridge.world.scores.ObjectiveBridge;
import org.spongepowered.common.bridge.world.scores.ScoreBridge;
import org.spongepowered.common.util.Constants;

import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -51,9 +50,6 @@ public final class SpongeScore implements Score {
public SpongeScore(final Component name) {
this.name = name;
this.legacyName = LegacyComponentSerializer.legacySection().serialize(name);
if (this.legacyName.length() > Constants.Scoreboards.SCORE_NAME_LENGTH) {
throw new IllegalArgumentException(String.format("The score name %s is too long! It must be at most %s characters.", this.legacyName, Constants.Scoreboards.SCORE_NAME_LENGTH));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public SpongeTeamBuilder() {
@Override
public Team.Builder name(final String name) {
this.name = checkNotNull(name, "Name cannot be null!");
checkState(name.length() < 17, "Name is " + name.length() + " characters long! It must be at most 16.");
if (this.displayName == null) {
this.displayName = Component.text(this.name);
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/spongepowered/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,6 @@ public static final class Scoreboards {

public static final int OBJECTIVE_PACKET_ADD = 0;
public static final int OBJECTIVE_PACKET_REMOVE = 1;
public static final int SCORE_NAME_LENGTH = 40;
}

public static final class Functional {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
import net.minecraft.network.protocol.game.ClientboundSetBorderWarningDistancePacket;
import net.minecraft.world.level.border.BorderChangeListener;
import net.minecraft.world.level.border.WorldBorder;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.common.accessor.world.level.border.WorldBorderAccessor;
import org.spongepowered.common.bridge.server.level.ServerPlayerBridge;

public final class PlayerOwnBorderListener implements BorderChangeListener {

Expand Down Expand Up @@ -81,7 +82,10 @@ public void onBorderSetDamageSafeZOne(final WorldBorder border, final double new
* This method is for cleaning up the player reference once they disconnect.
*/
public void onPlayerDisconnect() {
((ServerPlayer) this.player).worldBorder().ifPresent(border -> ((WorldBorderAccessor) border).accessor$listeners().remove(this));
final @Nullable WorldBorder border = ((ServerPlayerBridge) this.player).bridge$getWorldBorder();
if (border != null) {
((WorldBorderAccessor) border).accessor$listeners().remove(this);
}
}

private void sendBorderPacket(final Packet<ClientGamePacketListener> packet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public abstract class ServerPlayerMixin_API extends PlayerMixin_API implements S
private volatile Pointers api$pointers;

private final TabList api$tabList = new SpongeTabList((net.minecraft.server.level.ServerPlayer) (Object) this);
@Nullable private WorldBorderBridge api$worldBorder;

@Override
public ServerWorld world() {
Expand Down Expand Up @@ -327,10 +326,11 @@ public void simulateChat(final Component message, final Cause cause) {
@Override
@NonNull
public Optional<WorldBorder> worldBorder() {
if (this.api$worldBorder == null) {
final net.minecraft.world.level.border.@Nullable WorldBorder border = ((ServerPlayerBridge) this).bridge$getWorldBorder();
if (border == null) {
return Optional.empty();
}
return Optional.of(this.api$worldBorder.bridge$asImmutable());
return Optional.of(((WorldBorderBridge) border).bridge$asImmutable());
}

@Override
Expand Down Expand Up @@ -371,20 +371,21 @@ public Optional<WorldBorder> setWorldBorder(final @Nullable WorldBorder border)
return currentBorder;
}

if (this.api$worldBorder != null) { // is the world border about to be unset?
((WorldBorderAccessor) this.api$worldBorder).accessor$listeners().remove(
final net.minecraft.world.level.border.@Nullable WorldBorder oldWorldBorder = ((ServerPlayerBridge) this).bridge$getWorldBorder();
if (oldWorldBorder != null) { // is the world border about to be unset?
((WorldBorderAccessor) oldWorldBorder).accessor$listeners().remove(
((ServerPlayerBridge) this).bridge$getWorldBorderListener()); // remove the listener, if so
}
final Optional<WorldBorder> toSet = event.newBorder();
if (toSet.isPresent()) {
final net.minecraft.world.level.border.WorldBorder mutableWorldBorder =
new net.minecraft.world.level.border.WorldBorder();
this.api$worldBorder = ((WorldBorderBridge) mutableWorldBorder);
this.api$worldBorder.bridge$applyFrom(toSet.get());
((WorldBorderBridge) mutableWorldBorder).bridge$applyFrom(toSet.get());
((ServerPlayerBridge) this).bridge$replaceWorldBorder(mutableWorldBorder);
mutableWorldBorder.addListener(((ServerPlayerBridge) this).bridge$getWorldBorderListener());
this.connection.send(new ClientboundInitializeBorderPacket((net.minecraft.world.level.border.WorldBorder) this.api$worldBorder));
this.connection.send(new ClientboundInitializeBorderPacket(mutableWorldBorder));
} else { // unset the border if null
this.api$worldBorder = null;
((ServerPlayerBridge) this).bridge$replaceWorldBorder(null);
this.connection.send(new ClientboundInitializeBorderPacket(this.shadow$getCommandSenderWorld().getWorldBorder()));
}
return toSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
*/
package org.spongepowered.common.mixin.core.server.level;

import com.mojang.datafixers.util.Either;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.ImposterProtoChunk;
import net.minecraft.world.level.chunk.LevelChunk;
import org.spongepowered.api.ResourceKey;
Expand All @@ -34,12 +38,17 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.common.SpongeCommon;
import org.spongepowered.common.accessor.server.level.ChunkMapAccessor;
import org.spongepowered.common.bridge.server.level.ServerLevelBridge;
import org.spongepowered.common.event.ShouldFire;
import org.spongepowered.common.event.tracking.PhaseTracker;
import org.spongepowered.common.util.VecHelper;
import org.spongepowered.math.vector.Vector3i;

import java.util.concurrent.CompletableFuture;

@Mixin(ChunkHolder.class)
abstract class ChunkHolderMixin {
@Inject(
Expand All @@ -58,4 +67,11 @@ abstract class ChunkHolderMixin {
);
SpongeCommon.post(event);
}

@Inject(method = "getOrScheduleFuture", at = @At("HEAD"), cancellable = true)
private void impl$onGetOrScheduleFuture(final ChunkStatus $$0, final ChunkMap chunkMap, final CallbackInfoReturnable<CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>>> cir) {
if (!((ServerLevelBridge) ((ChunkMapAccessor) chunkMap).accessor$level()).bridge$isLoaded()) {
cir.setReturnValue(ChunkHolder.UNLOADED_CHUNK_FUTURE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
*/
package org.spongepowered.common.mixin.core.server.level;

import com.mojang.datafixers.util.Either;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.ai.village.poi.PoiManager;
Expand Down Expand Up @@ -52,6 +54,7 @@
import org.spongepowered.common.SpongeCommon;
import org.spongepowered.common.accessor.server.level.ServerChunkCacheAccessor;
import org.spongepowered.common.accessor.world.level.chunk.storage.ChunkStorageAccessor;
import org.spongepowered.common.bridge.server.level.ServerLevelBridge;
import org.spongepowered.common.bridge.world.DistanceManagerBridge;
import org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge;
import org.spongepowered.common.bridge.world.level.chunk.storage.IOWorkerBridge;
Expand All @@ -63,6 +66,8 @@
import org.spongepowered.common.util.DirectionUtil;
import org.spongepowered.math.vector.Vector3i;

import java.util.concurrent.CompletableFuture;

@Mixin(ChunkMap.class)
public abstract class ChunkMapMixin implements ChunkMapBridge {

Expand Down Expand Up @@ -195,4 +200,10 @@ public abstract class ChunkMapMixin implements ChunkMapBridge {
}
}

@Inject(method = "schedule", at = @At("HEAD"), cancellable = true)
private void impl$onSchedule(final CallbackInfoReturnable<CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>>> cir) {
if (!((ServerLevelBridge) this.level).bridge$isLoaded()) {
cir.setReturnValue(ChunkHolder.UNLOADED_CHUNK_FUTURE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.BiomeManager;
import net.minecraft.world.level.border.WorldBorder;
import net.minecraft.world.level.portal.PortalInfo;
import net.minecraft.world.level.storage.LevelData;
import net.minecraft.world.scores.Score;
Expand Down Expand Up @@ -194,6 +195,7 @@ public abstract class ServerPlayerMixin extends PlayerMixin implements SubjectBr
private final PlayerOwnBorderListener impl$borderListener = new PlayerOwnBorderListener((net.minecraft.server.level.ServerPlayer) (Object) this);
private boolean impl$sleepingIgnored;
private boolean impl$noGameModeEvent;
@Nullable private WorldBorder impl$worldBorder;

@Override
public net.minecraft.network.chat.@Nullable Component bridge$getConnectionMessageToSend() {
Expand Down Expand Up @@ -894,4 +896,14 @@ public void sendMessage(final OutgoingChatMessage $$0, final boolean $$1, final
this.impl$noGameModeEvent = false;
}
}

@Override
public @Nullable WorldBorder bridge$getWorldBorder() {
return this.impl$worldBorder;
}

@Override
public void bridge$replaceWorldBorder(final @Nullable WorldBorder border) {
this.impl$worldBorder = border;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,11 @@ public abstract class PlayerListMixin implements PlayerListBridge {
target = "Lnet/minecraft/server/players/PlayerList;broadcastAll(Lnet/minecraft/network/protocol/Packet;)V"
)
)
private void impl$sendScoreboard(final PlayerList playerList, final Packet<?> addPlayer,
private void impl$onlySendSelfAddPlayerOnVanished(final PlayerList playerList, final Packet<?> addPlayer,
final Connection playerConnection, final net.minecraft.server.level.ServerPlayer serverPlayer
) {
if (((VanishableBridge) serverPlayer).bridge$vanishState().invisible()) {
playerConnection.send(addPlayer);
return;
}
playerList.broadcastAll(addPlayer);
Expand All @@ -427,17 +428,8 @@ public abstract class PlayerListMixin implements PlayerListBridge {
method = "placeNewPlayer",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket;createPlayerInitializing(Ljava/util/Collection;)Lnet/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket;"
),
slice = @Slice(
from = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/level/ServerPlayer;sendServerStatus(Lnet/minecraft/network/protocol/status/ServerStatus;)V"
),
to = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/level/ServerLevel;addNewPlayer(Lnet/minecraft/server/level/ServerPlayer;)V"
)
target = "Lnet/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket;createPlayerInitializing(Ljava/util/Collection;)Lnet/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket;",
ordinal = 0
)
)
private ClientboundPlayerInfoUpdatePacket impl$onlySendAddPlayerForUnvanishedPlayers(final Collection<net.minecraft.server.level.ServerPlayer> $$0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,12 @@ public abstract class EntityMixin implements EntityBridge, PlatformEntityBridge,
(ServerWorld) targetWorld,
destinationPosition
);
if (!reposition.isCancelled() && reposition.destinationPosition() != destinationPosition) {

if (reposition.isCancelled()) {
cir.setReturnValue(Optional.empty());
this.impl$dontCreateExitPortal = true;
}
else if (reposition.destinationPosition() != destinationPosition) {
// Something changed so we want to re-rerun this loop.
// TODO: There is an open question here about whether we want to force the creation of a portal in this
// scenario, or whether we're happy if the repositioning will put someone in a nearby portal.
Expand Down
Loading

0 comments on commit 2445188

Please sign in to comment.