Search in sources :

Example 1 with ClientPlayNetworkHandler

use of net.minecraft.client.network.ClientPlayNetworkHandler in project meteor-rejects by AntiCope.

the class GhostCommand method execute.

private void execute(int radius) {
    ClientPlayNetworkHandler conn = mc.getNetworkHandler();
    if (conn == null)
        return;
    BlockPos pos = mc.player.getBlockPos();
    for (int dx = -radius; dx <= radius; dx++) for (int dy = -radius; dy <= radius; dy++) for (int dz = -radius; dz <= radius; dz++) {
        PlayerActionC2SPacket packet = new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, new BlockPos(pos.getX() + dx, pos.getY() + dy, pos.getZ() + dz), Direction.UP);
        conn.sendPacket(packet);
    }
}
Also used : PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) BlockPos(net.minecraft.util.math.BlockPos) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler)

Example 2 with ClientPlayNetworkHandler

use of net.minecraft.client.network.ClientPlayNetworkHandler in project KiwiClient by TangyKiwi.

the class MinecraftClientMixin method getWindowTitle.

@Inject(method = "getWindowTitle", at = @At(value = "TAIL"), cancellable = true)
private void getWindowTitle(final CallbackInfoReturnable<String> info) {
    MinecraftClient client = (MinecraftClient) (Object) this;
    String title = KiwiClient.name + " v" + KiwiClient.version;
    ClientPlayNetworkHandler clientPlayNetworkHandler = client.getNetworkHandler();
    if (clientPlayNetworkHandler != null && clientPlayNetworkHandler.getConnection().isOpen()) {
        title += " - ";
        if (client.getServer() != null && !client.getServer().isRemote()) {
            title += I18n.translate("title.singleplayer");
            discordRPC.update("Playing", "Singleplayer");
        } else if (client.isConnectedToRealms()) {
            title += I18n.translate("title.multiplayer.realms");
            discordRPC.update("Playing", "Realms");
        } else if (client.getServer() == null && (client.getCurrentServerEntry() == null || !client.getCurrentServerEntry().isLocal())) {
            title += I18n.translate("title.multiplayer.other");
            discordRPC.update("Playing", client.getCurrentServerEntry().address);
        } else {
            title += I18n.translate("title.multiplayer.lan");
            discordRPC.update("Playing", "LAN Server");
        }
    } else {
        discordRPC.update("Idle", "Main Menu");
    }
    info.setReturnValue(title);
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with ClientPlayNetworkHandler

use of net.minecraft.client.network.ClientPlayNetworkHandler in project ImmersivePortalsMod by qouteall.

the class ClientWorldLoader method createFakedClientWorld.

// fool minecraft using the faked world
private ClientWorld createFakedClientWorld(DimensionType dimension) {
    assert mc.world.dimension.getType() == mc.player.dimension;
    assert (mc.player.dimension != dimension);
    isLoadingFakedWorld = true;
    // TODO get load distance
    int chunkLoadDistance = 3;
    WorldRenderer worldRenderer = new WorldRenderer(mc);
    ClientWorld newWorld;
    try {
        ClientPlayNetworkHandler newNetworkHandler = new ClientPlayNetworkHandler(mc, new ChatScreen("You should not be seeing me. I'm just a faked screen."), new ClientConnection(NetworkSide.CLIENTBOUND), new GameProfile(null, "faked_profiler_id"));
        // multiple net handlers share the same playerListEntries object
        ((IEClientPlayNetworkHandler) newNetworkHandler).setPlayerListEntries(((IEClientPlayNetworkHandler) mc.player.networkHandler).getPlayerListEntries());
        newWorld = new ClientWorld(newNetworkHandler, new LevelInfo(0L, GameMode.CREATIVE, true, isHardCore, LevelGeneratorType.FLAT), dimension, chunkLoadDistance, mc.getProfiler(), worldRenderer);
    } catch (Exception e) {
        throw new IllegalStateException("Creating Faked World " + dimension + " " + clientWorldMap.keySet(), e);
    }
    worldRenderer.setWorld(newWorld);
    worldRenderer.apply(mc.getResourceManager());
    ((IEClientPlayNetworkHandler) ((IEClientWorld) newWorld).getNetHandler()).setWorld(newWorld);
    clientWorldMap.put(dimension, newWorld);
    worldRendererMap.put(dimension, worldRenderer);
    Helper.log("Faked World Created " + dimension);
    isLoadingFakedWorld = false;
    return newWorld;
}
Also used : ChatScreen(net.minecraft.client.gui.screen.ChatScreen) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) GameProfile(com.mojang.authlib.GameProfile) LevelInfo(net.minecraft.world.level.LevelInfo) ClientConnection(net.minecraft.network.ClientConnection) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) ClientWorld(net.minecraft.client.world.ClientWorld) WorldRenderer(net.minecraft.client.render.WorldRenderer) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler)

Example 4 with ClientPlayNetworkHandler

use of net.minecraft.client.network.ClientPlayNetworkHandler in project ImmersivePortalsMod by qouteall.

the class MyNetworkClient method processRedirectedPacket.

private static void processRedirectedPacket(DimensionType dimension, Packet packet) {
    MinecraftClient mc = MinecraftClient.getInstance();
    mc.execute(() -> {
        ClientWorld packetWorld = CGlobal.clientWorldLoader.getOrCreateFakedWorld(dimension);
        assert packetWorld != null;
        assert packetWorld.getChunkManager() instanceof MyClientChunkManager;
        ClientPlayNetworkHandler netHandler = ((IEClientWorld) packetWorld).getNetHandler();
        if ((netHandler).getWorld() != packetWorld) {
            ((IEClientPlayNetworkHandler) netHandler).setWorld(packetWorld);
            Helper.err("The world field of client net handler is wrong");
        }
        ClientWorld originalWorld = mc.world;
        // some packet handling may use mc.world so switch it
        mc.world = packetWorld;
        try {
            packet.apply(netHandler);
        } catch (Throwable e) {
            throw new IllegalStateException("handling packet in " + dimension, e);
        } finally {
            mc.world = originalWorld;
        }
    });
}
Also used : IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) MinecraftClient(net.minecraft.client.MinecraftClient) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) ClientWorld(net.minecraft.client.world.ClientWorld) MyClientChunkManager(com.qouteall.immersive_portals.chunk_loading.MyClientChunkManager) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler)

Example 5 with ClientPlayNetworkHandler

use of net.minecraft.client.network.ClientPlayNetworkHandler in project quilt-standard-libraries by QuiltMC.

the class ClientPlayNetworkHandlerMixin method initAddon.

@Inject(method = "<init>", at = @At("RETURN"))
private void initAddon(CallbackInfo ci) {
    this.addon = new ClientPlayNetworkAddon((ClientPlayNetworkHandler) (Object) this, this.client);
    // A bit of a hack but it allows the field above to be set in case someone registers handlers during INIT event which refers to said field
    ClientNetworkingImpl.setClientPlayAddon(this.addon);
    this.addon.lateInit();
}
Also used : ClientPlayNetworkAddon(org.quiltmc.qsl.networking.impl.client.ClientPlayNetworkAddon) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ClientPlayNetworkHandler (net.minecraft.client.network.ClientPlayNetworkHandler)11 MinecraftClient (net.minecraft.client.MinecraftClient)4 IEClientPlayNetworkHandler (com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler)3 IEClientWorld (com.qouteall.immersive_portals.ducks.IEClientWorld)3 PlayerActionC2SPacket (net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket)3 ClientWorld (net.minecraft.client.world.ClientWorld)2 BlockPos (net.minecraft.util.math.BlockPos)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 GameProfile (com.mojang.authlib.GameProfile)1 MyClientChunkManager (com.qouteall.immersive_portals.chunk_loading.MyClientChunkManager)1 Portal (com.qouteall.immersive_portals.portal.Portal)1 Unpooled (io.netty.buffer.Unpooled)1 Contract (moriyashiine.bewitchment.api.registry.Contract)1 Bewitchment (moriyashiine.bewitchment.common.Bewitchment)1 BWComponents (moriyashiine.bewitchment.common.registry.BWComponents)1 BWRegistries (moriyashiine.bewitchment.common.registry.BWRegistries)1 PacketSender (net.fabricmc.fabric.api.networking.v1.PacketSender)1 ServerPlayNetworking (net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking)1 NbtType (net.fabricmc.fabric.api.util.NbtType)1 BlockState (net.minecraft.block.BlockState)1