Search in sources :

Example 1 with MinecraftBridge

use of org.spongepowered.common.bridge.client.MinecraftBridge in project SpongeCommon by SpongePowered.

the class MinecraftMixin_API method server.

@Override
public Optional<LocalServer> server() {
    final MinecraftBridge minecraftBridge = (MinecraftBridge) (this);
    final IntegratedServer integratedServer = minecraftBridge.bridge$getTemporaryIntegratedServer();
    if (integratedServer != null) {
        return (Optional<LocalServer>) (Object) Optional.ofNullable(integratedServer);
    }
    return (Optional<LocalServer>) (Object) Optional.ofNullable(this.shadow$getSingleplayerServer());
}
Also used : IntegratedServer(net.minecraft.client.server.IntegratedServer) Optional(java.util.Optional) MinecraftBridge(org.spongepowered.common.bridge.client.MinecraftBridge)

Example 2 with MinecraftBridge

use of org.spongepowered.common.bridge.client.MinecraftBridge in project SpongeCommon by SpongePowered.

the class IntegratedServerMixin_Vanilla method vanilla$runEngineStartLifecycle.

@SuppressWarnings("ConstantConditions")
@Inject(method = "initServer", at = @At("HEAD"))
private void vanilla$runEngineStartLifecycle(final CallbackInfoReturnable<Boolean> cir) {
    if (!Sponge.isServerAvailable()) {
        ((MinecraftBridge) Minecraft.getInstance()).bridge$setTemporaryIntegratedServer((IntegratedServer) (Object) this);
    }
    final Lifecycle lifecycle = Launch.instance().lifecycle();
    lifecycle.establishServerServices();
    lifecycle.establishServerFeatures();
    lifecycle.establishServerRegistries(this);
    lifecycle.callStartingEngineEvent(this);
}
Also used : Lifecycle(org.spongepowered.common.launch.Lifecycle) MinecraftBridge(org.spongepowered.common.bridge.client.MinecraftBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with MinecraftBridge

use of org.spongepowered.common.bridge.client.MinecraftBridge in project SpongeCommon by SpongePowered.

the class SpongeChannelManager method handleLoginRequestPayload.

private boolean handleLoginRequestPayload(final EngineConnection connection, final ResourceKey channelKey, final int transactionId, final ChannelBuf payload) {
    if (channelKey.equals(Constants.Channels.SPONGE_CLIENT_TYPE)) {
        final ClientType clientType = ((MinecraftBridge) Sponge.client()).bridge$getClientType();
        final ChannelBuf responsePayload = this.bufferAllocator.buffer();
        responsePayload.writeString(clientType.getName());
        final Packet<?> mcPacket = PacketUtil.createLoginPayloadResponse(responsePayload, transactionId);
        PacketSender.sendTo(connection, mcPacket);
        return true;
    }
    if (channelKey.equals(Constants.Channels.SPONGE_CHANNEL_REGISTRY)) {
        this.handleChannelRegistry(connection, payload);
        // Respond with registered channels
        final ChannelBuf responsePayload = this.encodeChannelRegistry();
        final Packet<?> mcPacket = PacketUtil.createLoginPayloadResponse(responsePayload, transactionId);
        PacketSender.sendTo(connection, mcPacket);
        return true;
    }
    ResourceKey actualChannelKey = channelKey;
    ChannelBuf actualPayload = payload;
    if (channelKey.equals(Constants.Channels.FML_LOGIN_WRAPPER_CHANNEL)) {
        actualChannelKey = ResourceKey.resolve(payload.readString());
        final int length = payload.readVarInt();
        actualPayload = payload.readSlice(length);
    }
    final SpongeChannel channel = this.channels.get(actualChannelKey);
    if (channel != null) {
        channel.handleLoginRequestPayload(connection, transactionId, actualPayload);
        return true;
    }
    return false;
}
Also used : ClientType(org.spongepowered.common.entity.player.ClientType) MinecraftBridge(org.spongepowered.common.bridge.client.MinecraftBridge) ChannelBuf(org.spongepowered.api.network.channel.ChannelBuf) ResourceKey(org.spongepowered.api.ResourceKey)

Aggregations

MinecraftBridge (org.spongepowered.common.bridge.client.MinecraftBridge)3 Optional (java.util.Optional)1 IntegratedServer (net.minecraft.client.server.IntegratedServer)1 ResourceKey (org.spongepowered.api.ResourceKey)1 ChannelBuf (org.spongepowered.api.network.channel.ChannelBuf)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 ClientType (org.spongepowered.common.entity.player.ClientType)1 Lifecycle (org.spongepowered.common.launch.Lifecycle)1