Skip to content

Commit

Permalink
more backporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Treetrain1 committed Dec 11, 2023
1 parent 178ddea commit 38cef4f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
@ApiStatus.Internal
public interface DelayedPacketsHolder {
void frozenLib$setPacketList(List<ServerboundCustomPayloadPacket> packetList);
List<Packet<?>> frozenLib$getPacketList();
List<ServerboundCustomPayloadPacket> frozenLib$getPacketList();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2022 The Quilt Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.frozenblock.core.registry.mixin;

import net.minecraft.network.Connection;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
import org.quiltmc.qsl.frozenblock.core.registry.impl.sync.server.DelayedPacketsHolder;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlayerList.class)
public class PlayerListMixin {

@Inject(method = "placeNewPlayer", at = @At("TAIL"))
private void sendSync(Connection netManager, ServerPlayer player, CallbackInfo ci) {
var delayedList = ((DelayedPacketsHolder) player).frozenLib$getPacketList();

if (delayedList != null) {
for (var packet : delayedList) {
packet.handle(player.connection);
}
}

((DelayedPacketsHolder) player).frozenLib$setPacketList(null);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
/*
* Copyright 2023 FrozenBlock
* This file is part of FrozenLib.
* Copyright 2022 The Quilt Project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* http://www.apache.org/licenses/LICENSE-2.0
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.frozenblock.core.registry.mixin;
Expand All @@ -37,19 +35,19 @@ public abstract class ServerLoginNetworkHandlerMixin {

@Shadow
@Final
public Connection connection;
Connection connection;

@Shadow
protected abstract void placeNewPlayer(ServerPlayer player);

@Unique
private boolean quilt$continueJoining = false;
private boolean frozenLib$continueJoining = false;

@Inject(method = "placeNewPlayer", at = @At("HEAD"), cancellable = true)
private void quilt$applySyncHandler(ServerPlayer player, CallbackInfo ci) {
if (!player.server.isSingleplayerOwner(player.getGameProfile()) && !this.quilt$continueJoining && ServerRegistrySync.shouldSync()) {
private void applySyncHandler(ServerPlayer player, CallbackInfo ci) {
if (!player.server.isSingleplayerOwner(player.getGameProfile()) && !this.frozenLib$continueJoining && ServerRegistrySync.shouldSync()) {
this.connection.setListener(new ServerRegistrySyncNetworkHandler(player, this.connection, () -> {
this.quilt$continueJoining = true;
this.frozenLib$continueJoining = true;
this.connection.setListener((PacketListener) this);
this.placeNewPlayer(player);
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2022 The Quilt Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.frozenblock.core.registry.mixin;

import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
import net.minecraft.server.level.ServerPlayer;
import org.quiltmc.qsl.frozenblock.core.registry.impl.sync.server.DelayedPacketsHolder;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import java.util.List;

@Mixin(ServerPlayer.class)
public class ServerPlayerMixin implements DelayedPacketsHolder {

@Unique
private List<ServerboundCustomPayloadPacket> frozenLib$delayedPackets;

@Override
public void frozenLib$setPacketList(List<ServerboundCustomPayloadPacket> packetList) {
this.frozenLib$delayedPackets = packetList;
}

@Override
public List<ServerboundCustomPayloadPacket> frozenLib$getPacketList() {
return this.frozenLib$delayedPackets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"BuiltInRegistriesMixin",
"ConnectionMixin",
"MappedRegistryMixin",
"PlayerListMixin",
"RegistryDataLoaderMixin",
"ServerLoginNetworkHandlerMixin",
"ServerPlayerMixin",
"ServerStatusVersionMixin"
],
"injectors": {
Expand Down

0 comments on commit 38cef4f

Please sign in to comment.