-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/net/mcbrawls/packmanager/ResourcePackStatusEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.mcbrawls.packmanager; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.network.packet.c2s.common.ResourcePackStatusC2SPacket; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* An event invoked when the server receives a resource pack status packet. | ||
* This is only invoked during the play phase, not configuration. | ||
*/ | ||
public interface ResourcePackStatusEvent { | ||
Event<ResourcePackStatusEvent> EVENT = EventFactory.createArrayBacked( | ||
ResourcePackStatusEvent.class, | ||
callbacks -> (player, id, status) -> { | ||
for (ResourcePackStatusEvent callback : callbacks) { | ||
callback.onStatus(player, id, status); | ||
} | ||
} | ||
); | ||
|
||
/** | ||
* Called on resource pack status receipt from the client. | ||
* @param id the id of the resource pack | ||
* @param status the status of the client | ||
*/ | ||
void onStatus(ServerPlayerEntity player, UUID id, ResourcePackStatusC2SPacket.Status status); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/net/mcbrawls/packmanager/mixin/ServerPlayNetworkHandlerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package net.mcbrawls.packmanager.mixin; | ||
|
||
import net.mcbrawls.packmanager.ResourcePackStatusEvent; | ||
import net.minecraft.network.ClientConnection; | ||
import net.minecraft.network.packet.c2s.common.ResourcePackStatusC2SPacket; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.network.ConnectedClientData; | ||
import net.minecraft.server.network.ServerCommonNetworkHandler; | ||
import net.minecraft.server.network.ServerPlayNetworkHandler; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
@Mixin(ServerPlayNetworkHandler.class) | ||
public abstract class ServerPlayNetworkHandlerMixin extends ServerCommonNetworkHandler { | ||
@Shadow public ServerPlayerEntity player; | ||
|
||
private ServerPlayNetworkHandlerMixin(MinecraftServer server, ClientConnection connection, ConnectedClientData clientData) { | ||
super(server, connection, clientData); | ||
} | ||
|
||
@Override | ||
public void onResourcePackStatus(ResourcePackStatusC2SPacket packet) { | ||
super.onResourcePackStatus(packet); | ||
|
||
// invoke event if not disconnected | ||
if (!connection.disconnected) { | ||
ResourcePackStatusEvent.EVENT.invoker().onStatus(this.player, packet.id(), packet.status()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
accessWidener v2 named | ||
|
||
accessible field net/minecraft/network/ClientConnection disconnected Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters