Search in sources :

Example 6 with ClientPlayNetworkHandler

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

the class ClientTeleportationManager method changePlayerDimension.

/**
 * {@link ClientPlayNetworkHandler#onPlayerRespawn(PlayerRespawnS2CPacket)}
 */
private void changePlayerDimension(ClientPlayerEntity player, ClientWorld fromWorld, ClientWorld toWorld, Vec3d destination) {
    DimensionType toDimension = toWorld.dimension.getType();
    DimensionType fromDimension = fromWorld.dimension.getType();
    ClientPlayNetworkHandler workingNetHandler = ((IEClientWorld) fromWorld).getNetHandler();
    ClientPlayNetworkHandler fakedNetHandler = ((IEClientWorld) toWorld).getNetHandler();
    ((IEClientPlayNetworkHandler) workingNetHandler).setWorld(toWorld);
    ((IEClientPlayNetworkHandler) fakedNetHandler).setWorld(fromWorld);
    ((IEClientWorld) fromWorld).setNetHandler(fakedNetHandler);
    ((IEClientWorld) toWorld).setNetHandler(workingNetHandler);
    fromWorld.removeEntity(player.getEntityId());
    player.removed = false;
    player.world = toWorld;
    player.dimension = toDimension;
    player.x = destination.x;
    player.y = destination.y;
    player.z = destination.z;
    toWorld.addPlayer(player.getEntityId(), player);
    mc.world = toWorld;
    mc.worldRenderer = CGlobal.clientWorldLoader.getWorldRenderer(toDimension);
    toWorld.setScoreboard(fromWorld.getScoreboard());
    if (mc.particleManager != null)
        mc.particleManager.setWorld(toWorld);
    BlockEntityRenderDispatcher.INSTANCE.setWorld(toWorld);
    CGlobal.clientWorldLoader.getDimensionRenderHelper(toDimension).switchToMe();
    Helper.log(String.format("Client Changed Dimension from %s to %s time: %s", fromDimension, toDimension, tickTimeForTeleportation));
    Helper.log("Portal Number Near Player Now" + McHelper.getEntitiesNearby(mc.player, Portal.class, 10).count());
    // because the teleportation may happen before rendering
    // but after pre render info being updated
    MyRenderHelper.updatePreRenderInfo(MyRenderHelper.partialTicks);
    OFInterface.onPlayerTraveled.accept(fromDimension, toDimension);
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) Portal(com.qouteall.immersive_portals.portal.Portal) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler)

Example 7 with ClientPlayNetworkHandler

use of net.minecraft.client.network.ClientPlayNetworkHandler in project tweakermore by Fallen-Breath.

the class InventoryRefresher method refresh.

/**
 * Inspired by viaversion 1.14 -> 1.13 villager selection inventory forced resync
 * https://github.com/ViaVersion/ViaVersion/blob/4074352a531cfb0de6fa81e043ee761737748a7a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java#L238
 */
public static boolean refresh(KeyAction keyAction, IKeybind iKeybind) {
    MinecraftClient mc = MinecraftClient.getInstance();
    ClientPlayNetworkHandler networkHandler = mc.getNetworkHandler();
    if (networkHandler != null && mc.player != null) {
        ItemStack uniqueItem = new ItemStack(Items.STONE);
        // Tags with NaN are not equal
        uniqueItem.getOrCreateTag().putDouble("force_resync", Double.NaN);
        networkHandler.sendPacket(new ClickWindowC2SPacket(mc.player.container.syncId, -999, 2, SlotActionType.QUICK_CRAFT, uniqueItem, mc.player.container.getNextActionId(mc.player.inventory)));
    }
    return true;
}
Also used : ClickWindowC2SPacket(net.minecraft.network.packet.c2s.play.ClickWindowC2SPacket) MinecraftClient(net.minecraft.client.MinecraftClient) ItemStack(net.minecraft.item.ItemStack) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler)

Example 8 with ClientPlayNetworkHandler

use of net.minecraft.client.network.ClientPlayNetworkHandler in project bewitchment by MoriyaShiine.

the class SyncContractsPacket method handle.

public static void handle(MinecraftClient client, ClientPlayNetworkHandler network, PacketByteBuf buf, PacketSender sender) {
    NbtCompound contractsCompound = buf.readNbt();
    client.execute(new Runnable() {

        @Override
        public void run() {
            if (client.player != null) {
                BWComponents.CONTRACTS_COMPONENT.maybeGet(client.player).ifPresent(contractsComponent -> {
                    contractsComponent.getContracts().clear();
                    NbtList contractsList = contractsCompound.getList("Contracts", NbtType.COMPOUND);
                    for (int i = 0; i < contractsList.size(); i++) {
                        NbtCompound contractCompound = contractsList.getCompound(i);
                        contractsComponent.addContract(new Contract.Instance(BWRegistries.CONTRACTS.get(new Identifier(contractCompound.getString("Contract"))), contractCompound.getInt("Duration"), contractCompound.getInt("Cost")));
                    }
                });
            }
        }
    });
}
Also used : PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Contract(moriyashiine.bewitchment.api.registry.Contract) NbtList(net.minecraft.nbt.NbtList) PacketByteBuf(net.minecraft.network.PacketByteBuf) Unpooled(io.netty.buffer.Unpooled) BWRegistries(moriyashiine.bewitchment.common.registry.BWRegistries) NbtCompound(net.minecraft.nbt.NbtCompound) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) NbtType(net.fabricmc.fabric.api.util.NbtType) ServerPlayNetworking(net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking) BWComponents(moriyashiine.bewitchment.common.registry.BWComponents) Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) Bewitchment(moriyashiine.bewitchment.common.Bewitchment) Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Example 9 with ClientPlayNetworkHandler

use of net.minecraft.client.network.ClientPlayNetworkHandler in project EdenClient by HahaOO7.

the class Nuker method onTick.

private void onTick(ClientPlayerEntity player) {
    if (!enabled)
        return;
    ClientPlayNetworkHandler nh = MinecraftClient.getInstance().getNetworkHandler();
    BlockState air = Blocks.AIR.getDefaultState();
    ClientPlayerInteractionManager im = MinecraftClient.getInstance().interactionManager;
    if (im == null)
        return;
    if (nh == null)
        return;
    if (limit > 1) {
        List<BlockPos> minableBlocks = getInstantMinableBlocksInRange(player);
        if (!minableBlocks.isEmpty()) {
            target = null;
            minableBlocks.forEach(p -> {
                nh.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, p, getHitDirectionForBlock(player, p)));
                nh.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, p, getHitDirectionForBlock(player, p)));
                player.clientWorld.setBlockState(p, air);
            });
            nh.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
            return;
        }
    }
    if (target == null || Vec3d.ofCenter(target).distanceTo(player.getEyePos()) > distance)
        findTarget(player);
    if (target == null)
        return;
    Direction dir = getHitDirectionForBlock(player, target);
    if (im.updateBlockBreakingProgress(target, dir))
        nh.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
    else
        target = null;
}
Also used : ClientPlayerInteractionManager(net.minecraft.client.network.ClientPlayerInteractionManager) BlockState(net.minecraft.block.BlockState) PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) HandSwingC2SPacket(net.minecraft.network.packet.c2s.play.HandSwingC2SPacket) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler)

Example 10 with ClientPlayNetworkHandler

use of net.minecraft.client.network.ClientPlayNetworkHandler in project EdenClient by HahaOO7.

the class HeadHunt method clickPos.

private void clickPos(Vec3i target) {
    BlockPos bp = new BlockPos(target);
    Direction dir = Direction.UP;
    PlayerInteractBlockC2SPacket packet = new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, new BlockHitResult(Vec3d.of(bp.offset(dir)), dir, bp, false));
    ClientPlayNetworkHandler nh = MinecraftClient.getInstance().getNetworkHandler();
    if (nh == null)
        return;
    nh.sendPacket(packet);
    foundHeads.add(target);
    System.out.println("Head clicked: " + target);
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) PlayerInteractBlockC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket)

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