Skip to content

Commit

Permalink
store in transit resourcepack for firing the ResourcePackStatusEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
vectrixdevelops committed Oct 22, 2022
1 parent 87f278e commit a5c9372
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public interface ServerGamePacketListenerImplBridge {

@Nullable ResourcePack bridge$popAcceptedResourcePack();

void bridge$resendLatestResourcePackRequest();

void bridge$captureCurrentPlayerPosition();

void bridge$setLastMoveLocation(ServerLocation location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import net.minecraft.network.protocol.game.ClientboundMoveVehiclePacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
import net.minecraft.network.protocol.game.ClientboundResourcePackPacket;
import net.minecraft.network.protocol.game.ServerboundCommandSuggestionPacket;
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
Expand Down Expand Up @@ -88,6 +89,7 @@
import org.spongepowered.api.event.entity.living.AnimateHandEvent;
import org.spongepowered.api.event.message.PlayerChatEvent;
import org.spongepowered.api.event.network.ServerSideConnectionEvent;
import org.spongepowered.api.resourcepack.ResourcePack;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -103,6 +105,7 @@
import org.spongepowered.common.accessor.server.level.ServerPlayerGameModeAccessor;
import org.spongepowered.common.adventure.SpongeAdventure;
import org.spongepowered.common.bridge.network.ConnectionHolderBridge;
import org.spongepowered.common.bridge.network.protocol.game.ClientboundResourcePackPacketBridge;
import org.spongepowered.common.bridge.server.level.ServerPlayerBridge;
import org.spongepowered.common.bridge.server.network.ServerGamePacketListenerImplBridge;
import org.spongepowered.common.command.manager.SpongeCommandManager;
Expand Down Expand Up @@ -152,6 +155,8 @@ public abstract class ServerGamePacketListenerImplMixin implements ServerGamePac

private int impl$ignorePackets;

@Nullable private ResourcePack impl$lastReceivedPack, impl$lastAcceptedPack;

@Override
public Connection bridge$getConnection() {
return this.connection;
Expand All @@ -164,6 +169,9 @@ public abstract class ServerGamePacketListenerImplMixin implements ServerGamePac
private void impl$onClientboundPacketSend(final Packet<?> packet, final GenericFutureListener<? extends Future<? super Void>> listener, final CallbackInfo ci) {
if (packet instanceof ClientboundPlayerInfoPacket) {
((SpongeTabList) ((ServerPlayer) this.player).tabList()).updateEntriesOnSend((ClientboundPlayerInfoPacket) packet);
} else if (packet instanceof ClientboundResourcePackPacket) {
final ResourcePack pack = ((ClientboundResourcePackPacketBridge) packet).bridge$getSpongePack();
this.impl$lastReceivedPack = pack;
}
}

Expand Down Expand Up @@ -580,5 +588,20 @@ public abstract class ServerGamePacketListenerImplMixin implements ServerGamePac
}
}

@Override
public @Nullable ResourcePack bridge$popReceivedResourcePack(final boolean markAccepted) {
final ResourcePack pack = this.impl$lastReceivedPack;
this.impl$lastReceivedPack = null;
if (markAccepted) {
this.impl$lastAcceptedPack = pack;
}
return pack;
}

@Override
public @Nullable ResourcePack bridge$popAcceptedResourcePack() {
final ResourcePack pack = this.impl$lastAcceptedPack;
this.impl$lastAcceptedPack = null;
return pack;
}
}

0 comments on commit a5c9372

Please sign in to comment.