Search in sources :

Example 6 with CustomPayloadS2CPacket

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

the class MyNetwork method createRedirectedMessage.

public static CustomPayloadS2CPacket createRedirectedMessage(DimensionType dimension, Packet packet) {
    int messageType = 0;
    try {
        messageType = NetworkState.PLAY.getPacketId(NetworkSide.CLIENTBOUND, packet);
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeInt(dimension.getRawId());
    buf.writeInt(messageType);
    try {
        packet.write(buf);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    return new CustomPayloadS2CPacket(id_stcRedirected, buf);
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) IOException(java.io.IOException) IOException(java.io.IOException)

Example 7 with CustomPayloadS2CPacket

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

the class MyNetwork method createGlobalPortalUpdate.

public static CustomPayloadS2CPacket createGlobalPortalUpdate(GlobalPortalStorage storage) {
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeInt(storage.world.get().dimension.getType().getRawId());
    buf.writeCompoundTag(storage.toTag(new CompoundTag()));
    return new CustomPayloadS2CPacket(id_stcUpdateGlobalPortal, buf);
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 8 with CustomPayloadS2CPacket

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

the class NetherPortalGenerator method spawnLoadingIndicator.

public static void spawnLoadingIndicator(ServerWorld world, ObsidianFrame obsidianFrame) {
    IntegerAABBInclusive box = obsidianFrame.boxWithoutObsidian;
    Vec3d center = new Vec3d((double) (box.h.getX() + box.l.getX() + 1) / 2, (double) (box.h.getY() + box.l.getY() + 1) / 2 - 1, (double) (box.h.getZ() + box.l.getZ() + 1) / 2);
    CustomPayloadS2CPacket packet = MyNetwork.createSpawnLoadingIndicator(world.dimension.getType(), center);
    McHelper.getEntitiesNearby(world, center, ServerPlayerEntity.class, 64).forEach(player -> player.networkHandler.sendPacket(packet));
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) IntegerAABBInclusive(com.qouteall.immersive_portals.my_util.IntegerAABBInclusive) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Vec3d(net.minecraft.util.math.Vec3d)

Example 9 with CustomPayloadS2CPacket

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

the class GlobalPortalStorage method onDataChanged.

public void onDataChanged() {
    setDirty(true);
    CustomPayloadS2CPacket packet = MyNetwork.createGlobalPortalUpdate(this);
    McHelper.getCopiedPlayerList().forEach(player -> player.networkHandler.sendPacket(packet));
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket)

Example 10 with CustomPayloadS2CPacket

use of net.minecraft.client.network.packet.CustomPayloadS2CPacket in project fabric by FabricMC.

the class ContainerProviderImpl method openContainer.

@Override
public void openContainer(Identifier identifier, ServerPlayerEntity player, Consumer<PacketByteBuf> writer) {
    int syncId;
    if (player instanceof ServerPlayerEntitySyncHook) {
        ServerPlayerEntitySyncHook serverPlayerEntitySyncHook = (ServerPlayerEntitySyncHook) player;
        syncId = serverPlayerEntitySyncHook.fabric_incrementSyncId();
    } else if (player instanceof ServerPlayerEntityAccessor) {
        if (!emittedNoSyncHookWarning) {
            LOGGER.warn("ServerPlayerEntitySyncHook could not be applied - fabric-containers is using a hack!");
            emittedNoSyncHookWarning = true;
        }
        syncId = (((ServerPlayerEntityAccessor) player).getContainerSyncId() + 1) % 100;
        ((ServerPlayerEntityAccessor) player).setContainerSyncId(syncId);
    } else {
        throw new RuntimeException("Neither ServerPlayerEntitySyncHook nor Accessor present! This should not happen!");
    }
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeIdentifier(identifier);
    buf.writeByte(syncId);
    writer.accept(buf);
    player.networkHandler.sendPacket(new CustomPayloadS2CPacket(PacketTypes.OPEN_CONTAINER, buf));
    PacketByteBuf clonedBuf = new PacketByteBuf(buf.duplicate());
    clonedBuf.readIdentifier();
    clonedBuf.readUnsignedByte();
    Container container = createContainer(syncId, identifier, player, clonedBuf);
    if (container == null) {
        return;
    }
    player.container = container;
    player.container.addListener(player);
}
Also used : Container(net.minecraft.container.Container) CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) ServerPlayerEntityAccessor(net.fabricmc.fabric.mixin.container.ServerPlayerEntityAccessor)

Aggregations

CustomPayloadS2CPacket (net.minecraft.client.network.packet.CustomPayloadS2CPacket)10 PacketByteBuf (net.minecraft.util.PacketByteBuf)7 IOException (java.io.IOException)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 IntegerAABBInclusive (com.qouteall.immersive_portals.my_util.IntegerAABBInclusive)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ServerPlayerEntityAccessor (net.fabricmc.fabric.mixin.container.ServerPlayerEntityAccessor)1 Container (net.minecraft.container.Container)1 EntityType (net.minecraft.entity.EntityType)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 Vec3d (net.minecraft.util.math.Vec3d)1