Search in sources :

Example 1 with CPacketResourcePackStatus

use of net.minecraft.network.play.client.CPacketResourcePackStatus in project SpongeCommon by SpongePowered.

the class ResourcePackState method unwind.

@Override
public void unwind(BasicPacketContext phaseContext) {
    final EntityPlayerMP player = phaseContext.getPacketPlayer();
    final NetHandlerPlayServer connection = player.connection;
    final IMixinNetHandlerPlayServer mixinHandler = (IMixinNetHandlerPlayServer) connection;
    final CPacketResourcePackStatus resource = phaseContext.getPacket();
    final ResourcePackStatusEvent.ResourcePackStatus status;
    ResourcePack pack;
    switch(resource.action) {
        case ACCEPTED:
            pack = mixinHandler.popReceivedResourcePack(true);
            status = ResourcePackStatusEvent.ResourcePackStatus.ACCEPTED;
            break;
        case DECLINED:
            pack = mixinHandler.popReceivedResourcePack(false);
            status = ResourcePackStatusEvent.ResourcePackStatus.DECLINED;
            break;
        case SUCCESSFULLY_LOADED:
            pack = mixinHandler.popAcceptedResourcePack();
            status = ResourcePackStatusEvent.ResourcePackStatus.SUCCESSFULLY_LOADED;
            break;
        case FAILED_DOWNLOAD:
            pack = mixinHandler.popAcceptedResourcePack();
            status = ResourcePackStatusEvent.ResourcePackStatus.FAILED;
            break;
        default:
            throw new AssertionError();
    }
    if (pack == null) {
        return;
    }
    SpongeImpl.postEvent(SpongeEventFactory.createResourcePackStatusEvent(Sponge.getCauseStackManager().getCurrentCause(), pack, (Player) player, status));
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ResourcePack(org.spongepowered.api.resourcepack.ResourcePack) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CPacketResourcePackStatus(net.minecraft.network.play.client.CPacketResourcePackStatus) IMixinNetHandlerPlayServer(org.spongepowered.common.interfaces.network.IMixinNetHandlerPlayServer) IMixinNetHandlerPlayServer(org.spongepowered.common.interfaces.network.IMixinNetHandlerPlayServer) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) ResourcePackStatusEvent(org.spongepowered.api.event.entity.living.humanoid.player.ResourcePackStatusEvent)

Aggregations

EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)1 CPacketResourcePackStatus (net.minecraft.network.play.client.CPacketResourcePackStatus)1 Player (org.spongepowered.api.entity.living.player.Player)1 ResourcePackStatusEvent (org.spongepowered.api.event.entity.living.humanoid.player.ResourcePackStatusEvent)1 ResourcePack (org.spongepowered.api.resourcepack.ResourcePack)1 IMixinNetHandlerPlayServer (org.spongepowered.common.interfaces.network.IMixinNetHandlerPlayServer)1